aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/common_test/src/ct_config.erl10
-rw-r--r--lib/common_test/src/ct_run.erl1
-rw-r--r--lib/common_test/src/ct_testspec.erl18
-rw-r--r--lib/common_test/src/ct_util.hrl1
-rw-r--r--lib/common_test/src/vts.erl8
-rw-r--r--lib/common_test/test/ct_config_SUITE.erl127
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/cfg.cfg11
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/config.txt31
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/config.xml27
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/test/config_1_SUITE.erl100
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/test/config_2_SUITE.erl88
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/test/config_driver.erl41
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/test/config_server.erl87
13 files changed, 420 insertions, 130 deletions
diff --git a/lib/common_test/src/ct_config.erl b/lib/common_test/src/ct_config.erl
index 8e2f71647f..bc57930381 100755
--- a/lib/common_test/src/ct_config.erl
+++ b/lib/common_test/src/ct_config.erl
@@ -198,13 +198,13 @@ get_config_file_list(Opts)->
DefaultConfigs == []->
[];
true->
- [{ct_config_plain, DefaultConfigs}]
+ [{?ct_config_txt, DefaultConfigs}]
end ++
process_user_configs(Opts, []),
CfgFiles.
read_config_files(Opts) ->
- ct:pal("ct_config:read_config_files/1:~nOpts:~n~p", [Opts]),
+ %ct:pal("ct_config:read_config_files/1:~nOpts:~n~p", [Opts]),
AddCallback = fun(CallBack, [])->
[{CallBack, []}];
(CallBack, Files)->
@@ -220,7 +220,7 @@ read_config_files(Opts) ->
false->
[]
end,
- ct:pal("ct_config:read_config_files/1:~nConfigFiles:~n~p", [ConfigFiles]),
+ %ct:pal("ct_config:read_config_files/1:~nConfigFiles:~n~p", [ConfigFiles]),
read_config_files_int(ConfigFiles, fun store_config/3).
read_config_files_int([{Callback, File}|Files], FunToSave)->
@@ -687,7 +687,7 @@ check_callback_load(Callback)->
end.
check_config_files(Configs)->
- ct:pal("ct_config:check_config_files(~p)", [Configs]),
+ ct:pal("ct_config:check_config_files/1~nConfigs:~n~p", [Configs]),
lists:keysearch(nok, 1,
lists:flatten(
lists:map(fun({Callback, Files})->
@@ -719,7 +719,7 @@ prepare_user_configs([], Acc, _)->
prepare_config_list(Args)->
ConfigFiles = case lists:keysearch(ct_config, 1, Args) of
{value,{ct_config,Files}}->
- [{ct_config_plain, Files}];
+ [{?ct_config_txt, Files}];
false->
[]
end,
diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl
index cf5c99ee19..0e7da60821 100644
--- a/lib/common_test/src/ct_run.erl
+++ b/lib/common_test/src/ct_run.erl
@@ -467,6 +467,7 @@ install(Opts, LogDir) ->
case whereis(ct_util_server) of
undefined ->
VarFile = variables_file_name(LogDir),
+ io:format("Varfile=~p~n", [VarFile]),
case file:open(VarFile, [write]) of
{ok,Fd} ->
[io:format(Fd, "~p.\n", [Opt]) || Opt <- Opts],
diff --git a/lib/common_test/src/ct_testspec.erl b/lib/common_test/src/ct_testspec.erl
index 169c614955..8a384a1b3a 100644
--- a/lib/common_test/src/ct_testspec.erl
+++ b/lib/common_test/src/ct_testspec.erl
@@ -416,16 +416,17 @@ add_tests([{cover,File}|Ts],Spec) ->
add_tests([{cover,all_nodes,File}|Ts],Spec);
%% --- config ---
+% TODO finish that!
add_tests([{config,all_nodes,Files}|Ts],Spec) ->
- io:format("1: add_tests([{config,all_nodes,~p}|~p],~p~n", [Files, Ts, Spec]),
- Tests = lists:map(fun(N) -> {config,N,{ct_config_plain,Files}} end, list_nodes(Spec)),
+ %io:format("1: add_tests([{config,all_nodes,~p}|~p],~p~n", [Files, Ts, Spec]),
+ Tests = lists:map(fun(N) -> {config,N,{?ct_config_txt,Files}} end, list_nodes(Spec)),
add_tests(Tests++Ts,Spec);
add_tests([{config,Nodes,Files}|Ts],Spec) when is_list(Nodes) ->
- io:format("2: add_tests([{config,~p,~p}|~p],~p) when is_list(Nodes)~n", [Nodes,Files,Spec,Nodes]),
+ %io:format("2: add_tests([{config,~p,~p}|~p],~p) when is_list(Nodes)~n", [Nodes,Files,Spec,Nodes]),
Ts1 = separate(Nodes,config,[Files],Ts,Spec#testspec.nodes),
add_tests(Ts1,Spec);
add_tests([{config,Node,[{Callback,F}|Fs]}|Ts],Spec) when is_list(F) ->
- io:format("3: add_tests([{config,~p,[~p|~p]}|~p],~p) when is_list(~p)~n", [Node, F, Fs, Ts, Spec, F]),
+ %io:format("3: add_tests([{config,~p,[~p|~p]}|~p],~p) when is_list(~p)~n", [Node, F, Fs, Ts, Spec, F]),
Cfgs = Spec#testspec.config,
Node1 = ref2node(Node,Spec#testspec.nodes),
add_tests([{config,Node,Fs}|Ts],
@@ -436,18 +437,19 @@ add_tests([{config,Node,[{Callback,F}|Fs]}|Ts],Spec) when is_list(F) ->
% Spec#testspec{config=[{Node1,{Callback, get_absfile(F,Spec)}}|Cfgs]});
Spec#testspec{config=[{Node1,{Callback,[F]}}|Cfgs]});
add_tests([{config,_Node,[]}|Ts],Spec) ->
- io:format("4: add_tests([{config,_,[]}|~p],~p)~n", [Ts, Spec]),
+ %io:format("4: add_tests([{config,_,[]}|~p],~p)~n", [Ts, Spec]),
add_tests(Ts,Spec);
add_tests([{config,Node,F}|Ts],Spec) ->
- io:format("5: add_tests([{config,~p,~p}|~p],~p)~n", [Node, F, Ts, Spec]),
+ %io:format("5: add_tests([{config,~p,~p}|~p],~p)~n", [Node, F, Ts, Spec]),
add_tests([{config,Node,[F]}|Ts],Spec);
add_tests([{config,Files}|Ts],Spec) ->
- io:format("6: add_tests([{config,~p}|~p],~p)~n", [Files, Ts, Spec]),
+ %io:format("6: add_tests([{config,~p}|~p],~p)~n", [Files, Ts, Spec]),
add_tests([{config,all_nodes,Files}|Ts],Spec);
+% TODO add support for {userconfig, Nodes, {Callback, Files}}
%% --- userconfig ---
add_tests([{userconfig, {Callback, Files}}|Ts], Spec)->
- io:format("add_tests([{userconfig, {~p, ~p}}|~p], ~p)~n", [Callback, Files, Ts, Spec]),
+ %io:format("add_tests([{userconfig, {~p, ~p}}|~p], ~p)~n", [Callback, Files, Ts, Spec]),
Tests = lists:map(fun(N) -> {config,N,{Callback,Files}} end, list_nodes(Spec)),
add_tests(Tests++Ts,Spec);
diff --git a/lib/common_test/src/ct_util.hrl b/lib/common_test/src/ct_util.hrl
index c1dc14f943..fff59f3fde 100644
--- a/lib/common_test/src/ct_util.hrl
+++ b/lib/common_test/src/ct_util.hrl
@@ -50,3 +50,4 @@
-define(CT_MEVMGR_REF, ct_master_event).
-define(missing_suites_info, "missing_suites.info").
+-define(ct_config_txt, ct_config_plain). \ No newline at end of file
diff --git a/lib/common_test/src/vts.erl b/lib/common_test/src/vts.erl
index ad4845a7c3..c94a796ab8 100644
--- a/lib/common_test/src/vts.erl
+++ b/lib/common_test/src/vts.erl
@@ -161,10 +161,12 @@ init(Parent) ->
loop(State) ->
receive
{{init_data,ConfigFiles,EvHandlers,LogDir,Tests},From} ->
- ct_install(State),
+ ct:pal("State#state.current_log_dir=~p", [State#state.current_log_dir]),
+ NewState = State#state{config=ConfigFiles,event_handler=EvHandlers,
+ current_log_dir=LogDir,tests=Tests},
+ ct_install(NewState),
return(From,ok),
- loop(#state{config=ConfigFiles,event_handler=EvHandlers,
- current_log_dir=LogDir,tests=Tests});
+ loop(NewState);
{start_page,From} ->
return(From,start_page1()),
loop(State);
diff --git a/lib/common_test/test/ct_config_SUITE.erl b/lib/common_test/test/ct_config_SUITE.erl
index 38c8cbe6eb..4ae68fbfa8 100644
--- a/lib/common_test/test/ct_config_SUITE.erl
+++ b/lib/common_test/test/ct_config_SUITE.erl
@@ -62,7 +62,8 @@ all(doc) ->
all(suite) ->
[
require,
- nested_keys
+ userconfig_static,
+ userconfig_dynamic
].
@@ -74,41 +75,41 @@ all(suite) ->
%%%
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)),
+ run_test(require,
+ Config,
+ {config, filename:join(DataDir, "config/config.txt")},
+ ["config_1_SUITE"]).
- TestEvents = test_events(require),
- ok = ct_test_support:verify_events(TestEvents, Events, Config).
-
-nested_keys(Config) when is_list(Config) ->
+userconfig_static(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),
+ run_test(userconfig_static,
+ Config,
+ {userconfig, {ct_config_xml, filename:join(DataDir, "config/config.xml")}},
+ ["config_1_SUITE"]).
- 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).
+userconfig_dynamic(Config) when is_list(Config) ->
+ run_test(userconfig_dynamic,
+ Config,
+ {userconfig, {config_driver, "config_server"}},
+ ["config_2_SUITE"]).
%%%-----------------------------------------------------------------
%%% HELP FUNCTIONS
%%%-----------------------------------------------------------------
+run_test(Name, Config, CTConfig, SuiteNames)->
+ DataDir = ?config(data_dir, Config),
+ Joiner = fun(Suite) -> filename:join(DataDir, "config/test/"++Suite) end,
+ Suites = lists:map(Joiner, SuiteNames),
+ {Opts,ERPid} = setup_env({suite,Suites}, Config, CTConfig),
+ ok = ct_test_support:run(ct, run_test, [Opts], Config),
+ TestEvents = ct_test_support:get_events(ERPid, Config),
+ ct_test_support:log_events(Name,
+ reformat_events(TestEvents, ?eh),
+ ?config(priv_dir, Config)),
+ ExpEvents = expected_events(Name),
+ ok = ct_test_support:verify_events(ExpEvents, TestEvents, Config).
-setup(Test, Config, CTConfig) ->
+setup_env(Test, Config, CTConfig) ->
Opts0 = ct_test_support:get_opts(Config),
Level = ?config(trace_level, Config),
EvHArgs = [{cbm,ct_test_support},{trace_level,Level}],
@@ -116,46 +117,45 @@ setup(Test, Config, CTConfig) ->
ERPid = ct_test_support:start_event_receiver(Config),
{Opts,ERPid}.
-reformat(Events, EH) ->
+reformat_events(Events, EH) ->
ct_test_support:reformat(Events, EH).
-%reformat(Events, _EH) ->
-% Events.
%%%-----------------------------------------------------------------
%%% TEST EVENTS
%%%-----------------------------------------------------------------
-test_events(require) ->
+expected_events(ReqOrUCS) when ReqOrUCS==require; ReqOrUCS==userconfig_static->
[
{?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,tc_start,{config_1_SUITE,test_get_config_simple}},
+ {?eh,tc_done,{config_1_SUITE,test_get_config_simple,ok}},
{?eh,test_stats,{1,0,{0,0}}},
- {?eh,tc_start,{config_1_SUITE,test2}},
+ {?eh,tc_start,{config_1_SUITE,test_get_config_nested}},
+ {?eh,tc_done,{config_1_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,test_stats,{3,0,{0,0}}},
+ {?eh,tc_start,{config_1_SUITE,test_config_name_already_in_use1}},
{?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}},
+ {config_1_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,test_stats,{4,0,{1,0}}},
+ {?eh,tc_start,{config_1_SUITE,test_config_name_already_in_use2}},
{?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}},
+ {config_1_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,test7}},
- {?eh,tc_done,{config_1_SUITE,test7,ok}},
+ {?eh,tc_start,{config_1_SUITE,test_alias_tclocal}},
+ {?eh,tc_done,{config_1_SUITE,test_alias_tclocal,ok}},
{?eh,test_stats,{5,0,{2,0}}},
- {?eh,tc_start,{config_1_SUITE,test8}},
- {?eh,tc_done,{config_1_SUITE,test8,ok}},
+ {?eh,tc_start,{config_1_SUITE,test_get_config_undefined}},
+ {?eh,tc_done,{config_1_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}},
@@ -163,5 +163,24 @@ test_events(require) ->
{?eh,stop_logging,[]}
];
-test_events(nested_keys)->
-[].
+expected_events(userconfig_dynamic)->
+[
+ {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,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,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,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,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/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.