diff options
author | Andrey Pampukha <[email protected]> | 2010-03-03 10:27:38 +0100 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2010-06-09 16:19:08 +0200 |
commit | c5275f3dc1d78ecbe1bf311b7c04c3c815a293d9 (patch) | |
tree | 154b548bd268af91821634635ca204dc4eef9861 | |
parent | f2dcd87634cdcee65f0a930731a45005b4c20d08 (diff) | |
download | otp-c5275f3dc1d78ecbe1bf311b7c04c3c815a293d9.tar.gz otp-c5275f3dc1d78ecbe1bf311b7c04c3c815a293d9.tar.bz2 otp-c5275f3dc1d78ecbe1bf311b7c04c3c815a293d9.zip |
Added config test suite for CT
5 files changed, 374 insertions, 1 deletions
diff --git a/lib/common_test/test/Makefile b/lib/common_test/test/Makefile index 35ba22aa59..2b0a06871e 100644 --- a/lib/common_test/test/Makefile +++ b/lib/common_test/test/Makefile @@ -33,7 +33,8 @@ MODULES= \ ct_groups_test_2_SUITE \ ct_skip_SUITE \ ct_error_SUITE \ - ct_test_server_if_1_SUITE + ct_test_server_if_1_SUITE \ + ct_config_SUITE ERL_FILES= $(MODULES:%=%.erl) diff --git a/lib/common_test/test/ct_config_SUITE.erl b/lib/common_test/test/ct_config_SUITE.erl new file mode 100644 index 0000000000..38c8cbe6eb --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE.erl @@ -0,0 +1,167 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2010. 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% +%% + +%%%------------------------------------------------------------------- +%%% File: ct_config_SUITE +%%% +%%% Description: +%%% Test configuration handling in Common Test suites. +%%% +%%% The suites used for the test are located in the data directory. +%%%------------------------------------------------------------------- +-module(ct_config_SUITE). + +-compile(export_all). + +-include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + +-define(eh, ct_test_support_eh). + +%%-------------------------------------------------------------------- +%% TEST SERVER CALLBACK FUNCTIONS +%%-------------------------------------------------------------------- + +%%-------------------------------------------------------------------- +%% Description: Since Common Test starts another Test Server +%% instance, the tests need to be performed on a separate node (or +%% there will be clashes with logging processes etc). +%%-------------------------------------------------------------------- +init_per_suite(Config) -> + Config1 = ct_test_support:init_per_suite(Config), + Config1. + +end_per_suite(Config) -> + ct_test_support:end_per_suite(Config). + +init_per_testcase(TestCase, Config) -> + ct_test_support:init_per_testcase(TestCase, Config). + +end_per_testcase(TestCase, Config) -> + ct_test_support:end_per_testcase(TestCase, Config). + +all(doc) -> + [""]; + +all(suite) -> + [ + require, + nested_keys + ]. + + +%%-------------------------------------------------------------------- +%% TEST CASES +%%-------------------------------------------------------------------- + +%%%----------------------------------------------------------------- +%%% +require(Config) when is_list(Config) -> + DataDir = ?config(data_dir, Config), + Join = fun(D, S) -> filename:join(D, "config/test/"++S) end, + Suites = [Join(DataDir, "config_1_SUITE")], + CTConfig = {config, filename:join(DataDir, "config/cfg.cfg")}, + {Opts,ERPid} = setup({suite,Suites}, Config, CTConfig), + ok = ct_test_support:run(ct, run_test, [Opts], Config), + Events = ct_test_support:get_events(ERPid, Config), + + ct_test_support:log_events(require, + reformat(Events, ?eh), + ?config(priv_dir, Config)), + + TestEvents = test_events(require), + ok = ct_test_support:verify_events(TestEvents, Events, Config). + +nested_keys(Config) when is_list(Config) -> + DataDir = ?config(data_dir, Config), + Join = fun(D, S) -> filename:join(D, "config/test/"++S) end, + Suites = [Join(DataDir, "config_2_SUITE")], + CTConfig = {config, filename:join(DataDir, "config/cfg.cfg")}, + {Opts,ERPid} = setup({suite,Suites}, Config, CTConfig), + ok = ct_test_support:run(ct, run_test, [Opts], Config), + Events = ct_test_support:get_events(ERPid, Config), + + ct_test_support:log_events(nested_keys, + reformat(Events, ?eh), + ?config(priv_dir, Config)), + + TestEvents = test_events(nested_keys), + ok = ct_test_support:verify_events(TestEvents, Events, Config). + +%%%----------------------------------------------------------------- +%%% HELP FUNCTIONS +%%%----------------------------------------------------------------- + +setup(Test, Config, CTConfig) -> + Opts0 = ct_test_support:get_opts(Config), + Level = ?config(trace_level, Config), + EvHArgs = [{cbm,ct_test_support},{trace_level,Level}], + Opts = Opts0 ++ [Test,{event_handler,{?eh,EvHArgs}}, CTConfig], + ERPid = ct_test_support:start_event_receiver(Config), + {Opts,ERPid}. + +reformat(Events, EH) -> + ct_test_support:reformat(Events, EH). +%reformat(Events, _EH) -> +% Events. + +%%%----------------------------------------------------------------- +%%% TEST EVENTS +%%%----------------------------------------------------------------- +test_events(require) -> +[ + {?eh,start_logging,{'DEF','RUNDIR'}}, + {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}}, + {?eh,start_info,{1,1,8}}, + {?eh,tc_start,{config_1_SUITE,init_per_suite}}, + {?eh,tc_done,{config_1_SUITE,init_per_suite,ok}}, + {?eh,tc_start,{config_1_SUITE,test1}}, + {?eh,tc_done,{config_1_SUITE,test1,ok}}, + {?eh,test_stats,{1,0,{0,0}}}, + {?eh,tc_start,{config_1_SUITE,test2}}, + {?eh,tc_done, + {config_1_SUITE,test2,{skipped,{config_name_already_in_use,[x1]}}}}, + {?eh,test_stats,{1,0,{1,0}}}, + {?eh,tc_start,{config_1_SUITE,test3}}, + {?eh,tc_done,{config_1_SUITE,test3,ok}}, + {?eh,test_stats,{2,0,{1,0}}}, + {?eh,tc_start,{config_1_SUITE,test4}}, + {?eh,tc_done, + {config_1_SUITE,test4,{skipped,{config_name_already_in_use,[x1,alias]}}}}, + {?eh,test_stats,{2,0,{2,0}}}, + {?eh,tc_start,{config_1_SUITE,test5}}, + {?eh,tc_done,{config_1_SUITE,test5,ok}}, + {?eh,test_stats,{3,0,{2,0}}}, + {?eh,tc_start,{config_1_SUITE,test6}}, + {?eh,tc_done,{config_1_SUITE,test6,ok}}, + {?eh,test_stats,{4,0,{2,0}}}, + {?eh,tc_start,{config_1_SUITE,test7}}, + {?eh,tc_done,{config_1_SUITE,test7,ok}}, + {?eh,test_stats,{5,0,{2,0}}}, + {?eh,tc_start,{config_1_SUITE,test8}}, + {?eh,tc_done,{config_1_SUITE,test8,ok}}, + {?eh,test_stats,{6,0,{2,0}}}, + {?eh,tc_start,{config_1_SUITE,end_per_suite}}, + {?eh,tc_done,{config_1_SUITE,end_per_suite,ok}}, + {?eh,test_done,{'DEF','STOP_TIME'}}, + {?eh,stop_logging,[]} +]; + +test_events(nested_keys)-> +[]. diff --git a/lib/common_test/test/ct_config_SUITE_data/config/cfg.cfg b/lib/common_test/test/ct_config_SUITE_data/config/cfg.cfg new file mode 100644 index 0000000000..f0c1783189 --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/cfg.cfg @@ -0,0 +1,11 @@ +{x, suite}. +{gen_cfg2, + [ + {a,x}, + {b,y} + ]}. +{gen_cfg3, + [ + {v,w}, + {m,n} + ]}.
\ No newline at end of file diff --git a/lib/common_test/test/ct_config_SUITE_data/config/test/config_1_SUITE.erl b/lib/common_test/test/ct_config_SUITE_data/config/test/config_1_SUITE.erl new file mode 100644 index 0000000000..696014ee9f --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_1_SUITE.erl @@ -0,0 +1,135 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2010. 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_1_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +suite() -> + [ + {timetrap, {seconds,10}}, + %% x1 doesn't exist in cfg-file! + {require, x1, x}, + {require, gen_cfg2}, + {require, alias, gen_cfg3}, + %% x1 default value + {x1, {x,suite}} + ]. + +is_exported(Module, Function, Arity)-> + Exports = Module:module_info(exports), + case lists:keyfind(Function, 1, Exports) of + false-> + false; + {Function, Arity}-> + true; + {Function, _OtherArity}-> + false + end. + +get_all_config()-> + case is_exported(ct_util, get_all_config, 0) of + true-> + {ct_util, ct_util:get_all_config()}; + false-> + {ct_config, ct_config:get_all_config()} + end. + +init_per_suite(Config) -> + {Module, Cfg} = get_all_config(), + ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + Config. + +end_per_suite(_) -> + ok. + +all() -> [test1,test2,test3,test4,test5,test6,test7,test8]. + +init_per_testcase(_, Config) -> + {Module, Cfg} = get_all_config(), + ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + Config. + +end_per_testcase(_, _) -> + ok. + +test1(_) -> + suite = ct:get_config(x1), + [{a,x},{b,y}] = ct:get_config(gen_cfg2), + [{v,w},{m,n}] = ct:get_config(alias), + ok. + +%% should get skipped +test2() -> + [{timetrap, {seconds,2}}, + {require, x1, x}, + {x1, {x,test2}}]. +test2(_) -> + test2 = ct:get_config(x1), + [{a,x},{b,y}] = ct:get_config(gen_cfg2), + [{v,w},{m,n}] = ct:get_config(alias), + ct:fail("Test should've been skipped, you shouldn't see this!"), + ok. + +test3() -> + [{timetrap, {seconds,3}}, + {require, y1, y}, + {y1, {y,test3}}]. +test3(_) -> + suite = ct:get_config(x1), + test3 = ct:get_config(y1), + [{a,x},{b,y}] = ct:get_config(gen_cfg2), + [{v,w},{m,n}] = ct:get_config(alias), + ok. + +%% should get skipped +test4() -> + [{require,alias,something}, + {alias,{something,else}}, + {require, x1, x}, + {x1, {x,test4}}]. +test4(_) -> + ct:fail("Test should've been skipped, you shouldn't see this!"), + ok. + +test5() -> + [{require,newalias,gen_cfg2}]. +test5(_) -> + A = [{a,x},{b,y}] = ct:get_config(newalias), + A = ct:get_config(gen_cfg2), + ok. + +test6(_) -> + undefined = ct:get_config(y1), + ok. + +test7() -> + [{require, y1, y}, + {y1, {y,test6}}]. +test7(_) -> + suite = ct:get_config(x1), + test6 = ct:get_config(y1), + ok. + +%% should get skipped +test8() -> + [{require, x}]. +test8(_) -> + ok.
\ No newline at end of file diff --git a/lib/common_test/test/ct_config_SUITE_data/config/test/config_2_SUITE.erl b/lib/common_test/test/ct_config_SUITE_data/config/test/config_2_SUITE.erl new file mode 100644 index 0000000000..25e050984a --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_2_SUITE.erl @@ -0,0 +1,59 @@ +%% +%% 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_2_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +suite() -> + [ + {timetrap, {seconds,10}} + ]. + +is_exported(Module, Function, Arity)-> + Exports = Module:module_info(exports), + case lists:keyfind(Function, 1, Exports) of + false-> + false; + {Function, Arity}-> + true; + {Function, _OtherArity}-> + false + end. + +get_all_config()-> + case is_exported(ct_util, get_all_config, 0) of + true-> + {ct_util, ct_util:get_all_config()}; + false-> + {ct_config, ct_config:get_all_config()} + end. + +init_per_suite(Config) -> + {Module, Cfg} = get_all_config(), + ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + Config. + +end_per_suite(_) -> + ok. + +all() -> [test1]. + +init_per_testcase(_, Config) -> + {Module, Cfg} = get_all_config(), + ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + Config. + +end_per_testcase(_, _) -> + ok. + +test1(_)-> + x = ct:get_config({gen_cfg2, a}), + ok. |