4
%% Copyright Ericsson AB 1998-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
22
-include_lib("test_server/include/test_server.hrl").
24
%% Test server specific exports
25
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
26
init_per_group/2,end_per_group/2]).
27
-export([init_per_testcase/2, end_per_testcase/2]).
30
-export([interpret/1, guards/1, interpretable/1]).
31
-export([ append_1/1, append_2/1, member/1, reverse/1]).
33
%% Default timetrap timeout (set in init_per_testcase)
34
-define(default_timeout, ?t:minutes(1)).
36
init_per_testcase(interpretable, Config) ->
37
?line Dog=test_server:timetrap(?default_timeout),
38
[{watchdog, Dog}|Config];
39
init_per_testcase(_Case, Config) ->
41
%% Interpret some existing and non-existing modules
42
?line DataDir = ?config(data_dir, Config),
43
?line {module, lists1} = int:i(filename:join([DataDir,lists1])),
44
?line {module, guards} = int:i(filename:join([DataDir,guards])),
46
?line Dog=test_server:timetrap(?default_timeout),
47
[{watchdog, Dog}|Config].
49
end_per_testcase(interpretable, Config) ->
50
?line Dog=?config(watchdog, Config),
51
?line test_server:timetrap_cancel(Dog),
53
end_per_testcase(_Case, Config) ->
56
?line ok = int:n(lists1),
57
?line ok = int:n(guards),
59
?line Dog=?config(watchdog, Config),
60
?line test_server:timetrap_cancel(Dog),
63
suite() -> [{ct_hooks,[ts_install_cth]}].
66
[interpret, guards, {group, list_suite}, interpretable].
69
[{list_suite, [], [{group, append}, reverse, member]},
70
{append, [], [append_1, append_2]}].
72
init_per_suite(Config) ->
75
end_per_suite(_Config) ->
78
init_per_group(_GroupName, Config) ->
81
end_per_group(_GroupName, Config) ->
88
["Interpreting modules"];
89
interpret(Config) when is_list(Config) ->
90
?line int:n(int:interpreted()),
92
%% Interpret some existing and non-existing modules
93
?line DataDir = ?config(data_dir, Config),
94
?line {module, lists1} = int:i(filename:join([DataDir,lists1])),
95
?line {module, ordsets1} = int:i(filename:join([DataDir,ordsets1])),
96
?line error = int:i(non_existent_module),
98
%% Check that the interpreter has the right view.
99
?line ExpectedResult = lists:sort([lists1, ordsets1]),
100
?line Result = int:interpreted(),
101
?line ExpectedResult = lists:sort(Result),
103
%% Uniterpret the modules.
104
?line ok = int:n(non_existent_module),
105
?line ok = int:n(lists1),
106
?line [ordsets1] = int:interpreted(),
107
?line ok = int:n("ordsets1"),
108
?line [] = int:interpreted(),
116
guards(Config) when is_list(Config) ->
117
ok = guards:guards().
126
append_1(Config) when is_list(Config) ->
127
?line test_server:format("In append_1~n"),
128
?line test_server:format("code:which(lists1)=~p~n",
129
[code:which(lists1)]),
130
?line test_server:format("lists1:append([a],[b])=~p~n",
131
[spawn_eval(lists1,append,[[a],[b]])]),
133
?line "abcdef"=spawn_eval(lists1,append,[["abc","def"]]),
134
?line [hej, du,[glade, [bagare]]]=
135
spawn_eval(lists1,append,[[[hej], [du], [[glade, [bagare]]]]]),
136
?line [10, [elem]]=spawn_eval(lists1,append,[[[10], [[elem]]]]),
143
append_2(Config) when is_list(Config) ->
144
?line test_server:format("In append_2~n"),
145
?line test_server:format("code:which(lists1)=~p~n",
146
[code:which(lists1)]),
148
?line "abcdef"=spawn_eval(lists1,append,["abc", "def"]),
149
?line [hej, du]=spawn_eval(lists1,append,[[hej], [du]]),
150
?line [10, [elem]]=spawn_eval(lists1,append,[[10], [[elem]]]),
157
reverse(Config) when is_list(Config) ->
158
?line ok=reverse_test(0),
159
?line ok=reverse_test(1),
160
?line ok=reverse_test(2),
161
?line ok=reverse_test(537),
165
case spawn_eval(lists1,reverse,[[]]) of
172
List=spawn_eval(lists1,reverse,
173
[['The Element'|lists1:duplicate(Num, 'Ele')]]),
174
case spawn_eval(lists1,reverse,[List]) of
175
['The Element'|_Rest] ->
184
["Tests the lists1:member() implementation. The function "
185
"is `non-blocking', and only processes 2000 elements "
187
"This test case depends on lists1:reverse() to work, "
188
"wich is tested in a separate test case."];
189
member(Config) when list(Config) ->
190
?line ok=member_test(0),
191
?line ok=member_test(1),
192
?line ok=member_test(100),
193
?line ok=member_test(537),
197
case spawn_eval(lists1,member,['The Element', []]) of
201
{error, 'Found (!?)'}
204
List=spawn_eval(lists1,reverse,
205
[['The Element'|spawn_eval(lists1,duplicate,
207
case spawn_eval(lists1,member,['The Element', List]) of
216
spawn(fun() -> evaluator(Self, M,F,A) end),
222
evaluator(Pid, M,F,A) ->
223
Pid ! (catch apply(M,F,A)).
225
interpretable(suite) ->
227
interpretable(doc) ->
228
["Test int:interpretable/1"];
229
interpretable(Config) when is_list(Config) ->
231
%% First make sure that 'lists1' is not loaded
232
case code:is_loaded(lists1) of
234
?line code:purge(lists1),
235
?line code:delete(lists1),
236
?line code:purge(lists1);
241
?line DataDir = filename:dirname(?config(data_dir, Config)),
242
?line true = code:add_patha(DataDir),
243
?line true = int:interpretable(lists1),
244
?line true = int:interpretable(filename:join([DataDir,lists1])),
245
?line true = code:del_path(DataDir),
248
?line PrivDir = filename:join(?config(priv_dir, Config), ""),
249
?line {ok, _} = file:copy(filename:join([DataDir,"lists1.beam"]),
250
filename:join([PrivDir,"lists1.beam"])),
251
?line true = code:add_patha(PrivDir),
253
?line {error, no_src} = int:interpretable(lists1),
254
?line ok = file:delete(filename:join([PrivDir,"lists1.beam"])),
257
Src = filename:join([PrivDir,"lists1.erl"]),
258
?line {ok, _} = file:copy(filename:join([DataDir,"lists1.erl"]),
260
?line {error, no_beam} = int:interpretable(Src),
262
%% {error, no_debug_info}
263
?line {ok, _} = compile:file(Src, [{outdir,PrivDir}]),
264
?line {error, no_debug_info} = int:interpretable(Src),
265
?line {error, no_debug_info} = int:interpretable(lists1),
266
?line ok = file:delete(Src),
267
?line true = code:del_path(PrivDir),
270
?line {error, badarg} = int:interpretable(pride),
271
?line {error, badarg} = int:interpretable("prejudice.erl"),
273
%% {error, {app,App}}
274
?line {error, {app,_}} = int:interpretable(file),
275
?line {error, {app,_}} = int:interpretable(lists),
276
?line {error, {app,_}} = int:interpretable(gs),
277
?line case int:interpretable(dbg_ieval) of
281
case code:which(dbg_ieval) of
285
?line ?t:fail({unexpected_result, Other1})
288
?line ?t:fail({unexpected_result, Other2})