@@ -309,16 +309,18 @@ node_start_link(Host, Name, Retries) ->
309309 {ok , Cwd } = file :get_cwd (),
310310 ct :pal (" ~n === node_start_link debug (~p ) ===~n "
311311 " CWD: ~ts " , [NewNode , Cwd ]),
312- Path = code :get_path (),
313- % Path = lists:filter(fun filelib:is_dir/1, Path0),
312+ Path0 = code :get_path (),
313+ ct : pal ( " Path0: ~p~n " , [ Path0 ] ),
314314 lists :foreach (
315315 fun (Dir ) ->
316316 Exists = filelib :is_dir (Dir ),
317317 ct :pal (" PATH dir: ~ts exists=~p " , [Dir , Exists ])
318- end , Path ),
318+ end , Path0 ),
319319 ct :pal (" === end debug ===" ),
320+ Path = lists :filter (fun filelib :is_dir /1 , Path0 ),
321+ ct :pal (" Path: ~p~n " , [Path ]),
320322 ok = rpc :call (NewNode , file , set_cwd , [Cwd ]),
321- true = rpc : call (NewNode , code , set_path , [ Path ] ),
323+ true = trace_set_path (NewNode , Path ),
322324 ok = rpc :call (NewNode , error_logger , tty , [false ]),
323325 spawn_link (NewNode , ? MODULE , node_sup , []),
324326 rpc :multicall ([node () | nodes ()], global , sync , []),
@@ -344,6 +346,86 @@ node_sup() ->
344346 ignore
345347 end .
346348
349+ trace_set_path (Node , Path ) ->
350+ % % Execute all tracing on the remote node in one call to avoid
351+ % % session reference GC issues when round-tripping through rpc
352+ Res = rpc :call (Node , erlang , apply , [fun () ->
353+ Collector = self (),
354+ Tracer = spawn_link (fun F () ->
355+ receive
356+ {trace , Pid , call , MFA } ->
357+ Collector ! {trace_msg , {call , Pid , MFA }},
358+ F ();
359+ {trace , Pid , return_from , MFA , RetVal } ->
360+ Collector ! {trace_msg , {return_from , Pid , MFA , RetVal }},
361+ F ();
362+ {trace , Pid , exception_from , MFA , {Class , Reason }} ->
363+ Collector ! {trace_msg , {exception_from , Pid , MFA , Class , Reason }},
364+ F ();
365+ stop ->
366+ ok ;
367+ Other ->
368+ Collector ! {trace_msg , {unexpected , Other }},
369+ F ()
370+ end
371+ end ),
372+ Session = trace :session_create (mnesia_test_trace , Tracer , []),
373+
374+ MatchSpec = [{'_' , [], [{return_trace }, {exception_trace }]}],
375+
376+ SetupResults = [
377+ {process_all , trace :process (Session , all , true , [call ])},
378+ {code_set_path_1 , trace :function (Session , {code , set_path , 1 }, MatchSpec , [local ])},
379+ {code_set_path_2 , trace :function (Session , {code , set_path , 2 }, MatchSpec , [local ])},
380+ {code_server_set_path_5 , trace :function (Session , {code_server , set_path , 5 }, MatchSpec , [local ])},
381+ {code_server_check_path_1 , trace :function (Session , {code_server , check_path , 1 }, MatchSpec , [local ])},
382+ {code_server_do_check_path_4 , trace :function (Session , {code_server , do_check_path , 4 }, MatchSpec , [local ])},
383+ {code_server_is_dir_1 , trace :function (Session , {code_server , is_dir , 1 }, MatchSpec , [local ])},
384+ {erl_prim_loader_read_file_info_1 , trace :function (Session , {erl_prim_loader , read_file_info , 1 }, MatchSpec , [local ])}
385+ ],
386+
387+ % % Call code:set_path
388+ SetPathRes = code :set_path (Path ),
389+
390+ % % Collect trace messages
391+ timer :sleep (500 ),
392+ TraceMessages = collect_trace_msgs ([]),
393+
394+ % % Cleanup
395+ trace :session_destroy (Session ),
396+ Tracer ! stop ,
397+
398+ {SetPathRes , SetupResults , TraceMessages }
399+ end , []]),
400+
401+ case Res of
402+ {SetPathRes , SetupResults , TraceMessages } ->
403+ ct :pal (" *** [~p ] trace_set_path setup results: ~p " ,
404+ [Node , SetupResults ]),
405+ lists :foreach (fun (Msg ) ->
406+ ct :pal (" *** [~p ] TRACE: ~p " , [Node , Msg ])
407+ end , TraceMessages ),
408+ ct :pal (" *** [~p ] code:set_path result: ~p (path length: ~p )" ,
409+ [Node , SetPathRes , length (Path )]),
410+ case SetPathRes of
411+ true -> true ;
412+ Other ->
413+ error ({code_set_path_failed , Node , Other })
414+ end ;
415+ {badrpc , Reason } ->
416+ ct :pal (" *** [~p ] trace_set_path BADRPC: ~p ***" ,
417+ [Node , Reason ]),
418+ error ({code_set_path_failed , Node , {badrpc , Reason }})
419+ end .
420+
421+ collect_trace_msgs (Acc ) ->
422+ receive
423+ {trace_msg , Msg } ->
424+ collect_trace_msgs ([Msg | Acc ])
425+ after 0 ->
426+ lists :reverse (Acc )
427+ end .
428+
347429% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348430% % Index the test case structure
349431
@@ -836,7 +918,7 @@ init_nodes([Node | Nodes], File, Line) ->
836918 case node_start_link (Host , Name ) of
837919 {ok , Node1 } ->
838920 Path = code :get_path (),
839- true = rpc : call (Node1 , code , set_path , [ Path ] ),
921+ true = trace_set_path (Node1 , Path ),
840922 [Node1 | init_nodes (Nodes , File , Line )];
841923 Other ->
842924 ? skip (" Test case (~p (~p )) ignored: cannot start node ~p : ~p~n " ,
0 commit comments