aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/common_test/src/ct.erl23
-rwxr-xr-xlib/common_test/src/ct_config.erl1
-rw-r--r--lib/common_test/src/ct_master.erl29
-rw-r--r--lib/common_test/src/ct_testspec.erl8
-rw-r--r--lib/common_test/src/ct_util.hrl3
-rw-r--r--lib/common_test/test/ct_config_SUITE_data/config/config.txt2
6 files changed, 52 insertions, 14 deletions
diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl
index caae2326b6..6cc876b42e 100644
--- a/lib/common_test/src/ct.erl
+++ b/lib/common_test/src/ct.erl
@@ -807,8 +807,31 @@ decrypt_config_file(EncryptFileName, TargetFileName) ->
decrypt_config_file(EncryptFileName, TargetFileName, KeyOrFile) ->
ct_config:decrypt_config_file(EncryptFileName, TargetFileName, KeyOrFile).
+
+%%%-----------------------------------------------------------------
+%%% @spec add_config(Callback, Config) ->
+%%% ok | {error, Reason}
+%%% Callback = atom()
+%%% Config = string()
+%%% Reason = term()
+%%%
+%%% @doc <p>This function loads configuration variables using the
+%%% given callback module and configuration string. Callback module
+%%% should be either loaded or present in the code part. Loaded
+%%% configuration variables can later be removed using
+%%% <code>remove_config/2</code> function.</p>
add_config(Callback, Config)->
ct_config:add_config(Callback, Config).
+%%%-----------------------------------------------------------------
+%%% @spec remove_config(Callback, Config) ->
+%%% ok
+%%% Callback = atom()
+%%% Config = string()
+%%% Reason = term()
+%%%
+%%% @doc <p>This function removes configuration variables (together with
+%%% their aliases) which were loaded with specified callback module and
+%%% configuration string.</p>
remove_config(Callback, Config)->
ct_config:remove_config(Callback, Config).
diff --git a/lib/common_test/src/ct_config.erl b/lib/common_test/src/ct_config.erl
index 312dc8782f..6314361b35 100755
--- a/lib/common_test/src/ct_config.erl
+++ b/lib/common_test/src/ct_config.erl
@@ -753,6 +753,7 @@ prepare_config_list(Args)->
end,
ConfigFiles ++ UserConfigs.
+% TODO: add logging of the loaded configuration file to the CT FW log!!!
add_config(Callback, [])->
read_config_files_int([{Callback, []}], fun store_config/3);
add_config(Callback, [File|_Files]=Config) when is_list(File)->
diff --git a/lib/common_test/src/ct_master.erl b/lib/common_test/src/ct_master.erl
index 7eb2c3cfef..94afccde79 100644
--- a/lib/common_test/src/ct_master.erl
+++ b/lib/common_test/src/ct_master.erl
@@ -49,7 +49,8 @@
%%% OptTuples = {config,CfgFiles} | {dir,TestDirs} | {suite,Suites} |
%%% {testcase,Cases} | {spec,TestSpecs} | {allow_user_terms,Bool} |
%%% {logdir,LogDir} | {event_handler,EventHandlers} |
-%%% {silent_connections,Conns} | {cover,CoverSpecFile}
+%%% {silent_connections,Conns} | {cover,CoverSpecFile} |
+%%% {userconfig, UserCfgFiles}
%%% CfgFiles = string() | [string()]
%%% TestDirs = string() | [string()]
%%% Suites = atom() | [atom()]
@@ -98,8 +99,10 @@ run([TS|TestSpecs],AllowUserTerms,InclNodes,ExclNodes) when is_list(TS),
{error,Reason} ->
{error,Reason};
TSRec=#testspec{logdir=AllLogDirs,
- config=AllCfgFiles,
+ config=StdCfgFiles,
+ userconfig=UserCfgFiles,
event_handler=AllEvHs} ->
+ AllCfgFiles = {StdCfgFiles, UserCfgFiles},
RunSkipPerNode = ct_testspec:prepare_tests(TSRec),
RunSkipPerNode2 = exclude_nodes(ExclNodes,RunSkipPerNode),
run_all(RunSkipPerNode2,AllLogDirs,AllCfgFiles,AllEvHs,[],[],TS1)
@@ -157,8 +160,10 @@ run_on_node([TS|TestSpecs],AllowUserTerms,Node) when is_list(TS),is_atom(Node) -
{error,Reason} ->
{error,Reason};
TSRec=#testspec{logdir=AllLogDirs,
- config=AllCfgFiles,
+ config=StdCfgFiles,
+ userconfig=UserCfgFiles,
event_handler=AllEvHs} ->
+ AllCfgFiles = {StdCfgFiles, UserCfgFiles},
{Run,Skip} = ct_testspec:prepare_tests(TSRec,Node),
run_all([{Node,Run,Skip}],AllLogDirs,AllCfgFiles,AllEvHs,[],[],TS1)
end,
@@ -180,7 +185,9 @@ run_on_node(TestSpecs,Node) ->
-run_all([{Node,Run,Skip}|Rest],AllLogDirs,AllCfgFiles,AllEvHs,NodeOpts,LogDirs,Specs) ->
+run_all([{Node,Run,Skip}|Rest],AllLogDirs,
+ {AllStdCfgFiles, AllUserCfgFiles}=AllCfgFiles,
+ AllEvHs,NodeOpts,LogDirs,Specs) ->
LogDir =
lists:foldl(fun({N,Dir},_Found) when N == Node ->
Dir;
@@ -191,11 +198,17 @@ run_all([{Node,Run,Skip}|Rest],AllLogDirs,AllCfgFiles,AllEvHs,NodeOpts,LogDirs,S
(_Dir,Found) ->
Found
end,".",AllLogDirs),
- CfgFiles =
+
+ StdCfgFiles =
lists:foldr(fun({N,F},Fs) when N == Node -> [F|Fs];
({_N,_F},Fs) -> Fs;
(F,Fs) -> [F|Fs]
- end,[],AllCfgFiles),
+ end,[],AllStdCfgFiles),
+ UserCfgFiles =
+ lists:foldr(fun({N,F},Fs) when N == Node -> [{userconfig, F}|Fs];
+ ({_N,_F},Fs) -> Fs;
+ (F,Fs) -> [{userconfig, F}|Fs]
+ end,[],AllUserCfgFiles),
EvHs =
lists:foldr(fun({N,H,A},Hs) when N == Node -> [{H,A}|Hs];
({_N,_H,_A},Hs) -> Hs;
@@ -203,8 +216,8 @@ run_all([{Node,Run,Skip}|Rest],AllLogDirs,AllCfgFiles,AllEvHs,NodeOpts,LogDirs,S
end,[],AllEvHs),
NO = {Node,[{prepared_tests,{Run,Skip},Specs},
{logdir,LogDir},
- {config,CfgFiles},
- {event_handler,EvHs}]},
+ {config,StdCfgFiles},
+ {event_handler,EvHs}] ++ UserCfgFiles},
run_all(Rest,AllLogDirs,AllCfgFiles,AllEvHs,[NO|NodeOpts],[LogDir|LogDirs],Specs);
run_all([],AllLogDirs,_,AllEvHs,NodeOpts,LogDirs,Specs) ->
Handlers = [{H,A} || {Master,H,A} <- AllEvHs, Master == master],
diff --git a/lib/common_test/src/ct_testspec.erl b/lib/common_test/src/ct_testspec.erl
index cd7fe04738..a0da079c54 100644
--- a/lib/common_test/src/ct_testspec.erl
+++ b/lib/common_test/src/ct_testspec.erl
@@ -446,8 +446,7 @@ add_tests([{config,Node,[F|Fs]}|Ts],Spec) when is_list(F) ->
Cfgs = Spec#testspec.config,
Node1 = ref2node(Node,Spec#testspec.nodes),
add_tests([{config,Node,Fs}|Ts],
- Spec#testspec{config=[{Node1,{?ct_config_txt,
- get_absfile(?ct_config_txt, F,Spec)}}|Cfgs]});
+ Spec#testspec{config=[{Node1,get_absfile(F,Spec)}|Cfgs]});
add_tests([{config,_Node,[]}|Ts],Spec) ->
add_tests(Ts,Spec);
add_tests([{config,Node,F}|Ts],Spec) ->
@@ -455,6 +454,7 @@ add_tests([{config,Node,F}|Ts],Spec) ->
add_tests([{config,Files}|Ts],Spec) ->
add_tests([{config,all_nodes,Files}|Ts],Spec);
+
%% --- userconfig ---
add_tests([{userconfig,all_nodes,CBF}|Ts],Spec) ->
Tests = lists:map(fun(N) -> {userconfig,N,CBF} end, list_nodes(Spec)),
@@ -463,10 +463,10 @@ add_tests([{userconfig,Nodes,CBF}|Ts],Spec) when is_list(Nodes) ->
Ts1 = separate(Nodes,userconfig,[CBF],Ts,Spec#testspec.nodes),
add_tests(Ts1,Spec);
add_tests([{userconfig,Node,[{Callback, Config}|CBF]}|Ts],Spec) ->
- Cfgs = Spec#testspec.config,
+ Cfgs = Spec#testspec.userconfig,
Node1 = ref2node(Node,Spec#testspec.nodes),
add_tests([{userconfig,Node,CBF}|Ts],
- Spec#testspec{config=[{Node1,{Callback,
+ Spec#testspec{userconfig=[{Node1,{Callback,
get_absfile(Callback, Config ,Spec)}}|Cfgs]});
add_tests([{userconfig,_Node,[]}|Ts],Spec) ->
add_tests(Ts,Spec);
diff --git a/lib/common_test/src/ct_util.hrl b/lib/common_test/src/ct_util.hrl
index fff59f3fde..c2f51dfba5 100644
--- a/lib/common_test/src/ct_util.hrl
+++ b/lib/common_test/src/ct_util.hrl
@@ -32,6 +32,7 @@
logdir=["."],
cover=[],
config=[],
+ userconfig=[],
event_handler=[],
include=[],
alias=[],
@@ -50,4 +51,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
+-define(ct_config_txt, ct_config_plain).
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
index 0424dbf92e..fcbffcd7f3 100644
--- a/lib/common_test/test/ct_config_SUITE_data/config/config.txt
+++ b/lib/common_test/test/ct_config_SUITE_data/config/config.txt
@@ -28,4 +28,4 @@
{o, 'O'}
]}
]}
- ]}. \ No newline at end of file
+ ]}.