73
74
["This is to simply test that it is possible to start and stop the "
75
76
plain(Config) when is_list(Config) ->
76
{ok, Pid, _PortInfo} = megaco_flex_scanner_handler:start_link(),
77
megaco_flex_scanner_handler:stop(Pid),
79
process_flag(trap_exit, true),
80
p("start the flex handler"),
81
{ok, Pid, _PortInfo} = flex_scanner_handler_start(),
83
flex_scanner_handler_stop(Pid),
86
93
["Test that the handler detects and handles an exiting port."];
87
94
port_exit(Config) when is_list(Config) ->
88
97
process_flag(trap_exit, true),
90
{ok, Pid, {flex, Port}} = megaco_flex_scanner_handler:start_link(),
99
p("start the flex handler"),
100
{ok, Pid, {flex, Port}} = flex_scanner_handler_start(),
92
103
exit(Port, simulated_crash),
105
p("await handler exit"),
95
107
{'EXIT', Pid, _} ->
98
megaco_flex_scanner_handler:stop(Pid),
111
p("timeout - stop handler"),
112
flex_scanner_handler_stop(Pid),
113
p("end after timeout"),
108
123
["Send in various unexpected messages and requeststo the handler "
109
124
"to see that it does die on us. "];
110
125
garbage_in(Config) when is_list(Config) ->
111
128
process_flag(trap_exit, true),
113
{ok, Pid, _PortInfo} = megaco_flex_scanner_handler:start_link(),
130
p("start the flex handler"),
131
{ok, Pid, _PortInfo} = flex_scanner_handler_start(),
133
p("make an invalid call"),
115
134
{error, _} = gen_server:call(Pid, garbage_request),
135
p("make an invalid cast"),
116
136
gen_server:cast(Pid, garbage_msg),
137
p("send an unknown message"),
117
138
Pid ! garbage_info,
140
p("wait for any garbage response"),
143
p("end with unexpected message: ~p", [Any]),
121
144
{error, {unexpected_msg, Any}}
123
megaco_flex_scanner_handler:stop(Pid),
146
p("end with nothing received - stop handler"),
147
flex_scanner_handler_stop(Pid),
153
%% ------- Misc functions --------
155
flex_scanner_handler_start() ->
156
case megaco_flex_scanner_handler:start_link() of
157
{error, {failed_starting_scanner, {error, {load_driver, _}}}} ->
158
p("failed loading driver"),
159
?SKIP(could_not_load_driver);
160
{error, {failed_starting_scanner, {load_driver, _}}} ->
161
p("failed loading driver"),
162
?SKIP(could_not_load_driver);
164
p("driver load result: ~p", [Else]),
168
flex_scanner_handler_stop(Pid) ->
169
megaco_flex_scanner_handler:stop(Pid).
172
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
io:format("*** [~s] ~p ~w ***"
181
[formated_timestamp(), self(), TC | A]).
183
formated_timestamp() ->
184
format_timestamp(erlang:now()).
186
format_timestamp({_N1, _N2, N3} = Now) ->
187
{Date, Time} = calendar:now_to_datetime(Now),
188
{YYYY, MM, DD} = Date,
189
{Hour, Min, Sec} = Time,
191
io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w 4~w",
192
[YYYY,MM,DD,Hour,Min,Sec,round(N3/1000)]),
193
lists:flatten(FormatDate).