2222% %%
2323% %% This module implements an event handler that the CT Master
2424% %% uses to handle status and progress notifications sent to the
25- % %% master node during test runs. This module may be used as a
25+ % %% master node during test runs. It also keeps track of the
26+ % %% details of failures which are used by the CT Master to print
27+ % %% a summary at the end of its run. This module may be used as a
2628% %% template for other event handlers that can be plugged in to
2729% %% handle logging and reporting on the master node.
2830-module (ct_master_event_fork ).
3234
3335% % API
3436-export ([start_link /0 , add_handler /0 , add_handler /1 , stop /0 ]).
35- -export ([notify /1 , sync_notify /1 ]).
37+ -export ([notify /1 , sync_notify /1 , get_results / 0 ]).
3638
3739% % gen_event callbacks
3840-export ([init /1 , handle_event /2 , handle_call /2 ,
4244-include_lib (" common_test/src/ct_util.hrl" ).
4345
4446
45- -record (state , {}).
47+ -record (state , {auto_skipped = [], failed = [] }).
4648
4749% %====================================================================
4850% % gen_event callbacks
@@ -108,6 +110,13 @@ notify(Event) ->
108110sync_notify (Event ) ->
109111 gen_event :sync_notify (? CT_MEVMGR_REF ,Event ).
110112
113+ % %--------------------------------------------------------------------
114+ % % Function: sync_notify(Event) -> Results
115+ % % Description: Get the results for auto-skipped and failed test cases.
116+ % %--------------------------------------------------------------------
117+ get_results () ->
118+ gen_event :call (? CT_MEVMGR_REF ,? MODULE ,get_results ).
119+
111120% %====================================================================
112121% % gen_event callbacks
113122% %====================================================================
@@ -135,10 +144,10 @@ handle_event(#event{name=start_logging,node=Node,data=RunDir},State) ->
135144 ct_master_logs_fork :nodedir (Node ,RunDir ),
136145 {ok ,State };
137146
138- handle_event (# event {name = Name ,node = Node ,data = Data },State ) ->
147+ handle_event (Event = # event {name = Name ,node = Node ,data = Data },State ) ->
139148 print (" ~n === ~w ===~n " , [? MODULE ]),
140149 print (" ~tw on ~w : ~tp~n " , [Name ,Node ,Data ]),
141- {ok ,State }.
150+ {ok ,maybe_store_event ( Event , State ) }.
142151
143152% %--------------------------------------------------------------------
144153% % Function:
@@ -150,6 +159,11 @@ handle_event(#event{name=Name,node=Node,data=Data},State) ->
150159% % gen_event:call/3,4, this function is called for the specified event
151160% % handler to handle the request.
152161% %--------------------------------------------------------------------
162+ handle_call (get_results ,State = # state {auto_skipped = AutoSkipped ,failed = Failed }) ->
163+ {ok ,#{
164+ auto_skipped => lists :sort (AutoSkipped ),
165+ failed => lists :sort (Failed )
166+ },State };
153167handle_call (flush ,State ) ->
154168 case process_info (self (),message_queue_len ) of
155169 {message_queue_len ,0 } ->
@@ -194,3 +208,10 @@ code_change(_OldVsn,State,_Extra) ->
194208print (_Str ,_Args ) ->
195209% io:format(_Str,_Args),
196210 ok .
211+
212+ maybe_store_event (# event {name = tc_done ,node = Node ,data = {Suite ,FuncOrGroup ,{auto_skipped ,Reason }}},State = # state {auto_skipped = Acc }) ->
213+ State # state {auto_skipped = [{Node ,Suite ,FuncOrGroup ,Reason }|Acc ]};
214+ maybe_store_event (# event {name = tc_done ,node = Node ,data = {Suite ,FuncOrGroup ,{failed ,Reason }}},State = # state {failed = Acc }) ->
215+ State # state {failed = [{Node ,Suite ,FuncOrGroup ,Reason }|Acc ]};
216+ maybe_store_event (_Event ,State ) ->
217+ State .
0 commit comments