diff options
Diffstat (limited to 'lib/common_test/test/ct_config_SUITE_data')
7 files changed, 325 insertions, 60 deletions
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 deleted file mode 100644 index f0c1783189..0000000000 --- a/lib/common_test/test/ct_config_SUITE_data/config/cfg.cfg +++ /dev/null @@ -1,11 +0,0 @@ -{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/config.txt b/lib/common_test/test/ct_config_SUITE_data/config/config.txt new file mode 100644 index 0000000000..0424dbf92e --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/config.txt @@ -0,0 +1,31 @@ +{x, suite}. +{gen_cfg, + [ + {a,a_value}, + {b,b_value} + ]}. +{gen_cfg2, + [ + {c, "Hello, world!"}, + {d, atom_value}, + {e, {tuple,1,"third value",[]}}, + {f, []}, + {g, [1,atom,"string",13.6,{1,2,3}]} + ]}. +{gen_cfg3, + [ + {h, + [ + {i, third1}, + {j, "Third2"}, + {k, 'THIRD3'} + ]}, + {l, + [ + {m, + [ + {n, "N"}, + {o, 'O'} + ]} + ]} + ]}.
\ No newline at end of file diff --git a/lib/common_test/test/ct_config_SUITE_data/config/config.xml b/lib/common_test/test/ct_config_SUITE_data/config/config.xml new file mode 100644 index 0000000000..0a3e5f2e31 --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/config.xml @@ -0,0 +1,27 @@ +<config> + <x>suite</x> + <gen_cfg> + <a>a_value</a> + <b>b_value</b> + </gen_cfg> + <gen_cfg2> + <c>"Hello, world!"</c> + <d>atom_value</d> + <e>{tuple,1,"third value",[]}</e> + <f>[]</f> + <g>[1,atom,"string",13.6,{1,2,3}]</g> + </gen_cfg2> + <gen_cfg3> + <h> + <i>third1</i> + <j>"Third2"</j> + <k>'THIRD3'</k> + </h> + <l> + <m> + <n>"N"</n> + <o>'O'</o> + </m> + </l> + </gen_cfg3> +</config> 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 index 696014ee9f..e102c69d3d 100644 --- 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 @@ -16,23 +16,44 @@ %% %% %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_cfg2}, - {require, alias, gen_cfg3}, + {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 @@ -53,83 +74,78 @@ get_all_config()-> end. init_per_suite(Config) -> - {Module, Cfg} = get_all_config(), - ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + %{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]. +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]), + %{Module, Cfg} = get_all_config(), + %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), Config. end_per_testcase(_, _) -> ok. -test1(_) -> +%% 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), - [{a,x},{b,y}] = ct:get_config(gen_cfg2), - [{v,w},{m,n}] = ct:get_config(alias), ok. %% should get skipped -test2() -> +test_config_name_already_in_use1() -> [{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), +test_config_name_already_in_use1(_) -> ct:fail("Test should've been skipped, you shouldn't see this!"), ok. -test3() -> +%% test defaults in a testcase +test_default_tclocal() -> [{timetrap, {seconds,3}}, {require, y1, y}, {y1, {y,test3}}]. -test3(_) -> - suite = ct:get_config(x1), +test_default_tclocal(_) -> 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() -> +test_config_name_already_in_use2() -> [{require,alias,something}, {alias,{something,else}}, {require, x1, x}, {x1, {x,test4}}]. -test4(_) -> +test_config_name_already_in_use2(_) -> 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), +%% 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. -test6(_) -> +%% test for getting undefined variables +test_get_config_undefined(_) -> 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 index 25e050984a..86fd300a77 100644 --- 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 @@ -1,4 +1,14 @@ %% +%% %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 @@ -6,17 +16,39 @@ %% %% %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 @@ -37,23 +69,65 @@ get_all_config()-> end. init_per_suite(Config) -> - {Module, Cfg} = get_all_config(), - ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), + %{Module, Cfg} = get_all_config(), + %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]), Config. end_per_suite(_) -> ok. -all() -> [test1]. +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]), + %{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}), +% 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_driver.erl b/lib/common_test/test/ct_config_SUITE_data/config/test/config_driver.erl new file mode 100644 index 0000000000..37572500c7 --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_driver.erl @@ -0,0 +1,41 @@ +%% +%% %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: +%%% Config driver used in the CT's tests (config_2_SUITE) +%%%------------------------------------------------------------------- +-module(config_driver). +-export([read_config/1, check_parameter/1]). + +read_config(ServerName)-> + ServerModule = list_to_atom(ServerName), + ServerModule:start(), + ServerModule:get_config(). + +check_parameter(ServerName)-> + ServerModule = list_to_atom(ServerName), + case code:load_file(ServerModule) of + {module, ServerModule}-> + {ok, {config, ServerName}}; + {error, nofile}-> + {nok, {wrong_config, "File not found: " ++ ServerName ++ ".beam"}} + 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 new file mode 100644 index 0000000000..0ee0bcfc22 --- /dev/null +++ b/lib/common_test/test/ct_config_SUITE_data/config/test/config_server.erl @@ -0,0 +1,87 @@ +%% +%% %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: +%%% 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]). + +-define(REGISTERED_NAME, ct_test_config_server). +-define(vsn, 0.19). + +start()-> + case whereis(?REGISTERED_NAME) of + undefined-> + spawn(?MODULE, init, [?REGISTERED_NAME]), + wait(); + _Pid-> + ok + end, + ?REGISTERED_NAME. + +init(Name)-> + register(Name, self()), + loop(). + +get_config()-> + call(self(), get_config). + +stop()-> + call(self(), stop). + +call(Client, Request)-> + case whereis(?REGISTERED_NAME) of + undefined-> + {error, not_started, Request}; + Pid-> + Pid ! {Client, Request}, + receive + Reply-> + {ok, Reply} + after 4000-> + {error, timeout, Request} + end + end. + +loop()-> + receive + {Pid, stop}-> + Pid ! ok; + {Pid, get_config}-> + {D,T} = erlang:localtime(), + Pid ! + [{localtime, [{date, D}, {time, T}]}, + {node, erlang:node()}, + {now, erlang:now()}, + {config_server_pid, self()}, + {config_server_vsn, ?vsn}], + ?MODULE:loop() + end. + +wait()-> + case whereis(?REGISTERED_NAME) of + undefined-> + wait(); + _Pid-> + ok + end. |