Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ct: Remove usage of deprecated ct_slave in tests #9560

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/common_test/test/common_test.spec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{suites,"../common_test_test",all}.
{event_handler, {cte_track, []}}.
1 change: 1 addition & 0 deletions lib/common_test/test/common_test_gh.spec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{suites,"../common_test_test",all}.
{skip_suites,"../common_test_test",[ct_release_test_SUITE],"Versions not always correct"}.
{event_handler, {cte_track, []}}.
4 changes: 2 additions & 2 deletions lib/common_test/test/ct_auto_clean_SUITE.erl
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@
init_per_suite(Config) ->
DataDir = ?config(data_dir, Config),
CTHs = filelib:wildcard(filename:join(DataDir,"cth_*.erl")),
ct:pal("CTHs: ~p",[CTHs]),
[ct:pal("Compiling ~p: ~p",
ct:log("CTHs: ~p",[CTHs]),
[ct:log("Compiling ~p: ~p",
[FileName,compile:file(FileName,[{outdir,DataDir},debug_info])]) ||
FileName <- CTHs],
ct_test_support:init_per_suite([{path_dirs,[DataDir]} | Config]).
Original file line number Diff line number Diff line change
@@ -61,9 +61,10 @@ post_end_per_suite(_Suite, _Config, Return, State) ->
do_until(fun() -> ct:remaining_test_procs() end, {[],SharedGL,[]}),
AllProcs = processes(),
Remaining = AllProcs--proplists:get_value(all_procs, State),
ct:pal("Final remaining processes = ~p", [Remaining]),
%% only the end_per_suite process should remain at this point!
Remaining = [self()],
ct:pal("Final remaining processes = ~p", [pi(Remaining)]),
Me = self(),
%% only the end_per_suite process and application_master should remain at this point!
[_AppMaster, Me] = Remaining,
{Return, State}.

pre_init_per_group(_Suite, _Group, Config, State) ->
31 changes: 8 additions & 23 deletions lib/common_test/test/ct_cover_SUITE.erl
Original file line number Diff line number Diff line change
@@ -130,35 +130,25 @@ slave_start_slave(Config) ->
%% Check that cover is collected from test node and slave node.
cover_node_option(Config) ->
DataDir = ?config(data_dir,Config),
{ok,Node} = start_slave(existing_node_1, "-pa " ++ DataDir),
{ok, Controller, Node} = start_peer(existing_node_1, ["-pa", DataDir]),
false = check_cover(Node),
CoverSpec = default_cover_file_content() ++ [{nodes,[Node]}],
CoverFile = create_cover_file(cover_node_option,CoverSpec,Config),
{ok,Events} = run_test(cover_node_option,cover_node_option,
[{cover,CoverFile}],Config),
check_calls(Events,2),
{ok,Node} = ct_slave:stop(existing_node_1),
ok.

cover_node_option(cleanup,_Config) ->
_ = ct_slave:stop(existing_node_1),
ok.
ok = peer:stop(Controller).

%% Test ct_cover:add_nodes/1 and ct_cover:remove_nodes/1
%% Check that cover is collected from added node
ct_cover_add_remove_nodes(Config) ->
DataDir = ?config(data_dir,Config),
{ok,Node} = start_slave(existing_node_2, "-pa " ++ DataDir),
{ok,Controller,Node} = start_peer(existing_node_2, ["-pa", DataDir]),
false = check_cover(Node),
{ok,Events} = run_test(ct_cover_add_remove_nodes,ct_cover_add_remove_nodes,
[],Config),
check_calls(Events,2),
{ok,Node} = ct_slave:stop(existing_node_2),
ok.

ct_cover_add_remove_nodes(cleanup,_Config) ->
_ = ct_slave:stop(existing_node_2),
ok.
ok = peer:stop(Controller).

%% Test that the test suite itself can be cover compiled and that
%% data_dir is set correctly (OTP-9956)
@@ -206,7 +196,6 @@ cross(Config) ->
ok.

export_import(Config) ->
DataDir = ?config(data_dir,Config),
false = check_cover(Config),
CoverSpec1 =
default_cover_file_content() ++ [{export,"export_import.coverdata"}],
@@ -382,14 +371,10 @@ create_cover_file(Filename,Terms,Config) ->
ok = file:close(Fd),
File.

start_slave(Name,Args) ->
{ok, HostStr}=inet:gethostname(),
Host = list_to_atom(HostStr),
ct_slave:start(Host,Name,
[{erl_flags,Args},
{boot_timeout,10}, % extending some timers for slow test hosts
{init_timeout,10},
{startup_timeout,10}]).
start_peer(Name, Args) ->
{ok, Host} = inet:gethostname(),
?CT_PEER(#{host => Host, name => Name,
args => Args, timeout => timer:seconds(10)}).

rel_path(From, To) ->
Segments = do_rel_path(filename:split(From), filename:split(To)),
46 changes: 30 additions & 16 deletions lib/common_test/test/ct_cover_SUITE_data/cover_SUITE.erl
Original file line number Diff line number Diff line change
@@ -78,11 +78,13 @@ slave(_Config) ->
cover_compiled = code:which(cover_test_mod),
cover_test_mod:foo(),
N1 = nodename(slave,1),
{ok,Node} = start_slave(N1),
cover_compiled = rpc:call(Node,code,which,[cover_test_mod]),
{ok, Controller, Node} = start_slave(N1),
cover_compiled = erpc:call(Node,code,which,[cover_test_mod]),
rpc:call(Node,cover_test_mod,foo,[]),
{ok,Node} = ct_slave:stop(N1),
ok = cover:flush(Node),
ok = peer:stop(Controller),
ok.

slave(cleanup,_Config) ->
kill_slaves([nodename(slave,1)]).

@@ -91,14 +93,17 @@ slave_start_slave(_Config) ->
cover_test_mod:foo(),
N1 = nodename(slave_start_slave,1),
N2 = nodename(slave_start_slave,2),
{ok,Node} = start_slave(N1),
{ok, Controller, Node} = start_slave(N1),
cover_compiled = rpc:call(Node,code,which,[cover_test_mod]),
rpc:call(Node,cover_test_mod,foo,[]),
{ok,Node2} = start_slave(Node,N2), % start slave N2 from node Node
rpc:call(Node2,cover_test_mod,foo,[]),
{ok,Node2} = rpc:call(Node,ct_slave,stop,[N2]),
{ok,Node} = ct_slave:stop(N1),
erpc:call(Node,cover_test_mod,foo,[]),
{ok, Controller2, Node2} = start_slave(Node,N2), % start slave N2 from node Node
erpc:call(Node2,cover_test_mod,foo,[]),
ok = cover:flush(Node2),
ok = erpc:call(Node, peer, stop, [Controller2]),
ok = cover:flush(Node),
ok = peer:stop(Controller),
ok.

slave_start_slave(cleanup,_Config) ->
kill_slaves([nodename(slave_start_slave,1),
nodename(slave_start_slave,2)]).
@@ -160,10 +165,19 @@ start_slave(Name) ->
start_slave(node(),Name).

start_slave(FromNode,Name) ->
{ok, HostStr}=inet:gethostname(),
Host = list_to_atom(HostStr),
rpc:call(FromNode,ct_slave,start,
[Host,Name,
[{boot_timeout,15}, % extending some timers for slow test hosts
{init_timeout,15},
{startup_timeout,15}]]).
{ok, Host} = inet:gethostname(),
PeerOpts = #{
host => Host,
name => Name,
% extending some timers for slow test hosts
timeout => timer:seconds(15),
wait_boot => timer:seconds(15)
},
{ok, _Controller, Node} = StartPeer = erpc:call(FromNode, peer, start, [PeerOpts]),
% Previously, cover was started automatically by ct_slave, peer won't do
% that for us, so we have to start cover ourselves.
case test_server:is_cover() of
true -> {ok, [Node]} = cover:start(Node);
false -> ok
end,
StartPeer.
27 changes: 6 additions & 21 deletions lib/common_test/test/ct_cover_nomerge_SUITE.erl
Original file line number Diff line number Diff line change
@@ -59,9 +59,6 @@ init_per_testcase(TestCase, Config) ->
ct_test_support:init_per_testcase(TestCase, Config).

end_per_testcase(TestCase, Config) ->
try apply(?MODULE,TestCase,[cleanup,Config])
catch error:undef -> ok
end,
ct_test_support:end_per_testcase(TestCase, Config).

suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -92,30 +89,23 @@ remote(Config) ->
DataDir = ?config(data_dir, Config),
Spec = filename:join(DataDir, "remote.spec"),
%% extending some timers for slow test hosts
{ok,Node} = ct_slave:start(ct_nomerge,[{boot_timeout,15},
{init_timeout,15},
{startup_timeout,15}]),

{ok, Controller, Node} = ?CT_PEER(#{name => ct_nomerge, timeout => timer:seconds(15)}),

CoverSpec = [{nodes,[Node]},
{incl_mods,[?mod]}],
CoverFile = create_cover_file(remote,CoverSpec,Config),
{Opts,ERPid} = setup([{spec,Spec},{label,remote},{cover,CoverFile}], Config),
{ok,Events} = execute(remote, remote, Opts, ERPid, Config),
false = check_cover(Config),
check_calls(Events,2),
ok.
remote(cleanup,_Config) ->
{ok,_} = ct_slave:stop(ct_nomerge),
ok.
ok = peer:stop(Controller).

remote_nostop(Config) ->
DataDir = ?config(data_dir, Config),
Spec = filename:join(DataDir, "remote_nostop.spec"),
%% extending some timers for slow test hosts
{ok,Node} = ct_slave:start(ct_nomerge,[{boot_timeout,15},
{init_timeout,15},
{startup_timeout,15}]),

{ok, Controller, Node} = ?CT_PEER(#{name => ct_nomerge, timeout => timer:seconds(15)}),

CoverSpec = [{nodes,[Node]},
{incl_mods,[?mod]}],
CoverFile = create_cover_file(remote_nostop,CoverSpec,Config),
@@ -125,12 +115,7 @@ remote_nostop(Config) ->
{ok,Events} = execute(remote_nostop, remote_nostop, Opts, ERPid, Config),
{true,[Node],[cover_test_mod]} = check_cover(Config),
check_calls(Events,2),
ok.
remote_nostop(cleanup,Config) ->
CtNode = ?config(ct_node,Config),
ok = rpc:call(CtNode,cover,stop,[]),
{ok,_} = ct_slave:stop(ct_nomerge),
ok.
ok = peer:stop(Controller).


%%%-----------------------------------------------------------------
2 changes: 1 addition & 1 deletion lib/common_test/test/ct_error_SUITE.erl
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ init_per_suite(Config) ->
DataDir = ?config(data_dir, Config),
TestDir = filename:join(DataDir, "error/test/"),
CTH = filename:join(TestDir, "verify_config.erl"),
ct:pal("Compiling ~p: ~p",
ct:log("Compiling ~p: ~p",
[CTH,compile:file(CTH,[{outdir,TestDir},debug_info])]),
ct_test_support:init_per_suite([{path_dirs,[TestDir]} | Config]).

4 changes: 4 additions & 0 deletions lib/common_test/test/ct_event_handler_SUITE.erl
Original file line number Diff line number Diff line change
@@ -99,7 +99,9 @@ start_stop(Config) when is_list(Config) ->

ERPid = ct_test_support:start_event_receiver(Config),

ct:capture_start(),
ok = ct_test_support:run(Opts, Config),
ct:capture_stop(), % hush the tests

Events = ct_test_support:get_events(ERPid, Config),

@@ -146,7 +148,9 @@ results(Config) when is_list(Config) ->

ERPid = ct_test_support:start_event_receiver(Config),

ct:capture_start(),
ok = ct_test_support:run(Opts, Config),
ct:capture_stop(), % hush the tests

Events = ct_test_support:get_events(ERPid, Config),

22 changes: 11 additions & 11 deletions lib/common_test/test/ct_groups_search_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1012,7 +1012,7 @@ run_groups_with_options(Config) ->
({Path,_,_}) -> [Path]
end, M1All),

%% ct:pal("NOW RUNNING M1 TEST: ~p", [M1All]),
%% ct:log("NOW RUNNING M1 TEST: ~p", [M1All]),

{OptsM11,ERPidM11} = setup([{dir,DataDir},{suite,?M1},
{group,M1AllGrs},{label,m1_all_cases}], Config),
@@ -1022,7 +1022,7 @@ run_groups_with_options(Config) ->
lists:foldl(
fun({GrPath,TCs,Found}, N) ->
TestName = list_to_atom("m1_spec_cases_" ++ integer_to_list(N)),
%% ct:pal("NOW RUNNING M1 TEST ~p: ~p + ~p",
%% ct:log("NOW RUNNING M1 TEST ~p: ~p + ~p",
%% [TestName,GrPath,TCs]),
{OptsM12,ERPidM12} = setup([{dir,DataDir},{suite,?M1},
{group,GrPath},{testcase,TCs},
@@ -1032,7 +1032,7 @@ run_groups_with_options(Config) ->
N+1
end, 1, M1Rest),

%% ct:pal("NOW RUNNING M2 TEST: ~p", [M2All]),
%% ct:log("NOW RUNNING M2 TEST: ~p", [M2All]),

M2AllGrs = lists:flatmap(fun({Path,_,_}) when is_atom(hd(Path)) -> Path;
({Path,_,_}) when is_list(hd(Path)) -> Path;
@@ -1049,7 +1049,7 @@ run_groups_with_options(Config) ->
lists:foldl(
fun({GrPath,TCs,Found}, N) ->
TestName = list_to_atom("m2_spec_cases_" ++ integer_to_list(N)),
%% ct:pal("NOW RUNNING M2 TEST ~p: ~p + ~p", [TestName,GrPath,TCs]),
%% ct:log("NOW RUNNING M2 TEST ~p: ~p + ~p", [TestName,GrPath,TCs]),
{OptsM22,ERPidM22} = setup([{dir,DataDir},{suite,?M2},
{group,GrPath},{testcase,TCs},
{label,TestName}], Config),
@@ -1099,7 +1099,7 @@ run_groups_with_testspec(Config) ->
TestSpec = [{merge_tests,false},
{label,Name}] ++ GroupTerms,

ct:pal("Here's the test spec:~n~p", [TestSpec]),
ct:log("Here's the test spec:~n~p", [TestSpec]),

TestSpecName = ct_test_support:write_testspec(TestSpec, PrivDir,
"groups_search_spec"),
@@ -1137,7 +1137,7 @@ get_all_groups_and_cases(Config) ->

MGTFs = [apply(?MODULE, TC, [Config]) || TC <- FindGrTCs],

ct:pal("Extracted data from ~p test cases", [length(MGTFs)]),
ct:log("Extracted data from ~p test cases", [length(MGTFs)]),

lists:foldr(fun({M,Gs,TCs,F},
{M11,M12,M21,M22}) ->
@@ -1198,7 +1198,7 @@ test_events(TestName, {GrPath,TCs,Found}, Events)
ok -> ok
catch
throw:Reason ->
ct:pal("Test failed for ~p with group path ~p and cases ~p"
ct:log("Test failed for ~p with group path ~p and cases ~p"
"~nReason: ~p", [TestName,GrPath,TCs,Reason]),
throw(failed)
end;
@@ -1220,7 +1220,7 @@ test_events(run_groups_with_testspec, Params, Events) ->
ok -> ok
catch
throw:Reason ->
ct:pal("Test failed for run_groups_with_testspec."
ct:log("Test failed for run_groups_with_testspec."
"~nReason: ~p", [Reason]),
throw(failed)
end.
@@ -1242,12 +1242,12 @@ check_events([{_,tc_start,{Mod,TC}} | Evs],
[{Mod,TC} | Check]) when is_atom(TC) ->
check_events(Evs, Check);
check_events([{_,tc_start,{Mod,{init_per_group,G,_}}} | _Evs], Check) ->
ct:pal("CHECK FAILED!~nGroup ~p in ~p not found in ~p.",
ct:log("CHECK FAILED!~nGroup ~p in ~p not found in ~p.",
[G,Mod,Check]),
throw({test_not_found,{Mod,G}});
check_events([{_,tc_start,{Mod,TC}} | _Evs], Check)
when is_atom(TC), TC /= init_per_suite, TC /= end_per_suite ->
ct:pal("CHECK FAILED!~nCase ~p in ~p not found in ~p.",
ct:log("CHECK FAILED!~nCase ~p in ~p not found in ~p.",
[TC,Mod,Check]),
throw({test_not_found,{Mod,TC}});
check_events([Group | Evs], Check) when is_list(Group) ->
@@ -1258,7 +1258,7 @@ check_events(_, []) ->
check_events([Elem | Evs], Check) when is_tuple(Elem) ->
check_events(Evs, Check);
check_events([], Check = [_|_]) ->
ct:pal("CHECK FAILED!~nTests remain: ~p", [Check]),
ct:log("CHECK FAILED!~nTests remain: ~p", [Check]),
throw({tests_remain,Check});
check_events([Wut | _],_) ->
throw({unexpected,Wut}).
10 changes: 5 additions & 5 deletions lib/common_test/test/ct_hooks_SUITE.erl
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ init_per_suite(Config) ->
DataDir = ?config(data_dir, Config),
TestDir = filename:join(DataDir,"cth/tests/"),
CTHs = filelib:wildcard(filename:join(TestDir,"*_cth.erl")),
io:format("CTHs: ~p",[CTHs]),
[io:format("Compiling ~p: ~p",
ct:log("CTHs: ~p",[CTHs]),
[ct:log("Compiling ~p: ~p",
[FileName,compile:file(FileName,[{outdir,TestDir},debug_info])]) ||
FileName <- CTHs],
ct_test_support:init_per_suite([{path_dirs,[TestDir]} | Config]).
@@ -333,7 +333,7 @@ cth_log_formatter(Config) when is_list(Config) ->
{E,N,L+1};
(_, N) -> N
end, {0,0,0}, Ts),
ct:pal("~p ({Error,Notice,Log}) matches in ~tp",
ct:log("~p ({Error,Notice,Log}) matches in ~tp",
[Matches,TCLog]),
MatchList = tuple_to_list(Matches),
case [N || N <- MatchList, N<1] of
@@ -365,7 +365,7 @@ cth_log_unexpect(Config) when is_list(Config) ->
{E,I,L+1};
(_, N) -> N
end, {0,0,0}, Ts),
ct:pal("~p ({Error,Info,Log}) matches in ~tp",
ct:log("~p ({Error,Info,Log}) matches in ~tp",
[Matches,UnexpIoLog]),
MatchList = tuple_to_list(Matches),
case [N || N <- MatchList, N<3] of
@@ -547,7 +547,7 @@ verify_cth_log_output(Config, CTHooks, ExtraOpts) ->
{E,I,N,L+1};
(_, N) -> N
end, {0,0,0,0}, Ts),
ct:pal("~p ({Error,Info,Notice,Log}) matches in ~tp",
ct:log("~p ({Error,Info,Notice,Log}) matches in ~tp",
[Matches,TCLog]),
MatchList = tuple_to_list(Matches),
case [N || N <- MatchList, N<1] of
Loading