From 2a3fc026842241b0a1e1b2b1f691bd212499ffe0 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Sun, 15 Jul 2012 01:48:03 +0200 Subject: Implement support for test case execution break/continue --- lib/common_test/src/ct.erl | 87 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 5 deletions(-) (limited to 'lib/common_test/src/ct.erl') diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 571d99029f..4054b441ee 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -66,7 +66,8 @@ capture_start/0, capture_stop/0, capture_get/0, capture_get/1, fail/1, fail/2, comment/1, comment/2, make_priv_dir/0, testcases/2, userdata/2, userdata/3, - timetrap/1, get_timetrap_info/0, sleep/1]). + timetrap/1, get_timetrap_info/0, sleep/1, + break/1, break/2, continue/0, continue/1]). %% New API for manipulating with config handlers -export([add_config/2, remove_config/2]). @@ -151,7 +152,8 @@ run(TestDirs) -> %%% {repeat,N} | {duration,DurTime} | {until,StopTime} | %%% {force_stop,Bool} | {decrypt,DecryptKeyOrFile} | %%% {refresh_logs,LogDir} | {logopts,LogOpts} | {basic_html,Bool} | -%%% {ct_hooks, CTHs} | {enable_builtin_hooks,Bool} +%%% {ct_hooks, CTHs} | {enable_builtin_hooks,Bool} | +%%% {noinput,Bool} %%% TestDirs = [string()] | string() %%% Suites = [string()] | [atom()] | string() | atom() %%% Cases = [atom()] | atom() @@ -840,10 +842,11 @@ userdata(TestDir, Suite, Case) when is_atom(Case) -> %%%----------------------------------------------------------------- %%% @spec get_status() -> TestStatus | {error,Reason} | no_tests_running %%% TestStatus = [StatusElem] -%%% StatusElem = {current,{Suite,TestCase}} | {successful,Successful} | +%%% StatusElem = {current,TestCaseInfo} | {successful,Successful} | %%% {failed,Failed} | {skipped,Skipped} | {total,Total} +%%% TestCaseInfo = {Suite,TestCase} | [{Suite,TestCase}] %%% Suite = atom() -%%% TestCase = atom() +%%% TestCase = atom() | %%% Successful = integer() %%% Failed = integer() %%% Skipped = {UserSkipped,AutoSkipped} @@ -853,7 +856,8 @@ userdata(TestDir, Suite, Case) when is_atom(Case) -> %%% Reason = term() %%% %%% @doc Returns status of ongoing test. The returned list contains info about -%%% which test case is currently executing, as well as counters for +%%% which test case is currently executing (a list of cases when a +%%% parallel test case group is executing), as well as counters for %%% successful, failed, skipped, and total test cases so far. get_status() -> case get_testdata(curr_tc) of @@ -878,6 +882,8 @@ get_testdata(Key) -> Error; {'EXIT',_Reason} -> no_tests_running; + [CurrTC] when Key == curr_tc -> + {ok,CurrTC}; Data -> {ok,Data} end. @@ -1047,3 +1053,74 @@ sleep({seconds,Ss}) -> sleep(trunc(Ss * 1000)); sleep(Time) -> test_server:adjusted_sleep(Time). + +%%%----------------------------------------------------------------- +%%% @spec break(Comment) -> ok | {error,Reason} +%%% Comment = string() +%%% Reason = {multiple_cases_running,TestCases} +%%% TestCases = [atom()] +%%% +%%% @doc

This function will cancel all timetraps and pause the +%%% execution of the current test case until the user calls the +%%% continue/0 function. It gives the user the opportunity +%%% to interact with the erlang node running the tests, e.g. for +%%% debugging purposes or for manually executing a part of the +%%% test case. If a parallel group is executing, break/2 +%%% should be called instead.

+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} + end. + +%%%----------------------------------------------------------------- +%%% @spec break(TestCase, Comment) -> ok | {error,Reason} +%%% TestCase = atom() +%%% Comment = string() +%%% Reason = test_case_not_running +%%% +%%% @doc

This function works the same way as break/1, +%%% only the TestCase argument makes it possible to +%%% pause a test case executing in a parallel group. The +%%% continue/1 function should be used to resume +%%% execution of TestCase.

+break(TestCase, Comment) -> + 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); + Error -> + {error,Error} + end. + +%%%----------------------------------------------------------------- +%%% @spec continue() -> ok +%%% +%%% @doc

This function must be called in order to continue after a +%%% test case (not executing in a parallel group) has called +%%% break/1.

+continue() -> + test_server:continue(). + +%%%----------------------------------------------------------------- +%%% @spec continue(TestCase) -> ok +%%% TestCase = atom() +%%% +%%% @doc

This function must be called in order to continue after a +%%% test case has called break/2. If the paused test case, +%%% TestCase, executes in a parallel group, this +%%% function - rather than continue/0 - must be used +%%% in order to let the test case proceed.

+continue(TestCase) -> + test_server:continue(TestCase). -- cgit v1.2.3 From c41fbd49054693d61f9f78ef92da176aeea3bf83 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Tue, 21 Aug 2012 16:11:42 +0200 Subject: Fix error in documentation --- lib/common_test/src/ct.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/common_test/src/ct.erl') diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 4054b441ee..fe99222927 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -846,7 +846,7 @@ userdata(TestDir, Suite, Case) when is_atom(Case) -> %%% {failed,Failed} | {skipped,Skipped} | {total,Total} %%% TestCaseInfo = {Suite,TestCase} | [{Suite,TestCase}] %%% Suite = atom() -%%% TestCase = atom() | +%%% TestCase = atom() %%% Successful = integer() %%% Failed = integer() %%% Skipped = {UserSkipped,AutoSkipped} -- cgit v1.2.3