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
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(random_kill_SUITE).
-compile([export_all]).
%%-define(line_trace,1).
-include("test_server.hrl").
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
all(suite) -> [run].
-define(iterations,25). %% Kill this many processes,
%% possibly with reboots in between
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
run(suite) -> [];
run(Config) ->
registered(?iterations).
registered(0) ->
ok;
registered(N) ->
random:seed(3461*N,1159*N,351*N),
Pid = select_victim(registered),
test_server:resume_point(?MODULE,registered,[N-1]),
test_server:format("About to kill pid ~p (~p)\n~p",
[Pid,process_info(Pid,registered_name),info(Pid)]),
%%exit(Pid,kill),
registered(N-1).
info(Pid) ->
Rest0 = tl(pid_to_list(Pid)),
{P1,Rest1} = get_until($.,Rest0),
{P2,Rest2} = get_until($.,Rest1),
{P3,_} = get_until($>,Rest2),
c:i(list_to_integer(P1),list_to_integer(P2),list_to_integer(P3)).
get_until(Ch,L) ->
get_until(Ch,L,[]).
get_until(Ch,[],Acc) ->
{lists:reverse(Acc),[]};
get_until(Ch,[Ch|T],Acc) ->
{lists:reverse(Acc),T};
get_until(Ch,[H|T],Acc) ->
get_until(Ch,T,[H|Acc]).
select_victim(registered) ->
Pids =
lists:map(fun(Server)-> whereis(Server) end,registered()),
ImmunePids =
[self()|lists:map(fun(Job)-> element(2,Job) end,test_server:jobs())],
SuitablePids =
lists:filter(fun(Pid)-> case lists:member(Pid,ImmunePids) of
true -> false;
false -> true
end
end, Pids),
Selected = random:uniform(length(SuitablePids)),
io:format("Selected ~p if ~p",[Selected,length(SuitablePids)]),
lists:nth(Selected,SuitablePids).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|