Permalink
Browse files

Added test for named process sending tracing

  • Loading branch information...
1 parent df833d9 commit 5d253a721f08bc2608bf92637b82a9c3a81acb34 Gianfranco committed Jul 7, 2011
Showing with 32 additions and 3 deletions.
  1. +18 −2 src/audit_collector.erl
  2. +14 −1 test/audit_collector_tests.erl
View
20 src/audit_collector.erl
@@ -70,6 +70,8 @@ options_to_trace_flag([start|R]) ->
[procs,set_on_spawn|options_to_trace_flag(R)];
options_to_trace_flag([exit|R]) ->
[procs,set_on_spawn|options_to_trace_flag(R)];
+options_to_trace_flag([named_send|R]) ->
+ [procs,set_on_spawn,send|options_to_trace_flag(R)];
options_to_trace_flag([X|R]) ->
[X|options_to_trace_flag(R)];
options_to_trace_flag([]) -> [].
@@ -109,5 +111,19 @@ make_log([exit|R],History) ->
Acc++[{exited,P,C}];
(_,Acc) ->
Acc
- end,[],History)++make_log(R,History).
-
+ end,[],History)++make_log(R,History);
+make_log([named_send|R],History) ->
+ Registered = lists:foldl(
+ fun({trace_ts,P,register,Name,_},Acc) ->
+ Acc++[{P,Name}];
+ (_,Acc) -> Acc
+ end,[],History),
+ Sent = make_log([send],History),
+ lists:foldl(
+ fun({send,P,Msg},Acc) ->
+ case proplists:get_value(P,Registered) of
+ undefined ->
+ Acc;
+ Name -> Acc++[{send,Name,Msg}]
+ end
+ end,[],Sent)++make_log(R,History).
View
15 test/audit_collector_tests.erl
@@ -10,7 +10,8 @@ audit_collector_test_() ->
fun audit_collector_process_receive/0,
fun audit_collector_process_started/0,
fun audit_collector_process_exited/0,
- fun audit_collector_process_exited_deep/0
+ fun audit_collector_process_exited_deep/0,
+ fun audit_collector_process_named_send/0
]}.
audit_collector_process_send() ->
@@ -75,3 +76,15 @@ audit_collector_process_exited_deep() ->
],
audit_collector:review(process,[exit])).
+audit_collector_process_named_send() ->
+ audit_collector:audit(process,[named_send]),
+ Self = self(),
+ Sender = spawn_link(fun() -> register(iName,self()),
+ Self ! {i_sent_this,self()}
+ end),
+ receive {i_sent_this,Sender} -> ok end,
+ timer:sleep(10),
+ ?assertMatch(
+ [{send,iName,{i_sent_this,Sender}}],
+ audit_collector:review(process,[named_send])).
+

0 comments on commit 5d253a7

Please sign in to comment.