diff options
author | Micael Karlberg <bmk@erlang.org> | 2021-07-23 09:58:09 +0200 |
---|---|---|
committer | Micael Karlberg <bmk@erlang.org> | 2021-08-30 16:41:16 +0200 |
commit | 15d2b365f363dc118cc290b1640cc18f85f25ca7 (patch) | |
tree | 3d6b82f33459cc6734c9a30ac9eee5e618439cfb /lib/megaco/test | |
parent | b0bea27e7b7d0f189f4015c68c8ff2c1586a909c (diff) | |
download | erlang-15d2b365f363dc118cc290b1640cc18f85f25ca7.tar.gz |
[megaco|udp-transport|test] Add top groups for testing inet_backend's
Add top groups for testing the different backends (inet or
socket) in the megaco_udp_SUITE.
OTP-17533
Diffstat (limited to 'lib/megaco/test')
-rw-r--r-- | lib/megaco/test/megaco_test_lib.erl | 69 | ||||
-rw-r--r-- | lib/megaco/test/megaco_test_lib.hrl | 10 | ||||
-rw-r--r-- | lib/megaco/test/megaco_udp_SUITE.erl | 155 |
3 files changed, 186 insertions, 48 deletions
diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl index 10e7ed90c8..4e6dd93ebf 100644 --- a/lib/megaco/test/megaco_test_lib.erl +++ b/lib/megaco/test/megaco_test_lib.erl @@ -60,7 +60,12 @@ start_node/3, start_node/4, stop_nodes/3, - stop_node/3 + stop_node/3, + + is_socket_backend/1, + inet_backend_opts/1, + explicit_inet_backend/0, test_inet_backends/0, + open/3 ]). -export([init_per_suite/1, end_per_suite/1, @@ -2209,3 +2214,65 @@ p(F, A) -> print(Pre, F, A) -> io:format("*** [~s] [~s] ~p " ++ F ++ "~n", [?FTS(), Pre, self() | A]). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +explicit_inet_backend() -> + %% This is intentional! + %% This is a kernel flag, which if set disables + %% our own special handling of the inet_backend + %% in our test suites. + case application:get_all_env(kernel) of + Env when is_list(Env) -> + case lists:keysearch(inet_backend, 1, Env) of + {value, {inet_backend, _}} -> + true; + _ -> + false + end; + _ -> + false + end. + +test_inet_backends() -> + case init:get_argument(megaco) of + {ok, SnmpArgs} when is_list(SnmpArgs) -> + test_inet_backends(SnmpArgs, atom_to_list(?FUNCTION_NAME)); + error -> + false + end. + +test_inet_backends([], _) -> + false; +test_inet_backends([[Key, Val] | _], Key) -> + case list_to_atom(string:to_lower(Val)) of + Bool when is_boolean(Bool) -> + Bool; + _ -> + false + end; +test_inet_backends([_|Args], Key) -> + test_inet_backends(Args, Key). + + +inet_backend_opts(Config) when is_list(Config) -> + case lists:keysearch(socket_create_opts, 1, Config) of + {value, {socket_create_opts, InetBackendOpts}} -> + InetBackendOpts; + false -> + [] + end. + +is_socket_backend(Config) when is_list(Config) -> + case lists:keysearch(socket_create_opts, 1, Config) of + {value, {socket_create_opts, [{inet_backend, socket}]}} -> + true; + _ -> + false + end. + + +open(Config, Pid, Opts) + when is_list(Config) andalso is_pid(Pid) andalso is_list(Opts) -> + InetBackendOpts = inet_backend_opts(Config), + megaco_udp:open(Pid, InetBackendOpts ++ Opts). + diff --git a/lib/megaco/test/megaco_test_lib.hrl b/lib/megaco/test/megaco_test_lib.hrl index 0777adbcd0..cc41979b43 100644 --- a/lib/megaco/test/megaco_test_lib.hrl +++ b/lib/megaco/test/megaco_test_lib.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2020. All Rights Reserved. +%% Copyright Ericsson AB 1999-2021. 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. @@ -106,6 +106,14 @@ -define(FTS(TS), megaco:format_timestamp(TS)). -define(F(F,A), lists:flatten(io_lib:format(F, A))). +-define(INET_BACKEND_OPTS(C), ?LIB:inet_backend_opts(C)). +-define(EXPLICIT_INET_BACKEND(), ?LIB:explicit_inet_backend()). +-define(TEST_INET_BACKENDS(), ?LIB:test_inet_backends()). +-define(IS_SOCKET_BACKEND(C), ?LIB:is_socket_backend(C)). + +-define(OPEN(C, P, O), ?LIB:open(C, P, O)). + + -define(ANNOUNCE_SUITE_INIT(), io:format(user, "~n*** ~s *** suite ~w init~n~n", [?FTS(), ?MODULE])). -define(ANNOUNCE_GROUP_INIT(GR), diff --git a/lib/megaco/test/megaco_udp_SUITE.erl b/lib/megaco/test/megaco_udp_SUITE.erl index e8fea517f6..e59714804c 100644 --- a/lib/megaco/test/megaco_udp_SUITE.erl +++ b/lib/megaco/test/megaco_udp_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2020 All Rights Reserved. +%% Copyright Ericsson AB 2000-2021 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,17 +81,54 @@ suite() -> [{ct_hooks, [ts_install_cth]}]. all() -> + %% This is a temporary messure to ensure that we can + %% test the socket backend without effecting *all* + %% applications on *all* machines. + %% This flag is set only for *one* host. + case ?TEST_INET_BACKENDS() of + true -> + [ + {group, inet_backend_default}, + {group, inet_backend_inet}, + {group, inet_backend_socket} + ]; + _ -> + [ + {group, inet_backend_default} + ] + end. + %% [ + %% {group, start}, + %% {group, sending}, + %% {group, error} + %% ]. + +groups() -> [ - {group, start}, - {group, sending}, - {group, error} + {inet_backend_default, [], inet_backend_default_cases()}, + {inet_backend_inet, [], inet_backend_inet_cases()}, + {inet_backend_socket, [], inet_backend_socket_cases()}, + + {all, [], all_cases()}, + {start, [], start_cases()}, + {sending, [], sending_cases()}, + {error, [], error_cases()} ]. -groups() -> +inet_backend_default_cases() -> + [{all, [], all_cases()}]. + +inet_backend_inet_cases() -> + [{all, [], all_cases()}]. + +inet_backend_socket_cases() -> + [{all, [], all_cases()}]. + +all_cases() -> [ - {start, [], start_cases()}, - {sending, [], sending_cases()}, - {error, [], error_cases()} + {group, start}, + {group, sending}, + {group, error} ]. start_cases() -> @@ -167,6 +204,29 @@ end_per_suite(Config0) when is_list(Config0) -> %% ----- %% +init_per_group(inet_backend_default = Group, Config) -> + ?ANNOUNCE_GROUP_INIT(Group), + [{socket_create_opts, []} | Config]; +init_per_group(inet_backend_inet = Group, Config) -> + ?ANNOUNCE_GROUP_INIT(Group), + case ?EXPLICIT_INET_BACKEND() of + true -> + %% The environment trumps us, + %% so only the default group should be run! + {skip, "explicit inet backend"}; + false -> + [{socket_create_opts, [{inet_backend, inet}]} | Config] + end; +init_per_group(inet_backend_socket = Group, Config) -> + ?ANNOUNCE_GROUP_INIT(Group), + case ?EXPLICIT_INET_BACKEND() of + true -> + %% The environment trumps us, + %% so only the default group should be run! + {skip, "explicit inet backend"}; + false -> + [{socket_create_opts, [{inet_backend, socket}]} | Config] + end; init_per_group(Group, Config) -> ?ANNOUNCE_GROUP_INIT(Group), Config. @@ -203,7 +263,6 @@ end_per_testcase(Case, Config) -> - %% ================================================= %% %% ------------------ start ------------------------ @@ -217,7 +276,7 @@ start_normal(suite) -> start_normal(Config) when is_list(Config) -> ?ACQUIRE_NODES(1, Config), Opts = [{port, 0}, {receive_handle, apa}], - {ok, Pid} = start_case(Opts, ok), + {ok, Pid} = start_case(Config, Opts, ok), megaco_udp:stop_transport(Pid), ok. @@ -229,7 +288,7 @@ start_invalid_opt(suite) -> start_invalid_opt(Config) when is_list(Config) -> ?ACQUIRE_NODES(1, Config), Opts = [{port, 0}, {receivehandle, apa}], - start_case(Opts, error). + start_case(Config, Opts, error). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -250,22 +309,22 @@ start_and_stop(Config) when is_list(Config) -> ok = ?START_NODES(Nodes), Nodes end, - Case = fun(X) -> do_start_and_stop(Factor, X) end, + Case = fun(X) -> do_start_and_stop(Config, Factor, X) end, Post = fun(Nodes) -> p("stop nodes"), ?STOP_NODES(lists:reverse(Nodes)) end, try_tc(start_and_stop, Pre, Case, Post). -do_start_and_stop(Factor, [ServerNode, ClientNode]) -> +do_start_and_stop(Config, Factor, [ServerNode, ClientNode]) -> %% Create command sequences TOCalc = fun(BaseTO) -> to_calc(Factor, BaseTO) end, TO = TOCalc(?SECS(5)), p("create command sequences"), ServerPort = 2944, - ServerCmds = start_and_stop_server_commands(ServerPort), + ServerCmds = start_and_stop_server_commands(Config, ServerPort), {ok, ServerHost} = inet:gethostname(), - ClientCmds = start_and_stop_client_commands(TO, ServerPort, ServerHost), + ClientCmds = start_and_stop_client_commands(Config, TO, ServerPort, ServerHost), %% Start the test procs used in the test-case, one for each node p("start command handlers"), @@ -294,7 +353,7 @@ do_start_and_stop(Factor, [ServerNode, ClientNode]) -> ok. -start_and_stop_server_commands(Port) -> +start_and_stop_server_commands(Config, Port) -> Opts = [{port, Port}], Self = self(), [ @@ -313,7 +372,7 @@ start_and_stop_server_commands(Port) -> #{id => 3, desc => "Open", cmd => fun(State) -> - server_open(State, Opts) + server_open(Config, State, Opts) end}, #{id => 4, @@ -342,7 +401,7 @@ start_and_stop_server_commands(Port) -> ]. -start_and_stop_client_commands(TO, ServerPort, _ServerHost) -> +start_and_stop_client_commands(Config, TO, ServerPort, _ServerHost) -> Opts = [{port, ServerPort}], Self = self(), [ @@ -361,7 +420,7 @@ start_and_stop_client_commands(TO, ServerPort, _ServerHost) -> #{id => 3, desc => "Open", cmd => fun(State) -> - client_open(State, Opts) + client_open(Config, State, Opts) end}, #{id => 4, @@ -414,22 +473,22 @@ sendreceive(Config) when is_list(Config) -> ok = ?START_NODES(Nodes), Nodes end, - Case = fun(X) -> do_sendreceive(Factor, X) end, + Case = fun(X) -> do_sendreceive(Config, Factor, X) end, Post = fun(Nodes) -> p("stop nodes"), ?STOP_NODES(lists:reverse(Nodes)) end, try_tc(sendreceive, Pre, Case, Post). -do_sendreceive(Factor, [ServerNode, ClientNode]) -> +do_sendreceive(Config, Factor, [ServerNode, ClientNode]) -> %% Create command sequences p("create command sequences"), TOCalc = fun(BaseTO) -> to_calc(Factor, BaseTO) end, TO = TOCalc(?SECS(5)), ServerPort = 2944, - ServerCmds = sendreceive_server_commands(TO, ServerPort), + ServerCmds = sendreceive_server_commands(Config, TO, ServerPort), {ok, ServerHost} = inet:gethostname(), - ClientCmds = sendreceive_client_commands(TO, ServerPort, ServerHost), + ClientCmds = sendreceive_client_commands(Config, TO, ServerPort, ServerHost), %% Start the test procs used in the test-case, one for each node p("start command handlers"), @@ -458,7 +517,7 @@ do_sendreceive(Factor, [ServerNode, ClientNode]) -> ok. -sendreceive_server_commands(TO, Port) -> +sendreceive_server_commands(Config, TO, Port) -> Opts = [{port, Port}], Self = self(), [ @@ -477,7 +536,7 @@ sendreceive_server_commands(TO, Port) -> #{id => 3, desc => "Open", cmd => fun(State) -> - server_open(State, Opts) + server_open(Config, State, Opts) end}, #{id => 4, @@ -541,7 +600,7 @@ sendreceive_server_commands(TO, Port) -> end} ]. -sendreceive_client_commands(TO, ServerPort, ServerHost) -> +sendreceive_client_commands(Config, TO, ServerPort, ServerHost) -> OwnPort = ServerPort+1, Opts = [{port, OwnPort}], Self = self(), @@ -561,7 +620,7 @@ sendreceive_client_commands(TO, ServerPort, ServerHost) -> #{id => 3, desc => "Open", cmd => fun(State) -> - client_open(State, Opts) + client_open(Config, State, Opts) end}, #{id => 4, @@ -643,23 +702,23 @@ block_unblock(Config) when is_list(Config) -> ok = ?START_NODES(Nodes), Nodes end, - Case = fun(X) -> do_block_unblock(Factor, X) end, + Case = fun(X) -> do_block_unblock(Config, Factor, X) end, Post = fun(Nodes) -> p("stop nodes"), ?STOP_NODES(lists:reverse(Nodes)) end, try_tc(block_unblock, Pre, Case, Post). -do_block_unblock(Factor, [ServerNode, ClientNode]) -> +do_block_unblock(Config, Factor, [ServerNode, ClientNode]) -> %% Create command sequences p("create command sequences"), TOCalc = fun(BaseTO) -> to_calc(Factor, BaseTO) end, TO = TOCalc(?SECS(5)), ServerPort = 2944, p("generated command sequences with timeout: ~w msec", [TO]), - ServerCmds = block_unblock_server_commands(TO, ServerPort), + ServerCmds = block_unblock_server_commands(Config, TO, ServerPort), {ok, ServerHost} = inet:gethostname(), - ClientCmds = block_unblock_client_commands(TO, ServerPort, ServerHost), + ClientCmds = block_unblock_client_commands(Config, TO, ServerPort, ServerHost), %% Start the test procs used in the test-case, one for each node p("start command handlers"), @@ -707,7 +766,7 @@ do_block_unblock(Factor, [ServerNode, ClientNode]) -> ok. -block_unblock_server_commands(TO, Port) -> +block_unblock_server_commands(Config, TO, Port) -> Opts = [{port, Port}], Self = self(), [ @@ -726,7 +785,7 @@ block_unblock_server_commands(TO, Port) -> #{id => 3, desc => "Open", cmd => fun(State) -> - server_open(State, Opts) + server_open(Config, State, Opts) end}, #{id => 4, @@ -791,7 +850,7 @@ block_unblock_server_commands(TO, Port) -> ]. -block_unblock_client_commands(TO, ServerPort, ServerHost) -> +block_unblock_client_commands(Config, TO, ServerPort, ServerHost) -> OwnPort = ServerPort+1, Opts = [{port, OwnPort}], Self = self(), @@ -811,7 +870,7 @@ block_unblock_client_commands(TO, ServerPort, ServerHost) -> #{id => 3, desc => "Open", cmd => fun(State) -> - client_open(State, Opts) + client_open(Config, State, Opts) end}, #{id => 4, @@ -842,7 +901,7 @@ block_unblock_client_commands(TO, ServerPort, ServerHost) -> desc => "Pre-Block info", cmd => fun(#{socket := Socket} = State) -> p("Socket Info: " - "~n Port Info: ~p", [erlang:port_info(Socket)]), + "~n Port Info: ~p", [inet:info(Socket)]), {ok, State} end}, @@ -865,7 +924,7 @@ block_unblock_client_commands(TO, ServerPort, ServerHost) -> p("Socket Info: " "~n Active: ~p" "~n Port Info: ~p", - [Active, erlang:port_info(Socket)]), + [Active, inet:info(Socket)]), {ok, State} end}, @@ -890,7 +949,7 @@ block_unblock_client_commands(TO, ServerPort, ServerHost) -> p("Socket Info: " "~n Active: ~p" "~n Port Info: ~p", - [Active, erlang:port_info(Socket)]), + [Active, inet:info(Socket)]), ok end, client_await_nothing(State, Fail, TO div 2) @@ -909,7 +968,7 @@ block_unblock_client_commands(TO, ServerPort, ServerHost) -> p("Socket Info: " "~n Active: ~p" "~n Port Info: ~p", - [Active, erlang:port_info(Socket)]), + [Active, inet:info(Socket)]), {ok, State} end}, @@ -932,7 +991,7 @@ block_unblock_client_commands(TO, ServerPort, ServerHost) -> p("Socket Info: " "~n Active: ~p" "~n Port Info: ~p", - [Active, erlang:port_info(Socket)]), + [Active, inet:info(Socket)]), {ok, State} end}, @@ -991,10 +1050,10 @@ socket_failure(Config) when is_list(Config) -> %% Test functions %%====================================================================== -start_case(Opts, Expect) -> +start_case(Config, Opts, Expect) -> case (catch megaco_udp:start_transport()) of {ok, Pid} -> - case (catch megaco_udp:open(Pid, Opts)) of + case (catch ?OPEN(Config, Pid, Opts)) of {ok, _Handle, _CtrlPid} when Expect =:= ok -> {ok, Pid}; {ok, Handle, CtrlPid} -> @@ -1048,16 +1107,20 @@ server_start_command_handler(Node, Commands) -> server_start_transport(State) when is_map(State) -> case (catch megaco_udp:start_transport()) of {ok, Ref} -> + p("Transport started: ~p", [Ref]), {ok, State#{transport_ref => Ref}}; Error -> Error end. -server_open(#{transport_ref := Ref} = State, Options) +server_open(Config, #{transport_ref := Ref} = State, Options) when is_list(Options) -> Opts = [{receive_handle, self()}, {module, ?MODULE} | Options], - try megaco_udp:open(Ref, Opts) of + try ?OPEN(Config, Ref, Opts) of {ok, Socket, ControlPid} -> + p("opened: " + "~n Socket: ~p" + "~n ControlPid: ~p", [Socket, ControlPid]), {ok, State#{handle => {socket, Socket}, % Temporary control_pid => ControlPid}}; {error, {could_not_open_udp_port, eaddrinuse}} -> @@ -1167,10 +1230,10 @@ client_start_transport(State) when is_map(State) -> Error end. -client_open(#{transport_ref := Ref} = State, Options) +client_open(Config, #{transport_ref := Ref} = State, Options) when is_list(Options) -> Opts = [{receive_handle, self()}, {module, ?MODULE} | Options], - try megaco_udp:open(Ref, Opts) of + try ?OPEN(Config, Ref, Opts) of {ok, Socket, ControlPid} -> {ok, State#{handle => {socket, Socket}, socket => Socket, |