summaryrefslogtreecommitdiff
path: root/erts/emulator/test/exception_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'erts/emulator/test/exception_SUITE.erl')
-rw-r--r--erts/emulator/test/exception_SUITE.erl120
1 files changed, 96 insertions, 24 deletions
diff --git a/erts/emulator/test/exception_SUITE.erl b/erts/emulator/test/exception_SUITE.erl
index 80fc35d2be..ea76a473f2 100644
--- a/erts/emulator/test/exception_SUITE.erl
+++ b/erts/emulator/test/exception_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2021. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2022. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
-module(exception_SUITE).
-export([all/0, suite/0,
+ init_per_testcase/2, end_per_testcase/2,
badmatch/1, pending_errors/1, nil_arith/1, top_of_stacktrace/1,
stacktrace/1, nested_stacktrace/1, raise/1, gunilla/1, per/1,
change_exception_class/1,
@@ -51,6 +52,11 @@ all() ->
error_3, error_info,
no_line_numbers, line_numbers].
+init_per_testcase(_TestCase, Config) ->
+ Config.
+end_per_testcase(_TestCase, Config) ->
+ erts_test_utils:ept_check_leaked_nodes(Config).
+
-define(try_match(E),
catch ?MODULE:bar(),
{'EXIT', {{badmatch, nomatch}, _}} = (catch E = id(nomatch))).
@@ -163,7 +169,7 @@ pending({Code,[{?MODULE,Func,Arity,Loc}|_]}, Func, Args, Code)
pending(Reason, _Function, _Args, _Code) ->
ct:fail({bad_exit_reason,Reason}).
-%% Test that doing arithmetics on [] gives a badarith EXIT and not a crash.
+%% Test that doing arithmetic on [] gives a badarith EXIT and not a crash.
nil_arith(Config) when is_list(Config) ->
ba_plus_minus_times([], []),
@@ -699,7 +705,7 @@ error_info(_Config) ->
end,
%% Pick up external pid and port.
- {ok, ExternalNode} = test_server:start_node(?FUNCTION_NAME, slave, []),
+ {ok, Peer, ExternalNode} = ?CT_PEER(),
ExternalPid = rpc:call(ExternalNode, erlang, whereis, [code_server]),
ExternalPort = hd(rpc:call(ExternalNode, erlang, ports, [])),
@@ -1028,7 +1034,21 @@ error_info(_Config) ->
{nif_error, 1},
{nif_error, 2},
{node, [abc]},
- {nodes, [abc]},
+ {nodes, [abc], [{1, ".*not a valid node type.*"}]},
+ {nodes, [[abc]], [{1, ".*not a list of.*"}]},
+ {nodes, [DeadProcess], [{1, ".*not a valid node type or list of valid node types.*"}]},
+ {nodes, [abc, 17], [{1, ".*not a valid node type.*"},{2, ".*not a map.*"}]},
+ {nodes, [hidden, 17], [{2, ".*not a map.*"}]},
+ {nodes, [hidden, #{ 17 => true }], [{2, ".*invalid options in map.*"}]},
+ {nodes, [hidden, #{ connection_id => 17 }], [{2, ".*invalid options in map.*"}]},
+ {nodes, [hidden, #{ node_type => 17 }], [{2, ".*invalid options in map.*"}]},
+ {nodes, [abc, #{}], [{1, ".*not a valid node type.*"}]},
+ {nodes, [DeadProcess,#{node_type=>true}], [{1, ".*not a valid node type or list of valid node types.*"}]},
+ {nodes, [visible, 17], [{2,".*not a map.*"}]},
+ {nodes, [visible, #{connection_id=>blapp}], [{2,".*invalid options in map.*"}]},
+ {nodes, [visible, 17], [{2,".*not a map.*"}]},
+ {nodes, [known, #{connection_id=>true,node_type=>true}], [no_fail]},
+ {nodes, [[this,connected], #{connection_id=>true,node_type=>true}], [no_fail]},
{phash, [any, -1]},
{phash, [any, not_integer]},
{phash2, [any], [no_fail]},
@@ -1314,7 +1334,7 @@ error_info(_Config) ->
try
do_error_info(L)
after
- test_server:stop_node(ExternalNode)
+ peer:stop(Peer)
end.
dead_process() ->
@@ -1443,11 +1463,23 @@ line_numbers(Config) when is_list(Config) ->
[{file,"fake_file.erl"},{line,3}]},
{?MODULE,line_numbers,1,_}|_]}} =
(catch line1(bad_tag, 0)),
- {'EXIT',{badarith,
- [{?MODULE,line1,2,
- [{file,"fake_file.erl"},{line,5}]},
- {?MODULE,line_numbers,1,_}|_]}} =
- (catch line1(a, not_an_integer)),
+
+ %% The stacktrace for operators such a '+' can vary depending on
+ %% whether the JIT is used or not.
+ case catch line1(a, not_an_integer) of
+ {'EXIT',{badarith,
+ [{erlang,'+',[not_an_integer,1],_},
+ {?MODULE,line1,2,
+ [{file,"fake_file.erl"},{line,5}]},
+ {?MODULE,line_numbers,1,_}|_]}} ->
+ ok;
+ {'EXIT',{badarith,
+ [{?MODULE,line1,2,
+ [{file,"fake_file.erl"},{line,5}]},
+ {?MODULE,line_numbers,1,_}|_]}} ->
+ ok
+ end,
+
{'EXIT',{{badmatch,{ok,1}},
[{?MODULE,line1,2,
[{file,"fake_file.erl"},{line,7}]},
@@ -1480,7 +1512,7 @@ line_numbers(Config) when is_list(Config) ->
<<0,0>> = build_binary1(16),
{'EXIT',{badarg,
[{?MODULE,build_binary1,1,
- [{file,"bit_syntax.erl"},{line,72503}]},
+ [{file,"bit_syntax.erl"},{line,72503},{error_info,_}]},
{?MODULE,line_numbers,1,
[{file,ModFile},{line,_}]}|_]}} =
(catch build_binary1(bad_size)),
@@ -1488,21 +1520,20 @@ line_numbers(Config) when is_list(Config) ->
<<7,1,2,3>> = build_binary2(8, <<1,2,3>>),
{'EXIT',{badarg,
[{?MODULE,build_binary2,2,
- [{file,"bit_syntax.erl"},{line,72507}]},
+ [{file,"bit_syntax.erl"},{line,72507},{error_info,_}]},
{?MODULE,line_numbers,1,
[{file,ModFile},{line,_}]}|_]}} =
(catch build_binary2(bad_size, <<>>)),
{'EXIT',{badarg,
- [{erlang,bit_size,[bad_binary],[{error_info,_}]},
- {?MODULE,build_binary2,2,
- [{file,"bit_syntax.erl"},{line,72507}]},
+ [{?MODULE,build_binary2,2,
+ [{file,"bit_syntax.erl"},{line,72507},{error_info,_}]},
{?MODULE,line_numbers,1,
[{file,ModFile},{line,_}]}|_]}} =
(catch build_binary2(8, bad_binary)),
<<"abc",357:16>> = build_binary3(<<"abc">>),
{'EXIT',{badarg,[{?MODULE,build_binary3,1,
- [{file,"bit_syntax.erl"},{line,72511}]},
+ [{file,"bit_syntax.erl"},{line,72511},{error_info,_}]},
{?MODULE,line_numbers,1,
[{file,ModFile},{line,_}]}|_]}} =
(catch build_binary3(no_binary)),
@@ -1531,14 +1562,29 @@ line_numbers(Config) when is_list(Config) ->
{?MODULE,line_numbers,1,_}|_]}} =
(catch applied_bif_2()),
- {'EXIT',{badarith,
- [{?MODULE,increment1,1,[{file,"increment.erl"},{line,45}]},
- {?MODULE,line_numbers,1,_}|_]}} =
- (catch increment1(x)),
- {'EXIT',{badarith,
- [{?MODULE,increment2,1,[{file,"increment.erl"},{line,48}]},
- {?MODULE,line_numbers,1,_}|_]}} =
- (catch increment2(x)),
+ case catch increment1(x) of
+ {'EXIT',{badarith,
+ [{erlang,'+',[x,1],_},
+ {?MODULE,increment1,1,[{file,"increment.erl"},{line,45}]},
+ {?MODULE,line_numbers,1,_}|_]}} ->
+ ok;
+ {'EXIT',{badarith,
+ [{?MODULE,increment1,1,[{file,"increment.erl"},{line,45}]},
+ {?MODULE,line_numbers,1,_}|_]}} ->
+ ok
+ end,
+
+ case catch increment2(x) of
+ {'EXIT',{badarith,
+ [{erlang,'+',[x,1],_},
+ {?MODULE,increment2,1,[{file,"increment.erl"},{line,48}]},
+ {?MODULE,line_numbers,1,_}|_]}} ->
+ ok;
+ {'EXIT',{badarith,
+ [{?MODULE,increment2,1,[{file,"increment.erl"},{line,48}]},
+ {?MODULE,line_numbers,1,_}|_]}} ->
+ ok
+ end,
{'EXIT',{{badmap,not_a_map},
[{?MODULE,update_map,1,[{file,"map.erl"},{line,3}]}|_]}} =
@@ -1563,6 +1609,21 @@ line_numbers(Config) when is_list(Config) ->
{?MODULE,line_numbers,1,_}|_]}} =
(catch crash_huge_line(gurka)),
+ {'EXIT',{{badrecord,[1,2,3]},
+ [{?MODULE,bad_record,1,[{file,"bad_records.erl"},{line,4}]}|_]}} =
+ catch bad_record([1,2,3]),
+
+ %% GH-5960: When an instruction raised an exception at the very end of the
+ %% instruction (e.g. badmatch), and was directly followed by a line
+ %% instruction, the exception was raised for the wrong line.
+ ok = ambiguous_line(0),
+ {'EXIT',{{badmatch,_},
+ [{?MODULE,ambiguous_line,1,[{file,"ambiguous_line.erl"},
+ {line,3}]}|_]}} = catch ambiguous_line(1),
+ {'EXIT',{{badmatch,_},
+ [{?MODULE,ambiguous_line,1,[{file,"ambiguous_line.erl"},
+ {line,4}]}|_]}} = catch ambiguous_line(2),
+
ok.
id(I) -> I.
@@ -1690,3 +1751,14 @@ foo() -> id(100).
crash_huge_line(_) -> %Line 100000002
erlang:error(crash). %Line 100000003
+
+-file("bad_records.erl", 1).
+-record(foobar, {a,b,c,d}). %Line 2.
+bad_record(R) -> %Line 3.
+ R#foobar.a. %Line 4.
+
+-file("ambiguous_line.erl", 1).
+ambiguous_line(A) -> %Line 2.
+ true = A =/= 1, %Line 3.
+ true = A =/= 2, %Line 4.
+ ok.