summaryrefslogtreecommitdiff
path: root/lib/snmp/test/snmp_note_store_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp/test/snmp_note_store_SUITE.erl')
-rw-r--r--lib/snmp/test/snmp_note_store_SUITE.erl185
1 files changed, 132 insertions, 53 deletions
diff --git a/lib/snmp/test/snmp_note_store_SUITE.erl b/lib/snmp/test/snmp_note_store_SUITE.erl
index 832c03029e..3b6d9f9fcd 100644
--- a/lib/snmp/test/snmp_note_store_SUITE.erl
+++ b/lib/snmp/test/snmp_note_store_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2019. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2020. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -81,11 +81,34 @@ groups() ->
%% -----
%%
-init_per_suite(Config) when is_list(Config) ->
- Config.
+init_per_suite(Config0) when is_list(Config0) ->
+ ?IPRINT("init_per_suite -> entry with"
+ "~n Config: ~p", [Config0]),
-end_per_suite(Config) when is_list(Config) ->
- Config.
+ case ?LIB:init_per_suite(Config0) of
+ {skip, _} = SKIP ->
+ SKIP;
+
+ Config1 when is_list(Config1) ->
+ %% We need a monitor on this node also
+ snmp_test_sys_monitor:start(),
+
+ ?IPRINT("init_per_suite -> end when"
+ "~n Config1: ~p", [Config1]),
+
+ Config1
+ end.
+
+end_per_suite(Config0) when is_list(Config0) ->
+ ?IPRINT("end_per_suite -> entry with"
+ "~n Config: ~p", [Config0]),
+
+ snmp_test_sys_monitor:stop(),
+ Config1 = ?LIB:end_per_suite(Config0),
+
+ ?IPRINT("end_per_suite -> end"),
+
+ Config1.
@@ -106,9 +129,24 @@ end_per_group(_GroupName, Config) ->
%%
init_per_testcase(_Case, Config) when is_list(Config) ->
+ ?IPRINT("init_per_testcase -> entry with"
+ "~n Config: ~p", [Config]),
+
+ snmp_test_global_sys_monitor:reset_events(),
+
+ ?IPRINT("init_per_testcase -> end"),
+
Config.
end_per_testcase(_Case, Config) when is_list(Config) ->
+
+ ?IPRINT("end_per_testcase -> entry with"
+ "~n Config: ~p",
+ [Config]),
+
+ ?IPRINT("system events during test: ~p",
+ [snmp_test_global_sys_monitor:events()]),
+
Config.
@@ -143,42 +181,55 @@ notes(doc) ->
["Testing that it does what it is actually supposed to do, "
"namilly to handle notes. "];
notes(Config) when is_list(Config) ->
-
- {ok, Handler, Pid} = note_store_handler_start(),
-
- io:format("sleep some before we begin the tests~n", []),
- ?SLEEP(timer:seconds(1)),
+ Pre = fun() ->
+ ?IPRINT("try start note-store"),
+ case note_store_handler_start() of
+ {ok, Handler, Pid} ->
+ ?IPRINT("started - sleep some before we begin the tests"),
+ ?SLEEP(?SECS(1)),
+ {Handler, Pid};
+ {error, Reason} ->
+ {skip, ?F("Failed starting note-store: ~p", [Reason])}
+ end
+ end,
+ Case = fun(State) -> do_notes(State, Config) end,
+ Post = fun({Handler, _Pid}) ->
+ note_store_handler_stop(Handler)
+ end,
+ ?TC_TRY(notes, Pre, Case, Post).
+
+do_notes({_, Pid}, _Config) ->
%% Default lifetime is infinity. A note with lifetime
%% infinity is permanent
- io:format("create permanent note sune~n", []),
+ ?IPRINT("create permanent note: sune"),
true = snmp_note_store:set_note(Pid, sune, 10),
10 = snmp_note_store:get_note(Pid, sune),
10 = snmp_note_store:get_note(Pid, sune),
%% Lifetime is in 1/100 sec ticks, so 500 equals 5 seconds
- io:format("create 5 sec note kalle~n", []),
+ ?IPRINT("create 5 sec note kalle"),
true = snmp_note_store:set_note(Pid, 500, kalle, hobbe),
- io:format("wait 1 sec~n", []),
+ ?IPRINT("wait 1 sec"),
?SLEEP(timer:seconds(1)),
- io:format("get note kalle~n", []),
+ ?IPRINT("get note kalle"),
hobbe = snmp_note_store:get_note(Pid, kalle),
- io:format("wait 5 sec~n", []),
+ ?IPRINT("wait 5 sec"),
?SLEEP(timer:seconds(5)),
- io:format("get note kalle again (now it should not exist)~n", []),
+ ?IPRINT("get note kalle again (now it should not exist)"),
undefined = snmp_note_store:get_note(Pid, kalle),
- io:format("create 5 sec note kalle~n", []),
+ ?IPRINT("create 5 sec note kalle"),
true = snmp_note_store:set_note(Pid, 500, kalle, hobbe),
- io:format("wait 6 sec (to allow timer to clean up note)~n", []),
+ ?IPRINT("wait 6 sec (to allow timer to clean up note)"),
?SLEEP(timer:seconds(6)),
- io:format("get note kalle - should not exist~n", []),
+ ?IPRINT("get note kalle - should not exist"),
undefined = snmp_note_store:get_note(Pid, kalle),
- io:format("read the permanent note sune again~n", []),
+ ?IPRINT("read the permanent note sune again"),
10 = snmp_note_store:get_note(Pid, sune),
- note_store_handler_stop(Handler),
+ ?IPRINT("done"),
ok.
@@ -190,47 +241,65 @@ info(suite) ->
info(doc) ->
["Testing that we can retreive process info."];
info(Config) when is_list(Config) ->
-
- Prio = normal,
- Mod = ?MODULE,
- Opts = [{verbosity, trace}],
- {ok, Pid} = snmp_note_store:start_link(Prio, Mod, Opts),
+ Pre = fun() ->
+ ?IPRINT("try start note-store"),
+ Prio = normal,
+ Mod = ?MODULE,
+ Opts = [{verbosity, trace}],
+ case snmp_note_store:start_link(Prio, Mod, Opts) of
+ {ok, Pid} ->
+ ?IPRINT("note-store started: ~p", [Pid]),
+ Pid;
+ {error, Reason} ->
+ {skip, ?F("Failed starting note-store: ~p", [Reason])}
+ end
+ end,
+ Case = fun(State) -> do_info(State, Config) end,
+ Post = fun(Pid) ->
+ ?IPRINT("attempt stop note-store"),
+ snmp_note_store:stop(Pid)
+ end,
+ ?TC_TRY(info, Pre, Case, Post).
+
+do_info(Pid, _Config) ->
%% Get the info:
+ ?IPRINT("get initial info"),
Info = snmp_note_store:info(Pid),
- io:format("Info: ~p~n", [Info]),
+ ?IPRINT("Info: "
+ "~n ~p", [Info]),
%% Verify content
- io:format("get process memory~n", []),
+ ?IPRINT("verify content: get notes process memory"),
{value, {process_memory, ProcMem}} =
lists:keysearch(process_memory, 1, Info),
- io:format("get notes process memory~n", []),
+ ?IPRINT("get notes process memory"),
{value, {notes, NotesProcMem}} =
lists:keysearch(notes, 1, ProcMem),
- io:format("verify notes process memory~n", []),
+ ?IPRINT("verify notes process memory"),
if
is_integer(NotesProcMem) andalso (NotesProcMem > 0) ->
ok;
true ->
throw({error, {bad_notes_proc_memery, NotesProcMem}})
end,
- io:format("get timer process memory~n", []),
+ ?IPRINT("verify content: get timer process memory"),
{value, {timer, TmrProcMem}} =
lists:keysearch(timer, 1, ProcMem),
- io:format("verify timer process memory~n", []),
+ ?IPRINT("verify content: timer process memory"),
if
is_integer(TmrProcMem) andalso (TmrProcMem > 0) ->
ok;
true ->
throw({error, {bad_timer_proc_memery, TmrProcMem}})
end,
- io:format("get db memory~n", []),
+ ?IPRINT("verify content: get db memory"),
{value, {db_memory, DbMem}} =
lists:keysearch(db_memory, 1, Info),
- io:format("get notes db memory~n", []),
+ ?IPRINT("verify content: get notes db memory"),
{value, {notes, NotesDbMem}} =
lists:keysearch(notes, 1, DbMem),
- io:format("verify notes db memory~n", []),
+ ?IPRINT("verify content: notes db memory"),
if
is_integer(NotesDbMem) andalso (NotesDbMem > 0) ->
ok;
@@ -238,9 +307,7 @@ info(Config) when is_list(Config) ->
throw({error, {bad_notes_db_memery, NotesDbMem}})
end,
-
- snmp_note_store:stop(Pid),
-
+ ?IPRINT("done"),
ok.
@@ -251,23 +318,38 @@ garbage_in(suite) ->
garbage_in(doc) ->
["Test that the process handles garbage sent to it."];
garbage_in(Config) when is_list(Config) ->
-
- io:format("start note_store server~n", []),
- Prio = normal,
- Mod = ?MODULE,
- Opts = [{verbosity, trace}],
- {ok, Pid} = snmp_note_store:start_link(Prio, Mod, Opts),
-
- io:format("issue bad request~n", []),
+ Pre = fun() ->
+ ?IPRINT("try start note-store"),
+ Prio = normal,
+ Mod = ?MODULE,
+ Opts = [{verbosity, trace}],
+ case snmp_note_store:start_link(Prio, Mod, Opts) of
+ {ok, Pid} ->
+ ?IPRINT("note-store started: ~p", [Pid]),
+ Pid;
+ {error, Reason} ->
+ {skip, ?F("Failed starting note-store: ~p", [Reason])}
+ end
+ end,
+ Case = fun(State) -> do_garbage_in(State, Config) end,
+ Post = fun(Pid) ->
+ ?IPRINT("attempt stop note-store"),
+ snmp_note_store:stop(Pid)
+ end,
+ ?TC_TRY(garbage_in, Pre, Case, Post).
+
+do_garbage_in(Pid, _Config) ->
+
+ ?IPRINT("issue bad request"),
{error, _} = gen_server:call(Pid, bad_request),
- io:format("cast bad message~n", []),
+ ?IPRINT("cast bad message"),
gen_server:cast(Pid, bad_message),
- io:format("bang bad info~n", []),
+ ?IPRINT("bang bad info"),
Pid ! bad_info,
- io:format("verify note_Store server still alive and kicking~n", []),
+ ?IPRINT("verify note-store server still alive and kicking"),
Info = snmp_note_store:info(Pid),
if
is_list(Info) andalso (length(Info) > 0) ->
@@ -276,10 +358,7 @@ garbage_in(Config) when is_list(Config) ->
throw({error, {bad_info, Info}})
end,
- io:format("stop note_store server~n", []),
- snmp_note_store:stop(Pid),
-
- io:format("done~n", []),
+ ?IPRINT("done"),
ok.