summaryrefslogtreecommitdiff
path: root/lib/tools/test/instrument_SUITE.erl
blob: da5930e015027e8a464510d87ab13b5eeae2823e (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1998-2010. 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(instrument_SUITE).

-export([all/1,init_per_testcase/2,fin_per_testcase/2]).

-export(['+Mim true'/1, '+Mis true'/1]).

-include("test_server.hrl").

init_per_testcase(_Case, Config) ->
    ?line Dog=?t:timetrap(10000),
    [{watchdog, Dog}|Config].

fin_per_testcase(_Case, Config) ->
    Dog=?config(watchdog, Config),
    ?t:timetrap_cancel(Dog),
    ok.

all(suite) -> ['+Mim true', '+Mis true'].

'+Mim true'(doc) -> ["Check that memory data can be read and processed"];
'+Mim true'(suite) -> [];
'+Mim true'(Config) when is_list(Config) ->
    ?line Node = start_slave("+Mim true"),
    ?line MD = rpc:call(Node, instrument, memory_data, []),
    ?line [{total,[{sizes,S1,S2,S3},{blocks,B1,B2,B3}]}]
	= rpc:call(Node, instrument, memory_status, [total]),
    ?line stop_slave(Node),
    ?line true = S1 =< S2,
    ?line true = S2 =< S3,
    ?line true = B1 =< B2,
    ?line true = B2 =< B3,
    ?line MDS = instrument:sort(MD),
    ?line {Low, High} = instrument:mem_limits(MDS),
    ?line true = Low < High,
    ?line {_, AL} = MDS,
    ?line SumBlocks = instrument:sum_blocks(MD),
    ?line case SumBlocks of
	      N when is_integer(N) ->
		  ?line N = lists:foldl(fun ({_,_,Size,_}, Sum) ->
						Size+Sum
					end,
					0,
					AL),
		  ?line N =< S3;
	      Other ->
		  ?line ?t:fail(Other)
	  end,
    ?line lists:foldl(
	    fun ({TDescr,Addr,Size,Proc}, MinAddr) ->
		    ?line true = TDescr /= invalid_type,
		    ?line true = is_integer(TDescr),
		    ?line true = is_integer(Addr),
		    ?line true = is_integer(Size),
		    ?line true = Addr >= MinAddr,
		    ?line case Proc of
			      {0, Number, Serial} ->
				  ?line true = is_integer(Number),
				  ?line true = is_integer(Serial);
			      undefined ->
				  ok;
			      BadProc ->
				  ?line ?t:fail({badproc, BadProc})
			  end,
		    ?line NextMinAddr = Addr+Size,
		    ?line true = NextMinAddr =< High,
		    ?line NextMinAddr
	    end,
	    Low,
	    AL),
    ?line {_, DAL} = instrument:descr(MDS),
    ?line lists:foreach(
	    fun ({TDescr,_,_,Proc}) ->
		    ?line true = TDescr /= invalid_type,
		    ?line true = is_atom(TDescr) orelse is_list(TDescr),
		    ?line true = is_pid(Proc) orelse Proc == undefined
	    end,
	    DAL),
    ?line ASL = lists:map(fun ({_,A,S,_}) -> {A,S} end, AL),
    ?line ASL = lists:map(fun ({_,A,S,_}) -> {A,S} end, DAL),
    ?line instrument:holes(MDS),
    ?line {comment,
	   "total status - sum of blocks = " ++ integer_to_list(S1-SumBlocks)}.

'+Mis true'(doc) -> ["Check that memory data can be read and processed"];
'+Mis true'(suite) -> [];
'+Mis true'(Config) when is_list(Config) ->
    ?line Node = start_slave("+Mis true"),
    ?line [{total,[{sizes,S1,S2,S3},{blocks,B1,B2,B3}]}]
	= rpc:call(Node, instrument, memory_status, [total]),
    ?line true = S1 =< S2,
    ?line true = S2 =< S3,
    ?line true = B1 =< B2,
    ?line true = B2 =< B3,
    ?line true = is_list(rpc:call(Node,instrument,memory_status,[allocators])),
    ?line true = is_list(rpc:call(Node,instrument,memory_status,[classes])),
    ?line true = is_list(rpc:call(Node,instrument,memory_status,[types])),
    ?line ok.

start_slave(Args) ->
    ?line {A, B, C} = now(),
    ?line MicroSecs = A*1000000000000 + B*1000000 + C,
    ?line Name = "instr_" ++ integer_to_list(MicroSecs),
    ?line Pa = filename:dirname(code:which(?MODULE)),
    ?line {ok, Node} = ?t:start_node(list_to_atom(Name),
				     slave,
				     [{args, "-pa " ++ Pa ++ " " ++ Args}]),
    ?line Node.


stop_slave(Node) ->
    ?line true = ?t:stop_node(Node).