1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2008-2019. 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.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
%%
%%----------------------------------------------------------------------
%% Purpose: Test various aspects of the flex scanner handling
%%
%% Test: ts:run(megaco, megaco_flex_SUITE, [batch]).
%%
%%----------------------------------------------------------------------
-module(megaco_flex_SUITE).
-include("megaco_test_lib.hrl").
-export([
suite/0, all/0, groups/0,
init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2,
init_per_testcase/2, end_per_testcase/2,
plain/1,
port_exit/1,
garbage_in/1
]).
%%======================================================================
%% Common Test interface functions
%%======================================================================
suite() ->
[{ct_hooks, [ts_install_cth]}].
all() ->
[
plain,
port_exit,
garbage_in
].
groups() ->
[].
%%
%% -----
%%
init_per_suite(suite) ->
[];
init_per_suite(doc) ->
[];
init_per_suite(Config0) when is_list(Config0) ->
?ANNOUNCE_SUITE_INIT(),
p("init_per_suite -> entry with"
"~n Config: ~p"
"~n Nodes: ~p", [Config0, erlang:nodes()]),
case ?LIB:init_per_suite(Config0) of
{skip, _} = SKIP ->
SKIP;
Config1 when is_list(Config1) ->
case megaco_flex_scanner:is_enabled() of
true ->
%% We need a (local) monitor on this node also
megaco_test_sys_monitor:start(),
p("init_per_suite -> end when"
"~n Config: ~p"
"~n Nodes: ~p", [Config1, erlang:nodes()]),
Config1;
false ->
?SKIP(flex_scanner_not_enabled)
end
end.
end_per_suite(suite) -> [];
end_per_suite(doc) -> [];
end_per_suite(Config0) when is_list(Config0) ->
p("end_per_suite -> entry with"
"~n Config: ~p"
"~n Nodes: ~p", [Config0, erlang:nodes()]),
megaco_test_sys_monitor:stop(),
Config1 = ?LIB:end_per_suite(Config0),
p("end_per_suite -> end when"
"~n Nodes: ~p", [erlang:nodes()]),
Config1.
%%
%% -----
%%
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, Config) ->
Config.
%%
%% -----
%%
init_per_testcase(Case, Config) ->
p("init_per_testcase -> entry with"
"~n Config: ~p"
"~n Nodes: ~p", [Config, erlang:nodes()]),
megaco_test_global_sys_monitor:reset_events(),
megaco_test_lib:init_per_testcase(Case, Config).
end_per_testcase(Case, Config) ->
p("end_per_testcase -> entry with"
"~n Config: ~p"
"~n Nodes: ~p", [Config, erlang:nodes()]),
p("system events during test: "
"~n ~p", [megaco_test_global_sys_monitor:events()]),
megaco_test_lib:end_per_testcase(Case, Config).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plain(suite) ->
[];
plain(doc) ->
["This is to simply test that it is possible to start and stop the "
"flex handler."];
plain(Config) when is_list(Config) ->
put(tc, plain),
p("begin"),
process_flag(trap_exit, true),
p("start the flex handler"),
{ok, Pid, _PortInfo} = flex_scanner_handler_start(),
p("stop handler"),
flex_scanner_handler_stop(Pid),
p("end"),
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
port_exit(suite) ->
[];
port_exit(doc) ->
["Test that the handler detects and handles an exiting port."];
port_exit(Config) when is_list(Config) ->
put(tc, port_exit),
p("begin"),
process_flag(trap_exit, true),
p("start the flex handler"),
{ok, Pid, {flex, PortOrPorts}} = flex_scanner_handler_start(),
Port = case PortOrPorts of
P when is_port(P) ->
P;
Ports when is_tuple(Ports) ->
%% It does not matter which of the ports we choose
element(1, PortOrPorts);
Ports when is_list(Ports) ->
%% It does not matter which of the ports we choose
hd(Ports)
end,
p("simulate crash"),
exit(Port, simulated_crash),
p("await handler exit"),
receive
{'EXIT', Pid, _} ->
p("end"),
ok
after 5000 ->
p("timeout - stop handler"),
flex_scanner_handler_stop(Pid),
p("end after timeout"),
{error, timeout}
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
garbage_in(suite) ->
[];
garbage_in(doc) ->
["Send in various unexpected messages and requeststo the handler "
"to see that it does die on us. "];
garbage_in(Config) when is_list(Config) ->
put(tc, garbage_in),
p("begin"),
process_flag(trap_exit, true),
p("start the flex handler"),
{ok, Pid, _PortInfo} = flex_scanner_handler_start(),
p("make an invalid call"),
{error, _} = gen_server:call(Pid, garbage_request),
p("make an invalid cast"),
gen_server:cast(Pid, garbage_msg),
p("send an unknown message"),
Pid ! garbage_info,
p("wait for any garbage response"),
receive
Any ->
p("end with unexpected message: ~p", [Any]),
{error, {unexpected_msg, Any}}
after 1000 ->
p("end with nothing received - stop handler"),
flex_scanner_handler_stop(Pid),
ok
end.
%% ------- Misc functions --------
flex_scanner_handler_start() ->
case megaco_flex_scanner_handler:start_link() of
{error, {failed_starting_scanner, {error, {load_driver, _}}}} ->
p("failed loading driver"),
?SKIP(could_not_load_driver);
{error, {failed_starting_scanner, {load_driver, _}}} ->
p("failed loading driver"),
?SKIP(could_not_load_driver);
{error, {failed_starting_scanner, {load_driver, _}, _}} ->
p("failed loading driver"),
?SKIP(could_not_load_driver);
Else ->
p("driver load result: ~p", [Else]),
Else
end.
flex_scanner_handler_stop(Pid) ->
megaco_flex_scanner_handler:stop(Pid).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p(F) ->
p(F, []).
p(F, A) ->
case get(tc) of
undefined ->
io:format("*** [~s] ~p ***"
"~n" ++ F ++ "~n", [?FTS(), self() | A]);
TC ->
io:format("*** [~s] ~p ~w ***"
"~n " ++ F ++ "~n",
[?FTS(), self(), TC | A])
end.
|