aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common_test')
-rw-r--r--lib/common_test/src/ct_util.erl6
-rw-r--r--lib/common_test/test/ct_error_SUITE.erl61
-rw-r--r--lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl138
-rw-r--r--lib/common_test/test/ct_test_support.erl52
4 files changed, 252 insertions, 5 deletions
diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl
index 1d851f8d2f..ac9857487d 100644
--- a/lib/common_test/src/ct_util.erl
+++ b/lib/common_test/src/ct_util.erl
@@ -382,13 +382,17 @@ loop(Mode,TestData,StartDir) ->
TestData1 =
case lists:keysearch(Key,1,TestData) of
{value,{Key,Val}} ->
- case Fun(Val) of
+ try Fun(Val) of
'$delete' ->
return(From,deleted),
lists:keydelete(Key,1,TestData);
NewVal ->
return(From,NewVal),
[{Key,NewVal}|lists:keydelete(Key,1,TestData)]
+ catch
+ _:Error ->
+ return(From,{error,Error}),
+ TestData
end;
_ ->
case lists:member(create,Opts) of
diff --git a/lib/common_test/test/ct_error_SUITE.erl b/lib/common_test/test/ct_error_SUITE.erl
index 28f0494d20..194e7d42ae 100644
--- a/lib/common_test/test/ct_error_SUITE.erl
+++ b/lib/common_test/test/ct_error_SUITE.erl
@@ -66,7 +66,7 @@ all() ->
[cfg_error, lib_error, no_compile, timetrap_end_conf,
timetrap_normal, timetrap_extended, timetrap_parallel,
timetrap_fun, timetrap_fun_group, misc_errors,
- config_restored].
+ config_restored, config_func_errors].
groups() ->
[].
@@ -310,6 +310,25 @@ config_restored(Config) when is_list(Config) ->
ok = ct_test_support:verify_events(TestEvents, Events, Config).
%%%-----------------------------------------------------------------
+%%%
+config_func_errors(Config) when is_list(Config) ->
+ DataDir = ?config(data_dir, Config),
+ Suite = filename:join(DataDir, "error/test/config_func_error_1_SUITE"),
+ {Opts,ERPid} = setup([{suite,Suite}],
+ Config),
+ ok = ct_test_support:run(Opts, Config),
+ Events = ct_test_support:get_events(ERPid, Config),
+
+ ct_test_support:log_events(config_func_errors,
+ reformat(Events, ?eh),
+ ?config(priv_dir, Config),
+ Opts),
+
+ TestEvents = events_to_check(config_func_errors),
+ ok = ct_test_support:verify_events(TestEvents, Events, Config).
+
+
+%%%-----------------------------------------------------------------
%%% HELP FUNCTIONS
%%%-----------------------------------------------------------------
@@ -323,8 +342,6 @@ setup(Test, Config) ->
reformat(Events, EH) ->
ct_test_support:reformat(Events, EH).
- %reformat(Events, _EH) ->
- % Events.
%%%-----------------------------------------------------------------
%%% TEST EVENTS
@@ -1498,4 +1515,42 @@ test_events(config_restored) ->
{?eh,tc_done,{config_restored_SUITE,end_per_suite,ok}},
{?eh,test_done,{'DEF','STOP_TIME'}},
{?eh,stop_logging,[]}
+ ];
+
+test_events(config_func_errors) ->
+ [
+ {?eh,start_logging,{'DEF','RUNDIR'}},
+ {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
+ {?eh,start_info,{1,1,4}},
+ {?eh,tc_start,{config_func_error_1_SUITE,init_per_suite}},
+ {?eh,tc_done,{config_func_error_1_SUITE,init_per_suite,ok}},
+
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_iptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_iptc,'_'}},
+ {?eh,test_stats,{0,1,{0,0}}},
+
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_eptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_eptc,'_'}},
+ {?eh,test_stats,{0,2,{0,0}}},
+
+ [{?eh,tc_start,{config_func_error_1_SUITE,{init_per_group,g1,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{init_per_group,g1,[]},ok}},
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_iptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_iptc,'_'}},
+ {?eh,test_stats,{0,3,{0,0}}},
+ {?eh,tc_start,{config_func_error_1_SUITE,{end_per_group,g1,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{end_per_group,g1,[]},ok}}],
+
+ [{?eh,tc_start,{config_func_error_1_SUITE,{init_per_group,g2,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{init_per_group,g2,[]},ok}},
+ {?eh,tc_start,{config_func_error_1_SUITE,exit_in_eptc}},
+ {?eh,tc_done,{config_func_error_1_SUITE,exit_in_eptc,'_'}},
+ {?eh,test_stats,{0,4,{0,0}}},
+ {?eh,tc_start,{config_func_error_1_SUITE,{end_per_group,g2,[]}}},
+ {?eh,tc_done,{config_func_error_1_SUITE,{end_per_group,g2,[]},ok}}],
+
+ {?eh,tc_start,{config_func_error_1_SUITE,end_per_suite}},
+ {?eh,tc_done,{config_func_error_1_SUITE,end_per_suite,ok}},
+ {?eh,test_done,{'DEF','STOP_TIME'}},
+ {?eh,stop_logging,[]}
].
diff --git a/lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl b/lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl
new file mode 100644
index 0000000000..f1025213dc
--- /dev/null
+++ b/lib/common_test/test/ct_error_SUITE_data/error/test/config_func_error_1_SUITE.erl
@@ -0,0 +1,138 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2009-2012. 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%
+%%
+-module(config_func_error_1_SUITE).
+
+-compile(export_all).
+
+-include_lib("common_test/include/ct.hrl").
+
+%%--------------------------------------------------------------------
+%% Function: suite() -> Info
+%% Info = [tuple()]
+%%--------------------------------------------------------------------
+suite() ->
+ [{timetrap,{seconds,5}}].
+
+%%--------------------------------------------------------------------
+%% Function: init_per_suite(Config0) ->
+%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
+%% Config0 = Config1 = [tuple()]
+%% Reason = term()
+%%--------------------------------------------------------------------
+init_per_suite(Config) ->
+ Config.
+
+%%--------------------------------------------------------------------
+%% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
+%% Config0 = Config1 = [tuple()]
+%%--------------------------------------------------------------------
+end_per_suite(_Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Function: init_per_group(GroupName, Config0) ->
+%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
+%% GroupName = atom()
+%% Config0 = Config1 = [tuple()]
+%% Reason = term()
+%%--------------------------------------------------------------------
+init_per_group(_GroupName, Config) ->
+ Config.
+
+%%--------------------------------------------------------------------
+%% Function: end_per_group(GroupName, Config0) ->
+%% void() | {save_config,Config1}
+%% GroupName = atom()
+%% Config0 = Config1 = [tuple()]
+%%--------------------------------------------------------------------
+end_per_group(_GroupName, _Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Function: init_per_testcase(TestCase, Config0) ->
+%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
+%% TestCase = atom()
+%% Config0 = Config1 = [tuple()]
+%% Reason = term()
+%%--------------------------------------------------------------------
+bad_proc(Config) ->
+ ct:pal("Bye bye from ~p", [self()]),
+ %% this call will either generate an exit immediately
+ %% or return a fun to be executed here
+ ErrorFun = ct_test_support:random_error(Config),
+ ct:log("Calling error fun now...", []),
+ ErrorFun(),
+ ct:sleep(10000),
+ ok.
+
+init_per_testcase(exit_in_iptc, Config) ->
+ spawn_link(?MODULE, bad_proc, [Config]),
+ ct:sleep(10000),
+ Config;
+init_per_testcase(_, Config) ->
+ Config.
+
+%%--------------------------------------------------------------------
+%% Function: end_per_testcase(TestCase, Config0) ->
+%% void() | {save_config,Config1}
+%% TestCase = atom()
+%% Config0 = Config1 = [tuple()]
+%%--------------------------------------------------------------------
+end_per_testcase(exit_in_eptc, Config) ->
+ spawn_link(?MODULE, bad_proc, [Config]),
+ ct:sleep(10000),
+ ok;
+end_per_testcase(_TestCase, _Config) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Function: groups() -> [Group]
+%% Group = {GroupName,Properties,GroupsAndTestCases}
+%% GroupName = atom()
+%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
+%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
+%% TestCase = atom()
+%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}
+%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |
+%% repeat_until_any_ok | repeat_until_any_fail
+%% N = integer() | forever
+%%--------------------------------------------------------------------
+groups() ->
+ [{g1, [], [exit_in_iptc]},
+ {g2, [], [exit_in_eptc]}].
+
+%%--------------------------------------------------------------------
+%% Function: all() -> GroupsAndTestCases | {skip,Reason}
+%% GroupsAndTestCases = [{group,GroupName} | TestCase]
+%% GroupName = atom()
+%% TestCase = atom()
+%% Reason = term()
+%%--------------------------------------------------------------------
+all() ->
+ [exit_in_iptc,
+ exit_in_eptc,
+ {group, g1},
+ {group, g2}].
+
+exit_in_iptc(_) ->
+ ok.
+
+exit_in_eptc(_) ->
+ ok.
+
diff --git a/lib/common_test/test/ct_test_support.erl b/lib/common_test/test/ct_test_support.erl
index 772274ce7e..2e2b45d59f 100644
--- a/lib/common_test/test/ct_test_support.erl
+++ b/lib/common_test/test/ct_test_support.erl
@@ -40,6 +40,8 @@
-export([ct_test_halt/1, ct_rpc/2]).
+-export([random_error/1]).
+
-include_lib("kernel/include/file.hrl").
%%%-----------------------------------------------------------------
@@ -110,7 +112,6 @@ start_slave(NodeName, Config, Level) ->
_ ->
ok
end,
-
TraceFile = filename:join(DataDir, "ct.trace"),
case file:read_file_info(TraceFile) of
{ok,_} ->
@@ -395,6 +396,55 @@ ct_rpc({M,F,A}, Config) ->
%%%-----------------------------------------------------------------
+%%% random_error/1
+random_error(Config) when is_list(Config) ->
+ random:seed(now()),
+ Gen = fun(0,_) -> ok; (N,Fun) -> Fun(N-1, Fun) end,
+ Gen(random:uniform(100), Gen),
+
+ ErrorTypes = ['BADMATCH','BADARG','CASE_CLAUSE','FUNCTION_CLAUSE',
+ 'EXIT','THROW','UNDEF'],
+ Type = lists:nth(random:uniform(length(ErrorTypes)), ErrorTypes),
+ Where = case random:uniform(2) of
+ 1 ->
+ io:format("ct_test_support *returning* error of type ~w",
+ [Type]),
+ tc;
+ 2 ->
+ io:format("ct_test_support *generating* error of type ~w",
+ [Type]),
+ lib
+ end,
+ ErrorFun =
+ fun() ->
+ case Type of
+ 'BADMATCH' ->
+ ok = proplists:get_value(undefined, Config);
+ 'BADARG' ->
+ size(proplists:get_value(priv_dir, Config));
+ 'FUNCTION_CLAUSE' ->
+ random_error(x);
+ 'EXIT' ->
+ spawn_link(fun() ->
+ undef_proc ! hello,
+ ok
+ end);
+ 'THROW' ->
+ PrivDir = proplists:get_value(priv_dir, Config),
+ if is_list(PrivDir) -> throw(generated_throw) end;
+ 'UNDEF' ->
+ apply(?MODULE, random_error, [])
+ end
+ end,
+ %% either call the fun here or return it to the caller (to be
+ %% executed in a test case instead)
+ case Where of
+ tc -> ErrorFun;
+ lib -> ErrorFun()
+ end.
+
+
+%%%-----------------------------------------------------------------
%%% EVENT HANDLING
handle_event(EH, Event) ->