aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common_test/test')
-rw-r--r--lib/common_test/test/ct_error_SUITE.erl61
-rw-r--r--lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl138
-rw-r--r--lib/common_test/test/ct_telnet_SUITE.erl135
-rw-r--r--lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl105
-rw-r--r--lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_own_server_SUITE.erl48
-rw-r--r--lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_timetrap_SUITE.erl4
-rw-r--r--lib/common_test/test/ct_test_support.erl52
-rw-r--r--lib/common_test/test/telnet_server.erl15
8 files changed, 475 insertions, 83 deletions
diff --git a/lib/common_test/test/ct_error_SUITE.erl b/lib/common_test/test/ct_error_SUITE.erl
index 28f0494d20..194e7d42ae 100644
--- a/lib/common_test/test/ct_error_SUITE.erl
+++ b/lib/common_test/test/ct_error_SUITE.erl
@@ -66,7 +66,7 @@ all() ->
[cfg_error, lib_error, no_compile, timetrap_end_conf,
timetrap_normal, timetrap_extended, timetrap_parallel,
timetrap_fun, timetrap_fun_group, misc_errors,
- config_restored].
+ config_restored, config_func_errors].
groups() ->
[].
@@ -310,6 +310,25 @@ config_restored(Config) when is_list(Config) ->
ok = ct_test_support:verify_events(TestEvents, Events, Config).
%%%-----------------------------------------------------------------
+%%%
+config_func_errors(Config) when is_list(Config) ->
+ DataDir = ?config(data_dir, Config),
+ Suite = filename:join(DataDir, "error/test/config_func_error_1_SUITE"),
+ {Opts,ERPid} = setup([{suite,Suite}],
+ Config),
+ ok = ct_test_support:run(Opts, Config),
+ Events = ct_test_support:get_events(ERPid, Config),
+
+ ct_test_support:log_events(config_func_errors,
+ reformat(Events, ?eh),
+ ?config(priv_dir, Config),
+ Opts),
+
+ TestEvents = events_to_check(config_func_errors),
+ ok = ct_test_support:verify_events(TestEvents, Events, Config).
+
+
+%%%-----------------------------------------------------------------
%%% HELP FUNCTIONS
%%%-----------------------------------------------------------------
@@ -323,8 +342,6 @@ setup(Test, Config) ->
reformat(Events, EH) ->
ct_test_support:reformat(Events, EH).
- %reformat(Events, _EH) ->
- % Events.
%%%-----------------------------------------------------------------
%%% TEST EVENTS
@@ -1498,4 +1515,42 @@ test_events(config_restored) ->
{?eh,tc_done,{config_restored_SUITE,end_per_suite,ok}},
{?eh,test_done,{'DEF','STOP_TIME'}},
{?eh,stop_logging,[]}
+ ];
+
+test_events(config_func_errors) ->
+ [
+ {?eh,start_logging,{'DEF','RUNDIR'}},
+ {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
+ {?eh,start_info,{1,1,4}},
+ {?eh,tc_start,{config_func_error_1_SUITE,init_per_suite}},
+ {?eh,tc_done,{config_func_error_1_SUITE,init_per_suite,ok}},
+
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_iptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_iptc,'_'}},
+ {?eh,test_stats,{0,1,{0,0}}},
+
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_eptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_eptc,'_'}},
+ {?eh,test_stats,{0,2,{0,0}}},
+
+ [{?eh,tc_start,{config_func_error_1_SUITE,{init_per_group,g1,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{init_per_group,g1,[]},ok}},
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_iptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_iptc,'_'}},
+ {?eh,test_stats,{0,3,{0,0}}},
+ {?eh,tc_start,{config_func_error_1_SUITE,{end_per_group,g1,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{end_per_group,g1,[]},ok}}],
+
+ [{?eh,tc_start,{config_func_error_1_SUITE,{init_per_group,g2,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{init_per_group,g2,[]},ok}},
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_eptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_eptc,'_'}},
+ {?eh,test_stats,{0,4,{0,0}}},
+ {?eh,tc_start,{config_func_error_1_SUITE,{end_per_group,g2,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{end_per_group,g2,[]},ok}}],
+
+ {?eh,tc_start,{config_func_error_1_SUITE,end_per_suite}},
+ {?eh,tc_done,{config_func_error_1_SUITE,end_per_suite,ok}},
+ {?eh,test_done,{'DEF','STOP_TIME'}},
+ {?eh,stop_logging,[]}
].
diff --git a/lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl b/lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl
new file mode 100644
index 0000000000..f1025213dc
--- /dev/null
+++ b/lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl
@@ -0,0 +1,138 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(config_func_error_1_SUITE).
+
+-compile(export_all).
+
+-include_lib("common_test/include/ct.hrl").
+
+%%--------------------------------------------------------------------
+%% Function: suite() -> Info
+%% Info = [tuple()]
+%%--------------------------------------------------------------------
+suite() ->
+ [{timetrap,{seconds,5}}].
+
+%%--------------------------------------------------------------------
+%% Function: init_per_suite(Config0) ->
+%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
+%% Config0 = Config1 = [tuple()]
+%% Reason = term()
+%%--------------------------------------------------------------------
+init_per_suite(Config) ->
+ Config.
+
+%%--------------------------------------------------------------------
+%% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
+%% Config0 = Config1 = [tuple()]
+%%--------------------------------------------------------------------
+end_per_suite(_Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Function: init_per_group(GroupName, Config0) ->
+%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
+%% GroupName = atom()
+%% Config0 = Config1 = [tuple()]
+%% Reason = term()
+%%--------------------------------------------------------------------
+init_per_group(_GroupName, Config) ->
+ Config.
+
+%%--------------------------------------------------------------------
+%% Function: end_per_group(GroupName, Config0) ->
+%% void() | {save_config,Config1}
+%% GroupName = atom()
+%% Config0 = Config1 = [tuple()]
+%%--------------------------------------------------------------------
+end_per_group(_GroupName, _Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Function: init_per_testcase(TestCase, Config0) ->
+%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
+%% TestCase = atom()
+%% Config0 = Config1 = [tuple()]
+%% Reason = term()
+%%--------------------------------------------------------------------
+bad_proc(Config) ->
+ ct:pal("Bye bye from ~p", [self()]),
+ %% this call will either generate an exit immediately
+ %% or return a fun to be executed here
+ ErrorFun = ct_test_support:random_error(Config),
+ ct:log("Calling error fun now...", []),
+ ErrorFun(),
+ ct:sleep(10000),
+ ok.
+
+init_per_testcase(exit_in_iptc, Config) ->
+ spawn_link(?MODULE, bad_proc, [Config]),
+ ct:sleep(10000),
+ Config;
+init_per_testcase(_, Config) ->
+ Config.
+
+%%--------------------------------------------------------------------
+%% Function: end_per_testcase(TestCase, Config0) ->
+%% void() | {save_config,Config1}
+%% TestCase = atom()
+%% Config0 = Config1 = [tuple()]
+%%--------------------------------------------------------------------
+end_per_testcase(exit_in_eptc, Config) ->
+ spawn_link(?MODULE, bad_proc, [Config]),
+ ct:sleep(10000),
+ ok;
+end_per_testcase(_TestCase, _Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Function: groups() -> [Group]
+%% Group = {GroupName,Properties,GroupsAndTestCases}
+%% GroupName = atom()
+%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
+%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
+%% TestCase = atom()
+%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
+%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
+%% repeat_until_any_ok | repeat_until_any_fail
+%% N = integer() | forever
+%%--------------------------------------------------------------------
+groups() ->
+ [{g1, [], [exit_in_iptc]},
+ {g2, [], [exit_in_eptc]}].
+
+%%--------------------------------------------------------------------
+%% Function: all() -> GroupsAndTestCases | {skip,Reason}
+%% GroupsAndTestCases = [{group,GroupName} | TestCase]
+%% GroupName = atom()
+%% TestCase = atom()
+%% Reason = term()
+%%--------------------------------------------------------------------
+all() ->
+ [exit_in_iptc,
+ exit_in_eptc,
+ {group, g1},
+ {group, g2}].
+
+exit_in_iptc(_) ->
+ ok.
+
+exit_in_eptc(_) ->
+ ok.
+
diff --git a/lib/common_test/test/ct_telnet_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE.erl
index e2ee207754..25debf09d4 100644
--- a/lib/common_test/test/ct_telnet_SUITE.erl
+++ b/lib/common_test/test/ct_telnet_SUITE.erl
@@ -46,6 +46,26 @@
%% instance, the tests need to be performed on a separate node (or
%% there will be clashes with logging processes etc).
%%--------------------------------------------------------------------
+suite() -> [{ct_hooks,[ts_install_cth]}].
+
+groups() ->
+ [{legacy, [], [unix_telnet,own_server,timetrap]},
+ {raw, [], [unix_telnet,own_server,timetrap]},
+ {html, [], [unix_telnet,own_server]},
+ {silent, [], [unix_telnet,own_server]}].
+
+all() ->
+ [
+ {group,legacy},
+ {group,raw},
+ {group,html},
+ {group,silent}
+ ].
+
+%%--------------------------------------------------------------------
+%% CONFIG FUNCTIONS
+%%--------------------------------------------------------------------
+
init_per_suite(Config) ->
ct_test_support:init_per_suite(Config).
@@ -67,14 +87,6 @@ end_per_testcase(TestCase, Config) ->
end,
ct_test_support:end_per_testcase(TestCase, Config).
-suite() -> [{ct_hooks,[ts_install_cth]}].
-
-all() ->
- [
- unix_telnet,
- own_server,
- timetrap
- ].
%%--------------------------------------------------------------------
%% TEST CASES
@@ -82,27 +94,43 @@ all() ->
%%%-----------------------------------------------------------------
%%%
-unix_telnet(Config) when is_list(Config) ->
- all_tests_in_suite(unix_telnet,"ct_telnet_basic_SUITE","telnet.cfg",Config).
+unix_telnet(Config) ->
+ CfgFile = "telnet.unix_telnet." ++
+ atom_to_list(groupname(Config)) ++ ".cfg",
+ all_tests_in_suite(unix_telnet,"ct_telnet_basic_SUITE",CfgFile,Config).
own_server(Config) ->
+ CfgFile = "telnet.own_server." ++
+ atom_to_list(groupname(Config)) ++ ".cfg",
all_tests_in_suite(own_server,"ct_telnet_own_server_SUITE",
- "telnet2.cfg",Config).
+ CfgFile,Config).
timetrap(Config) ->
+ CfgFile = "telnet.timetrap." ++
+ atom_to_list(groupname(Config)) ++ ".cfg",
all_tests_in_suite(timetrap,"ct_telnet_timetrap_SUITE",
- "telnet3.cfg",Config).
+ CfgFile,Config).
%%%-----------------------------------------------------------------
%%% HELP FUNCTIONS
%%%-----------------------------------------------------------------
+groupname(Config) ->
+ case proplists:get_value(tc_group_properties, Config) of
+ undefined ->
+ undefined;
+ TGP ->
+ proplists:get_value(name, TGP)
+ end.
+
all_tests_in_suite(TestCase, SuiteName, CfgFileName, Config) ->
+ PrivDir = ?config(priv_dir, Config),
DataDir = ?config(data_dir, Config),
Suite = filename:join(DataDir, SuiteName),
- CfgFile = filename:join(DataDir, CfgFileName),
- Cfg = telnet_config(TestCase),
- ok = file:write_file(CfgFile, io_lib:write(Cfg) ++ "."),
+ CfgFile = filename:join(PrivDir, CfgFileName),
+ Cfg = telnet_config(TestCase, groupname(Config)),
+ Txt = lists:flatten([lists:flatten(io_lib:write(C))++".\n" || C <- Cfg]),
+ ok = file:write_file(CfgFile, Txt),
{Opts,ERPid} = setup([{suite,Suite},
{label,TestCase},
{config,CfgFile}],
@@ -132,15 +160,36 @@ execute(Name, Opts, ERPid, Config) ->
reformat(Events, EH) ->
ct_test_support:reformat(Events, EH).
-
-telnet_config(unix_telnet) ->
- {unix, ct:get_config(unix)};
-telnet_config(_) ->
- {unix,[{telnet,"localhost"},
- {port, ?erl_telnet_server_port},
- {username,?erl_telnet_server_user},
- {password,?erl_telnet_server_pwd},
- {keep_alive,true}]}.
+telnet_config(_, undefined) ->
+ [];
+telnet_config(unix_telnet, legacy) ->
+ [{unix, ct:get_config(unix)},
+ {ct_conn_log,[]}];
+%% LogType same as GroupName
+telnet_config(unix_telnet, LogType) ->
+ [{unix, ct:get_config(unix)},
+ {ct_conn_log,
+ [{ct_telnet,[{log_type,LogType},
+ {hosts,[telnet_server_conn1,
+ telnet_server_conn2,
+ telnet_server_conn3,
+ telnet_server_conn4]}]}]}];
+telnet_config(_, LogType) ->
+ [{unix,[{telnet,"localhost"},
+ {port, ?erl_telnet_server_port},
+ {username,?erl_telnet_server_user},
+ {password,?erl_telnet_server_pwd},
+ {keep_alive,true}]} |
+ if LogType == legacy ->
+ [{ct_conn_log,[]}];
+ true ->
+ [{ct_conn_log,
+ [{ct_telnet,[{log_type,LogType},
+ {hosts,[telnet_server_conn1,
+ telnet_server_conn2,
+ telnet_server_conn3,
+ telnet_server_conn4]}]}]}]
+ end].
%%%-----------------------------------------------------------------
%%% TEST EVENTS
@@ -159,14 +208,44 @@ events_to_check(timetrap,_Config) ->
all_cases(Suite,Config) ->
{module,_} = code:load_abs(filename:join(?config(data_dir,Config),
Suite)),
- TCs = Suite:all(),
+ GroupsAndTCs = Suite:all(),
+
+ Terms =
+ lists:flatmap(
+ fun({group,G}) ->
+ {value,{G,Props,GTCs}} =
+ lists:keysearch(G,1,Suite:groups()),
+ GTCs1 = case lists:member(parallel,Props) of
+ true ->
+ %%! TEMPORARY WORKAROUND FOR PROBLEM
+ %%! WITH ct_test_support NOT HANDLING
+ %%! VERIFICATION OF PARALLEL GROUPS
+ %%! CORRECTLY!
+ [];
+ false ->
+ [[{?eh,tc_start,{Suite,GTC}},
+ {?eh,tc_done,{Suite,GTC,ok}}] ||
+ GTC <- GTCs]
+ end,
+ [{?eh,tc_start,{Suite,{init_per_group,G,Props}}},
+ {?eh,tc_done,{Suite,{init_per_group,G,Props},ok}} |
+ GTCs1] ++
+ [{?eh,tc_start,{Suite,{end_per_group,G,Props}}},
+ {?eh,tc_done,{Suite,{end_per_group,G,Props},ok}}];
+ (TC) ->
+ [{?eh,tc_done,{Suite,TC,ok}}]
+ end, GroupsAndTCs),
+
code:purge(Suite),
code:delete(Suite),
+ FlatTerms = lists:flatten(Terms),
+
+ ct:log("Verifying with terms:~n~p", [FlatTerms]),
+
OneTest =
- [{?eh,start_logging,{'DEF','RUNDIR'}}] ++
- [{?eh,tc_done,{Suite,TC,ok}} || TC <- TCs] ++
- [{?eh,stop_logging,[]}],
+ [{?eh,start_logging,{'DEF','RUNDIR'}} |
+ FlatTerms] ++ [{?eh,stop_logging,[]}],
%% 2 tests (ct:run_test + script_start) is default
OneTest ++ OneTest.
diff --git a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl
index 914b95f9cf..80616af064 100644
--- a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl
+++ b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl
@@ -5,45 +5,101 @@
-include_lib("common_test/include/ct.hrl").
+-define(no_of_sessions, 4).
+-define(conn_name(N), (list_to_atom("telnet_server_conn"++integer_to_list(N)))).
+-define(get_n(Cfg), (proplists:get_value(n, Cfg))).
+
%%--------------------------------------------------------------------
%% TEST SERVER CALLBACK FUNCTIONS
%%--------------------------------------------------------------------
+suite() -> [
+ {require,ct_conn_log},
+ {ct_hooks, [{cth_conn_log,[]}]}
+ ].
+
+operations() ->
+ [start_stop, send_and_get, expect, already_closed,
+ cmd, sendf, close_wrong_type].
+
+mult_case(_Case, 0) ->
+ [];
+mult_case(Case, N) ->
+ [list_to_atom(atom_to_list(Case)++integer_to_list(N)) |
+ mult_case(Case, N-1)].
+
+groups() ->
+ [{single_connection,[],operations()},
+ {multiple_connections,[parallel],
+ lists:reverse(mult_case(sessions,?no_of_sessions))}].
+
+all() ->
+ [{group,single_connection},
+ {group,multiple_connections}].
+
init_per_suite(Config) ->
+ ct:pal("Will use these log hook options: ~p",
+ [ct:get_config(ct_conn_log,[])]),
Config.
end_per_suite(_Config) ->
ok.
+init_per_group(Group, Config) ->
+ if Group == single_connection ->
+ ct:require(?conn_name(1),{unix,[telnet]});
+ true ->
+ ok
+ end,
+ [{n,1} | Config].
-suite() -> [{require,telnet_temp,{unix,[telnet]}}].
+end_per_group(_GroupName, Config) ->
+ Config.
-all() ->
- [start_stop, send_and_get, expect, already_closed,
- cmd, sendf, close_wrong_type].
+init_per_testcase(Case, Config) when (Case == sessions1) or
+ (Case == sessions2) or
+ (Case == sessions3) or
+ (Case == sessions4) ->
+ N = lists:last(atom_to_list(Case))-48,
+ ct:log("Using connection ~w for session ~w on ~w",
+ [?conn_name(N),N,self()]),
+ ct:require(?conn_name(N),{unix,[telnet]}),
+ [{n,N} | proplists:delete(n,Config)];
+init_per_testcase(Case, Config) ->
+ ct:log("Testcase ~w using connection ~w",
+ [Case,?conn_name(?get_n(Config))]),
+ Config.
-groups() ->
- [].
+end_per_testcase(_Case, _) ->
+ ok.
-init_per_group(_GroupName, Config) ->
- Config.
+%%%-----------------------------------------------------------------
+%%% TEST CASES
-end_per_group(_GroupName, Config) ->
- Config.
+sessions(Config) ->
+ [apply(?MODULE,Op,[Config]) || Op <- operations()],
+ ok.
+
+sessions1(Config) -> sessions(Config).
+sessions2(Config) -> sessions(Config).
+sessions3(Config) -> sessions(Config).
+sessions4(Config) -> sessions(Config).
-start_stop(_Config) ->
- {ok, Handle} = ct_telnet:open(telnet_temp),
+start_stop(Config) ->
+ ct:log("Opening ~w...", [?conn_name(?get_n(Config))]),
+ {ok, Handle} = ct_telnet:open(?conn_name(?get_n(Config))),
ok = ct_telnet:close(Handle),
ok.
-send_and_get(_) ->
- {ok, Handle} = ct_telnet:open(telnet_temp),
+
+send_and_get(Config) ->
+ {ok, Handle} = ct_telnet:open(?conn_name(?get_n(Config))),
ok = ct_telnet:send(Handle, "ayt"),
{ok, _Data} = ct_telnet:get_data(Handle),
ok = ct_telnet:close(Handle),
ok.
-expect(_) ->
- {ok, Handle} = ct_telnet:open(telnet_temp),
+expect(Config) ->
+ {ok, Handle} = ct_telnet:open(?conn_name(?get_n(Config))),
ok = ct_telnet:send(Handle, "echo ayt"),
ok = case ct_telnet:expect(Handle, ["ayt"]) of
{ok, _} ->
@@ -54,21 +110,21 @@ expect(_) ->
ok = ct_telnet:close(Handle),
ok.
-already_closed(_) ->
- {ok, Handle} = ct_telnet:open(telnet_temp),
+already_closed(Config) ->
+ {ok, Handle} = ct_telnet:open(?conn_name(?get_n(Config))),
ok = ct_telnet:close(Handle),
{error, already_closed} = ct_telnet:close(Handle),
ok.
-cmd(_) ->
- {ok, Handle} = ct_telnet:open(telnet_temp),
+cmd(Config) ->
+ {ok, Handle} = ct_telnet:open(?conn_name(?get_n(Config))),
{ok, _} = ct_telnet:cmd(Handle, "display"),
{ok, _} = ct_telnet:cmdf(Handle, "~s ~s", ["set", "bsasdel"]),
ok = ct_telnet:close(Handle),
ok.
-sendf(_) ->
- {ok, Handle} = ct_telnet:open(telnet_temp),
+sendf(Config) ->
+ {ok, Handle} = ct_telnet:open(?conn_name(?get_n(Config))),
ok = ct_telnet:sendf(Handle, "~s", ["ayt"]),
ok = ct_telnet:close(Handle),
ok.
@@ -76,3 +132,8 @@ sendf(_) ->
close_wrong_type(_) ->
{error, _} = ct_telnet:close(whatever),
ok.
+
+%%%-----------------------------------------------------------------
+%%% HELP FUNCS
+
+
diff --git a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_own_server_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_own_server_SUITE.erl
index 3f7c0d68bf..8d142e85a8 100644
--- a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_own_server_SUITE.erl
+++ b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_own_server_SUITE.erl
@@ -8,14 +8,12 @@
%% TEST SERVER CALLBACK FUNCTIONS
%%--------------------------------------------------------------------
-init_per_suite(Config) ->
- Config.
-
-end_per_suite(_Config) ->
- ok.
-
-
-suite() -> [{require,erl_telnet_server,{unix,[telnet]}}].
+suite() ->
+ [
+ {require,telnet_server_conn1,{unix,[telnet]}},
+ {require,ct_conn_log},
+ {ct_hooks, [{cth_conn_log,[]}]}
+ ].
all() ->
[expect,
@@ -35,6 +33,14 @@ all() ->
groups() ->
[].
+init_per_suite(Config) ->
+ ct:pal("Will use these log hook options: ~p",
+ [ct:get_config(ct_conn_log,[])]),
+ Config.
+
+end_per_suite(_Config) ->
+ ok.
+
init_per_group(_GroupName, Config) ->
Config.
@@ -43,7 +49,7 @@ end_per_group(_GroupName, Config) ->
%% Simple expect
expect(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo ayt"),
{ok,["ayt"]} = ct_telnet:expect(Handle, ["ayt"]),
ok = ct_telnet:close(Handle),
@@ -51,7 +57,7 @@ expect(_) ->
%% Expect with repeat option
expect_repeat(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_ml xy xy"),
{ok,[["xy"],["xy"]],done} = ct_telnet:expect(Handle, ["xy"],[{repeat,2}]),
ok = ct_telnet:close(Handle),
@@ -59,7 +65,7 @@ expect_repeat(_) ->
%% Expect with sequence option
expect_sequence(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_ml ab cd ef"),
{ok,[["ab"],["cd"],["ef"]]} = ct_telnet:expect(Handle,
[["ab"],["cd"],["ef"]],
@@ -70,7 +76,7 @@ expect_sequence(_) ->
%% Check that expect returns when a prompt is found, even if pattern
%% is not matched.
expect_error_prompt(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo xxx> yyy"),
{error,{prompt,"> "}} = ct_telnet:expect(Handle, ["yyy"]),
ok = ct_telnet:close(Handle),
@@ -80,7 +86,7 @@ expect_error_prompt(_) ->
%% expected pattern is received - as long as not newline or prompt is
%% received it will not match.
expect_error_timeout(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_no_prompt xxx"),
{error,timeout} = ct_telnet:expect(Handle, ["xxx"], [{timeout,1000}]),
ok = ct_telnet:close(Handle),
@@ -89,7 +95,7 @@ expect_error_timeout(_) ->
%% expect with ignore_prompt option should not return even if a prompt
%% is found. The pattern after the prompt (here "> ") can be matched.
ignore_prompt(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo xxx> yyy"),
{ok,["yyy"]} = ct_telnet:expect(Handle, ["yyy"], [ignore_prompt]),
ok = ct_telnet:close(Handle),
@@ -97,7 +103,7 @@ ignore_prompt(_) ->
%% expect with ignore_prompt and repeat options.
ignore_prompt_repeat(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_ml yyy> yyy>"),
{ok,[["yyy"],["yyy"]],done} = ct_telnet:expect(Handle, ["yyy"],
[{repeat,2},
@@ -107,7 +113,7 @@ ignore_prompt_repeat(_) ->
%% expect with ignore_prompt and sequence options.
ignore_prompt_sequence(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_ml xxx> yyy> zzz> "),
{ok,[["xxx"],["yyy"],["zzz"]]} = ct_telnet:expect(Handle,
[["xxx"],["yyy"],["zzz"]],
@@ -121,7 +127,7 @@ ignore_prompt_sequence(_) ->
%% As for expect without the ignore_prompt option, it a newline or a
%% prompt is required in order for the pattern to match.
ignore_prompt_timeout(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo xxx"),
{error,timeout} = ct_telnet:expect(Handle, ["yyy"], [ignore_prompt,
{timeout,1000}]),
@@ -140,7 +146,7 @@ ignore_prompt_timeout(_) ->
%% no_prompt_check option shall match pattern both when prompt is sent
%% and when it is not.
no_prompt_check(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo xxx"),
{ok,["xxx"]} = ct_telnet:expect(Handle, ["xxx"], [no_prompt_check]),
ok = ct_telnet:send(Handle, "echo_no_prompt yyy"),
@@ -150,7 +156,7 @@ no_prompt_check(_) ->
%% no_prompt_check and repeat options
no_prompt_check_repeat(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_ml xxx xxx"),
{ok,[["xxx"],["xxx"]],done} = ct_telnet:expect(Handle,["xxx"],
[{repeat,2},
@@ -164,7 +170,7 @@ no_prompt_check_repeat(_) ->
%% no_prompt_check and sequence options
no_prompt_check_sequence(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo_ml_no_prompt ab cd ef"),
{ok,[["ab"],["cd"],["ef"]]} = ct_telnet:expect(Handle,
[["ab"],["cd"],["ef"]],
@@ -176,7 +182,7 @@ no_prompt_check_sequence(_) ->
%% Check that expect returns after idle timeout when no_prompt_check
%% option is used.
no_prompt_check_timeout(_) ->
- {ok, Handle} = ct_telnet:open(erl_telnet_server),
+ {ok, Handle} = ct_telnet:open(telnet_server_conn1),
ok = ct_telnet:send(Handle, "echo xxx"),
{error,timeout} = ct_telnet:expect(Handle, ["yyy"], [no_prompt_check,
{timeout,1000}]),
diff --git a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_timetrap_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_timetrap_SUITE.erl
index f274fb9112..c45a4f0984 100644
--- a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_timetrap_SUITE.erl
+++ b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_timetrap_SUITE.erl
@@ -4,7 +4,7 @@
-include_lib("common_test/include/ct.hrl").
--define(name,erl_telnet_server).
+-define(name, telnet_server_conn1).
%%--------------------------------------------------------------------
%% TEST SERVER CALLBACK FUNCTIONS
@@ -17,6 +17,8 @@ end_per_suite(_Config) ->
ok.
suite() -> [{require,?name,{unix,[telnet]}},
+ {require,ct_conn_log},
+ {ct_hooks, [{cth_conn_log,[]}]},
{timetrap,{seconds,7}}].
all() ->
diff --git a/lib/common_test/test/ct_test_support.erl b/lib/common_test/test/ct_test_support.erl
index 772274ce7e..2e2b45d59f 100644
--- a/lib/common_test/test/ct_test_support.erl
+++ b/lib/common_test/test/ct_test_support.erl
@@ -40,6 +40,8 @@
-export([ct_test_halt/1, ct_rpc/2]).
+-export([random_error/1]).
+
-include_lib("kernel/include/file.hrl").
%%%-----------------------------------------------------------------
@@ -110,7 +112,6 @@ start_slave(NodeName, Config, Level) ->
_ ->
ok
end,
-
TraceFile = filename:join(DataDir, "ct.trace"),
case file:read_file_info(TraceFile) of
{ok,_} ->
@@ -395,6 +396,55 @@ ct_rpc({M,F,A}, Config) ->
%%%-----------------------------------------------------------------
+%%% random_error/1
+random_error(Config) when is_list(Config) ->
+ random:seed(now()),
+ Gen = fun(0,_) -> ok; (N,Fun) -> Fun(N-1, Fun) end,
+ Gen(random:uniform(100), Gen),
+
+ ErrorTypes = ['BADMATCH','BADARG','CASE_CLAUSE','FUNCTION_CLAUSE',
+ 'EXIT','THROW','UNDEF'],
+ Type = lists:nth(random:uniform(length(ErrorTypes)), ErrorTypes),
+ Where = case random:uniform(2) of
+ 1 ->
+ io:format("ct_test_support *returning* error of type ~w",
+ [Type]),
+ tc;
+ 2 ->
+ io:format("ct_test_support *generating* error of type ~w",
+ [Type]),
+ lib
+ end,
+ ErrorFun =
+ fun() ->
+ case Type of
+ 'BADMATCH' ->
+ ok = proplists:get_value(undefined, Config);
+ 'BADARG' ->
+ size(proplists:get_value(priv_dir, Config));
+ 'FUNCTION_CLAUSE' ->
+ random_error(x);
+ 'EXIT' ->
+ spawn_link(fun() ->
+ undef_proc ! hello,
+ ok
+ end);
+ 'THROW' ->
+ PrivDir = proplists:get_value(priv_dir, Config),
+ if is_list(PrivDir) -> throw(generated_throw) end;
+ 'UNDEF' ->
+ apply(?MODULE, random_error, [])
+ end
+ end,
+ %% either call the fun here or return it to the caller (to be
+ %% executed in a test case instead)
+ case Where of
+ tc -> ErrorFun;
+ lib -> ErrorFun()
+ end.
+
+
+%%%-----------------------------------------------------------------
%%% EVENT HANDLING
handle_event(EH, Event) ->
diff --git a/lib/common_test/test/telnet_server.erl b/lib/common_test/test/telnet_server.erl
index 31884aa182..1760100d8e 100644
--- a/lib/common_test/test/telnet_server.erl
+++ b/lib/common_test/test/telnet_server.erl
@@ -64,18 +64,19 @@ accept(#state{listen=LSock}=State) ->
{Acceptor,Sock} when is_port(Sock) ->
case init_client(State#state{client=Sock}) of
stopped ->
- io:format("telnet_server stopped\n"),
+ io:format("[telnet_server] telnet_server stopped\n"),
ok;
R ->
- io:format("connection to client closed with reason ~p~n",[R]),
+ io:format("[telnet_server] connection to client"
+ "closed with reason ~p~n",[R]),
accept(State)
end;
{Acceptor,closed} ->
- io:format("listen socket closed unexpectedly, "
+ io:format("[telnet_server] listen socket closed unexpectedly, "
"terminating telnet_server\n"),
ok;
stop ->
- io:format("telnet_server stopped\n"),
+ io:format("[telnet_server] telnet_server stopped\n"),
ok
end.
@@ -188,7 +189,7 @@ do_handle_data(_Data,State) ->
check_user(User,State) ->
case lists:keyfind(User,1,State#state.users) of
{User,Pwd} ->
- dbg("user ok\n"),
+ dbg("user ok\n"),
send("Password: ",State),
{ok,State#state{authorized={user,Pwd}}};
false ->
@@ -223,6 +224,6 @@ get_line([],_) ->
false.
dbg(_F) ->
- io:format(_F).
+ dbg(_F,[]).
dbg(_F,_A) ->
- io:format(_F,_A).
+ io:format("[telnet_server] "++_F,_A).