From d7c10478a2287ce3f0c9ac077d835919e2745f91 Mon Sep 17 00:00:00 2001 From: Andrey Pampukha Date: Thu, 18 Mar 2010 16:48:27 +0100 Subject: Rename suites for ct_config and add tests for disappearing variables Tests for disappearing variables added to ct_dynamic_SUITE. --- lib/common_test/test/ct_config_SUITE.erl | 92 ++++++----- .../config/test/config_1_SUITE.erl | 151 ------------------ .../config/test/config_2_SUITE.erl | 133 ---------------- .../config/test/config_dynamic_SUITE.erl | 172 +++++++++++++++++++++ .../config/test/config_server.erl | 16 +- .../config/test/config_static_SUITE.erl | 151 ++++++++++++++++++ 6 files changed, 379 insertions(+), 336 deletions(-) delete mode 100644 lib/common_test/test/ct_config_SUITE_data/config/test/config_1_SUITE.erl delete mode 100644 lib/common_test/test/ct_config_SUITE_data/config/test/config_2_SUITE.erl create mode 100644 lib/common_test/test/ct_config_SUITE_data/config/test/config_dynamic_SUITE.erl create mode 100644 lib/common_test/test/ct_config_SUITE_data/config/test/config_static_SUITE.erl (limited to 'lib/common_test/test') diff --git a/lib/common_test/test/ct_config_SUITE.erl b/lib/common_test/test/ct_config_SUITE.erl index ad7c521946..a7fa6fe52e 100644 --- a/lib/common_test/test/ct_config_SUITE.erl +++ b/lib/common_test/test/ct_config_SUITE.erl @@ -78,31 +78,31 @@ all(suite) -> %%% require(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), - run_test(require, + run_test(config_static_SUITE, Config, {config, filename:join(DataDir, "config/config.txt")}, - ["config_1_SUITE"]). + ["config_static_SUITE"]). userconfig_static(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), - run_test(userconfig_static, + run_test(config_static_SUITE, Config, {userconfig, {ct_config_xml, filename:join(DataDir, "config/config.xml")}}, - ["config_1_SUITE"]). + ["config_static_SUITE"]). userconfig_dynamic(Config) when is_list(Config) -> - run_test(userconfig_dynamic, + run_test(config_dynamic_SUITE, Config, {userconfig, {config_driver, "config_server"}}, - ["config_2_SUITE"]). + ["config_dynamic_SUITE"]). testspec_legacy(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), make_spec(DataDir, "config/spec_legacy.spec", - [config_1_SUITE], + [config_static_SUITE], [{config, filename:join(DataDir, "config/config.txt")}]), - run_test(testspec_legacy, + run_test(config_static_SUITE, Config, {spec, filename:join(DataDir, "config/spec_legacy.spec")}, []), @@ -112,9 +112,9 @@ testspec_static(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), make_spec(DataDir, "config/spec_static.spec", - [config_1_SUITE], + [config_static_SUITE], [{userconfig, {ct_config_xml, filename:join(DataDir, "config/config.xml")}}]), - run_test(testspec_static, + run_test(config_static_SUITE, Config, {spec, filename:join(DataDir, "config/spec_static.spec")}, []), @@ -123,9 +123,9 @@ testspec_static(Config) when is_list(Config) -> testspec_dynamic(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), make_spec(DataDir, "config/spec_dynamic.spec", - [config_2_SUITE], + [config_dynamic_SUITE], [{userconfig, {config_driver, "config_server"}}]), - run_test(testspec_dynamic, + run_test(config_dynamic_SUITE, Config, {spec, filename:join(DataDir, "config/spec_dynamic.spec")}, []), @@ -134,7 +134,7 @@ testspec_dynamic(Config) when is_list(Config) -> %%%----------------------------------------------------------------- %%% HELP FUNCTIONS %%%----------------------------------------------------------------- -% {suites, "ct_config_SUITE_data/config/test", config_2_SUITE}. +% {suites, "ct_config_SUITE_data/config/test", config_dynamic_SUITE}. make_spec(DataDir, Filename, Suites, Config)-> {ok, Fd} = file:open(filename:join(DataDir, Filename), [write]), ok = file:write(Fd, @@ -169,66 +169,64 @@ reformat_events(Events, EH) -> %%%----------------------------------------------------------------- %%% TEST EVENTS %%%----------------------------------------------------------------- -expected_events(Static) when - Static == require; Static == testspec_legacy; - Static == userconfig_static; Static == testspec_static-> +expected_events(config_static_SUITE)-> [ {?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,test_get_config_simple}}, - {?eh,tc_done,{config_1_SUITE,test_get_config_simple,ok}}, + {?eh,tc_start,{config_static_SUITE,init_per_suite}}, + {?eh,tc_done,{config_static_SUITE,init_per_suite,ok}}, + {?eh,tc_start,{config_static_SUITE,test_get_config_simple}}, + {?eh,tc_done,{config_static_SUITE,test_get_config_simple,ok}}, {?eh,test_stats,{1,0,{0,0}}}, - {?eh,tc_start,{config_1_SUITE,test_get_config_nested}}, - {?eh,tc_done,{config_1_SUITE,test_get_config_nested,ok}}, + {?eh,tc_start,{config_static_SUITE,test_get_config_nested}}, + {?eh,tc_done,{config_static_SUITE,test_get_config_nested,ok}}, {?eh,test_stats,{2,0,{0,0}}}, - {?eh,tc_start,{config_1_SUITE,test_default_suitewide}}, - {?eh,tc_done,{config_1_SUITE,test_default_suitewide,ok}}, + {?eh,tc_start,{config_static_SUITE,test_default_suitewide}}, + {?eh,tc_done,{config_static_SUITE,test_default_suitewide,ok}}, {?eh,test_stats,{3,0,{0,0}}}, - {?eh,tc_start,{config_1_SUITE,test_config_name_already_in_use1}}, + {?eh,tc_start,{config_static_SUITE,test_config_name_already_in_use1}}, {?eh,tc_done, - {config_1_SUITE,test_config_name_already_in_use1,{skipped,{config_name_already_in_use,[x1]}}}}, + {config_static_SUITE,test_config_name_already_in_use1,{skipped,{config_name_already_in_use,[x1]}}}}, {?eh,test_stats,{3,0,{1,0}}}, - {?eh,tc_start,{config_1_SUITE,test_default_tclocal}}, - {?eh,tc_done,{config_1_SUITE,test_default_tclocal,ok}}, + {?eh,tc_start,{config_static_SUITE,test_default_tclocal}}, + {?eh,tc_done,{config_static_SUITE,test_default_tclocal,ok}}, {?eh,test_stats,{4,0,{1,0}}}, - {?eh,tc_start,{config_1_SUITE,test_config_name_already_in_use2}}, + {?eh,tc_start,{config_static_SUITE,test_config_name_already_in_use2}}, {?eh,tc_done, - {config_1_SUITE,test_config_name_already_in_use2, + {config_static_SUITE,test_config_name_already_in_use2, {skipped,{config_name_already_in_use,[x1,alias]}}}}, {?eh,test_stats,{4,0,{2,0}}}, - {?eh,tc_start,{config_1_SUITE,test_alias_tclocal}}, - {?eh,tc_done,{config_1_SUITE,test_alias_tclocal,ok}}, + {?eh,tc_start,{config_static_SUITE,test_alias_tclocal}}, + {?eh,tc_done,{config_static_SUITE,test_alias_tclocal,ok}}, {?eh,test_stats,{5,0,{2,0}}}, - {?eh,tc_start,{config_1_SUITE,test_get_config_undefined}}, - {?eh,tc_done,{config_1_SUITE,test_get_config_undefined,ok}}, + {?eh,tc_start,{config_static_SUITE,test_get_config_undefined}}, + {?eh,tc_done,{config_static_SUITE,test_get_config_undefined,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,tc_start,{config_static_SUITE,end_per_suite}}, + {?eh,tc_done,{config_static_SUITE,end_per_suite,ok}}, {?eh,test_done,{'DEF','STOP_TIME'}}, {?eh,stop_logging,[]} ]; -expected_events(Dynamic) when Dynamic == testspec_dynamic; Dynamic == userconfig_dynamic-> +expected_events(config_dynamic_SUITE)-> [ {ct_test_support_eh,start_logging,{'DEF','RUNDIR'}}, {ct_test_support_eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}}, {ct_test_support_eh,start_info,{1,1,3}}, - {ct_test_support_eh,tc_start,{config_2_SUITE,init_per_suite}}, - {ct_test_support_eh,tc_done,{config_2_SUITE,init_per_suite,ok}}, - {ct_test_support_eh,tc_start,{config_2_SUITE,test_get_known_variable}}, - {ct_test_support_eh,tc_done,{config_2_SUITE,test_get_known_variable,ok}}, + {ct_test_support_eh,tc_start,{config_dynamic_SUITE,init_per_suite}}, + {ct_test_support_eh,tc_done,{config_dynamic_SUITE,init_per_suite,ok}}, + {ct_test_support_eh,tc_start,{config_dynamic_SUITE,test_get_known_variable}}, + {ct_test_support_eh,tc_done,{config_dynamic_SUITE,test_get_known_variable,ok}}, {ct_test_support_eh,test_stats,{1,0,{0,0}}}, - {ct_test_support_eh,tc_start,{config_2_SUITE,test_localtime_update}}, - {ct_test_support_eh,tc_done,{config_2_SUITE,test_localtime_update,ok}}, + {ct_test_support_eh,tc_start,{config_dynamic_SUITE,test_localtime_update}}, + {ct_test_support_eh,tc_done,{config_dynamic_SUITE,test_localtime_update,ok}}, {ct_test_support_eh,test_stats,{2,0,{0,0}}}, - {ct_test_support_eh,tc_start,{config_2_SUITE,test_server_pid}}, - {ct_test_support_eh,tc_done,{config_2_SUITE,test_server_pid,ok}}, + {ct_test_support_eh,tc_start,{config_dynamic_SUITE,test_server_pid}}, + {ct_test_support_eh,tc_done,{config_dynamic_SUITE,test_server_pid,ok}}, {ct_test_support_eh,test_stats,{3,0,{0,0}}}, - {ct_test_support_eh,tc_start,{config_2_SUITE,end_per_suite}}, - {ct_test_support_eh,tc_done,{config_2_SUITE,end_per_suite,ok}}, + {ct_test_support_eh,tc_start,{config_dynamic_SUITE,end_per_suite}}, + {ct_test_support_eh,tc_done,{config_dynamic_SUITE,end_per_suite,ok}}, {ct_test_support_eh,test_done,{'DEF','STOP_TIME'}}, {ct_test_support_eh,stop_logging,[]} ]. \ 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 deleted file mode 100644 index e102c69d3d..0000000000 --- a/lib/common_test/test/ct_config_SUITE_data/config/test/config_1_SUITE.erl +++ /dev/null @@ -1,151 +0,0 @@ -%% -%% %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: config_1_SUITE -%%% -%%% Description: -%%% Test suite for common_test which tests the get_config and require -%%% functionality -%%%------------------------------------------------------------------- --module(config_1_SUITE). - --compile(export_all). - --include_lib("common_test/include/ct.hrl"). - -% The config contains variables: -% x - atom -% gen_cfg - list with two key-values tagged with a and b -% gen_cfg2 - list of five key-values tagged with c, d, e, f and g -% gen_cfg3 - list of two complex key-values taggen with: -% h: three elements inside - i, j and k -% l: m inside, contains n and o - -suite() -> - [ - {timetrap, {seconds,10}}, - %% x1 doesn't exist in cfg-file! - {require, x1, x}, - {require, gen_cfg3}, - {require, alias, gen_cfg}, - %% x1 default value - {x1, {x,suite}} - ]. - -% to get it running on development branch (without userconfig features) -% function to print full config is in the ct_util, for me it's moved to ct_config -% two following functions are only for the design period -% after merging of userconfigs to the main branch ct_config:get_all_config/0 -% should be called instead -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() -> [test_get_config_simple, test_get_config_nested, test_default_suitewide, - test_config_name_already_in_use1, test_default_tclocal, - test_config_name_already_in_use2, test_alias_tclocal, - test_get_config_undefined]. - -init_per_testcase(_, Config) -> - %{Module, Cfg} = get_all_config(), - %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), - Config. - -end_per_testcase(_, _) -> - ok. - -%% test getting a simple value -test_get_config_simple(_)-> - suite = ct:get_config(x), - ok. - -%% test getting a nested value -test_get_config_nested(_)-> - a_value = ct:get_config({gen_cfg, a}), - ok. - -%% test suite-wide default value -test_default_suitewide(_)-> - suite = ct:get_config(x1), - ok. - -%% should get skipped -test_config_name_already_in_use1() -> - [{timetrap, {seconds,2}}, - {require, x1, x}, - {x1, {x,test2}}]. -test_config_name_already_in_use1(_) -> - ct:fail("Test should've been skipped, you shouldn't see this!"), - ok. - -%% test defaults in a testcase -test_default_tclocal() -> - [{timetrap, {seconds,3}}, - {require, y1, y}, - {y1, {y,test3}}]. -test_default_tclocal(_) -> - test3 = ct:get_config(y1), - ok. - -%% should get skipped -test_config_name_already_in_use2() -> - [{require,alias,something}, - {alias,{something,else}}, - {require, x1, x}, - {x1, {x,test4}}]. -test_config_name_already_in_use2(_) -> - ct:fail("Test should've been skipped, you shouldn't see this!"), - ok. - -%% test aliases -test_alias_tclocal() -> - [{require,newalias,gen_cfg}]. -test_alias_tclocal(_) -> - A = [{a,a_value},{b,b_value}] = ct:get_config(newalias), - A = ct:get_config(gen_cfg), - ok. - -%% test for getting undefined variables -test_get_config_undefined(_) -> - undefined = ct:get_config(y1), - ok. 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 deleted file mode 100644 index 86fd300a77..0000000000 --- a/lib/common_test/test/ct_config_SUITE_data/config/test/config_2_SUITE.erl +++ /dev/null @@ -1,133 +0,0 @@ -%% -%% %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 suite for common_test which tests the userconfig functionality -%%%------------------------------------------------------------------- --module(config_2_SUITE). - --compile(export_all). - --include_lib("common_test/include/ct.hrl"). - -%% This suite will be run with dynamic userconfig -%% test_driver.erl is compliant to ct_config_* callback -%% and test_server is simple server for getting runtime-changing data -%% which will return the list with the following variables: -%% localtime = the erlang:localtime() result in list [{date, Date}, {time, Time}] -%% node = erlang:node() - can be compared in the testcase -%% now = erlang:now() - easier to compare than localtime() -%% config_server_pid - pid of the config server, should NOT change! -%% config_server_vsn - .19 - -suite() -> - [ - {timetrap, {seconds,10}} - ]. - -% to get it running on development branch (without userconfig features) -% function to print full config is in the ct_util, for me it's moved to ct_config -% two following functions are only for the design period -% after merging of userconfigs to the main branch ct_config:get_all_config/0 -% should be called instead -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() -> [test_get_known_variable, test_localtime_update, - test_server_pid]. - -init_per_testcase(_, Config) -> - %{Module, Cfg} = get_all_config(), - %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), - Config. - -end_per_testcase(_, _) -> - ok. - -% test that usual config works -test_get_known_variable(_)-> - Node = erlang:node(), - 0.19 = ct:get_config(config_server_vsn), - Node = ct:get_config(node), - ok. - -% localtime will be updated in 5 seconds, check that -test_localtime_update(_)-> - Seconds = 5, - LT1 = ct:get_config(localtime), - timer:sleep(Seconds*1000), - LT2 = ct:reload_config(localtime), - case is_diff_ok(LT1, LT2, Seconds) of - {false, Actual, Exp}-> - ct:fail(io_lib:format("Time difference ~p is not ok, expected ~p", [Actual, Exp])); - true-> - ok - end. - -% server pid should not change -test_server_pid()-> - [{require, cfvsn, config_server_vsn}]. -test_server_pid(_)-> - Pid = ct:get_config(config_server_pid), - Pid = ct:reload_config(config_server_pid), - Vsn = ct:get_config(config_server_vsn), - % aliases remain after config reloading - Vsn = ct:get_config(cfvsn), - ok. - -my_dt_to_datetime([{date, D},{time, T}])-> - {D, T}. - -is_diff_ok(DT1, DT2, Seconds)-> - GS1 = calendar:datetime_to_gregorian_seconds(my_dt_to_datetime(DT1)), - GS2 = calendar:datetime_to_gregorian_seconds(my_dt_to_datetime(DT2)), - if - GS2-GS1 > Seconds+Seconds/2; - GS2-GS1 < Seconds-Seconds/2-> - {false, GS2-GS1, Seconds}; - true-> - true - end. diff --git a/lib/common_test/test/ct_config_SUITE_data/config/test/config_dynamic_SUITE.erl b/lib/common_test/test/ct_config_SUITE_data/config/test/config_dynamic_SUITE.erl new file mode 100644 index 0000000000..1013c46c7d --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_dynamic_SUITE.erl @@ -0,0 +1,172 @@ +%% +%% %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 suite for common_test which tests the userconfig functionality +%%%------------------------------------------------------------------- +-module(config_2_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +%% This suite will be run with dynamic userconfig +%% test_driver.erl is compliant to ct_config_* callback +%% and test_server is simple server for getting runtime-changing data +%% which will return the list with the following variables: +%% localtime = the erlang:localtime() result in list [{date, Date}, {time, Time}] +%% node = erlang:node() - can be compared in the testcase +%% now = erlang:now() - easier to compare than localtime() +%% config_server_pid - pid of the config server, should NOT change! +%% config_server_vsn - .19 +%% config_server_iteration - a number of iteration config_server's loop done +%% disappearable_variable - hereAmI - will be absent on even iterations + +suite() -> + [ + {timetrap, {seconds,10}} + ]. + +% to get it running on development branch (without userconfig features) +% function to print full config is in the ct_util, for me it's moved to ct_config +% two following functions are only for the design period +% after merging of userconfigs to the main branch ct_config:get_all_config/0 +% should be called instead +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() -> [test_get_known_variable, test_localtime_update, + test_server_pid, test_disappearable_variable, + test_disappearable_variable_alias]. + +init_per_testcase(_, Config) -> + %{Module, Cfg} = get_all_config(), + %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + Config. + +end_per_testcase(_, _) -> + ok. + +% test that usual config works +test_get_known_variable(_)-> + Node = erlang:node(), + 0.19 = ct:get_config(config_server_vsn), + Node = ct:get_config(node), + ok. + +% localtime will be updated in 5 seconds, check that +test_localtime_update(_)-> + Seconds = 5, + LT1 = ct:get_config(localtime), + timer:sleep(Seconds*1000), + LT2 = ct:reload_config(localtime), + case is_diff_ok(LT1, LT2, Seconds) of + {false, Actual, Exp}-> + ct:fail(io_lib:format("Time difference ~p is not ok, expected ~p", [Actual, Exp])); + true-> + ok + end. + +% server pid should not change +test_server_pid()-> + [{require, cfvsn, config_server_vsn}]. +test_server_pid(_)-> + Pid = ct:get_config(config_server_pid), + Pid = ct:reload_config(config_server_pid), + Vsn = ct:get_config(config_server_vsn), + % aliases remain after config reloading + Vsn = ct:get_config(cfvsn), + ok. + +% test that variables may disappear from the config_2_SUITE +test_disappearable_variable(_)-> + % ask CT for config_server_iteration variable + Iter = ct:reload_config(config_server_iteration), + % here we should reload this variable in case it's odd + if Iter rem 2 == 1-> + Iter2 = ct:reload_config(config_server_iteration), + Iter2 = Iter+1; + true->ok + end, + % now disappearable_variable should be in place + hereAmI = ct:get_config(disappearable_variable), + % and now it should disappear + undefined = ct:reload_config(disappearable_variable). + +% alias of disappearable_variable should disappear too +test_disappearable_variable_alias(_)-> + % the same rules apply for this testcase as for previous one + Iter = ct:reload_config(config_server_iteration), + Iter2 = if + Iter rem 2 == 1 -> + NewIter = ct:reload_config(config_server_iteration), + NewIter = Iter+1; + true-> + Iter + end, + ct:require(diav, disappearable_variable), + hereAmI = ct:get_config(disappearable_variable), + hereAmI = ct:get_config(diav), + undefined = ct:reload_config(disappearable_variable), + % after reloading, it's even again + Iter3=ct:get_config(config_server_iteration), + Iter3 = Iter2+1, + % and alias does not exist + undefined = ct:get_config(diav). + +my_dt_to_datetime([{date, D},{time, T}])-> + {D, T}. + +is_diff_ok(DT1, DT2, Seconds)-> + GS1 = calendar:datetime_to_gregorian_seconds(my_dt_to_datetime(DT1)), + GS2 = calendar:datetime_to_gregorian_seconds(my_dt_to_datetime(DT2)), + if + GS2-GS1 > Seconds+Seconds/2; + GS2-GS1 < Seconds-Seconds/2-> + {false, GS2-GS1, Seconds}; + true-> + true + end. diff --git a/lib/common_test/test/ct_config_SUITE_data/config/test/config_server.erl b/lib/common_test/test/ct_config_SUITE_data/config/test/config_server.erl index 0ee0bcfc22..f56bdf15ad 100644 --- a/lib/common_test/test/ct_config_SUITE_data/config/test/config_server.erl +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_server.erl @@ -24,7 +24,7 @@ %%% Config server used in the CT's tests (config_2_SUITE) %%%------------------------------------------------------------------- -module(config_server). --export([start/0, stop/0, init/1, get_config/0, loop/0]). +-export([start/0, stop/0, loop/1, init/1, get_config/0]). -define(REGISTERED_NAME, ct_test_config_server). -define(vsn, 0.19). @@ -41,7 +41,7 @@ start()-> init(Name)-> register(Name, self()), - loop(). + loop(0). get_config()-> call(self(), get_config). @@ -63,19 +63,25 @@ call(Client, Request)-> end end. -loop()-> +loop(Iteration)-> receive {Pid, stop}-> Pid ! ok; {Pid, get_config}-> {D,T} = erlang:localtime(), - Pid ! + Config = [{localtime, [{date, D}, {time, T}]}, {node, erlang:node()}, + {config_server_iteration, Iteration}, {now, erlang:now()}, {config_server_pid, self()}, {config_server_vsn, ?vsn}], - ?MODULE:loop() + Config2 = if Iteration rem 2 == 0-> + Config ++ [{disappearable_variable, hereAmI}]; + true-> Config + end, + Pid ! Config2, + ?MODULE:loop(Iteration+1) end. wait()-> diff --git a/lib/common_test/test/ct_config_SUITE_data/config/test/config_static_SUITE.erl b/lib/common_test/test/ct_config_SUITE_data/config/test/config_static_SUITE.erl new file mode 100644 index 0000000000..e102c69d3d --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_static_SUITE.erl @@ -0,0 +1,151 @@ +%% +%% %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: config_1_SUITE +%%% +%%% Description: +%%% Test suite for common_test which tests the get_config and require +%%% functionality +%%%------------------------------------------------------------------- +-module(config_1_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +% The config contains variables: +% x - atom +% gen_cfg - list with two key-values tagged with a and b +% gen_cfg2 - list of five key-values tagged with c, d, e, f and g +% gen_cfg3 - list of two complex key-values taggen with: +% h: three elements inside - i, j and k +% l: m inside, contains n and o + +suite() -> + [ + {timetrap, {seconds,10}}, + %% x1 doesn't exist in cfg-file! + {require, x1, x}, + {require, gen_cfg3}, + {require, alias, gen_cfg}, + %% x1 default value + {x1, {x,suite}} + ]. + +% to get it running on development branch (without userconfig features) +% function to print full config is in the ct_util, for me it's moved to ct_config +% two following functions are only for the design period +% after merging of userconfigs to the main branch ct_config:get_all_config/0 +% should be called instead +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() -> [test_get_config_simple, test_get_config_nested, test_default_suitewide, + test_config_name_already_in_use1, test_default_tclocal, + test_config_name_already_in_use2, test_alias_tclocal, + test_get_config_undefined]. + +init_per_testcase(_, Config) -> + %{Module, Cfg} = get_all_config(), + %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + Config. + +end_per_testcase(_, _) -> + ok. + +%% test getting a simple value +test_get_config_simple(_)-> + suite = ct:get_config(x), + ok. + +%% test getting a nested value +test_get_config_nested(_)-> + a_value = ct:get_config({gen_cfg, a}), + ok. + +%% test suite-wide default value +test_default_suitewide(_)-> + suite = ct:get_config(x1), + ok. + +%% should get skipped +test_config_name_already_in_use1() -> + [{timetrap, {seconds,2}}, + {require, x1, x}, + {x1, {x,test2}}]. +test_config_name_already_in_use1(_) -> + ct:fail("Test should've been skipped, you shouldn't see this!"), + ok. + +%% test defaults in a testcase +test_default_tclocal() -> + [{timetrap, {seconds,3}}, + {require, y1, y}, + {y1, {y,test3}}]. +test_default_tclocal(_) -> + test3 = ct:get_config(y1), + ok. + +%% should get skipped +test_config_name_already_in_use2() -> + [{require,alias,something}, + {alias,{something,else}}, + {require, x1, x}, + {x1, {x,test4}}]. +test_config_name_already_in_use2(_) -> + ct:fail("Test should've been skipped, you shouldn't see this!"), + ok. + +%% test aliases +test_alias_tclocal() -> + [{require,newalias,gen_cfg}]. +test_alias_tclocal(_) -> + A = [{a,a_value},{b,b_value}] = ct:get_config(newalias), + A = ct:get_config(gen_cfg), + ok. + +%% test for getting undefined variables +test_get_config_undefined(_) -> + undefined = ct:get_config(y1), + ok. -- cgit v1.2.3