aboutsummaryrefslogtreecommitdiffstats
path: root/lib/runtime_tools/test/dyntrace_lttng_SUITE.erl
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2016-04-18 14:46:54 +0200
committerBjörn-Egil Dahlberg <[email protected]>2016-04-29 18:31:36 +0200
commit30bdb63be449ac92c98e35cf1d2ec7729981f5b6 (patch)
tree9ce9628dcc58588e49bcc1be1660bfe9cd7c3237 /lib/runtime_tools/test/dyntrace_lttng_SUITE.erl
parenta80b7eeb9927309cdbc68296ca9892486a3a8707 (diff)
downloadotp-30bdb63be449ac92c98e35cf1d2ec7729981f5b6.tar.gz
otp-30bdb63be449ac92c98e35cf1d2ec7729981f5b6.tar.bz2
otp-30bdb63be449ac92c98e35cf1d2ec7729981f5b6.zip
runtime_tools: Add lttng dyntrace tests
Diffstat (limited to 'lib/runtime_tools/test/dyntrace_lttng_SUITE.erl')
-rw-r--r--lib/runtime_tools/test/dyntrace_lttng_SUITE.erl293
1 files changed, 293 insertions, 0 deletions
diff --git a/lib/runtime_tools/test/dyntrace_lttng_SUITE.erl b/lib/runtime_tools/test/dyntrace_lttng_SUITE.erl
new file mode 100644
index 0000000000..185819f348
--- /dev/null
+++ b/lib/runtime_tools/test/dyntrace_lttng_SUITE.erl
@@ -0,0 +1,293 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2012-2016. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(dyntrace_lttng_SUITE).
+-include_lib("common_test/include/ct.hrl").
+
+-export([all/0, suite/0]).
+-export([init_per_suite/1, end_per_suite/1]).
+-export([init_per_testcase/2, end_per_testcase/2]).
+
+%% Test cases
+-export([t_lttng_list/1,
+ t_procs/1,
+ t_ports/1,
+ t_running_process/1,
+ t_running_port/1,
+ t_call/1,
+ t_send/1,
+ t_receive/1,
+ t_garbage_collection/1]).
+
+suite() ->
+ [{ct_hooks,[ts_install_cth]},
+ {timetrap, {seconds, 10}}].
+
+all() ->
+ [t_lttng_list,
+ t_procs,
+ t_ports,
+ t_running_process,
+ t_running_port,
+ t_call,
+ t_send,
+ t_receive,
+ t_garbage_collection].
+
+
+
+init_per_suite(Config) ->
+ case erlang:system_info(dynamic_trace) of
+ lttng ->
+ ensure_lttng_stopped("--all"),
+ Config;
+ _ ->
+ {skip, "No LTTng configured on system."}
+ end.
+
+end_per_suite(_Config) ->
+ ensure_lttng_stopped("--all"),
+ ok.
+
+init_per_testcase(Case, Config) ->
+ %% ensure loaded
+ _ = dyntrace:module_info(),
+ Name = atom_to_list(Case),
+ ok = ensure_lttng_started(Name, Config),
+ [{session, Name}|Config].
+
+end_per_testcase(Case, _Config) ->
+ Name = atom_to_list(Case),
+ ok = ensure_lttng_stopped(Name),
+ ok.
+
+%% tracepoints
+%%
+%% com_ericsson_dyntrace:gc_major_end
+%% com_ericsson_dyntrace:gc_major_start
+%% com_ericsson_dyntrace:gc_minor_end
+%% com_ericsson_dyntrace:gc_minor_start
+%% com_ericsson_dyntrace:message_receive
+%% com_ericsson_dyntrace:message_send
+%% -com_ericsson_dyntrace:message_queued
+%% com_ericsson_dyntrace:function_exception
+%% com_ericsson_dyntrace:function_return
+%% com_ericsson_dyntrace:function_call
+%% com_ericsson_dyntrace:port_link
+%% com_ericsson_dyntrace:port_exit
+%% com_ericsson_dyntrace:port_open
+%% com_ericsson_dyntrace:process_scheduled
+%% com_ericsson_dyntrace:process_register
+%% com_ericsson_dyntrace:process_exit
+%% com_ericsson_dyntrace:process_link
+%% com_ericsson_dyntrace:process_spawn
+%%
+%% Testcases
+%%
+
+t_lttng_list(_Config) ->
+ {ok, _} = cmd("lttng list -u"),
+ ok.
+
+t_procs(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:process_*", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},procs]),
+
+ Pid = spawn_link(fun() -> waiter() end),
+ Pid ! {self(), ok},
+ ok = receive {Pid,ok} -> ok end,
+ timer:sleep(1000),
+
+ _ = erlang:trace(all, false, [procs]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:process_spawn", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:process_link", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:process_exit", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:process_register", Res),
+ ok.
+
+t_ports(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:port_*", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},ports]),
+
+ _ = os:cmd("ls"),
+
+ _ = erlang:trace(all, false, [{tracer, dyntrace, []},ports]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:port_open", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:port_link", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:port_exit", Res),
+ ok.
+
+t_running_process(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:process_scheduled", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},running]),
+
+ Pid = spawn_link(fun() -> waiter() end),
+ Pid ! {self(), ok},
+ ok = receive {Pid,ok} -> ok end,
+ timer:sleep(1000),
+
+ _ = erlang:trace(all, false, [running]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:process_scheduled", Res),
+ ok.
+
+t_running_port(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:port_scheduled", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},running_ports]),
+
+ _ = os:cmd("ls"),
+ _ = os:cmd("ls"),
+
+ _ = erlang:trace(all, false, [running_ports]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:port_scheduled", Res),
+ ok.
+
+
+t_call(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:function_*", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []}, call]),
+ _ = erlang:trace_pattern({?MODULE, '_', '_'}, [{'_',[],[{exception_trace}]}], [local]),
+
+ DontLink = spawn(fun() -> foo_clause_exception(nope) end),
+ Pid = spawn_link(fun() -> waiter() end),
+ Pid ! {self(), ok},
+ ok = receive {Pid,ok} -> ok end,
+
+ timer:sleep(10),
+ undefined = erlang:process_info(DontLink),
+
+ _ = erlang:trace_pattern({?MODULE, '_', '_'}, false, [local]),
+ _ = erlang:trace(all, false, [call]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:function_call", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:function_return", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:function_exception", Res),
+ ok.
+
+t_send(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:message_send", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},send]),
+
+ Pid = spawn_link(fun() -> waiter() end),
+ Pid ! {self(), ok},
+ ok = receive {Pid,ok} -> ok end,
+ _ = os:cmd("ls"),
+ timer:sleep(10),
+
+ _ = erlang:trace(all, false, [send]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:message_send", Res),
+ ok.
+
+t_receive(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:message_receive", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},'receive']),
+
+ Pid = spawn_link(fun() -> waiter() end),
+ Pid ! {self(), ok},
+ ok = receive {Pid,ok} -> ok end,
+ timer:sleep(10),
+ _ = erlang:trace(all, false, ['receive']),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:message_receive", Res),
+ ok.
+
+t_garbage_collection(Config) when is_list(Config) ->
+ ok = lttng_start_event("com_ericsson_dyntrace:gc_*", Config),
+ _ = erlang:trace(new, true, [{tracer, dyntrace, []},garbage_collection]),
+
+ Pid = spawn_link(fun() -> gcfier() end),
+ Pid ! {self(), ok},
+ ok = receive {Pid,ok} -> ok end,
+ timer:sleep(10),
+ _ = erlang:trace(all, false, [garbage_collection]),
+ Res = lttng_stop_and_view(Config),
+ ok = check_tracepoint("com_ericsson_dyntrace:gc_major_start", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:gc_major_end", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:gc_minor_start", Res),
+ ok = check_tracepoint("com_ericsson_dyntrace:gc_minor_end", Res),
+ ok.
+
+%% aux
+
+gcfier() ->
+ receive
+ {Pid, ok} ->
+ _ = lists:reverse(lists:seq(1,10000)),
+ true = erlang:garbage_collect(),
+ Pid ! {self(), ok}
+ end.
+
+
+waiter() ->
+ true = register(?MODULE, self()),
+ receive
+ {Pid, ok} ->
+ Child = spawn(fun() -> receive ok -> ok end end),
+ link(Child),
+ unlink(Child),
+ _ = lists:seq(1,1000),
+ Child ! ok,
+ true = unregister(?MODULE),
+ Pid ! {self(),ok}
+ end.
+
+foo_clause_exception({1,2}) -> badness.
+
+%% lttng
+lttng_stop_and_view(Config) ->
+ Path = proplists:get_value(priv_dir, Config),
+ Name = proplists:get_value(session, Config),
+ {ok,_} = cmd("lttng stop " ++ Name),
+ {ok,Res} = cmd("lttng view " ++ Name ++ " --trace-path=" ++ Path),
+ Res.
+
+check_tracepoint(TP, Data) ->
+ case re:run(Data, TP, [global]) of
+ {match, _} -> ok;
+ _ -> notfound
+ end.
+
+lttng_start_event(Event, Config) ->
+ Name = proplists:get_value(session, Config),
+ {ok, _} = cmd("lttng enable-event -u " ++ Event ++ " --session=" ++ Name),
+ {ok, _} = cmd("lttng start " ++ Name),
+ ok.
+
+ensure_lttng_started(Name, Config) ->
+ Out = case proplists:get_value(priv_dir, Config) of
+ undefined -> [];
+ Path -> "--output="++Path++" "
+ end,
+ {ok,_} = cmd("lttng create " ++ Out ++ Name),
+ ok.
+
+ensure_lttng_stopped(Name) ->
+ {ok,_} = cmd("lttng stop"),
+ {ok,_} = cmd("lttng destroy " ++ Name),
+ ok.
+
+cmd(Cmd) ->
+ io:format("<< ~ts~n", [Cmd]),
+ Res = os:cmd(Cmd),
+ io:format(">> ~ts~n", [Res]),
+ {ok,Res}.