From 4d086abb73f7b9af178c966d5fb66012c4ec6612 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Mon, 13 May 2013 16:12:10 +0200 Subject: [common_test] Add test for ct_telnet using own telnet server The new test suite ct_telnet_SUITE_data/ct_telnet_own_server_SUITE uses the very simple telnet_server.erl located in the common_test test directory. --- lib/common_test/test/ct_telnet_SUITE.erl | 44 +++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'lib/common_test/test/ct_telnet_SUITE.erl') diff --git a/lib/common_test/test/ct_telnet_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE.erl index b4f24baa0c..c75f0f5843 100644 --- a/lib/common_test/test/ct_telnet_SUITE.erl +++ b/lib/common_test/test/ct_telnet_SUITE.erl @@ -33,6 +33,10 @@ -define(eh, ct_test_support_eh). +-define(erl_telnet_server_port,1234). +-define(erl_telnet_server_user,"telnuser"). +-define(erl_telnet_server_pwd,"telnpwd"). + %%-------------------------------------------------------------------- %% TEST SERVER CALLBACK FUNCTIONS %%-------------------------------------------------------------------- @@ -48,10 +52,18 @@ init_per_suite(Config) -> end_per_suite(Config) -> ct_test_support:end_per_suite(Config). +init_per_testcase(own_server=TestCase, Config) -> + TS = telnet_server:start([{port,1234},{users,[{?erl_telnet_server_user, + ?erl_telnet_server_pwd}]}]), + ct_test_support:init_per_testcase(TestCase, [{telnet_server,TS}|Config]); init_per_testcase(TestCase, Config) -> ct_test_support:init_per_testcase(TestCase, Config). end_per_testcase(TestCase, Config) -> + case ?config(telnet_server,Config) of + undefined -> ok; + TS -> telnet_server:stop(TS) + end, ct_test_support:end_per_testcase(TestCase, Config). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -71,11 +83,26 @@ default(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), Suite = filename:join(DataDir, "ct_telnet_basic_SUITE"), Cfg = {unix, ct:get_config(unix)}, - ok = file:write_file(filename:join(DataDir, "telnet.cfg"), io_lib:write(Cfg) ++ "."), CfgFile = filename:join(DataDir, "telnet.cfg"), + ok = file:write_file(CfgFile, io_lib:write(Cfg) ++ "."), {Opts,ERPid} = setup([{suite,Suite},{label,default}, {config, CfgFile}], Config), ok = execute(default, Opts, ERPid, Config). +own_server(Config) -> + DataDir = ?config(data_dir, Config), + Suite = filename:join(DataDir, "ct_telnet_own_server_SUITE"), + Cfg = {unix,[{telnet,"localhost"}, + {port, 1234}, + {username,?erl_telnet_server_user}, + {password,?erl_telnet_server_pwd}, + {wait_for_linebreak, false}, +% {not_require_user_and_pass, true}, + {keep_alive,true}]}, + CfgFile = filename:join(DataDir, "telnet2.cfg"), + ok = file:write_file(CfgFile, io_lib:write(Cfg) ++ "."), + {Opts,ERPid} = setup([{suite,Suite},{label,own_server}, {config, CfgFile}], Config), + ok = execute(own_server, Opts, ERPid, Config). + %%%----------------------------------------------------------------- %%% HELP FUNCTIONS %%%----------------------------------------------------------------- @@ -107,15 +134,20 @@ reformat(Events, EH) -> %%% TEST EVENTS %%%----------------------------------------------------------------- events_to_check(default,Config) -> + all_cases(ct_telnet_basic_SUITE,Config); +events_to_check(own_server,Config) -> + all_cases(ct_telnet_own_server_SUITE,Config). + +all_cases(Suite,Config) -> {module,_} = code:load_abs(filename:join(?config(data_dir,Config), - ct_telnet_basic_SUITE)), - TCs = ct_telnet_basic_SUITE:all(), - code:purge(ct_telnet_basic_SUITE), - code:delete(ct_telnet_basic_SUITE), + Suite)), + TCs = Suite:all(), + code:purge(Suite), + code:delete(Suite), OneTest = [{?eh,start_logging,{'DEF','RUNDIR'}}] ++ - [{?eh,tc_done,{ct_telnet_basic_SUITE,TC,ok}} || TC <- TCs] ++ + [{?eh,tc_done,{Suite,TC,ok}} || TC <- TCs] ++ [{?eh,stop_logging,[]}], %% 2 tests (ct:run_test + script_start) is default -- cgit v1.2.3 From 55d975b3a1266d50b5a55004a004d0f244d5a17b Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 15 May 2013 12:09:36 +0200 Subject: [common_test] Add new option 'no_prompt_check' to ct_telnet:expect/3. If this option is used, ct_telnet will not search for a prompt before attempting to match the given pattern. This is useful if, for instance, the Pattern itself matches the prompt or if the telnet session starts interactive programs which do not display the normal prompt. --- lib/common_test/test/ct_telnet_SUITE.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/common_test/test/ct_telnet_SUITE.erl') diff --git a/lib/common_test/test/ct_telnet_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE.erl index c75f0f5843..a378c531f0 100644 --- a/lib/common_test/test/ct_telnet_SUITE.erl +++ b/lib/common_test/test/ct_telnet_SUITE.erl @@ -53,8 +53,9 @@ end_per_suite(Config) -> ct_test_support:end_per_suite(Config). init_per_testcase(own_server=TestCase, Config) -> - TS = telnet_server:start([{port,1234},{users,[{?erl_telnet_server_user, - ?erl_telnet_server_pwd}]}]), + TS = telnet_server:start([{port,?erl_telnet_server_port}, + {users,[{?erl_telnet_server_user, + ?erl_telnet_server_pwd}]}]), ct_test_support:init_per_testcase(TestCase, [{telnet_server,TS}|Config]); init_per_testcase(TestCase, Config) -> ct_test_support:init_per_testcase(TestCase, Config). @@ -92,7 +93,7 @@ own_server(Config) -> DataDir = ?config(data_dir, Config), Suite = filename:join(DataDir, "ct_telnet_own_server_SUITE"), Cfg = {unix,[{telnet,"localhost"}, - {port, 1234}, + {port, ?erl_telnet_server_port}, {username,?erl_telnet_server_user}, {password,?erl_telnet_server_pwd}, {wait_for_linebreak, false}, -- cgit v1.2.3 From cae4bc87c2b3009a505f91a1c2d38a484cc9a1e4 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 15 May 2013 16:49:17 +0200 Subject: [common_test] Refactor ct_telnet_SUITE.erl --- lib/common_test/test/ct_telnet_SUITE.erl | 54 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'lib/common_test/test/ct_telnet_SUITE.erl') diff --git a/lib/common_test/test/ct_telnet_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE.erl index a378c531f0..17617f59eb 100644 --- a/lib/common_test/test/ct_telnet_SUITE.erl +++ b/lib/common_test/test/ct_telnet_SUITE.erl @@ -52,7 +52,7 @@ init_per_suite(Config) -> end_per_suite(Config) -> ct_test_support:end_per_suite(Config). -init_per_testcase(own_server=TestCase, Config) -> +init_per_testcase(TestCase, Config) when TestCase=/=unix_telnet-> TS = telnet_server:start([{port,?erl_telnet_server_port}, {users,[{?erl_telnet_server_user, ?erl_telnet_server_pwd}]}]), @@ -71,7 +71,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [ - default + unix_telnet, + own_server ]. %%-------------------------------------------------------------------- @@ -80,34 +81,29 @@ all() -> %%%----------------------------------------------------------------- %%% -default(Config) when is_list(Config) -> - DataDir = ?config(data_dir, Config), - Suite = filename:join(DataDir, "ct_telnet_basic_SUITE"), - Cfg = {unix, ct:get_config(unix)}, - CfgFile = filename:join(DataDir, "telnet.cfg"), - ok = file:write_file(CfgFile, io_lib:write(Cfg) ++ "."), - {Opts,ERPid} = setup([{suite,Suite},{label,default}, {config, CfgFile}], Config), - ok = execute(default, Opts, ERPid, Config). +unix_telnet(Config) when is_list(Config) -> + all_tests_in_suite(unix_telnet,"ct_telnet_basic_SUITE","telnet.cfg",Config). own_server(Config) -> - DataDir = ?config(data_dir, Config), - Suite = filename:join(DataDir, "ct_telnet_own_server_SUITE"), - Cfg = {unix,[{telnet,"localhost"}, - {port, ?erl_telnet_server_port}, - {username,?erl_telnet_server_user}, - {password,?erl_telnet_server_pwd}, - {wait_for_linebreak, false}, -% {not_require_user_and_pass, true}, - {keep_alive,true}]}, - CfgFile = filename:join(DataDir, "telnet2.cfg"), - ok = file:write_file(CfgFile, io_lib:write(Cfg) ++ "."), - {Opts,ERPid} = setup([{suite,Suite},{label,own_server}, {config, CfgFile}], Config), - ok = execute(own_server, Opts, ERPid, Config). + all_tests_in_suite(own_server,"ct_telnet_own_server_SUITE", + "telnet2.cfg",Config). %%%----------------------------------------------------------------- %%% HELP FUNCTIONS %%%----------------------------------------------------------------- +all_tests_in_suite(TestCase, SuiteName, CfgFileName, 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) ++ "."), + {Opts,ERPid} = setup([{suite,Suite}, + {label,TestCase}, + {config,CfgFile}], + Config), + ok = execute(TestCase, Opts, ERPid, Config). + setup(Test, Config) -> Opts0 = ct_test_support:get_opts(Config), Level = ?config(trace_level, Config), @@ -131,10 +127,20 @@ 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}]}. + %%%----------------------------------------------------------------- %%% TEST EVENTS %%%----------------------------------------------------------------- -events_to_check(default,Config) -> +events_to_check(unix_telnet,Config) -> all_cases(ct_telnet_basic_SUITE,Config); events_to_check(own_server,Config) -> all_cases(ct_telnet_own_server_SUITE,Config). -- cgit v1.2.3