aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/test/snmp_agent_mibs_test.erl
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2013-05-24 15:41:43 +0200
committerMicael Karlberg <[email protected]>2013-05-24 15:41:43 +0200
commitfd747e9088186657a29fa252cae06a7d7c08761a (patch)
treebc5020edd5f670e44b8ac5c6d5b22a432ce1b54e /lib/snmp/test/snmp_agent_mibs_test.erl
parent49d1609d1ccdd967f20140a2285f118df887f3e9 (diff)
downloadotp-fd747e9088186657a29fa252cae06a7d7c08761a.tar.gz
otp-fd747e9088186657a29fa252cae06a7d7c08761a.tar.bz2
otp-fd747e9088186657a29fa252cae06a7d7c08761a.zip
[snmp/agent] Some restructuring and some new test cases of mib-server suite
Diffstat (limited to 'lib/snmp/test/snmp_agent_mibs_test.erl')
-rw-r--r--lib/snmp/test/snmp_agent_mibs_test.erl186
1 files changed, 115 insertions, 71 deletions
diff --git a/lib/snmp/test/snmp_agent_mibs_test.erl b/lib/snmp/test/snmp_agent_mibs_test.erl
index 4569be0b5a..248fe7d83e 100644
--- a/lib/snmp/test/snmp_agent_mibs_test.erl
+++ b/lib/snmp/test/snmp_agent_mibs_test.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2003-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2003-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -20,6 +20,7 @@
%%
%%----------------------------------------------------------------------
%% Purpose: Test suite of the agent mib-server.
+%% Some of these tests should really be in a mib-storage suite.
%%----------------------------------------------------------------------
-module(snmp_agent_mibs_test).
@@ -58,7 +59,9 @@
size_check_ets1/1,
size_check_ets2/1,
+ size_check_ets2_bad_file1/1,
size_check_ets3/1,
+ size_check_ets3_bad_file1/1,
size_check_dets/1,
size_check_mnesia/1,
load_unload/1,
@@ -85,28 +88,51 @@
%% External functions
%%======================================================================
-init_per_testcase(size_check_ets2, Config) when is_list(Config) ->
- Dir = ?config(priv_dir, Config),
- EtsDir = join(Dir, "ets_dir2/"),
- ?line ok = file:make_dir(EtsDir),
- [{ets_dir, EtsDir}|Config];
-init_per_testcase(size_check_ets3, Config) when is_list(Config) ->
- Dir = ?config(priv_dir, Config),
- EtsDir = join(Dir, "ets_dir3/"),
- ?line ok = file:make_dir(EtsDir),
- [{ets_dir, EtsDir}|Config];
-init_per_testcase(size_check_dets, Config) when is_list(Config) ->
- Dir = ?config(priv_dir, Config),
- DetsDir = join(Dir, "dets_dir/"),
- ?line ok = file:make_dir(DetsDir),
- [{dets_dir, DetsDir}|Config];
-init_per_testcase(size_check_mnesia, Config) when is_list(Config) ->
- Dir = ?config(priv_dir, Config),
- MnesiaDir = join(Dir, "mnesia_dir/"),
- ?line ok = file:make_dir(MnesiaDir),
- mnesia_start([{dir, MnesiaDir}]),
- [{mnesia_dir, MnesiaDir}|Config];
-init_per_testcase(cache_test, Config) when is_list(Config) ->
+init_per_suite(Config0) when is_list(Config0) ->
+
+ ?DBG("init_per_suite -> entry with"
+ "~n Config0: ~p", [Config0]),
+
+ Config1 = snmp_test_lib:init_suite_top_dir(?MODULE, Config0),
+
+ ?DBG("init_per_suite -> done when"
+ "~n Config1: ~p", [Config1]),
+
+ Config1.
+
+end_per_suite(Config) when is_list(Config) ->
+
+ ?DBG("end_per_suite -> entry with"
+ "~n Config: ~p", [Config]),
+
+ Config.
+
+
+init_per_testcase(Case, Config0) when is_list(Config0) ->
+ Config1 = snmp_test_lib:fix_data_dir(Config0),
+ CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config1),
+ DbDir = join(CaseTopDir, "db_dir/"),
+ ?line ok = file:make_dir(DbDir),
+ init_per_testcase2(Case, [{db_dir, DbDir},
+ {case_top_dir, CaseTopDir} | Config1]).
+
+init_per_testcase2(size_check_ets2_bad_file1, Config) when is_list(Config) ->
+ DbDir = ?config(db_dir, Config),
+ %% Create a ad file
+ ok = file:write_file(join(DbDir, "snmpa_symbolic_store.db"),
+ "calvin and hoppes play chess"),
+ Config;
+init_per_testcase2(size_check_ets3_bad_file1, Config) when is_list(Config) ->
+ DbDir = ?config(db_dir, Config),
+ %% Create a ad file
+ ok = file:write_file(join(DbDir, "snmpa_symbolic_store.db"),
+ "calvin and hoppes play chess"),
+ Config;
+init_per_testcase2(size_check_mnesia, Config) when is_list(Config) ->
+ DbDir = ?config(db_dir, Config),
+ mnesia_start([{dir, DbDir}]),
+ Config;
+init_per_testcase2(cache_test, Config) when is_list(Config) ->
Min = timer:minutes(5),
Timeout =
case lists:keysearch(tc_timeout, 1, Config) of
@@ -119,25 +145,26 @@ init_per_testcase(cache_test, Config) when is_list(Config) ->
end,
Dog = test_server:timetrap(Timeout),
[{watchdog, Dog} | Config];
-init_per_testcase(_Case, Config) when is_list(Config) ->
+init_per_testcase2(_Case, Config) when is_list(Config) ->
Config.
-end_per_testcase(EtsCase, Config)
- when (is_list(Config) andalso
- ((EtsCase =:= size_check_ets2) orelse
- (EtsCase =:= size_check_ets3))) ->
- Dir = ?config(ets_dir, Config),
- ?line ok = ?DEL_DIR(Dir),
- lists:keydelete(ets_dir, 1, Config);
-end_per_testcase(size_check_dets, Config) when is_list(Config) ->
- Dir = ?config(dets_dir, Config),
- ?line ok = ?DEL_DIR(Dir),
- lists:keydelete(dets_dir, 1, Config);
+%% end_per_testcase(EtsCase, Config)
+%% when (is_list(Config) andalso
+%% ((EtsCase =:= size_check_ets2) orelse
+%% (EtsCase =:= size_check_ets3))) ->
+%% Dir = ?config(ets_dir, Config),
+%% ?line ok = ?DEL_DIR(Dir),
+%% lists:keydelete(ets_dir, 1, Config);
+%% end_per_testcase(size_check_dets, Config) when is_list(Config) ->
+%% Dir = ?config(dets_dir, Config),
+%% ?line ok = ?DEL_DIR(Dir),
+%% lists:keydelete(dets_dir, 1, Config);
end_per_testcase(size_check_mnesia, Config) when is_list(Config) ->
mnesia_stop(),
- Dir = ?config(mnesia_dir, Config),
- ?line ok = ?DEL_DIR(Dir),
- lists:keydelete(mnesia_dir, 1, Config);
+ %% Dir = ?config(db_dir, Config),
+ %% ?line ok = ?DEL_DIR(Dir),
+ %% lists:keydelete(mnesia_dir, 1, Config);
+ Config;
end_per_testcase(cache_test, Config) when is_list(Config) ->
Dog = ?config(watchdog, Config),
test_server:timetrap_cancel(Dog),
@@ -151,23 +178,28 @@ end_per_testcase(_Case, Config) when is_list(Config) ->
%%======================================================================
all() ->
-cases().
+ cases().
groups() ->
[{size_check, [],
[
- size_check_ets1, % Plain ets
- size_check_ets2, % ets with a file
- size_check_ets3, % ets with a checksummed file
- size_check_dets, % Plain dets
- size_check_mnesia % Plain mnesia
+ size_check_ets1, % Plain ets
+ size_check_ets2, % ets with a file
+ size_check_ets2_bad_file1, % ets with a bad file
+ size_check_ets3, % ets with a checksummed file
+ size_check_ets3_bad_file1, % ets with bad file (checksummed)
+ size_check_dets, % Plain dets
+ size_check_mnesia % Plain mnesia
]
}].
-init_per_group(_GroupName, Config) ->
- Config.
+
+init_per_group(GroupName, Config) ->
+ snmp_test_lib:init_group_top_dir(GroupName, Config).
end_per_group(_GroupName, Config) ->
+ %% Do we really need to do this?
+ %% lists:keydelete(snmp_group_top_dir, 1, Config).
Config.
@@ -181,17 +213,6 @@ cases() ->
cache_test
].
-init_per_suite(Config) when is_list(Config) ->
- %% Data dir points wrong
- DataDir0 = ?config(data_dir, Config),
- DataDir1 = filename:split(filename:absname(DataDir0)),
- [_|DataDir2] = lists:reverse(DataDir1),
- DataDir = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]),
- [{snmp_data_dir, DataDir ++ "/"}|Config].
-
-end_per_suite(Config) when is_list(Config) ->
- lists:keydelete(snmp_data_dir, 1, Config).
-
%%======================================================================
%% Test functions
@@ -219,7 +240,7 @@ load_unload(suite) -> [];
load_unload(Config) when is_list(Config) ->
Prio = normal,
Verbosity = log,
- MibDir = ?config(snmp_data_dir, Config),
+ MibDir = ?config(data_dir, Config),
?DBG("load_unload -> start symbolic store", []),
?line sym_start(Prio, Verbosity),
@@ -273,42 +294,65 @@ size_check_ets1(Config) when is_list(Config) ->
size_check_ets2(suite) ->
[];
size_check_ets2(Config) when is_list(Config) ->
- Dir = ?config(ets_dir, Config),
- MibStorage = [{module, snmpa_mib_storage_ets},
+ Dir = ?config(db_dir, Config),
+ MibStorage = [{module, snmpa_mib_storage_ets},
{options, [{dir, Dir}]}],
do_size_check([{mib_storage, MibStorage}|Config]).
+size_check_ets2_bad_file1(suite) ->
+ [];
+size_check_ets2_bad_file1(Config) when is_list(Config) ->
+ Dir = ?config(db_dir, Config),
+ %% Ensure that the bad file does not cause any problems (action = clear)
+ MibStorage = [{module, snmpa_mib_storage_ets},
+ {options, [{dir, Dir},
+ {action, clear}]}],
+ do_size_check([{mib_storage, MibStorage}|Config]).
+
size_check_ets3(suite) ->
[];
size_check_ets3(Config) when is_list(Config) ->
- Dir = ?config(ets_dir, Config),
- MibStorage = [{module, snmpa_mib_storage_ets},
- {options, [{dir, Dir}, {checksum, true}]}],
+ Dir = ?config(db_dir, Config),
+ MibStorage = [{module, snmpa_mib_storage_ets},
+ {options, [{dir, Dir},
+ {checksum, true}]}],
+ do_size_check([{mib_storage, MibStorage}|Config]).
+
+size_check_ets3_bad_file1(suite) ->
+ [];
+size_check_ets3_bad_file1(Config) when is_list(Config) ->
+ Dir = ?config(db_dir, Config),
+ %% Ensure that the bad file does not cause any problems (action = clear)
+ MibStorage = [{module, snmpa_mib_storage_ets},
+ {options, [{dir, Dir},
+ {action, clear},
+ {checksum, true}]}],
do_size_check([{mib_storage, MibStorage}|Config]).
size_check_dets(suite) ->
[];
size_check_dets(Config) when is_list(Config) ->
- Dir = ?config(dets_dir, Config),
- MibStorage = [{module, snmpa_mib_storage_dets},
+ Dir = ?config(db_dir, Config),
+ MibStorage = [{module, snmpa_mib_storage_dets},
{options, [{dir, Dir}]}],
do_size_check([{mib_storage, MibStorage}|Config]).
size_check_mnesia(suite) ->
[];
size_check_mnesia(Config) when is_list(Config) ->
- MibStorage = [{module, snmpa_mib_storage_mnesia},
+ MibStorage = [{module, snmpa_mib_storage_mnesia},
{options, [{nodes, [node()]}]}],
do_size_check([{mib_storage, MibStorage}|Config]).
do_size_check(Config) ->
- ?DBG("do_size_check -> start", []),
+ ?DBG("do_size_check -> start with"
+ "~n Config: ~p", [Config]),
Prio = normal,
Verbosity = trace,
MibStorage = ?config(mib_storage, Config),
?DBG("do_size_check -> MibStorage: ~p", [MibStorage]),
- MibDir = ?config(snmp_data_dir, Config),
+ MibDir = ?config(data_dir, Config),
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
?DBG("do_size_check -> start symbolic store", []),
@@ -358,7 +402,7 @@ me_lookup(suite) -> [];
me_lookup(Config) when is_list(Config) ->
Prio = normal,
Verbosity = trace,
- MibDir = ?config(snmp_data_dir, Config),
+ MibDir = ?config(data_dir, Config),
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
Mibs = ["Test2", "TestTrap", "TestTrapv2"],
StdMibs = ["OTP-SNMPEA-MIB",
@@ -411,7 +455,7 @@ which_mib(suite) -> [];
which_mib(Config) when is_list(Config) ->
Prio = normal,
Verbosity = trace,
- MibDir = ?config(snmp_data_dir, Config),
+ MibDir = ?config(data_dir, Config),
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
Mibs = ["Test2", "TestTrap", "TestTrapv2"],
StdMibs = ["OTP-SNMPEA-MIB",
@@ -469,7 +513,7 @@ cache_test(Config) when is_list(Config) ->
Prio = normal,
Verbosity = trace,
MibStorage = [{module, snmpa_mib_storage_ets}],
- MibDir = ?config(snmp_data_dir, Config),
+ MibDir = ?config(data_dir, Config),
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
Mibs = ["Test2", "TestTrap", "TestTrapv2"],
StdMibs = ["OTP-SNMPEA-MIB",