Skip to content

Commit

Permalink
erts: Fix misc trace test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sverker committed Oct 3, 2024
1 parent 7c44844 commit 4e1d8f5
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 31 deletions.
2 changes: 1 addition & 1 deletion erts/emulator/test/call_trace_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ testcases() ->
exception_nocatch, bit_syntax, errors, on_load].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/match_spec_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ testcases_match_spec_test() ->
maps, guard_bifs].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/port_trace_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ testcases() ->
driver_remote_send_term].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/trace_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ testcases() ->
ms_excessive_nesting].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
3 changes: 2 additions & 1 deletion erts/emulator/test/trace_bif_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

%%
%% %CopyrightBegin%
%%
Expand Down Expand Up @@ -48,7 +49,7 @@ testcases() ->
trace_bif_return, trace_info_old_code].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/trace_call_count_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ testcases() ->
[basic, on_and_off, info, pause_and_restart, combo].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
11 changes: 6 additions & 5 deletions erts/emulator/test/trace_call_memory_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ testcases() ->
spawn_memory_lambda, conflict_traces, big_words].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down Expand Up @@ -316,12 +316,13 @@ parallel_map(Config) when is_list(Config) ->
end.

do_parallel() ->
Allocs = [spawn_link(fun() -> alloc_2tup(), receive_message() end) || _ <- lists:seq(1, 3)],
Grand = [spawn_link(fun() -> receive_message() end) || _ <- lists:seq(1, 3)],
Allocs = [spawn_monitor(fun() -> alloc_2tup(), receive_message() end) || _ <- lists:seq(1, 3)],
Grand = [spawn_monitor(fun() -> receive_message() end) || _ <- lists:seq(1, 3)],
pre_stop = receive_message(),
[P ! {atom, <<"1234">>} || P <- Grand], %% 6 words on the heap: 3 for binary, 3 for tuple
[P ! {atom, <<"1234">>} || {P,_} <- Grand], %% 3 words on the heap for tuple (binary is literal)
{stop, 1} = receive_message(),
[exit(P, normal) || P <- Allocs].
[P ! atom || {P,_} <- Allocs], %% no words on the heap for atom
[receive {'DOWN', MRef, process, P, normal} -> ok end || {P,MRef} <- Allocs++Grand].

trace_all() ->
[{doc, "Enables memory tracing for all processes, mainly ensuring there are no core dumps"}].
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/trace_call_time_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ testcases() ->
catch_crash].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/trace_local_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
init_per_testcase/2, end_per_testcase/2]).

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
6 changes: 3 additions & 3 deletions erts/emulator/test/trace_meta_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ testcases() ->
combo, nosilent].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down Expand Up @@ -395,9 +395,9 @@ tracer_test() ->
?erlang_trace_info({erlang,phash2,2}, meta_match_spec),
%% Initiate trace messages that will fail
Ref2 = make_ref(),
apply_slave_async(?MODULE, receiver, [Ref2]),
Slave ! Ref2,
receive_no_next(100),
apply_slave(?MODULE, receiver, [Ref2]),
receive_no_next(0),
{meta,[]} =
?erlang_trace_info({?MODULE,receiver,1}, meta),
{meta_match_spec, MatchSpec} =
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/trace_nif_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ testcases() ->


init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down
7 changes: 4 additions & 3 deletions erts/emulator/test/trace_port_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ testcases() ->
default_tracer, tracer_port_crash].

init_per_suite(Config) ->
trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down Expand Up @@ -227,13 +227,14 @@ receive_trace_non_scheduler(Config) when is_list(Config) ->
fun() ->
receive
go ->
Ref = S ! erlang:trace_delivered(all),
Ref = erlang:trace_delivered(all),
S ! {sync,Ref},
receive {trace_delivered, Ref, all} -> ok end
end
end),
trac(Receiver, true, ['receive']),
Receiver ! go,
Ref = receive R -> R end,
Ref = receive {sync,R} -> R end,
expect({trace,Receiver,'receive',go}),
expect({trace,Receiver,'receive',{trace_delivered, all, Ref}}),

Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/test/trace_session_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ set_on_spawn2(S1, Tracer1, Opts1, S2, Tracer2, Opts2) ->
{Tracer1, {trace, GrandChild, exit, die}}],

[{Tracer2, {trace, GrandChild, spawned, Child, '_'}},
{Tracer2,{trace, '_', exit, die}}]
{Tracer2, {trace, GrandChild, exit, die}}]
}),

1 = erlang_trace(S1, self(), false, [procs, set_on_spawn | Opts1]),
Expand Down
43 changes: 34 additions & 9 deletions erts/emulator/test/trace_sessions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
%%

-export([all/0, groups/1,
init_per_suite/1, end_per_suite/1, suite_controller/2,
init_per_suite/2, end_per_suite/1, suite_controller/2,
init_per_group/2, end_per_group/2,
init_per_testcase/1, end_per_testcase/1,
erlang_trace/3,
Expand All @@ -55,10 +55,13 @@ all() ->
groups(Testcases) ->
[{Group, [], Testcases} || Group <- group_list()].

init_per_suite(Config) ->
init_per_suite(Config, SuiteModule) ->
SessionsBefore = trace:session_info(all),
Pid = spawn(?MODULE, suite_controller, [start, []]),
[{suite_controller, Pid}, {sessions_before, SessionsBefore} | Config].
[{suite_controller, Pid},
{sessions_before, SessionsBefore},
{suite_module, SuiteModule}
| Config].

end_per_suite(Config) ->
SessionsBefore = proplists:get_value(sessions_before, Config),
Expand Down Expand Up @@ -228,17 +231,14 @@ init_group([pre_session|Tail], Config) ->
%% Set a dummy call_count on all (local) functions.
trace:function(S, {'_','_','_'}, true, [local]),

%% Re-set a dummy global call trace on all exported functions.
[[trace:function(S, {Module, Func, Arity}, true, [global])
|| {Func,Arity} <- Module:module_info(exports)]
|| Module <- erlang:loaded(),
erlang:function_exported(Module, module_info, 1)],
%% Re-set a dummy global call trace on exported functions.
set_dummy_global_trace(S, Config),

%% Set a dummy send trace on all processes and ports
%% but disable send trace to not get any messages.
1 = trace:send(S, false, []),
trace:process(S, all, true, [send]),
trace:port(S, all, true, [send]),
1 = trace:send(S, false, []),

ets:insert(?MODULE, {pre_session, S, Tracer}),
init_group(Tail, Config);
Expand Down Expand Up @@ -287,3 +287,28 @@ init_per_testcase(Config) ->

end_per_testcase(Config) ->
suite_controller_check(Config).



set_dummy_global_trace(S, Config) ->
%% Modules = [M || M <- erlang:loaded(),
%% erlang:function_exported(M, module_info, 1)],
%% Calling trace_pattern on all loaded modules takes too long time
%% on some machines. Do it on a subset of modules instead.

%% Set a dummy global call trace on some exported functions.
SuiteModule = proplists:get_value(suite_module, Config),
Modules = [erlang, ets, lists, maps, SuiteModule],
io:format("~w modules to trace...\n", [length(Modules)]),

[begin
{Micros, 1} = timer:tc(fun() ->
trace:function(S, {Mod, Func, Arity},
true, [global])
end),
io:format("~10w: ~w:~w/~w", [Micros, Mod, Func, Arity])
end
|| Mod <- Modules,
{Func, Arity} <- Mod:module_info(exports)],

ok.
2 changes: 1 addition & 1 deletion erts/emulator/test/tracer_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ init_per_suite(Config) ->
erlang:trace_pattern({'_','_','_'}, false, []),
purge(),

trace_sessions:init_per_suite(Config).
trace_sessions:init_per_suite(Config, ?MODULE).

end_per_suite(Config) ->
trace_sessions:end_per_suite(Config).
Expand Down

0 comments on commit 4e1d8f5

Please sign in to comment.