aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test/c_SUITE.erl
blob: 8c55b616b98f2aa88c6206a11e66c39c75460ded (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 1998-2011. 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(c_SUITE).
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
	 init_per_group/2,end_per_group/2]).
-export([c_1/1, c_2/1, c_3/1, c_4/1, nc_1/1, nc_2/1, nc_3/1, nc_4/1,
	 ls/1, memory/1]).

-include_lib("test_server/include/test_server.hrl").

-import(c, [c/2, nc/2]).

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

all() -> 
    [c_1, c_2, c_3, c_4, nc_1, nc_2, nc_3, nc_4, ls, memory].

groups() -> 
    [].

init_per_suite(Config) ->
    Config.

end_per_suite(_Config) ->
    ok.

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.


%%% Write output to a directory other than current directory:

c_1(doc) ->
    ["Checks that c:c works also with option 'outdir' [ticket OTP-1209]."];
c_1(suite) ->
    [];
c_1(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m.erl"),
    ?line W = ?config(priv_dir, Config),
    ?line Result = c(R,[{outdir,W}]),
    ?line {ok, m} = Result.

c_2(doc) ->
    ["Checks that c:c works also with option 'outdir' [ticket OTP-1209]."];
c_2(suite) ->
    [];
c_2(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m"),
    ?line W = ?config(priv_dir, Config),
    ?line Result = c(R,[{outdir,W}]),
    ?line {ok, m} = Result.


%%% Put results in current directory (or rather, change current dir
%%% to the output dir):

c_3(doc) ->
    ["Checks that c:c works also with option 'outdir' (same as current"
     "directory). [ticket OTP-1209]."];
c_3(suite) ->
    [];
c_3(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m.erl"),
    ?line W = ?config(priv_dir, Config),
    ?line file:set_cwd(W),
    ?line Result = c(R,[{outdir,W}]),
    ?line {ok, m} = Result.

c_4(doc) ->
    ["Checks that c:c works also with option 'outdir' (same as current"
     "directory). [ticket OTP-1209]."];
c_4(suite) ->
    [];
c_4(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m"),
    ?line W = ?config(priv_dir, Config),
    ?line file:set_cwd(W),
    ?line Result = c(R,[{outdir,W}]),
    ?line {ok, m} = Result.

%%% Write output to a directory other than current directory:

nc_1(doc) ->
    ["Checks that c:nc works also with option 'outdir'."];
nc_1(suite) ->
    [];
nc_1(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m.erl"),
    ?line W = ?config(priv_dir, Config),
    ?line Result = nc(R,[{outdir,W}]),
    ?line {ok, m} = Result.

nc_2(doc) ->
    ["Checks that c:nc works also with option 'outdir'."];
nc_2(suite) ->
    [];
nc_2(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m"),
    ?line W = ?config(priv_dir, Config),
    ?line Result = nc(R,[{outdir,W}]),
    ?line {ok, m} = Result.


%%% Put results in current directory (or rather, change current dir
%%% to the output dir):

nc_3(doc) ->
    ["Checks that c:nc works also with option 'outdir' (same as current"
     "directory)."];
nc_3(suite) ->
    [];
nc_3(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m.erl"),
    ?line W = ?config(priv_dir, Config),
    ?line file:set_cwd(W),
    ?line Result = nc(R,[{outdir,W}]),
    ?line {ok, m} = Result.

nc_4(doc) ->
    ["Checks that c:nc works also with option 'outdir' (same as current"
     "directory)."];
nc_4(suite) ->
    [];
nc_4(Config) when is_list(Config) ->
    ?line R = filename:join(?config(data_dir, Config), "m"),
    ?line W = ?config(priv_dir, Config),
    ?line file:set_cwd(W),
    ?line Result = nc(R,[{outdir,W}]),
    ?line {ok, m} = Result.

ls(Config) when is_list(Config) ->
    Directory = ?config(data_dir, Config),
    ok = c:ls(Directory),
    File = filename:join(Directory, "m.erl"),
    ok = c:ls(File),
    ok = c:ls("no_such_file").

memory(doc) ->
    ["Checks that c:memory/[0,1] returns consistent results."];
memory(suite) ->
    [];
memory(Config) when is_list(Config) ->
    try
	?line ML = c:memory(),
	?line T =  mget(total, ML),
	?line P =  mget(processes, ML),
	?line S =  mget(system, ML),
	?line A =  mget(atom, ML),
	?line AU = mget(atom_used, ML),
	?line B =  mget(binary, ML),
	?line C =  mget(code, ML),
	?line E =  mget(ets, ML),
	?line T = P + S,
	?line if S >= A + B + C + E -> ok end,
	?line if A >= AU -> ok end,
	?line ok
    catch
	error:notsup ->
	    ?line {skipped,
		   "erlang:memory/[0,1] and c:memory/[0,1] not supported"}
    end.

% Help function for c_SUITE:memory/1    
mget(K, L) ->
    ?line {value,{K,V}} = lists:keysearch(K, 1, L),
    ?line test_v(c:memory(K)), % Check that c:memory/1 also accept this
                               % argument and returns an integer (usally
                               % *not* the same as V).
    ?line test_v(V).

% Help function for c_SUITE:memory/1    
test_v(V) when is_integer(V) ->
    ?line V.