@@ -183,6 +183,7 @@ groups() ->
183183
184184 {all , [], all_cases ()},
185185 {start_and_stop_tests , [], start_and_stop_tests_cases ()},
186+ {notify , [], notify_cases ()},
186187 {misc_tests , [], misc_tests_cases ()},
187188 {usm_priv_aes_tests , [], usm_priv_aes_tests_cases ()},
188189 {user_tests , [], user_tests_cases ()},
@@ -238,6 +239,11 @@ start_and_stop_tests_cases() ->
238239 simple_start_and_stop3 ,
239240 simple_start_and_monitor_crash1 ,
240241 simple_start_and_monitor_crash2 ,
242+ {group , notify }
243+ ].
244+
245+ notify_cases () ->
246+ [
241247 notify_started01 ,
242248 notify_started02
243249 ].
@@ -1247,48 +1253,68 @@ do_notify_started01(Config) ->
12471253 {config , [{verbosity , log }, {dir , ConfDir }, {db_dir , DbDir }]}],
12481254
12491255 ? IPRINT (" [tc] request start notification (1)" ),
1250- Pid1 = snmpm :notify_started (10000 ),
1256+ NotifyPid1 = snmpm :notify_started (#{verbose => true ,
1257+ tick_time => 1000 ,
1258+ timeout => 10000 }),
12511259 receive
1252- {snmpm_start_timeout , Pid1 } ->
1253- ? IPRINT (" [tc] received expected start timeout" ),
1260+ {snmpm_start_timeout , NotifyPid1 } ->
1261+ ? IPRINT (" [tc] received expected start timeout ( ~p ) " , [ NotifyPid1 ] ),
12541262 ok ;
12551263 Any1 ->
1256- ? FAIL ({unexpected_message , Any1 })
1264+ ? EPRINT (" received unexpected message (1): "
1265+ " ~n ~p "
1266+ " ~n Notify Process (~p ) Info: ~p " ,
1267+ [Any1 ,
1268+ NotifyPid1 , (catch erlang :process_info (NotifyPid1 ))]),
1269+ ? FAIL ({unexpected_message , 1 , Any1 })
12571270 after 15000 ->
1258- ? FAIL ({unexpected_timeout , Pid1 })
1271+ ? EPRINT (" unexpected timeout: "
1272+ " ~n Notify Process (~p ) Info: ~p " ,
1273+ [NotifyPid1 , (catch erlang :process_info (NotifyPid1 ))]),
1274+ ? FAIL ({unexpected_timeout , 1 , NotifyPid1 })
12591275 end ,
12601276
12611277 ? IPRINT (" [tc] request start notification (2)" ),
1262- Pid2 = snmpm :notify_started (10000 ),
1278+ NotifyPid2 = snmpm :notify_started (#{verbose => true ,
1279+ tick_time => 1000 ,
1280+ timeout => ? NS_TIMEOUT }),
12631281
12641282 ? IPRINT (" [tc] start the snmpm starter" ),
1265- StarterPid = snmpm_starter (Opts , 5000 ),
1283+ { StarterPid , _StarterMRef } = snmpm_starter (Opts , 5000 ),
12661284
1267- ? IPRINT (" [tc] await the start notification" ),
1285+ ? IPRINT (" [tc] await the start notification: "
1286+ " ~n Notify Process: ~p "
1287+ " ~n Starter Process: ~p " , [NotifyPid2 , StarterPid ]),
12681288 Ref =
12691289 receive
1270- {snmpm_started , Pid2 } ->
1290+ {snmpm_started , NotifyPid2 } ->
12711291 ? IPRINT (" [tc] received start notification message -> "
12721292 " create the monitor" ),
12731293 snmpm :monitor ();
1274- {snmpm_start_timeout , StarterPid } ->
1275- ? EPRINT (" [tc] Start Timeout: "
1276- " ~n Starter Process (~p ) Info: ~p " ,
1277- [StarterPid , (catch erlang :process_info (StarterPid ))]),
1294+ {snmpm_start_timeout , NotifyPid2 } ->
1295+ ? EPRINT (" [tc] received unexpected start timeout when"
1296+ " ~n Starter Process (~p ) info: ~s " ,
1297+ [StarterPid ,
1298+ format_process_info (StarterPid , " " )]),
1299+ exit (StarterPid , kill ),
12781300 ? FAIL (start_timeout );
12791301 Any2 ->
12801302 ? EPRINT (" [tc] Unexpected Message: "
1281- " ~n Notify Process Info: ~p "
1282- " ~n Starter Process info: ~p " ,
1283- [(catch erlang :process_info (Pid2 )),
1284- (catch erlang :process_info (StarterPid ))]),
1303+ " ~n ~p "
1304+ " ~n Notify Process (~p ) Info: ~s "
1305+ " ~n Starter Process (~p ) info: ~s " ,
1306+ [Any2 ,
1307+ NotifyPid2 ,
1308+ format_process_info (NotifyPid2 , " " ),
1309+ StarterPid ,
1310+ format_process_info (StarterPid , " " )]),
12851311 ? FAIL ({unexpected_message , Any2 })
12861312 after 15000 ->
12871313 ? EPRINT (" [tc] Unexpected Start Timeout: "
1288- " ~n Notify Process Info: ~p "
1289- " ~n Starter Process info: ~p " ,
1290- [(catch erlang :process_info (Pid2 )),
1291- (catch erlang :process_info (StarterPid ))]),
1314+ " ~n Notify Process ( ~p ) Info: ~p "
1315+ " ~n Starter Process ( ~p ) info: ~p " ,
1316+ [NotifyPid2 , (catch erlang :process_info (NotifyPid2 )),
1317+ StarterPid , (catch erlang :process_info (StarterPid ))]),
12921318 ? FAIL (unexpected_start_timeout )
12931319 end ,
12941320
@@ -1319,10 +1345,51 @@ do_notify_started01(Config) ->
13191345 ? IPRINT (" [tc] end" ),
13201346 ok .
13211347
1348+ format_process_info (P , Indent ) when is_pid (P ) andalso is_list (Indent ) ->
1349+ try
1350+ begin
1351+ CurrentFunction = pi (P , current_function ),
1352+ CurrentStackTrace = pi (P , current_stacktrace ),
1353+ Reductions = pi (P , reductions ),
1354+ Memory = pi (P , memory ),
1355+ HeapSize = pi (P , heap_size ),
1356+ MaxHeapSize = pi (P , max_heap_size ),
1357+ TotHeapSize = pi (P , total_heap_size ),
1358+ Status = pi (P , status ),
1359+ ? F (" ~n "
1360+ " ~s Current Function: ~p~n "
1361+ " ~s Current StackTrace: ~p~n "
1362+ " ~s Reductions: ~p~n "
1363+ " ~s Memory: ~p~n "
1364+ " ~s HeapSize: ~p~n "
1365+ " ~s Max Heap Size: ~p~n "
1366+ " ~s Total Heap Size: ~p~n "
1367+ " ~s Status: ~p~n " ,
1368+ [Indent , CurrentFunction ,
1369+ Indent , CurrentStackTrace ,
1370+ Indent , Reductions ,
1371+ Indent , Memory ,
1372+ Indent , HeapSize ,
1373+ Indent , MaxHeapSize ,
1374+ Indent , TotHeapSize ,
1375+ Indent , Status ])
1376+ end
1377+ catch
1378+ _ :_ :_ ->
1379+ " -"
1380+ end .
13221381
1382+ pi (Pid , Key ) ->
1383+ case ? PI (Pid , Key ) of
1384+ undefined ->
1385+ throw (no_process );
1386+ Value ->
1387+ Value
1388+ end .
1389+
13231390snmpm_starter (Opts , To ) ->
13241391 Parent = self (),
1325- spawn (
1392+ spawn_monitor (
13261393 fun () ->
13271394 ? IPRINT (" [snmpm-starter] wait ~w msec" , [To ]),
13281395 ? SLEEP (To ),
@@ -1473,7 +1540,10 @@ ns02_client(Parent, N) when is_pid(Parent) ->
14731540 put (tname , ns02_client ),
14741541 ? IPRINT (" starting" ),
14751542 ns02_client_loop (Parent ,
1476- dummy , snmpm :notify_started (? NS_TIMEOUT ),
1543+ dummy ,
1544+ snmpm :notify_started (#{verbose => true ,
1545+ tick_time => 1000 ,
1546+ timeout => ? NS_TIMEOUT }),
14771547 snmp_misc :now (ms ), undefined ,
14781548 N ).
14791549
@@ -1514,7 +1584,10 @@ ns02_client_loop(Parent, Ref, Pid, Begin, End, N) ->
15141584 " ~n Obj: ~p "
15151585 " ~n Reason: ~p " , [N , Obj , Reason ]),
15161586 ns02_client_loop (Parent ,
1517- dummy , snmpm :notify_started (? NS_TIMEOUT ),
1587+ dummy ,
1588+ snmpm :notify_started (#{verbose => true ,
1589+ tick_time => 1000 ,
1590+ timeout => ? NS_TIMEOUT }),
15181591 Begin , snmp_misc :now (ms ),
15191592 N - 1 )
15201593 end .
0 commit comments