aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/test/kernel_config_SUITE.erl
blob: a227c37cc8e4efc5e87e54e720d43c312dd7f037 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2011. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(kernel_config_SUITE).

-include_lib("common_test/include/ct.hrl").

-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, sync/1]).

-export([init_per_suite/1, end_per_suite/1]).

suite() ->
    [{ct_hooks,[ts_install_cth]},
     {timetrap,{minutes,2}}].

all() -> 
    [sync].

groups() -> 
    [].

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.


init_per_suite(Config) when is_list(Config) ->
    Config.

end_per_suite(Config) when is_list(Config) ->
    stop_node(init_test),
    Config.

config(Fd) ->
    M = from($@, atom_to_list(node())),
    io:format(Fd, "[{kernel, [{sync_nodes_optional, ['cp1@~s','cp2@~s']},"
	          "{sync_nodes_timeout, 15000}]}].~n",
	      [M, M]).

from(H, [H | T]) -> T;
from(H, [_ | T]) -> from(H, T);
from(_, []) -> [].

%%-----------------------------------------------------------------
%% Test suite for sync_nodes.   This is quite tricky.
%%
%% Should be started in a CC view with:
%% erl -sname XXX where XX not in [cp1, cp2]
%%-----------------------------------------------------------------
sync(Conf) when is_list(Conf) ->
    % Write a config file
    Dir = proplists:get_value(priv_dir,Conf),
    {ok, Fd} = file:open(Dir ++ "sys.config", [write]),
    config(Fd),
    file:close(Fd),
    Config = Dir ++ "sys",

    %% Reset wall_clock
    {T1,_} = erlang:statistics(wall_clock),
    io:format("~p~n", [{t1, T1}]),
    ?line Command = lists:concat([lib:progname(),
				  " -detached -sname cp1 ",
				  "-config ", Config,
				  " -env ERL_CRASH_DUMP erl_crash_dump.cp1"]),
    io:format("Command: ~s", [Command]),
    ?line open_port({spawn, Command}, [stream]),
    io:format("started~n"),
    ct:sleep(12000),
    io:format("waited12~n"),
    ?line Host = from($@, atom_to_list(node())),
    ?line Cp1 = list_to_atom("cp1@"++Host),
    ?line wait_for_node(Cp1),
    io:format("waitednode~n"),
    %% Check time since last call
    ?line {TT, T} = erlang:statistics(wall_clock),
    io:format("~p~n", [{t2, {TT, T}}]),
    ?line stop_node(cp1),
    if
	TT-T1 < 15000 -> ct:fail({too_short_time, TT-T1});
	true -> ok
    end,
    ok.

wait_for_node(Node) ->
    case rpc:call(Node, init, get_status, []) of
	{started,_} -> ok;
	{badrpc, R} -> ct:fail({rpc_failed, R});
	_Other -> wait_for_node(Node)
    end.


stop_node(Node) ->
    M = list_to_atom(lists:concat([Node,
				   [$@],
				   from($@,atom_to_list(node()))])),
    rpc:cast(M, erlang, halt, []).