aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/test_lib.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2010-04-22 13:39:30 +0200
committerBjörn Gustavsson <[email protected]>2010-05-10 07:16:04 +0200
commitf0d8728a851901e9080eb35aee0b6b8e24b2d91e (patch)
treea31f78b3f323dbfb2f5014fa4406b57f4c68cc11 /lib/compiler/test/test_lib.erl
parent23362aeb8f364adb64a0825ea40dcb1158babe13 (diff)
downloadotp-f0d8728a851901e9080eb35aee0b6b8e24b2d91e.tar.gz
otp-f0d8728a851901e9080eb35aee0b6b8e24b2d91e.tar.bz2
otp-f0d8728a851901e9080eb35aee0b6b8e24b2d91e.zip
Move p_run/2 to test_lib
It can be useful for other test suites.
Diffstat (limited to 'lib/compiler/test/test_lib.erl')
-rw-r--r--lib/compiler/test/test_lib.erl34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/compiler/test/test_lib.erl b/lib/compiler/test/test_lib.erl
index 844bbfc4b9..05236ee010 100644
--- a/lib/compiler/test/test_lib.erl
+++ b/lib/compiler/test/test_lib.erl
@@ -20,7 +20,7 @@
-include("test_server.hrl").
--export([recompile/1,opt_opts/1,get_data_dir/1,smoke_disasm/1]).
+-export([recompile/1,opt_opts/1,get_data_dir/1,smoke_disasm/1,p_run/2]).
recompile(Mod) when is_atom(Mod) ->
case whereis(cover_server) of
@@ -72,3 +72,35 @@ get_data_dir(Config) ->
{ok,Data2,_} = regexp:sub(Data1, "_post_opt_SUITE", "_SUITE"),
{ok,Data,_} = regexp:sub(Data2, "_inline_SUITE", "_SUITE"),
Data.
+
+%% p_run(fun(Data) -> ok|error, List) -> ok
+%% Will fail the test case if there were any errors.
+
+p_run(Test, List) ->
+ N = erlang:system_info(schedulers) + 1,
+ p_run_loop(Test, List, N, [], 0, 0).
+
+p_run_loop(_, [], _, [], Errors, Ws) ->
+ case Errors of
+ 0 ->
+ case Ws of
+ 0 -> ok;
+ 1 -> {comment,"1 warning"};
+ N -> {comment,integer_to_list(N)++" warnings"}
+ end;
+ N -> ?t:fail({N,errors})
+ end;
+p_run_loop(Test, [H|T], N, Refs, Errors, Ws) when length(Refs) < N ->
+ {_,Ref} = erlang:spawn_monitor(fun() -> exit(Test(H)) end),
+ p_run_loop(Test, T, N, [Ref|Refs], Errors, Ws);
+p_run_loop(Test, List, N, Refs0, Errors0, Ws0) ->
+ receive
+ {'DOWN',Ref,process,_,Res} ->
+ {Errors,Ws} = case Res of
+ ok -> {Errors0,Ws0};
+ error -> {Errors0+1,Ws0};
+ warning -> {Errors0,Ws0+1}
+ end,
+ Refs = Refs0 -- [Ref],
+ p_run_loop(Test, List, N, Refs, Errors, Ws)
+ end.