aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common_test')
-rwxr-xr-xlib/common_test/src/ct_config.erl60
-rwxr-xr-xlib/common_test/src/ct_config_plain.erl13
-rwxr-xr-xlib/common_test/src/ct_config_xml.erl15
-rw-r--r--lib/common_test/src/ct_run.erl72
4 files changed, 95 insertions, 65 deletions
diff --git a/lib/common_test/src/ct_config.erl b/lib/common_test/src/ct_config.erl
index dbb0e0b152..63e44b6301 100755
--- a/lib/common_test/src/ct_config.erl
+++ b/lib/common_test/src/ct_config.erl
@@ -48,6 +48,8 @@
-export([get_ref_from_name/1, get_name_from_ref/1, get_key_from_name/1]).
+-export([check_config_files/1, prepare_config_list/1]).
+
-include("ct_util.hrl").
-define(cryptfile, ".ct_config.crypt").
@@ -179,6 +181,8 @@ process_user_configs(Opts, Acc)->
case lists:keytake(userconfig, 1, Opts) of
false->
Acc;
+ {value, {userconfig, {Callback, []}}, NewOpts}->
+ process_user_configs(NewOpts, [{Callback, []} | Acc]);
{value, {userconfig, {Callback, Files=[File|_]}}, NewOpts} when
is_list(File)->
process_user_configs(NewOpts, [{Callback, Files} | Acc]);
@@ -202,9 +206,12 @@ get_config_file_list(Opts)->
CfgFiles.
read_config_files(Opts) ->
- AddCallback = fun(CallBack, Files)->
- lists:map(fun(X)-> {CallBack, X} end, Files)
- end,
+ ct:pal("ct_config:read_config_files/1:~nOpts:~n~p", [Opts]),
+ AddCallback = fun(CallBack, [])->
+ [{CallBack, []}];
+ (CallBack, Files)->
+ lists:map(fun(X)-> {CallBack, X} end, Files)
+ end,
ConfigFiles = case lists:keyfind(config, 1, Opts) of
{config, ConfigLists}->
lists:foldr(fun({Callback,Files}, Acc)->
@@ -215,10 +222,11 @@ read_config_files(Opts) ->
false->
[]
end,
+ 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)->
- case Callback:read_config_file(File) of
+ case Callback:read_config(File) of
{ok, Config}->
FunToSave(Config, Callback, File),
read_config_files_int(Files, FunToSave);
@@ -666,3 +674,47 @@ random_bytes(N) ->
random_bytes_1(0, Acc) -> Acc;
random_bytes_1(N, Acc) -> random_bytes_1(N-1, [random:uniform(255)|Acc]).
+
+check_config_files(Configs)->
+ lists:keysearch(nok, 1,
+ lists:flatten(
+ lists:map(fun({Callback, Files})->
+ case code:load_file(Callback) of
+ {module, Callback}->
+ lists:map(fun(File)->
+ Callback:check_parameter(File)
+ end,
+ Files);
+ {error, _}->
+ {nok, {callback, Callback}}
+ end
+ end,
+ Configs))).
+
+prepare_user_configs([ConfigString|UserConfigs], Acc, new)->
+ prepare_user_configs(UserConfigs,
+ [{list_to_atom(ConfigString), []}|Acc],
+ cur);
+prepare_user_configs(["and"|UserConfigs], Acc, _)->
+ prepare_user_configs(UserConfigs, Acc, new);
+prepare_user_configs([ConfigString|UserConfigs], [{LastMod, LastList}|Acc], cur)->
+ prepare_user_configs(UserConfigs,
+ [{LastMod, [ConfigString|LastList]}|Acc],
+ cur);
+prepare_user_configs([], Acc, _)->
+ Acc.
+
+prepare_config_list(Args)->
+ ConfigFiles = case lists:keysearch(ct_config, 1, Args) of
+ {value,{ct_config,Files}}->
+ [{ct_config_plain, Files}];
+ false->
+ []
+ end,
+ UserConfigs = case lists:keysearch(userconfig, 1, Args) of
+ {value,{userconfig,UserConfigFiles}}->
+ prepare_user_configs(UserConfigFiles, [], new);
+ false->
+ []
+ end,
+ ConfigFiles ++ UserConfigs.
diff --git a/lib/common_test/src/ct_config_plain.erl b/lib/common_test/src/ct_config_plain.erl
index be0433aa9f..327fc66b40 100755
--- a/lib/common_test/src/ct_config_plain.erl
+++ b/lib/common_test/src/ct_config_plain.erl
@@ -22,9 +22,9 @@
%% Created : 15 February 2010
%%----------------------------------------------------------------------
-module(ct_config_plain).
--export([read_config_file/1]).
+-export([read_config/1, check_parameter/1]).
-read_config_file(ConfigFile) ->
+read_config(ConfigFile) ->
case file:consult(ConfigFile) of
{ok,Config} ->
{ok, Config};
@@ -65,6 +65,15 @@ read_config_file(ConfigFile) ->
end
end.
+% check against existence of config file
+check_parameter(File)->
+ case filelib:is_file(File) of
+ true->
+ {ok, {file, File}};
+ false->
+ {nok, {nofile, File}}
+ end.
+
read_config_terms(Bin) when is_binary(Bin) ->
case catch binary_to_list(Bin) of
{'EXIT',_} ->
diff --git a/lib/common_test/src/ct_config_xml.erl b/lib/common_test/src/ct_config_xml.erl
index 79f25cead7..4b16c7c675 100755
--- a/lib/common_test/src/ct_config_xml.erl
+++ b/lib/common_test/src/ct_config_xml.erl
@@ -22,10 +22,10 @@
%% Created : 16 February 2010
%%----------------------------------------------------------------------
-module(ct_config_xml).
--export([read_config_file/1]).
+-export([read_config/1, check_parameter/1]).
-% the only function to be called outside
-read_config_file(ConfigFile) ->
+% read config file
+read_config(ConfigFile) ->
case catch do_read_xml_config(ConfigFile) of
{ok, Config}->
{ok, Config};
@@ -33,6 +33,15 @@ read_config_file(ConfigFile) ->
{error, Error, ErroneousString}
end.
+% check against existence of the file
+check_parameter(File)->
+ case filelib:is_file(File) of
+ true->
+ {ok, {file, File}};
+ false->
+ {nok, {nofile, File}}
+ end.
+
% actual reading of the config
do_read_xml_config(ConfigFile)->
{ok, EntityList, _}=
diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl
index d3239b7ce3..cf5c99ee19 100644
--- a/lib/common_test/src/ct_run.erl
+++ b/lib/common_test/src/ct_run.erl
@@ -208,19 +208,7 @@ script_start1(Parent, Args) ->
end
end;
false ->
- ConfigFiles = case lists:keysearch(ct_config, 1, Args) of
- {value,{ct_config,Files}}->
- [{ct_config_plain, Files}];
- false->
- []
- end,
- UserConfigs = case lists:keysearch(userconfig, 1, Args) of
- {value,{userconfig,UserConfigFiles}}->
- prepare_user_configs(UserConfigFiles, [], new);
- false->
- []
- end,
- Config = ConfigFiles ++ UserConfigs,
+ Config = ct_config:prepare_config_list(Args),
case Config of
[] ->
case install([{config,[]},
@@ -252,48 +240,15 @@ script_start1(Parent, Args) ->
end,
Parent ! {self(), Result}.
-prepare_user_configs([ConfigString|UserConfigs], Acc, new)->
- prepare_user_configs(UserConfigs,
- [{list_to_atom(ConfigString), []}|Acc],
- cur);
-prepare_user_configs(["and"|UserConfigs], Acc, _)->
- prepare_user_configs(UserConfigs, Acc, new);
-prepare_user_configs([ConfigString|UserConfigs], [{LastMod, LastList}|Acc], cur)->
- prepare_user_configs(UserConfigs,
- [{LastMod, [ConfigString|LastList]}|Acc],
- cur);
-prepare_user_configs([], Acc, _)->
- Acc.
-
check_and_install_configfiles(Configs, LogDir, EvHandlers) ->
- % Configs is list of tuples such as {Callback=atom(), Files=list()}
- % The ugly code below checks:
- % 1. that all config files are present
- % 2. thar all callback modules are loadable
- case lists:keysearch(nok, 1,
- lists:flatten(
- lists:map(fun({Callback, Files})->
- case code:load_file(Callback) of
- {module, Callback}->
- lists:map(fun(File)->
- case filelib:is_file(File) of
- true->
- {ok, File};
- false->
- {nok, {config, File}}
- end
- end,
- Files);
- {error, _}->
- {nok, {callback, Callback}}
- end
- end,
- Configs))) of
+ case ct_config:check_config_files(Configs) of
false->
install([{config,Configs},
{event_handler,EvHandlers}], LogDir);
- {value, {nok, {config, File}}} ->
+ {value, {nok, {nofile, File}}} ->
{error,{cant_read_config_file,File}};
+ {value, {nok, {wrong_config, Message}}}->
+ {error,{wrong_config, Message}};
{value, {nok, {callback, File}}} ->
{error,{cant_load_callback_module,File}}
end.
@@ -740,11 +695,16 @@ run_prepared(LogDir, CfgFiles, EvHandlers, Run, Skip, Cover, Opts) ->
exit(Reason)
end.
-check_config_file(File)->
- AbsName = ?abs(File),
- case filelib:is_file(AbsName) of
- true -> AbsName;
- false -> exit({no_such_file,AbsName})
+check_config_file(Callback, File)->
+ case Callback:check_parameter(File) of
+ {ok, {file, File}}->
+ ?abs(File);
+ {ok, {config, _}}->
+ File;
+ {nok, {wrong_config, Message}}->
+ exit({wrong_config, {Callback, Message}});
+ {nok, {nofile, File}}->
+ exit({no_such_file, ?abs(File)})
end.
run_dir(LogDir, CfgFiles, EvHandlers, StepOrCover, Opts) ->
@@ -763,7 +723,7 @@ run_dir(LogDir, CfgFiles, EvHandlers, StepOrCover, Opts) ->
end,
{Callback,
lists:map(fun(File)->
- check_config_file(File)
+ check_config_file(Callback, File)
end, FileList)}
end,
CfgFiles),