aboutsummaryrefslogtreecommitdiffstats
path: root/lib/debugger/test/line_number_SUITE.erl
blob: d1f56d3493dd57ab7699447ef5288779d25750da (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1999-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(line_number_SUITE).

-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
	 init_per_testcase/2,end_per_testcase/2,
	 init_per_suite/1,end_per_suite/1,
	 line_numbers/1]).
-export([crash/1]).

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

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

all() ->
    cases().

groups() ->
    [].

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.

cases() ->
    [line_numbers].

init_per_testcase(_Case, Config) ->
    test_lib:interpret(?MODULE),
    Dog = test_server:timetrap(?t:minutes(1)),
    [{watchdog,Dog}|Config].

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

init_per_suite(Config) when is_list(Config) ->
    ?line test_lib:interpret(?MODULE),
    ?line true = lists:member(?MODULE, int:interpreted()),
    Config.

end_per_suite(Config) when is_list(Config) ->
    ok.





%%
%% === Make sure that this is always line 70 ===
%%
line1(Tag, X) ->				%Line 72
    case Tag of					%Line 73
	a ->
	    Y = X + 1,				%Line 75
	    Res = id({ok,Y}),			%Line 76
	    ?MODULE:crash({ok,42} = Res);	%Line 77
	b ->
	    x = id(x),				%Line 79
	    ok					%Line 80
    end.					%Line 81

crash(_) ->					%Line 83
    erlang:error(crash).			%Line 84

close_calls(Where) ->				%Line 86
    put(where_to_crash, Where),			%Line 87
    try
	call1(),				%Line 89
	call2(),				%Line 90
	call3(),				%Line 91
	no_crash				%Line 92
    catch error:crash ->
	    erlang:get_stacktrace()		%Line 94
    end.					%Line 95

call1() ->					%Line 97
    maybe_crash(call1),				%Line 98
    ok.						%Line 99

call2() ->					%Line 101
    maybe_crash(call2),				%Line 102
    ok.						%Line 103

call3() ->					%Line 105
    maybe_crash(call3),				%Line 106
    ok.						%Line 107

maybe_crash(Name) ->				%Line 109
    case get(where_to_crash) of			%Line 110
	Name ->
	    erlang:error(crash);		%Line 112
	_ ->
	    ok					%Line 114
    end.					%Line 115

build_binary1(Size) ->				%Line 117
    id(42),					%Line 118
    <<0:Size>>.					%Line 119

build_binary2(Size, Bin) ->			%Line 121
    id(0),					%Line 122
    <<7:Size,Bin/binary>>.			%Line 123

do_call_abs(x, Arg) ->				%Line 125
    abs(Arg).					%Line 126

do_call_unsafe_bif(x, Arg) ->			%Line 128
    link(Arg).					%Line 129


line_numbers(Config) when is_list(Config) ->
    File = ?MODULE_STRING ++ ".erl",
    {'EXIT',{{case_clause,bad_tag},
	     [{?MODULE,line1,2,
	       [{file,File},{line,73}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch line1(bad_tag, 0)),
    {'EXIT',{badarith,
	     [{?MODULE,line1,2,
	       [{file,File},{line,75}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch line1(a, not_an_integer)),
    {'EXIT',{{badmatch,{ok,1}},
	     [{?MODULE,line1,2,
	       [{file,File},{line,77}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch line1(a, 0)),
    {'EXIT',{crash,
	     [{?MODULE,crash,1,
	       [{file,File},{line,84}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch line1(a, 41)),

    [{?MODULE,maybe_crash,1,[{file,File},{line,112}]},
     {?MODULE,call1,0,[{file,File},{line,98}]},
     {?MODULE,close_calls,1,[{file,File},{line,89}]},
     {?MODULE,line_numbers,1,[{file,File},{line,_}]}|_] =
	close_calls(call1),
    [{?MODULE,maybe_crash,1,[{file,File},{line,112}]},
     {?MODULE,call2,0,[{file,File},{line,102}]},
     {?MODULE,close_calls,1,[{file,File},{line,90}]},
     {?MODULE,line_numbers,1,[{file,File},{line,_}]}|_] =
	close_calls(call2),
    [{?MODULE,maybe_crash,1,[{file,File},{line,112}]},
     {?MODULE,call3,0,[{file,File},{line,106}]},
     {?MODULE,close_calls,1,[{file,File},{line,91}]},
     {?MODULE,line_numbers,1,[{file,File},{line,_}]}|_] =
	close_calls(call3),
    no_crash = close_calls(other),

    <<0,0>> = build_binary1(16),
    {'EXIT',{badarg,
	     [{?MODULE,build_binary1,1,
	       [{file,File},{line,119}]},
	      {?MODULE,line_numbers,1,
	       [{file,ModFile},{line,_}]}|_]}} =
	(catch build_binary1(bad_size)),

    <<7,1,2,3>> = build_binary2(8, <<1,2,3>>),
    {'EXIT',{badarg,
	     [{?MODULE,build_binary2,2,
	       [{file,File},{line,123}]},
	      {?MODULE,line_numbers,1,
	       [{file,ModFile},{line,_}]}|_]}} =
	(catch build_binary2(bad_size, <<>>)),
    {'EXIT',{badarg,
	     [%% Beam has an extra here:
	      %%   {erlang,bit_size,[bad_binary],[]}
	      %% Since this is an artifact of the implementation,
	      %% we don't attempt to mimic it in the debugger.
	      {?MODULE,build_binary2,2,
	       [{file,File},{line,123}]},
	      {?MODULE,line_numbers,1,
	       [{file,ModFile},{line,_}]}|_]}} =
	(catch build_binary2(8, bad_binary)),

    {'EXIT',{function_clause,
	     [{?MODULE,do_call_abs,[y,y],
	       [{file,File},{line,125}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch do_call_abs(y, y)),
    {'EXIT',{badarg,
	     [{erlang,abs,[[]],[]},
	      {?MODULE,do_call_abs,2,
	       [{file,File},{line,126}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch do_call_abs(x, [])),

    {'EXIT',{badarg,
	     [{erlang,link,[[]],[]},
	      {?MODULE,do_call_unsafe_bif,2,
	       [{file,File},{line,129}]},
	      {?MODULE,line_numbers,1,_}|_]}} =
	(catch do_call_unsafe_bif(x, [])),

    ok.

id(I) ->
    I.