diff options
| author | Micael Karlberg <bmk@erlang.org> | 2022-04-29 17:06:48 +0200 |
|---|---|---|
| committer | Micael Karlberg <bmk@erlang.org> | 2022-04-29 17:06:48 +0200 |
| commit | 4d5a9b1a1cbc7de6793cf34b8b9447774a067215 (patch) | |
| tree | 403c076b09e106e38321fe9e065d21ee68dbbdfd /lib/megaco | |
| parent | 437165ac62aa1fbc49522cdddd10f884978d494b (diff) | |
| parent | e7147628008dcc69b52238facfde5c2601cdef0a (diff) | |
| download | erlang-4d5a9b1a1cbc7de6793cf34b8b9447774a067215.tar.gz | |
Merge branch 'bmk/megaco/20220420/test_tweaking'
Diffstat (limited to 'lib/megaco')
| -rw-r--r-- | lib/megaco/examples/meas/megaco_codec_meas.erl | 43 | ||||
| -rw-r--r-- | lib/megaco/test/megaco_pending_limit_SUITE.erl | 571 | ||||
| -rw-r--r-- | lib/megaco/test/megaco_tcp_SUITE.erl | 41 | ||||
| -rw-r--r-- | lib/megaco/test/megaco_test_lib.erl | 333 | ||||
| -rw-r--r-- | lib/megaco/test/megaco_test_lib.hrl | 2 | ||||
| -rw-r--r-- | lib/megaco/test/megaco_timer_SUITE.erl | 82 |
6 files changed, 600 insertions, 472 deletions
diff --git a/lib/megaco/examples/meas/megaco_codec_meas.erl b/lib/megaco/examples/meas/megaco_codec_meas.erl index ae28fa43a0..06983e4dd5 100644 --- a/lib/megaco/examples/meas/megaco_codec_meas.erl +++ b/lib/megaco/examples/meas/megaco_codec_meas.erl @@ -50,7 +50,7 @@ -export([start1/0]). %% Internal exports --export([do_measure_codec/8, do_measure_codec_loop/7]). +-export([do_measure_codec/7, do_measure_codec_loop/7]). -export([flex_scanner_handler/1]). @@ -416,20 +416,21 @@ measure_codec(Factor, Codec, Func, Conf, Version, Bin, MCount) is_atom(Func) andalso is_list(Conf) andalso is_integer(MCount) andalso (MCount > 0) -> - Self = self(), - Pid = spawn_link(?MODULE, do_measure_codec, - [Factor, Self, Codec, Func, Conf, Version, Bin, MCount]), + {Pid, MRef} = + spawn_monitor(?MODULE, do_measure_codec, + [Factor, Codec, Func, Conf, Version, Bin, MCount]), receive - {measure_result, Pid, Func, Res} -> + {'DOWN', MRef, process, Pid, {measure_result, Res}} -> {ok, Res}; - {error, Pid, Error} -> + {'DOWN', MRef, process, Pid, {error, Error}} -> {error, Error}; - Else -> + {'DOWN', MRef, process, Pid, Else} -> {error, {unexpected_result, Else}} after ?MEASURE_TIMEOUT -> Info = case (catch process_info(Pid)) of I when is_list(I) -> + erlang:demonitor(MRef), exit(Pid, kill), I; _ -> @@ -439,23 +440,17 @@ measure_codec(Factor, Codec, Func, Conf, Version, Bin, MCount) end. -do_measure_codec(Factor, Parent, Codec, Func, Conf, Version, Bin, MCount) -> +do_measure_codec(Factor, Codec, Func, Conf, Version, Bin, MCount) -> {ok, Count} = measure_warmup(Codec, Func, Conf, Version, Bin, MCount), Count2 = Count div Factor, - %% io:format("do_measure_codec(~w, ~w) -> warmed up:" - %% "~n MCount: ~w" - %% "~n Count: ~w" - %% "~n Count2: ~w", [Codec, Func, MCount, Count, Count2]), Res = timer:tc(?MODULE, do_measure_codec_loop, [Codec, Func, Conf, Version, Bin, Count2, dummy]), case Res of {Time, {ok, M}} -> - %% io:format("~w ", [Time]), - Parent ! {measure_result, self(), Func, {M, Count2, Time}}; + exit({measure_result, {M, Count2, Time}}); {_Time, Error} -> - Parent ! {error, self(), Error} - end, - unlink(Parent). % Make sure Parent don't get our exit signal + exit({error, Error}) + end. %% This function does more or less what the real measure function @@ -467,11 +462,17 @@ measure_warmup(Codec, Func, Conf, Version, M, MCount) -> Res = timer:tc(?MODULE, do_measure_codec_loop, [Codec, Func, Conf, Version, M, MCount, dummy]), case Res of - {Time, {ok, _}} when is_integer(Time) -> + {Time, {ok, _}} when is_integer(Time) andalso (Time > 0) -> %% OK so far, now calculate the count: - Count = round(?MEASURE_COUNT_TIME/(Time/MCount)), - %% io:format("~w ", [Count]), - {ok, Count}; + %% For some reason we get a 'badarith' on some platforms + %% here. Since this is just the warmup we can try-catch. + try round(?MEASURE_COUNT_TIME/(Time/MCount)) of + Count -> + {ok, Count} + catch + _:_:_ -> + {error, {failed_calculated_count, Time, MCount}} + end; {Time, Error} -> {error, {warmup_failed, Time, Error}} end. diff --git a/lib/megaco/test/megaco_pending_limit_SUITE.erl b/lib/megaco/test/megaco_pending_limit_SUITE.erl index d5db6e6bc0..472598128f 100644 --- a/lib/megaco/test/megaco_pending_limit_SUITE.erl +++ b/lib/megaco/test/megaco_pending_limit_SUITE.erl @@ -46,31 +46,6 @@ ]). --ifdef(megaco_hipe_special). --export([ - %% Case: recv_limit_exceeded1 - rle1_mgc_verify_service_change_req_msg/2, - rle1_mgc_verify_notify_req_msg/1, - rle1_mg_verify_handle_connect/1, - rle1_mg_verify_service_change_rep/1, - rle1_mg_verify_trans_rep/1, - - %% Case: otp_4956 - otp_4956_mgc_verify_handle_connect/1, - otp_4956_mgc_verify_service_change_req/2, - otp_4956_mgc_verify_notify_req1/1, - otp_4956_mgc_verify_notify_req2/1, - otp_4956_mgc_verify_handle_trans_req_abort/1, - otp_4956_mgc_verify_handle_disconnect/1, - otp_4956_mg_verify_service_change_rep_msg/1, - otp_4956_mg_verify_pending_msg/1, - otp_4956_mg_verify_pending_limit_msg/1, - - %% Utility - encode_msg/3, - decode_msg/3 - ]). --endif. -include_lib("megaco/include/megaco.hrl"). -include_lib("megaco/include/megaco_message_v1.hrl"). @@ -89,6 +64,10 @@ -define(MGC_START(Pid, Mid, ET, Conf, Verb), megaco_test_mgc:start(Pid, Mid, ET, Conf, Verb)). +-define(MGC_START(Pid, ET, Conf), + ?MGC_START(Pid, {deviceName, "ctrl"}, ET, Conf, ?MGC_VERBOSITY)). +-define(MGC_START(Pid, ET), + ?MGC_START(Pid, ET, [])). -define(MGC_STOP(Pid), megaco_test_mgc:stop(Pid)). -define(MGC_GET_STATS(Pid, No), megaco_test_mgc:get_stats(Pid, No)). -define(MGC_RESET_STATS(Pid), megaco_test_mgc:reset_stats(Pid)). @@ -110,6 +89,10 @@ -define(MG_START(Pid, Mid, Enc, Transp, Conf, Verb), megaco_test_mg:start(Pid, Mid, Enc, Transp, Conf, Verb)). +-define(MG_START(Pid, Enc, Transp, Conf), + ?MG_START(Pid, {deviceName, "mg"}, Enc, Transp, Conf, ?MG_VERBOSITY)). +-define(MG_START(Pid, Enc, Transp), + ?MG_START(Pid, Enc, Transp, [])). -define(MG_STOP(Pid), megaco_test_mg:stop(Pid)). -define(MG_GET_STATS(Pid, No), megaco_test_mg:get_stats(Pid, No)). -define(MG_RESET_STATS(Pid), megaco_test_mg:reset_stats(Pid)). @@ -278,30 +261,39 @@ sent_timer_late_reply(suite) -> sent_timer_late_reply(doc) -> "..."; sent_timer_late_reply(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, sent_timer_late_reply), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun() -> ok end, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_sent_timer_late_reply(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_sent_timer_late_reply(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], MgcConf = [{megaco_trace, false}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, MgcConf, ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET, MgcConf), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConf = [{megaco_trace, io}], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConf, ?MG_VERBOSITY), + MgConf = [{megaco_trace, io}], + {ok, Mg} = ?MG_START(MgNode, text, tcp, MgConf), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -342,11 +334,7 @@ sent_timer_late_reply(Config) when is_list(Config) -> i("[MGC] stop"), ?MGC_STOP(Mgc), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. @@ -357,29 +345,37 @@ sent_timer_exceeded(suite) -> sent_timer_exceeded(doc) -> "..."; sent_timer_exceeded(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, sent_timer_exceeded), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun() -> ok end, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_sent_timer_exceeded(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_sent_timer_exceeded(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), - i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + i("[MG] start"), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -419,11 +415,7 @@ sent_timer_exceeded(Config) when is_list(Config) -> i("[MGC] stop"), ?MGC_STOP(Mgc), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. @@ -434,29 +426,37 @@ sent_timer_exceeded_long(suite) -> sent_timer_exceeded_long(doc) -> "..."; sent_timer_exceeded_long(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, sent_timer_exceeded_long), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun() -> ok end, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_sent_timer_exceeded_long(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_sent_timer_exceeded_long(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -494,11 +494,7 @@ sent_timer_exceeded_long(Config) when is_list(Config) -> i("[MGC] stop"), ?MGC_STOP(Mgc), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. @@ -508,35 +504,42 @@ sent_timer_exceeded_long(Config) when is_list(Config) -> %% This test case can only be run with the stack compiled with %% the MEGACO_TEST_CODE flag. Therefor there is no point in %% including this test case in the usual test suite --ifdef(MEGACO_TEST_CODE). sent_resend_late_reply(suite) -> []; sent_resend_late_reply(doc) -> "..."; sent_resend_late_reply(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, sent_resend_late_reply), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun megaco_test_code/0, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_sent_resend_late_reply(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_sent_resend_late_reply(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -594,53 +597,48 @@ sent_resend_late_reply(Config) when is_list(Config) -> i("done", []), ok. --else. - -sent_resend_late_reply(suite) -> - []; -sent_resend_late_reply(doc) -> - "..."; -sent_resend_late_reply(Config) when is_list(Config) -> - ?SKIP("included only if compiled with USE_MEGACO_TEST_CODE=true"). - --endif. - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% This test case can only be run with the stack compiled with %% the MEGACO_TEST_CODE flag. Therefor there is no point in %% including this test case in the usual test suite --ifdef(MEGACO_TEST_CODE). sent_resend_exceeded(suite) -> []; sent_resend_exceeded(doc) -> "..."; sent_resend_exceeded(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, sent_resend_exceeded), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun megaco_test_code/0, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_sent_resend_exceeded(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_sent_resend_exceeded(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -686,60 +684,51 @@ sent_resend_exceeded(Config) when is_list(Config) -> i("[MGC] stop"), ?MGC_STOP(Mgc), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. --else. - -sent_resend_exceeded(suite) -> - []; -sent_resend_exceeded(doc) -> - "..."; -sent_resend_exceeded(Config) when is_list(Config) -> - ?SKIP("included only if compiled with USE_MEGACO_TEST_CODE=true"). - --endif. - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% This test case can only be run with the stack compiled with %% the MEGACO_TEST_CODE flag. Therefor there is no point in %% including this test case in the usual test suite --ifdef(MEGACO_TEST_CODE). sent_resend_exceeded_long(suite) -> []; sent_resend_exceeded_long(doc) -> "..."; sent_resend_exceeded_long(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, sent_resend_exceeded_long), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun megaco_test_code/0, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_sent_resend_exceeded_long(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_sent_resend_exceeded_long(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -786,26 +775,10 @@ sent_resend_exceeded_long(Config) when is_list(Config) -> i("[MGC] stop"), ?MGC_STOP(Mgc), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. --else. - -sent_resend_exceeded_long(suite) -> - []; -sent_resend_exceeded_long(doc) -> - "..."; -sent_resend_exceeded_long(Config) when is_list(Config) -> - ?SKIP("included only if compiled with USE_MEGACO_TEST_CODE=true"). - --endif. - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% %%% %%% Received peinding test cases %%% @@ -817,19 +790,30 @@ recv_limit_exceeded1(suite) -> recv_limit_exceeded1(doc) -> "Received pending limit exceeded (exactly)"; recv_limit_exceeded1(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, rle1), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun() -> ok end, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_recv_limit_exceeded1(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_recv_limit_exceeded1(#{nodes := [MgcNode, MgNode]}) -> d("[MGC] start the simulator "), {ok, Mgc} = megaco_test_tcp_generator:start_link("MGC", MgcNode), @@ -868,27 +852,13 @@ recv_limit_exceeded1(Config) when is_list(Config) -> i("[MG] stop generator"), megaco_test_megaco_generator:stop(Mg), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. %% %% MGC generator stuff %% --ifdef(megaco_hipe_special). --define(rle1_mgc_decode_msg_fun(Mod, Conf), - {?MODULE, decode_msg, [Mod, Conf]}). --define(rle1_mgc_encode_msg_fun(Mod, Conf), - {?MODULE, encode_msg, [Mod, Conf]}). --define(rle1_mgc_verify_service_change_req_msg_fun(Mid), - {?MODULE, rle1_mgc_verify_service_change_req_msg, [Mid]}). --define(rle1_mgc_verify_notify_req_msg_fun(), - {?MODULE, rle1_mgc_verify_notify_req_msg, []}). --else. -define(rle1_mgc_decode_msg_fun(Mod, Conf), rle1_mgc_decode_msg_fun(Mod, Conf)). -define(rle1_mgc_encode_msg_fun(Mod, Conf), @@ -897,7 +867,6 @@ recv_limit_exceeded1(Config) when is_list(Config) -> rle1_mgc_verify_service_change_req_msg_fun(Mid)). -define(rle1_mgc_verify_notify_req_msg_fun(), rle1_mgc_verify_notify_req_msg_fun()). --endif. rle1_mgc_event_sequence(text, tcp) -> Mid = {deviceName,"ctrl"}, @@ -942,17 +911,15 @@ rle1_mgc_event_sequence2(Mid, EM, EC) -> ], EvSeq. --ifndef(megaco_hipe_special). rle1_mgc_encode_msg_fun(Mod, Conf) -> fun(M) -> encode_msg(M, Mod, Conf) end. rle1_mgc_decode_msg_fun(Mod, Conf) -> - fun(M) -> + fun(M) -> decode_msg(M, Mod, Conf) end. --endif. rle1_mgc_service_change_reply_msg(Mid, TransId, Cid) -> SCRP = #'ServiceChangeResParm'{serviceChangeMgcId = Mid}, @@ -983,12 +950,10 @@ rle1_mgc_pending_msg(Mid, TransId) -> messageBody = Body}, #'MegacoMessage'{mess = Mess}. --ifndef(megaco_hipe_special). rle1_mgc_verify_service_change_req_msg_fun(Mid) -> fun(M) -> rle1_mgc_verify_service_change_req_msg(M, Mid) end. --endif. rle1_mgc_verify_service_change_req_msg(#'MegacoMessage'{mess = Mess} = M, _Mid1) -> @@ -1018,12 +983,10 @@ rle1_mgc_verify_service_change_req_msg(#'MegacoMessage'{mess = Mess} = M, rle1_mgc_verify_service_change_req_msg(M, _Mid) -> {error, {invalid_message, M}}. --ifndef(megaco_hipe_special). rle1_mgc_verify_notify_req_msg_fun() -> fun(M) -> rle1_mgc_verify_notify_req_msg(M) end. --endif. rle1_mgc_verify_notify_req_msg(#'MegacoMessage'{mess = Mess} = M) -> io:format("rle1_mgc_verify_notify_req_msg -> entry with" @@ -1054,21 +1017,12 @@ rle1_mgc_verify_notify_req_msg(M) -> %% %% MG generator stuff %% --ifdef(megaco_hipe_special). --define(rle1_mg_verify_handle_connect_fun(), - {?MODULE, rle1_mg_verify_handle_connect, []}). --define(rle1_mg_verify_service_change_rep_fun(), - {?MODULE, rle1_mg_verify_service_change_rep, []}). --define(rle1_mg_verify_trans_rep_fun(), - {?MODULE, rle1_mg_verify_trans_rep, []}). --else. -define(rle1_mg_verify_handle_connect_fun(), fun rle1_mg_verify_handle_connect/1). -define(rle1_mg_verify_service_change_rep_fun(), fun rle1_mg_verify_service_change_rep/1). -define(rle1_mg_verify_trans_rep_fun(), fun rle1_mg_verify_trans_rep/1). --endif. rle1_mg_event_sequence(text, tcp) -> Mid = {deviceName,"mg"}, @@ -1284,20 +1238,6 @@ otp_4956(Config) when is_list(Config) -> %% %% MGC generator stuff %% --ifdef(megaco_hipe_special). --define(otp_4956_mgc_verify_handle_connect_fun(), - {?MODULE, otp_4956_mgc_verify_handle_connect, []}). --define(otp_4956_mgc_verify_service_change_req_fun(Mid), - {?MODULE, otp_4956_mgc_verify_service_change_req, [Mid]}). --define(otp_4956_mgc_verify_notify_req1_fun(), - {?MODULE, otp_4956_mgc_verify_notify_req1, []}). --define(otp_4956_mgc_verify_notify_req2_fun(), - {?MODULE, otp_4956_mgc_verify_notify_req2, []}). --define(otp_4956_mgc_verify_handle_trans_req_abort_fun(), - {?MODULE, otp_4956_mgc_verify_handle_trans_req_abort, []}). --define(otp_4956_mgc_verify_handle_disconnect_fun(), - {?MODULE, otp_4956_mgc_verify_handle_disconnect, []}). --else. -define(otp_4956_mgc_verify_handle_connect_fun(), otp_4956_mgc_verify_handle_connect_fun()). -define(otp_4956_mgc_verify_service_change_req_fun(Mid), @@ -1310,7 +1250,6 @@ otp_4956(Config) when is_list(Config) -> otp_4956_mgc_verify_handle_trans_req_abort_fun()). -define(otp_4956_mgc_verify_handle_disconnect_fun(), fun otp_4956_mgc_verify_handle_disconnect/1). --endif. otp_4956_mgc_event_sequence(text, tcp) -> Mid = {deviceName,"ctrl"}, @@ -1355,24 +1294,20 @@ otp_4956_mgc_event_sequence(text, tcp) -> EvSeq. --ifndef(megaco_hipe_special). otp_4956_mgc_verify_handle_connect_fun() -> fun(M) -> otp_4956_mgc_verify_handle_connect(M) end. --endif. otp_4956_mgc_verify_handle_connect({handle_connect, CH, ?VERSION}) -> {ok, CH, ok}; otp_4956_mgc_verify_handle_connect(Else) -> {error, Else, ok}. --ifndef(megaco_hipe_special). otp_4956_mgc_verify_service_change_req_fun(Mid) -> fun(Req) -> otp_4956_mgc_verify_service_change_req(Req, Mid) end. --endif. otp_4956_mgc_verify_service_change_req( {handle_trans_request, _, ?VERSION, [AR]}, Mid) -> @@ -1434,12 +1369,10 @@ otp_4956_mgc_verify_service_change_req(Else, _Mid) -> ErrReply = {discard_ack, ED}, {error, Else, ErrReply}. --ifndef(megaco_hipe_special). otp_4956_mgc_verify_notify_req1_fun() -> fun(Req) -> otp_4956_mgc_verify_notify_req1(Req) end. --endif. otp_4956_mgc_verify_notify_req1({handle_trans_request, _, ?VERSION, [AR]}) -> io:format("otp_4956_mgc_verify_notify_req1 -> entry with" @@ -1470,12 +1403,10 @@ otp_4956_mgc_verify_notify_req1(Else) -> ErrReply = {discard_ack, ED}, {error, Else, ErrReply}. --ifndef(megaco_hipe_special). otp_4956_mgc_verify_notify_req2_fun() -> fun(Ev) -> otp_4956_mgc_verify_notify_req2(Ev) end. --endif. otp_4956_mgc_verify_notify_req2({handle_trans_request, _, ?VERSION, [AR]}) -> case AR of @@ -1500,12 +1431,10 @@ otp_4956_mgc_verify_notify_req2(Else) -> ErrReply = {discard_ack, ED}, {error, Else, ErrReply}. --ifndef(megaco_hipe_special). otp_4956_mgc_verify_handle_trans_req_abort_fun() -> fun(Req) -> otp_4956_mgc_verify_handle_trans_req_abort(Req) end. --endif. otp_4956_mgc_verify_handle_trans_req_abort({handle_trans_request_abort, CH, ?VERSION, 2, Pid}) -> @@ -1574,18 +1503,6 @@ otp_4956_mgc_notify_reply_ar(Cid, TermId) -> %% %% MG generator stuff %% --ifdef(megaco_hipe_special). --define(otp_4956_mg_decode_msg_fun(Mod, Conf), - {?MODULE, decode_msg, [Mod, Conf]}). --define(otp_4956_mg_encode_msg_fun(Mod, Conf), - {?MODULE, encode_msg, [Mod, Conf]}). --define(otp_4956_mg_verify_service_change_rep_msg_fun(), - {?MODULE, otp_4956_mg_verify_service_change_rep_msg, []}). --define(otp_4956_mg_verify_pending_msg_fun(), - {?MODULE, otp_4956_mg_verify_pending_msg, []}). --define(otp_4956_mg_verify_pending_limit_msg_fun(), - {?MODULE, otp_4956_mg_verify_pending_limit_msg, []}). --else. -define(otp_4956_mg_decode_msg_fun(Mod, Conf), otp_4956_mg_decode_msg_fun(Mod, Conf)). -define(otp_4956_mg_encode_msg_fun(Mod, Conf), @@ -1596,7 +1513,6 @@ otp_4956_mgc_notify_reply_ar(Cid, TermId) -> otp_4956_mg_verify_pending_msg_fun()). -define(otp_4956_mg_verify_pending_limit_msg_fun(), otp_4956_mg_verify_pending_limit_msg_fun()). --endif. otp_4956_mg_event_sequence(text, tcp) -> DecodeFun = ?otp_4956_mg_decode_msg_fun(megaco_pretty_text_encoder, []), @@ -1642,7 +1558,6 @@ otp_4956_mg_event_sequence(text, tcp) -> ], EvSeq. --ifndef(megaco_hipe_special). otp_4956_mg_encode_msg_fun(Mod, Conf) -> fun(M) -> encode_msg(M, Mod, Conf) @@ -1652,14 +1567,11 @@ otp_4956_mg_decode_msg_fun(Mod, Conf) -> fun(M) -> decode_msg(M, Mod, Conf) end. --endif. --ifndef(megaco_hipe_special). otp_4956_mg_verify_service_change_rep_msg_fun() -> fun(M) -> otp_4956_mg_verify_service_change_rep_msg(M) end. --endif. otp_4956_mg_verify_service_change_rep_msg( #'MegacoMessage'{mess = Mess} = M) -> @@ -1687,12 +1599,10 @@ otp_4956_mg_verify_service_change_rep_msg( otp_4956_mg_verify_service_change_rep_msg(M) -> {error, {invalid_message, M}}. --ifndef(megaco_hipe_special). otp_4956_mg_verify_pending_msg_fun() -> fun(M) -> otp_4956_mg_verify_pending_msg(M) end. --endif. otp_4956_mg_verify_pending_msg(#'MegacoMessage'{mess = Mess} = M) -> io:format("otp_4956_mg_verify_pending_msg -> entry with" @@ -1710,12 +1620,10 @@ otp_4956_mg_verify_pending_msg(M) -> "~n", [M]), {error, {invalid_message, M}}. --ifndef(megaco_hipe_special). otp_4956_mg_verify_pending_limit_msg_fun() -> fun(M) -> otp_4956_mg_verify_pending_limit_msg(M) end. --endif. otp_4956_mg_verify_pending_limit_msg(#'MegacoMessage'{mess = Mess} = M) -> io:format("otp_4956_mg_verify_pending_limit_msg -> entry with" @@ -1800,13 +1708,10 @@ otp_5310(Config) when is_list(Config) -> %% Start the MGC and MGs i("[MGC] start"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], - {ok, Mgc} = - ?MGC_START(MgcNode, {deviceName, "ctrl"}, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), @@ -1951,29 +1856,37 @@ otp_5619(suite) -> otp_5619(doc) -> "..."; otp_5619(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(sname, "TEST"), - put(tc, otp_5619), - i("starting"), - - MgcNode = make_node_name(mgc), - MgNode = make_node_name(mg), - d("start nodes: " - "~n MgcNode: ~p" - "~n MgNode: ~p", - [MgcNode, MgNode]), - ok = ?START_NODES([MgcNode, MgNode], true), - + Cond = fun() -> ok end, + Pre = fun() -> + put(tc, ?FUNCTION_NAME), + MgcNode = make_node_name(pl_5619_mgc), + MgNode = make_node_name(pl_5619_mg), + i("try start nodes: " + "~n MgcNode: ~p" + "~n MgNode: ~p", + [MgcNode, MgNode]), + Nodes = [MgcNode, MgNode], + ok = ?START_NODES(Nodes, true), + #{nodes => Nodes} + end, + Case = fun(State) -> + do_otp_5619(State) + end, + Post = fun(#{nodes := Nodes}) -> + i("stop nodes"), + ?STOP_NODES(Nodes), + ok + end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_otp_5619(#{nodes := [MgcNode, MgNode]}) -> %% Start the MGC and MGs i("[MGC] start"), - MgcMid = {deviceName, "ctrl"}, ET = [{text, tcp}, {text, udp}, {binary, tcp}, {binary, udp}], - {ok, Mgc} = ?MGC_START(MgcNode, MgcMid, ET, [], ?MGC_VERBOSITY), + {ok, Mgc} = ?MGC_START(MgcNode, ET), i("[MG] start"), - MgMid = {deviceName, "mg"}, - MgConfig = [], - {ok, Mg} = ?MG_START(MgNode, MgMid, text, tcp, MgConfig, ?MG_VERBOSITY), + {ok, Mg} = ?MG_START(MgNode, text, tcp), d("MG user info: ~p", [?MG_USER_INFO(Mg, all)]), d("MG conn info: ~p", [?MG_CONN_INFO(Mg, all)]), @@ -2027,11 +1940,7 @@ otp_5619(Config) when is_list(Config) -> i("[MGC] stop~n"), ?MGC_STOP(Mgc), - %% Cleanup - d("stop nodes"), - ?STOP_NODES([MgcNode, MgNode]), - - i("done", []), + i("done"), ok. @@ -2160,14 +2069,12 @@ cre_megacoMessage(Mess) -> %% having received the first pending (which %% indicates that the other side _IS_ %% working on the request). --ifdef(MEGACO_TEST_CODE). init_request_timer({short, Ref}) -> {long, Ref}; init_request_timer(O) -> O. --endif. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -2187,12 +2094,6 @@ decode_msg(M, Mod, Conf) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% tim() -> -%% {A,B,C} = erlang:now(), -%% A*1000000000+B*1000+(C div 1000). - - make_node_name(Name) -> case string:tokens(atom_to_list(node()), [$@]) of [_,Host] -> @@ -2218,11 +2119,31 @@ await_completion(Ids) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +try_tc(TCName, Cond, Pre, Case, Post) -> + try_tc(TCName, "TEST", ?TEST_VERBOSITY, Cond, Pre, Case, Post). + +try_tc(TCName, Name, Verbosity, Cond, Pre, Case, Post) -> + ?TRY_TC(TCName, Name, Verbosity, Cond, Pre, Case, Post). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + sleep(X) -> receive after X -> ok end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-ifdef(MEGACO_TEST_CODE). +megaco_test_code() -> + ok. +-else. +megaco_test_code() -> + exit({skip, "Included only if compiled with USE_MEGACO_TEST_CODE=true"}). +-endif. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + p(F, A) -> io:format("*** [~s] ~p ***" "~n " ++ F ++ "~n", diff --git a/lib/megaco/test/megaco_tcp_SUITE.erl b/lib/megaco/test/megaco_tcp_SUITE.erl index 43ecb335be..300772e564 100644 --- a/lib/megaco/test/megaco_tcp_SUITE.erl +++ b/lib/megaco/test/megaco_tcp_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2021. All Rights Reserved. +%% Copyright Ericsson AB 2000-2022. 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. @@ -318,10 +318,10 @@ start_and_stop(doc) -> start_and_stop(Config) when is_list(Config) -> Pre = fun() -> p("create nodes"), - ServerNode = make_node_name(server), - ClientNode = make_node_name(client), + ServerNode = make_node_name(t_sas_server), + ClientNode = make_node_name(t_sas_client), Nodes = [ServerNode, ClientNode], - ok = ?START_NODES(Nodes), + ok = ?START_NODES(Nodes, true), Nodes end, Case = fun(X) -> do_start_and_stop(Config, X) end, @@ -461,10 +461,10 @@ sendreceive(suite) -> sendreceive(Config) when is_list(Config) -> Pre = fun() -> p("create nodes"), - ServerNode = make_node_name(server), - ClientNode = make_node_name(client), + ServerNode = make_node_name(t_sr_server), + ClientNode = make_node_name(t_sr_client), Nodes = [ServerNode, ClientNode], - ok = ?START_NODES(Nodes), + ok = ?START_NODES(Nodes, true), Nodes end, Case = fun(X) -> do_sendreceive(Config, X) end, @@ -673,10 +673,10 @@ block_unblock(suite) -> block_unblock(Config) when is_list(Config) -> Pre = fun() -> p("create nodes"), - ServerNode = make_node_name(server), - ClientNode = make_node_name(client), + ServerNode = make_node_name(t_bb_server), + ClientNode = make_node_name(t_bb_client), Nodes = [ServerNode, ClientNode], - ok = ?START_NODES(Nodes), + ok = ?START_NODES(Nodes, true), Nodes end, Case = fun(X) -> do_block_unblock(Config, X) end, @@ -1054,14 +1054,22 @@ process_received_message(ReceiveHandle, ControlPid, SendHandle, BinMsg) await_server_listening(Server, Client) -> receive {listening, Server} -> - p("received listening message from server [~p] => " + p("[await-server-listening] " + "received listening message from server [~p] => " "send continue to client [~p]" "~n", [Server, Client]), Client ! {continue, self()}, ok; {'EXIT', Server, SReason} -> + p("[await-server-listening] unexpected server (~p) exit: " + "~n ~p" + "~n", [Server, SReason]), exit({server_crash, SReason}); {'EXIT', Client, CReason} -> + p("[await-server-listening] " + "unexpected client (~p) exit: " + "~n ~p" + "~n", [Client, CReason]), exit({client_crash, CReason}) after 5000 -> %% There is no normal reason why this should take any time. @@ -1076,13 +1084,22 @@ await_server_listening(Server, Client) -> await_client_blocked(Server, Client) -> receive {blocked, Client} -> - p("received blocked message from client [~p] => " + p("[await-client-blocked] " + "received blocked message from client [~p] => " "send continue to server [~p]~n", [Client, Server]), Server ! {continue, self()}, ok; {'EXIT', Client, CReason} -> + p("[await-client-blocked] " + "unexpected client (~p) exit: " + "~n ~p" + "~n", [Client, CReason]), exit({client_crash, CReason}); {'EXIT', Server, SReason} -> + p("[await-client-blocked] " + "unexpected server (~p) exit: " + "~n ~p" + "~n", [Server, SReason]), exit({server_crash, SReason}) after 5000 -> %% There is no normal reason why this should take any time. diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl index 01bd778632..97237a8327 100644 --- a/lib/megaco/test/megaco_test_lib.erl +++ b/lib/megaco/test/megaco_test_lib.erl @@ -50,7 +50,7 @@ display_system_info/1, display_system_info/2, display_system_info/3, executor/1, executor/2, - try_tc/6, + try_tc/6, try_tc/7, prepare_test_case/5, @@ -720,41 +720,138 @@ num_schedulers_to_factor() -> linux_which_distro(Version) -> + try do_linux_which_distro(Version) + catch + throw:{distro, Distro} -> + Distro + end. + +do_linux_which_distro(Version) -> + %% Many (linux) distro's use the /etc/issue file, so try that first. + %% Then we just keep going until we are "done". + DistroStr = do_linux_which_distro_issue(Version), + %% Still not sure; try fedora + _ = do_linux_which_distro_fedora(Version), + %% Still not sure; try suse + _ = do_linux_which_distro_suse(Version), + %% And the fallback + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + other. + +do_linux_which_distro_issue(Version) -> case file:read_file_info("/etc/issue") of {ok, _} -> case [string:trim(S) || S <- string:tokens(os:cmd("cat /etc/issue"), [$\n])] of - [DistroStr|_] -> - io:format("Linux: ~s" - "~n ~s" - "~n", - [Version, DistroStr]), + [DistroStr | _] -> case DistroStr of "Wind River Linux" ++ _ -> - wind_river; + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, wind_river}); "MontaVista" ++ _ -> - montavista; + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, montavista}); "Yellow Dog" ++ _ -> - yellow_dog; + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, yellow_dog}); + "Ubuntu" ++ _ -> + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, ubuntu}); + "Linux Mint" ++ _ -> + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, linux_mint}); _ -> - other + DistroStr end; X -> + X + end; + _ -> + "Unknown" + end. + +do_linux_which_distro_fedora(Version) -> + %% Check if fedora + case file:read_file_info("/etc/fedora-release") of + {ok, _} -> + case [string:trim(S) || + S <- string:tokens(os:cmd("cat /etc/fedora-release"), + [$\n])] of + [DistroStr | _] -> + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]); + _ -> io:format("Linux: ~s" - "~n ~p" + "~n ~s" "~n", - [Version, X]), - other + [Version, "Fedora"]) + end, + throw({distro, fedora}); + _ -> + ignore + end. + +do_linux_which_distro_suse(Version) -> + %% Check if its a SuSE + case file:read_file_info("/etc/SuSE-release") of + {ok, _} -> + case [string:trim(S) || + S <- string:tokens(os:cmd("cat /etc/SuSE-release"), + [$\n])] of + ["SUSE Linux Enterprise Server" ++ _ = DistroStr | _] -> + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, sles}); + [DistroStr | _] -> + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, DistroStr]), + throw({distro, suse}); + _ -> + io:format("Linux: ~s" + "~n ~s" + "~n", + [Version, "SuSE"]), + throw({distro, suse}) end; _ -> - io:format("Linux: ~s" - "~n", [Version]), - other + ignore end. - + analyze_and_print_linux_host_info(Version) -> - Distro = linux_which_distro(Version), + Distro = + case file:read_file_info("/etc/issue") of + {ok, _} -> + linux_which_distro(Version); + _ -> + io:format("Linux: ~s" + "~n", [Version]), + other + end, Factor = case (catch linux_which_cpuinfo(Distro)) of {ok, {CPU, BogoMIPS}} -> @@ -1145,7 +1242,7 @@ analyze_and_print_openbsd_host_info(Version) -> (NCPU >= 2) -> 5; true -> - 10 + 12 end; (CPUSpeed >= 1000) -> if @@ -1158,7 +1255,7 @@ analyze_and_print_openbsd_host_info(Version) -> (NCPU >= 2) -> 6; true -> - 10 + 14 end; true -> if @@ -1191,6 +1288,7 @@ analyze_and_print_openbsd_host_info(Version) -> end catch _:_:_ -> + io:format("TS Scale Factor: ~w~n", [timetrap_scale_factor()]), {10, []} end. @@ -2166,104 +2264,141 @@ executor(Fun, Timeout) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -try_tc(TCName, Name, Verbosity, Pre, Case, Post) - when is_function(Pre, 0) andalso +try_tc(TCName, Name, Verbosity, Pre, Case, Post) -> + Cond = fun() -> ok end, + try_tc(TCName, Name, Verbosity, Cond, Pre, Case, Post). + +try_tc(TCName, Name, Verbosity, Cond, Pre, Case, Post) + when is_function(Cond, 0) andalso + is_function(Pre, 0) andalso is_function(Case, 1) andalso is_function(Post, 1) -> tc_begin(TCName, Name, Verbosity), - try Pre() of - State -> - tc_print("pre done: try test case"), - try - begin - Res = Case(State), - sleep(seconds(1)), - tc_print("test case done: try post"), - _ = executor(fun() -> - put(verbosity, Verbosity), - put(sname, Name), - put(tc, TCName), - Post(State) - end), - tc_end("ok"), - Res - end - catch - C:{skip, _} = SKIP:_ when (C =:= throw) orelse - (C =:= exit) -> - tc_print("test case (~w) skip: try post", [C]), - _ = executor(fun() -> - put(verbosity, Verbosity), - put(sname, Name), - put(tc, TCName), - Post(State) - end), - tc_end( f("skipping(caught,~w,tc)", [C]) ), - SKIP; - C:E:S -> - %% We always check the system events - %% before we accept a failure. - %% We do *not* run the Post here because it might - %% generate sys events itself... - p("try_tc -> test case failed: try post"), - _ = executor(fun() -> Post(State) end), - case megaco_test_global_sys_monitor:events() of - [] -> - tc_print("test case failed: try post"), + try Cond() of + ok -> + tc_print("starting: try pre"), + try Pre() of + State -> + tc_print("pre done: try test case"), + try + begin + Res = Case(State), + sleep(seconds(1)), + tc_print("test case done: try post"), _ = executor(fun() -> put(verbosity, Verbosity), put(sname, Name), put(tc, TCName), Post(State) end), - tc_end( f("failed(caught,~w,tc)", [C]) ), - erlang:raise(C, E, S); - SysEvs -> - tc_print("System Events received during tc: " - "~n ~p" - "~nwhen tc failed:" - "~n C: ~p" - "~n E: ~p" - "~n S: ~p", - [SysEvs, C, E, S]), + tc_end("ok"), + Res + end + catch + C:{skip, _} = SKIP:_ when (C =:= throw) orelse + (C =:= exit) -> + tc_print("test case (~w) skip: try post", [C]), _ = executor(fun() -> put(verbosity, Verbosity), put(sname, Name), put(tc, TCName), Post(State) end), - tc_end( f("skipping(catched-sysevs,~w,tc)", + tc_end( f("skipping(caught,~w,tc)", [C]) ), + SKIP; + C:E:S -> + %% We always check the system events + %% before we accept a failure. + %% We do *not* run the Post here because it might + %% generate sys events itself... + p("try_tc -> test case failed: try post"), + _ = executor(fun() -> Post(State) end), + case megaco_test_global_sys_monitor:events() of + [] -> + tc_print("test case failed: try post"), + _ = executor(fun() -> + put(verbosity, + Verbosity), + put(sname, Name), + put(tc, TCName), + Post(State) + end), + tc_end( f("failed(caught,~w,tc)", [C]) ), + erlang:raise(C, E, S); + SysEvs -> + tc_print("System Events " + "received during tc: " + "~n ~p" + "~nwhen tc failed:" + "~n C: ~p" + "~n E: ~p" + "~n S: ~p", + [SysEvs, C, E, S]), + _ = executor(fun() -> + put(verbosity, + Verbosity), + put(sname, Name), + put(tc, TCName), + Post(State) + end), + tc_end( f("skipping(catched-sysevs,~w,tc)", + [C]) ), + SKIP = + {skip, "TC failure with system events"}, + SKIP + end + end + catch + C:{skip, _} = SKIP:_ when (C =:= throw) orelse + (C =:= exit) -> + tc_end( f("skipping(caught,~w,tc-pre)", [C]) ), + SKIP; + C:E:S -> + case megaco_test_global_sys_monitor:events() of + [] -> + tc_print("tc-pre failed: auto-skip" + "~n C: ~p" + "~n E: ~p" + "~n S: ~p", + [C, E, S]), + tc_end( f("auto-skip(caught,~w,tc-pre)", [C]) ), + SKIP = {skip, f("TC-Pre failure (~w)", [C])}, + SKIP; + SysEvs -> + tc_print("System Events received: " + "~n ~p" + "~nwhen tc-pre failed:" + "~n C: ~p" + "~n E: ~p" + "~n S: ~p", + [SysEvs, C, E, S], "", ""), + tc_end( f("skipping(catched-sysevs,~w,tc-pre)", [C]) ), - SKIP = {skip, "TC failure with system events"}, + SKIP = {skip, "TC-Pre failure with system events"}, SKIP - end - end + end + end; + {skip, _} = SKIP -> + tc_end("skipping(cond)"), + SKIP; + {error, Reason} -> + tc_end("failed(cond)"), + exit({tc_cond_failed, Reason}) catch - C:{skip, _} = SKIP:_ when (C =:= throw) orelse - (C =:= exit) -> - tc_end( f("skipping(caught,~w,tc-pre)", [C]) ), + C:{skip, _} = SKIP when ((C =:= throw) orelse (C =:= exit)) -> + tc_end( f("skipping(caught,~w,cond)", [C]) ), SKIP; C:E:S -> + %% We always check the system events before we accept a failure case megaco_test_global_sys_monitor:events() of [] -> - tc_print("tc-pre failed: auto-skip" - "~n C: ~p" - "~n E: ~p" - "~n S: ~p", - [C, E, S]), - tc_end( f("auto-skip(caught,~w,tc-pre)", [C]) ), - SKIP = {skip, f("TC-Pre failure (~w)", [C])}, - SKIP; + tc_end( f("failed(caught,~w,cond)", [C]) ), + erlang:raise(C, E, S); SysEvs -> tc_print("System Events received: " - "~n ~p" - "~nwhen tc-pre failed:" - "~n C: ~p" - "~n E: ~p" - "~n S: ~p", - [SysEvs, C, E, S], "", ""), - tc_end( f("skipping(catched-sysevs,~w,tc-pre)", [C]) ), - SKIP = {skip, "TC-Pre failure with system events"}, + "~n ~p", [SysEvs], "", ""), + tc_end( f("skipping(catched-sysevs,~w,cond)", [C]) ), + SKIP = {skip, "TC cond failure with system events"}, SKIP end end. @@ -2525,6 +2660,16 @@ stop_node(Node) -> end. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +timetrap_scale_factor() -> + case (catch test_server:timetrap_scale_factor()) of + {'EXIT', _} -> + 1; + N -> + N + end. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/lib/megaco/test/megaco_test_lib.hrl b/lib/megaco/test/megaco_test_lib.hrl index cb6d6ace7a..5f5a26adf9 100644 --- a/lib/megaco/test/megaco_test_lib.hrl +++ b/lib/megaco/test/megaco_test_lib.hrl @@ -90,6 +90,8 @@ -define(TRY_TC(TCN, N, V, PRE, CASE, POST), ?LIB:try_tc(TCN, N, V, PRE, CASE, POST)). +-define(TRY_TC(TCN, N, V, COND, PRE, CASE, POST), + ?LIB:try_tc(TCN, N, V, COND, PRE, CASE, POST)). -define(ACQUIRE_NODES(N, Config), ?LIB:prepare_test_case([init, {stop_app, megaco}], diff --git a/lib/megaco/test/megaco_timer_SUITE.erl b/lib/megaco/test/megaco_timer_SUITE.erl index c150dad897..2cdd83481b 100644 --- a/lib/megaco/test/megaco_timer_SUITE.erl +++ b/lib/megaco/test/megaco_timer_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2019. All Rights Reserved. +%% Copyright Ericsson AB 2007-2022. 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. @@ -143,9 +143,6 @@ end_per_group(_GroupName, Config) -> %% ----- %% -%% init_per_testcase(multi_user_extreme_load = Case, Config) -> -%% C = lists:keydelete(tc_timeout, 1, Config), -%% do_init_per_testcase(Case, [{tc_timeout, min(20)}|C]); init_per_testcase(Case, Config) -> do_init_per_testcase(Case, Config). @@ -183,6 +180,12 @@ simple_init(suite) -> simple_init(doc) -> []; simple_init(Config) when is_list(Config) -> + Pre = fun() -> #{} end, + Case = fun(_) -> do_simple_init() end, + Post = fun(_) -> ok end, + try_tc(?FUNCTION_NAME, Pre, Case, Post). + +do_simple_init() -> put(verbosity, ?TEST_VERBOSITY), put(tc, si), put(sname, "TEST"), @@ -297,6 +300,12 @@ simple_usage(suite) -> simple_usage(doc) -> []; simple_usage(Config) when is_list(Config) -> + Pre = fun() -> #{} end, + Case = fun(_) -> do_simple_usage() end, + Post = fun(_) -> ok end, + try_tc(?FUNCTION_NAME, Pre, Case, Post). + +do_simple_usage() -> put(verbosity, ?TEST_VERBOSITY), put(tc, su), put(sname, "TEST"), @@ -389,23 +398,34 @@ integer_timer_start_and_expire(suite) -> integer_timer_start_and_expire(doc) -> []; integer_timer_start_and_expire(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(tc, itsae), - put(sname, "TEST"), - i("starting"), - + Cond = fun() -> + Key = megaco_factor, + case lists:keysearch(Key, 1, Config) of + {value, {Key, F}} when (F > 5) -> + {skip, ?F("Megaco Factor (~w) > 5", [F])}; + _ -> + ok + end + end, + Pre = fun() -> #{} end, + Case = fun(_) -> do_integer_timer_start_and_expire() end, + Post = fun(_) -> ok end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_integer_timer_start_and_expire() -> Timeout = 5000, + i("start timer"), Ref = tmr_start(Timeout), + i("await timer expire"), receive - {timeout, Timeout} -> - ok + {timeout, Timeout} -> + i("received expected timer expire message"), + ok after Timeout + 500 -> - tmr_stop(Ref), - no_timeout() - end, - - i("done", []), - ok. + i("timeout-message timeout"), + tmr_stop(Ref), + no_timeout() + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -415,9 +435,21 @@ integer_timer_start_and_stop(suite) -> integer_timer_start_and_stop(doc) -> []; integer_timer_start_and_stop(Config) when is_list(Config) -> - put(verbosity, ?TEST_VERBOSITY), - put(tc, itsas), - put(sname, "TEST"), + Cond = fun() -> + Key = megaco_factor, + case lists:keysearch(Key, 1, Config) of + {value, {Key, F}} when (F > 5) -> + {skip, ?F("Megaco Factor (~w) > 5", [F])}; + _ -> + ok + end + end, + Pre = fun() -> #{} end, + Case = fun(_) -> do_integer_timer_start_and_stop() end, + Post = fun(_) -> ok end, + try_tc(?FUNCTION_NAME, Cond, Pre, Case, Post). + +do_integer_timer_start_and_stop() -> i("starting"), Timeout = 5000, @@ -475,6 +507,16 @@ timeout(Pid, Timeout, Tc) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +try_tc(Name, Pre, Case, Post) -> + Cond = fun() -> ok end, + try_tc(Name, Cond, Pre, Case, Post). + +try_tc(Name, Cond, Pre, Case, Post) -> + ?TRY_TC(Name, "TEST", ?TEST_VERBOSITY, Cond, Pre, Case, Post). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + unexpected_result(A, B) -> error({unexpected_result, A, B}). |
