aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/test/ct_test_support.erl
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2014-02-06 19:05:32 +0100
committerPeter Andersson <[email protected]>2014-02-07 16:03:18 +0100
commitc31d60198b643c58498242f8c1de6641d7902b4a (patch)
tree7c7c07b01aa387ecf706e29ce5d91c386f04843d /lib/common_test/test/ct_test_support.erl
parent88a40030a9d7a81a51824cfa17427f4ed4ed2156 (diff)
downloadotp-c31d60198b643c58498242f8c1de6641d7902b4a.tar.gz
otp-c31d60198b643c58498242f8c1de6641d7902b4a.tar.bz2
otp-c31d60198b643c58498242f8c1de6641d7902b4a.zip
Fix problem with logging exits that happen in init_per_testcase
Diffstat (limited to 'lib/common_test/test/ct_test_support.erl')
-rw-r--r--lib/common_test/test/ct_test_support.erl52
1 files changed, 51 insertions, 1 deletions
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) ->