aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2010-12-08 17:16:49 +0100
committerLukas Larsson <[email protected]>2010-12-08 18:08:28 +0100
commit8ed5c47ca047405b2c00a979a8567412e5283322 (patch)
treeb934eaf290cb2dd3249ff2bc81ddff8079b9710d /lib/common_test
parent8b33f2edabbfd684e619238bbfaa10cc16e2a0a7 (diff)
downloadotp-8ed5c47ca047405b2c00a979a8567412e5283322.tar.gz
otp-8ed5c47ca047405b2c00a979a8567412e5283322.tar.bz2
otp-8ed5c47ca047405b2c00a979a8567412e5283322.zip
Add so that failures in SCB:init/1 causes the entire scb scope to fail
Diffstat (limited to 'lib/common_test')
-rw-r--r--lib/common_test/src/ct_run.erl2
-rw-r--r--lib/common_test/src/ct_suite_callback.erl9
-rw-r--r--lib/common_test/src/ct_util.erl10
-rw-r--r--lib/common_test/test/ct_suite_callback_SUITE.erl76
4 files changed, 76 insertions, 21 deletions
diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl
index 78782d346a..7d6a2f54d9 100644
--- a/lib/common_test/src/ct_run.erl
+++ b/lib/common_test/src/ct_run.erl
@@ -2203,6 +2203,8 @@ opts2args(EnvStartOpts) ->
end, EHs),
[_LastAnd|StrsR] = lists:reverse(lists:flatten(Strs)),
[{event_handler_init,lists:reverse(StrsR)}];
+ ({suite_callbacks,[]}) ->
+ [];
({Opt,As=[A|_]}) when is_atom(A) ->
[{Opt,[atom_to_list(Atom) || Atom <- As]}];
({Opt,Strs=[S|_]}) when is_list(S) ->
diff --git a/lib/common_test/src/ct_suite_callback.erl b/lib/common_test/src/ct_suite_callback.erl
index 4f6bf9942e..8372303737 100644
--- a/lib/common_test/src/ct_suite_callback.erl
+++ b/lib/common_test/src/ct_suite_callback.erl
@@ -46,8 +46,7 @@
{error, Reason :: term()}.
init(Opts) ->
call([{CB, call_init, undefined} || CB <- get_new_callbacks(Opts)],
- ct_suite_callback_init_dummy, init, []),
- ok.
+ ok, init, []).
%% @doc Called after all suites are done.
@@ -181,9 +180,11 @@ call([{CB, call_init, NextFun} | Rest], Config, Meta, CBs) ->
[Mod,NewId]),
call(NewRest, Config, Meta, NewCBs)
catch Error:Reason ->
+ Trace = erlang:get_stacktrace(),
ct_logs:log("Suite Callback","Failed to start a SCB: ~p:~p",
- [Error,{Reason,erlang:get_stacktrace()}]),
- call(Rest, Config, Meta, CBs)
+ [Error,{Reason,Trace}]),
+ call([], {fail,"Failed to start SCB"
+ ", see the CT Log for details"}, Meta, CBs)
end;
call([{CBId, Fun} | Rest], Config, Meta, CBs) ->
try
diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl
index fddeff881e..2f5a90a543 100644
--- a/lib/common_test/src/ct_util.erl
+++ b/lib/common_test/src/ct_util.erl
@@ -163,8 +163,14 @@ do_start(Parent,Mode,LogDir) ->
{StartTime,TestLogDir} = ct_logs:init(Mode),
%% Initiate suite_callbacks
- ok = ct_suite_callback:init(Opts),
-
+ case catch ct_suite_callback:init(Opts) of
+ ok ->
+ ok;
+ {_,SCBReason} ->
+ ct_logs:tc_print('Suite Callback',SCBReason,[]),
+ Parent ! {self(), SCBReason},
+ self() ! {{stop,normal},{self(),make_ref()}}
+ end,
ct_event:notify(#event{name=test_start,
node=node(),
diff --git a/lib/common_test/test/ct_suite_callback_SUITE.erl b/lib/common_test/test/ct_suite_callback_SUITE.erl
index e6e4d5706b..8d620be7ba 100644
--- a/lib/common_test/test/ct_suite_callback_SUITE.erl
+++ b/lib/common_test/test/ct_suite_callback_SUITE.erl
@@ -70,15 +70,18 @@ all() ->
all(suite).
all(suite) ->
- lists:reverse(
+ %% lists:reverse(
[
- one_scb, two_scb, faulty_scb_no_init, minimal_scb,
+ one_scb, two_scb, faulty_scb_no_init, faulty_scb_exit_in_init,
+ faulty_scb_exit_in_init_scope_suite, minimal_scb,
minimal_and_maximal_scb, faulty_scb_undef, scope_per_suite_scb,
scope_per_group_scb, scope_suite_scb,
fail_pre_suite_scb, fail_post_suite_scb, skip_pre_suite_scb,
skip_post_suite_scb, recover_post_suite_scb, update_config_scb,
state_update_scb
- ]).
+ ]
+ %%)
+ .
%%--------------------------------------------------------------------
@@ -96,7 +99,8 @@ two_scb(Config) when is_list(Config) ->
faulty_scb_no_init(Config) when is_list(Config) ->
do_test(faulty_scb_no_init, "ct_scb_empty_SUITE.erl",[askjhdkljashdkaj],
- Config).
+ Config,{error,"Failed to start SCB, see the "
+ "CT Log for details"}).
minimal_scb(Config) when is_list(Config) ->
do_test(minimal_scb, "ct_scb_empty_SUITE.erl",[minimal_scb],Config).
@@ -109,6 +113,17 @@ faulty_scb_undef(Config) when is_list(Config) ->
do_test(faulty_scb_undef, "ct_scb_empty_SUITE.erl",
[undef_scb],Config).
+faulty_scb_exit_in_init_scope_suite(Config) when is_list(Config) ->
+ do_test(faulty_scb_exit_in_init_scope_suite,
+ "ct_exit_in_init_scope_suite_scb_SUITE.erl",
+ [],Config).
+
+faulty_scb_exit_in_init(Config) when is_list(Config) ->
+ do_test(faulty_scb_exit_in_init, "ct_scb_empty_SUITE.erl",
+ [crash_init_scb], Config,
+ {error,"Failed to start SCB, see the "
+ "CT Log for details"}).
+
scope_per_suite_scb(Config) when is_list(Config) ->
do_test(scope_per_suite_scb, "ct_scope_per_suite_scb_SUITE.erl",
[],Config).
@@ -153,21 +168,28 @@ state_update_scb(Config) ->
%%% HELP FUNCTIONS
%%%-----------------------------------------------------------------
-do_test(Tag, SuiteWildCard, SCBs, Config) ->
+do_test(Tag, SWC, SCBs, Config) ->
+ do_test(Tag, SWC, SCBs, Config, ok).
+do_test(Tag, SWC, SCBs, Config, {error,_} = Res) ->
+ do_test(Tag, SWC, SCBs, Config, Res, 1);
+do_test(Tag, SWC, SCBs, Config, Res) ->
+ do_test(Tag, SWC, SCBs, Config, Res, 2).
+
+do_test(Tag, SuiteWildCard, SCBs, Config, Res, EC) ->
DataDir = ?config(data_dir, Config),
Suites = filelib:wildcard(
filename:join([DataDir,"scb/tests",SuiteWildCard])),
{Opts,ERPid} = setup([{suite,Suites},
{suite_callbacks,SCBs},{label,Tag}], Config),
- ok = ct_test_support:run(Opts, Config),
+ Res = ct_test_support:run(Opts, Config),
Events = ct_test_support:get_events(ERPid, Config),
ct_test_support:log_events(Tag,
reformat(Events, ?eh),
?config(priv_dir, Config)),
- TestEvents = events_to_check(Tag),
+ TestEvents = events_to_check(Tag, EC),
ok = ct_test_support:verify_events(TestEvents, Events, Config).
setup(Test, Config) ->
@@ -258,14 +280,6 @@ test_events(faulty_scb_no_init) ->
[
{?eh,start_logging,{'DEF','RUNDIR'}},
{?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
- {?eh,tc_start,{ct_scb_empty_SUITE,init_per_suite}},
- {?eh,tc_done,{ct_scb_empty_SUITE,init_per_suite,ok}},
-
- {?eh,tc_start,{ct_scb_empty_SUITE,test_case}},
- {?eh,tc_done,{ct_scb_empty_SUITE,test_case,ok}},
-
- {?eh,tc_start,{ct_scb_empty_SUITE,end_per_suite}},
- {?eh,tc_done,{ct_scb_empty_SUITE,end_per_suite,ok}},
{?eh,test_done,{'DEF','STOP_TIME'}},
{?eh,stop_logging,[]}
];
@@ -337,6 +351,38 @@ test_events(faulty_scb_undef) ->
{?eh,stop_logging,[]}
];
+test_events(faulty_scb_exit_in_init_scope_suite) ->
+ [{?eh,start_logging,{'DEF','RUNDIR'}},
+ {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
+ {?eh,tc_start,{'_',init_per_suite}},
+ {?eh,scb,{empty_scb,init,[[]]}},
+ {?eh,tc_done,
+ {ct_exit_in_init_scope_suite_scb_SUITE,init_per_suite,
+ {failed,
+ {error,
+ "Failed to start SCB, see the CT Log for details"}}}},
+ {?eh,tc_auto_skip,
+ {ct_exit_in_init_scope_suite_scb_SUITE,test_case,
+ {failed,
+ {ct_exit_in_init_scope_suite_scb_SUITE,init_per_suite,
+ {failed,
+ "Failed to start SCB, see the CT Log for details"}}}}},
+ {?eh,tc_auto_skip,
+ {ct_exit_in_init_scope_suite_scb_SUITE,end_per_suite,
+ {failed,
+ {ct_exit_in_init_scope_suite_scb_SUITE,init_per_suite,
+ {failed,
+ "Failed to start SCB, see the CT Log for details"}}}}},
+ {?eh,test_done,{'DEF','STOP_TIME'}},
+ {?eh,stop_logging,[]}];
+
+test_events(faulty_scb_exit_in_init) ->
+ [{?eh,start_logging,{'DEF','RUNDIR'}},
+ {?eh,scb,{empty_scb,init,[[]]}},
+ {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
+ {?eh,test_done,{'DEF','STOP_TIME'}},
+ {?eh,stop_logging,[]}];
+
test_events(scope_per_suite_scb) ->
[
{?eh,start_logging,{'DEF','RUNDIR'}},