aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/src/ct_hooks.erl
diff options
context:
space:
mode:
authorLukas <[email protected]>2011-09-26 12:01:57 +0200
committerLukas <[email protected]>2011-09-26 12:01:57 +0200
commit516cbd4312c6fc8ca082d763b9a295acbc7e395c (patch)
treed9e8ff409547a52497ff53e75b2216f80d759d62 /lib/common_test/src/ct_hooks.erl
parent97f3a064f27843a9f825210c1c7a27075b7b3ad7 (diff)
parent7d0d76f3a8170ddb5a3b07fd46fce835bb631cef (diff)
downloadotp-516cbd4312c6fc8ca082d763b9a295acbc7e395c.tar.gz
otp-516cbd4312c6fc8ca082d763b9a295acbc7e395c.tar.bz2
otp-516cbd4312c6fc8ca082d763b9a295acbc7e395c.zip
Merge branch 'lukas/common_test/system_logs_to_ct_log/OTP-9543' into dev
* lukas/common_test/system_logs_to_ct_log/OTP-9543: Add documentation for cth_log_redirect and built-in hooks Correct wrong match from lists:keyfind Update cth_log_redirect to wait for all error_logger events before ending test Force logging to framework log for parallel tests Add ct_log:ct_log funcion Add a hook for redirecting SASL and error_logger messages Add -enable_builtin_hooks <bool> config option Export write_events and add option to return a string
Diffstat (limited to 'lib/common_test/src/ct_hooks.erl')
-rw-r--r--lib/common_test/src/ct_hooks.erl27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/common_test/src/ct_hooks.erl b/lib/common_test/src/ct_hooks.erl
index f243b87f54..886195aae5 100644
--- a/lib/common_test/src/ct_hooks.erl
+++ b/lib/common_test/src/ct_hooks.erl
@@ -34,6 +34,12 @@
%% If you change this, remember to update ct_util:look -> stop clause as well.
-define(config_name, ct_hooks).
+%% All of the hooks which are to be started by default. Remove by issuing
+%% -enable_builtin_hooks false to when starting common test.
+-define(BUILTIN_HOOKS,[#ct_hook_config{ module = cth_log_redirect,
+ opts = [],
+ prio = ctfirst }]).
+
-record(ct_hook_config, {id, module, prio, scope, opts = [], state = []}).
%% -------------------------------------------------------------------------
@@ -44,7 +50,8 @@
-spec init(State :: term()) -> ok |
{error, Reason :: term()}.
init(Opts) ->
- call(get_new_hooks(Opts, undefined), ok, init, []).
+ call(get_new_hooks(Opts, undefined) ++ get_builtin_hooks(Opts),
+ ok, init, []).
%% @doc Called after all suites are done.
@@ -283,6 +290,14 @@ get_new_hooks(Config) when is_list(Config) ->
get_new_hooks(_Config) ->
[].
+get_builtin_hooks(Opts) ->
+ case proplists:get_value(enable_builtin_hooks,Opts) of
+ false ->
+ [];
+ _Else ->
+ [{HookConf, call_id, undefined} || HookConf <- ?BUILTIN_HOOKS]
+ end.
+
save_suite_data_async(Hooks) ->
ct_util:save_suite_data_async(?config_name, Hooks).
@@ -290,7 +305,7 @@ get_hooks() ->
lists:keysort(#ct_hook_config.prio,ct_util:read_suite_data(?config_name)).
%% Sort all calls in this order:
-%% call_id < call_init < Hook Priority 1 < .. < Hook Priority N
+%% call_id < call_init < ctfirst < Priority 1 < .. < Priority N < ctlast
%% If Hook Priority is equal, check when it has been installed and
%% sort on that instead.
resort(Calls, Hooks) ->
@@ -311,6 +326,14 @@ resort(Calls, Hooks) ->
%% If priorities are equal, we check the position in the
%% hooks list
pos(Id1,Hooks) < pos(Id2,Hooks);
+ P1 == ctfirst ->
+ true;
+ P2 == ctfirst ->
+ false;
+ P1 == ctlast ->
+ false;
+ P2 == ctlast ->
+ true;
true ->
P1 < P2
end