Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote branch 'origin/peppe/common_test/break_cont_error' into …
…maint

* origin/peppe/common_test/break_cont_error:
  Make sure the test can never hang when ct:break/1/2 is called
  • Loading branch information
Peter Andersson committed Aug 28, 2012
2 parents 3a354d4 + 701315c commit ee5133a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 39 deletions.
85 changes: 60 additions & 25 deletions lib/common_test/src/ct.erl
Expand Up @@ -157,7 +157,7 @@ run(TestDirs) ->
%%% {refresh_logs,LogDir} | {logopts,LogOpts} |
%%% {verbosity,VLevels} | {basic_html,Bool} |
%%% {ct_hooks, CTHs} | {enable_builtin_hooks,Bool} |
%%% {noinput,Bool}
%%% {release_shell,Bool}
%%% TestDirs = [string()] | string()
%%% Suites = [string()] | [atom()] | string() | atom()
%%% Cases = [atom()] | atom()
Expand Down Expand Up @@ -194,15 +194,24 @@ run(TestDirs) ->
%%% CTHs = [CTHModule | {CTHModule, CTHInitArgs}]
%%% CTHModule = atom()
%%% CTHInitArgs = term()
%%% Result = [TestResult] | {error,Reason}
%%% @doc Run tests as specified by the combination of options in <code>Opts</code>.
%%% Result = {Ok,Failed,{UserSkipped,AutoSkipped}} | TestRunnerPid | {error,Reason}
%%% Ok = integer()
%%% Failed = integer()
%%% UserSkipped = integer()
%%% AutoSkipped = integer()
%%% TestRunnerPid = pid()
%%% Reason = term()
%%% @doc <p>Run tests as specified by the combination of options in <code>Opts</code>.
%%% The options are the same as those used with the
%%% <seealso marker="ct_run#ct_run"><code>ct_run</code></seealso> program.
%%% Note that here a <code>TestDir</code> can be used to point out the path to
%%% a <code>Suite</code>. Note also that the option <code>testcase</code>
%%% corresponds to the <code>-case</code> option in the <code>ct_run</code>
%%% program. Configuration files specified in <code>Opts</code> will be
%%% installed automatically at startup.
%%% installed automatically at startup.</p>
%%% <p><code>TestRunnerPid</code> is returned if <code>release_shell == true</code>
%%% (see the User's Guide for details).</p>
%%% <p><code>Reason</code> indicates what type of error has been encountered.</p>
run_test(Opts) ->
ct_run:run_test(Opts).

Expand Down Expand Up @@ -960,6 +969,8 @@ get_testdata(Key) ->
Error;
{'EXIT',_Reason} ->
no_tests_running;
undefined ->
{error,no_testdata};
[CurrTC] when Key == curr_tc ->
{ok,CurrTC};
Data ->
Expand Down Expand Up @@ -1159,7 +1170,8 @@ sync_notify(Name,Data) ->
%%%-----------------------------------------------------------------
%%% @spec break(Comment) -> ok | {error,Reason}
%%% Comment = string()
%%% Reason = {multiple_cases_running,TestCases}
%%% Reason = {multiple_cases_running,TestCases} |
%%% 'enable break with release_shell option'
%%% TestCases = [atom()]
%%%
%%% @doc <p>This function will cancel all timetraps and pause the
Expand All @@ -1170,40 +1182,63 @@ sync_notify(Name,Data) ->
%%% test case. If a parallel group is executing, <c>break/2</c>
%%% should be called instead.</p>
break(Comment) ->
case get_testdata(curr_tc) of
{ok,{_,TestCase}} ->
test_server:break(?MODULE, Comment);
{ok,Cases} when is_list(Cases) ->
{error,{multiple_cases_running,
[TC || {_,TC} <- Cases]}};
Error ->
{error,Error}
case {ct_util:get_testdata(starter),
ct_util:get_testdata(release_shell)} of
{ct,ReleaseSh} when ReleaseSh /= true ->
Warning = "ct:break/1 can only be used if release_shell == true.\n",
ct_logs:log("Warning!", Warning, []),
io:format(user, "Warning! " ++ Warning, []),
{error,'enable break with release_shell option'};
_ ->
case get_testdata(curr_tc) of
{ok,{_,TestCase}} ->
test_server:break(?MODULE, Comment);
{ok,Cases} when is_list(Cases) ->
{error,{'multiple cases running',
[TC || {_,TC} <- Cases]}};
Error = {error,_} ->
Error;
Error ->
{error,Error}
end
end.

%%%-----------------------------------------------------------------
%%% @spec break(TestCase, Comment) -> ok | {error,Reason}
%%% TestCase = atom()
%%% Comment = string()
%%% Reason = test_case_not_running
%%% Reason = 'test case not running' |
%%% 'enable break with release_shell option'
%%%
%%% @doc <p>This function works the same way as <c>break/1</c>,
%%% only the <c>TestCase</c> argument makes it possible to
%%% pause a test case executing in a parallel group. The
%%% <c>continue/1</c> function should be used to resume
%%% execution of <c>TestCase</c>.</p>
break(TestCase, Comment) ->
case get_testdata(curr_tc) of
{ok,Cases} when is_list(Cases) ->
case lists:keymember(TestCase, 2, Cases) of
true ->
case {ct_util:get_testdata(starter),
ct_util:get_testdata(release_shell)} of
{ct,ReleaseSh} when ReleaseSh /= true ->
Warning = "ct:break/2 can only be used if release_shell == true.\n",
ct_logs:log("Warning!", Warning, []),
io:format(user, "Warning! " ++ Warning, []),
{error,'enable break with release_shell option'};
_ ->
case get_testdata(curr_tc) of
{ok,Cases} when is_list(Cases) ->
case lists:keymember(TestCase, 2, Cases) of
true ->
test_server:break(?MODULE, TestCase, Comment);
false ->
{error,'test case not running'}
end;
{ok,{_,TestCase}} ->
test_server:break(?MODULE, TestCase, Comment);
false ->
{error,test_case_not_running}
end;
{ok,{_,TestCase}} ->
test_server:break(?MODULE, TestCase, Comment);
Error ->
{error,Error}
Error = {error,_} ->
Error;
Error ->
{error,Error}
end
end.

%%%-----------------------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions lib/common_test/src/ct_run.erl
Expand Up @@ -76,7 +76,8 @@
scale_timetraps = false,
create_priv_dir,
testspecs = [],
tests}).
tests,
starter}).

%%%-----------------------------------------------------------------
%%% @spec script_start() -> void()
Expand Down Expand Up @@ -334,7 +335,8 @@ script_start1(Parent, Args) ->
stylesheet = Stylesheet,
multiply_timetraps = MultTT,
scale_timetraps = ScaleTT,
create_priv_dir = CreatePrivDir},
create_priv_dir = CreatePrivDir,
starter = script},

%% check if log files should be refreshed or go on to run tests...
Result = run_or_refresh(StartOpts, Args),
Expand Down Expand Up @@ -1003,7 +1005,8 @@ run_test2(StartOpts) ->
stylesheet = Stylesheet,
multiply_timetraps = MultiplyTT,
scale_timetraps = ScaleTT,
create_priv_dir = CreatePrivDir},
create_priv_dir = CreatePrivDir,
starter = ct},

%% test specification
case proplists:get_value(spec, StartOpts) of
Expand Down Expand Up @@ -1632,6 +1635,7 @@ do_run(Tests, Skip, Opts, Args) when is_record(Opts, opts) ->
"run ct:start_interactive()\n\n",[]),
{error,interactive_mode};
_Pid ->
ct_util:set_testdata({starter,Opts#opts.starter}),
compile_and_run(Tests, Skip,
Opts1#opts{verbosity=Verbosity}, Args)
end
Expand Down Expand Up @@ -1677,8 +1681,9 @@ compile_and_run(Tests, Skip, Opts, Args) ->

{Tests1,Skip1} = final_tests(Tests,Skip,SavedErrors),

possibly_spawn(true == proplists:get_value(noinput, Args),
Tests1, Skip1, Opts);
ReleaseSh = proplists:get_value(release_shell, Args),
ct_util:set_testdata({release_shell,ReleaseSh}),
possibly_spawn(ReleaseSh == true, Tests1, Skip1, Opts);
false ->
io:nl(),
ct_util:stop(clean),
Expand Down
6 changes: 3 additions & 3 deletions lib/common_test/src/ct_testspec.erl
Expand Up @@ -779,8 +779,8 @@ add_tests([{event_handler,Node,HOrHs,Args}|Ts],Spec) ->
add_tests([{enable_builtin_hooks,Bool}|Ts],Spec) ->
add_tests(Ts, Spec#testspec{enable_builtin_hooks = Bool});

add_tests([{noinput,Bool}|Ts],Spec) ->
add_tests(Ts, Spec#testspec{noinput = Bool});
add_tests([{release_shell,Bool}|Ts],Spec) ->
add_tests(Ts, Spec#testspec{release_shell = Bool});

%% --- handled/errors ---
add_tests([{define,_,_}|Ts],Spec) -> % handled
Expand Down Expand Up @@ -1283,7 +1283,7 @@ valid_terms() ->
{ct_hooks,2},
{ct_hooks,3},
{enable_builtin_hooks,2},
{noinput,2},
{release_shell,2},
{multiply_timetraps,2},
{multiply_timetraps,3},
{scale_timetraps,2},
Expand Down
2 changes: 1 addition & 1 deletion lib/common_test/src/ct_util.hrl
Expand Up @@ -43,7 +43,7 @@
event_handler=[],
ct_hooks=[],
enable_builtin_hooks=true,
noinput=false,
release_shell=false,
include=[],
auto_compile=[],
stylesheet=[],
Expand Down
10 changes: 5 additions & 5 deletions lib/common_test/test/ct_testspec_2_SUITE.erl
Expand Up @@ -91,7 +91,7 @@ all() ->
%% {ct_hooks,2}
%% {ct_hooks,3}
%% {enable_builtin_hooks,2}
%% {noinput,2}
%% {release_shell,2}
%% {multiply_timetraps,2}
%% {multiply_timetraps,3}
%% {scale_timetraps,2}
Expand Down Expand Up @@ -198,7 +198,7 @@ basic_compatible_no_nodes(_Config) ->
ct_hooks = [{Node,{cth_mod1,[]}},
{Node,{cth_mod2,[]}}],
enable_builtin_hooks = true,
noinput = false,
release_shell = false,
include = Incls,
auto_compile = [],
stylesheet = [],
Expand Down Expand Up @@ -325,7 +325,7 @@ basic_compatible_nodes(_Config) ->
{Node1,{cth_mod2,[]}},
{Node2,{cth_mod2,[]}}],
enable_builtin_hooks = true,
noinput = false,
release_shell = false,
include = Incls,
auto_compile = [],
stylesheet = [],
Expand Down Expand Up @@ -542,7 +542,7 @@ misc_config_terms(_Config) ->

{enable_builtin_hooks,false},

{noinput,true},
{release_shell,true},

{auto_compile,false},
{auto_compile,n1@h1,true},
Expand Down Expand Up @@ -590,7 +590,7 @@ misc_config_terms(_Config) ->
{n1@h1,CfgD},
{n2@h2,CfgD}],
enable_builtin_hooks = false,
noinput = true,
release_shell = true,
auto_compile = [{Node,false},
{n1@h1,true},
{n2@h2,false}],
Expand Down

0 comments on commit ee5133a

Please sign in to comment.