Skip to content

Commit

Permalink
tests: add tests for > 16 live x registers
Browse files Browse the repository at this point in the history
Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Feb 25, 2024
1 parent 31960dd commit 983544a
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/erlang_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ compile_erlang(test_atomvm_random)
compile_erlang(float_decode)
compile_erlang(test_utf8_atoms)

compile_erlang(twentyone_param_function)
compile_erlang(complex_list_match_xregs)
compile_erlang(twentyone_param_fun)

add_custom_target(erlang_test_modules DEPENDS
code_load_files

Expand Down Expand Up @@ -946,5 +950,10 @@ add_custom_target(erlang_test_modules DEPENDS
test_atomvm_random.beam

float_decode.beam

test_utf8_atoms.beam

twentyone_param_function.beam
complex_list_match_xregs.beam
twentyone_param_fun.beam
)
56 changes: 56 additions & 0 deletions tests/erlang_tests/complex_list_match_xregs.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
%
% This file is part of AtomVM.
%
% Copyright 2024 Davide Bettio <[email protected]>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(complex_list_match_xregs).
-export([start/0, test_a/1, list_a/0, list_b/0, list_c/0]).

start() ->
{ok, {"first", "list"}} = ?MODULE:test_a(?MODULE:list_a()),
{x, $o} = ?MODULE:test_a(?MODULE:list_b()),
ok_baz = ?MODULE:test_a(?MODULE:list_c()),
0.

test_a(["This", "is", _, _, _, _, _, "baz", "baar"]) ->
error_a;
test_a(["This", "is", _, _, "foo", _, _, "baz"]) ->
ok_baz;
test_a(["This", "is", "baz", _, _, _, _, "baz"]) ->
error_c;
test_a(["This", "is", "not" | _Tail]) ->
error_d;
test_a(["This", "is", _, N, _, W]) ->
{ok, {N, W}};
test_a(["This" | Tail]) ->
{foo, "This", Tail};
test_a([[$F, X, $o | Tail], Tail]) ->
{x, X};
test_a([[$F, Y, $o | _Tail1], _Tail2]) ->
{x, Y};
test_a(List) ->
{error, List}.

list_a() ->
["This", "is", "the", "first", "test", "list"].

list_b() ->
[[$F, $o, $o, "bar"], "bar"].

list_c() ->
["This", "is", "aaa", "bbb", "foo", "ccc", "ddd", "baz"].
80 changes: 80 additions & 0 deletions tests/erlang_tests/twentyone_param_fun.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
%
% This file is part of AtomVM.
%
% Copyright 2024 Davide Bettio <[email protected]>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(twentyone_param_fun).
-export([start/0, sum_mul/3, id/1, g/18]).

start() ->
{X, Fun} = ?MODULE:g(20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37),
Ref = erlang:make_ref(),
{A, Ref2} = Fun(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, Ref),
{B, Ref} = Fun(
1, 2, 3, 40, 50, 60, 70, 80, 90, 100, 110, 120, 13, 14, 15, 16, 17, 18, 19, X, Ref2
),
1337 - (A + B).

g(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, D, C11, C12, C13, C14, C15, C16, C17) when
is_integer(C17)
->
Fun =
(fun(
P1,
P2,
P3,
P4,
P5,
P6,
P7,
P8,
P9,
P10,
P11,
P12,
P13,
P14,
P15,
P16,
P17,
P18,
P19,
P20,
Ref
) when is_reference(Ref) ->
Sum =
?MODULE:sum_mul(P1 - C1, P2, 1) +
?MODULE:sum_mul(P3, P4 - C2, 2) +
?MODULE:sum_mul(P5 - C3, P6, 3) +
?MODULE:sum_mul(P5, P6 - C4, 4) +
?MODULE:sum_mul(P7 - C5, P8, 5) +
?MODULE:sum_mul(P9, P10 - C6, 6) +
?MODULE:sum_mul(P11 - C7, P12, 7) +
?MODULE:sum_mul(P13 - C9, P14 - C8, 8) +
?MODULE:sum_mul(P15 - C10, P16 - C11, 9) +
?MODULE:sum_mul(P17 - C13, P18 - C12, 10) +
?MODULE:sum_mul(P19 - C14, P20 - C15, 11) + C16 - C17,
{?MODULE:id(Sum), ?MODULE:id(Ref)}
end),
{D, Fun}.

sum_mul(A, B, C) ->
(A + B) * C.

id(X) ->
X.
58 changes: 58 additions & 0 deletions tests/erlang_tests/twentyone_param_function.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
%
% This file is part of AtomVM.
%
% Copyright 2024 Davide Bettio <[email protected]>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(twentyone_param_function).
-export([start/0, f/21, sum_mul/3, id/1, get_mf/0]).

start() ->
Ref = erlang:make_ref(),
{M, F} = ?MODULE:get_mf(),
{A, Ref2} = f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, Ref),
{B, Ref} = ?MODULE:f(
1, 2, 3, 40, 50, 60, 70, 80, 90, 100, 110, 120, 13, 14, 15, 16, 17, 18, 19, 20, Ref2
),
{C, Ref} = M:F(
-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, Ref
),
A + B + C - 7417.

f(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, Ref) ->
Sum =
?MODULE:sum_mul(P1, P2, 1) +
?MODULE:sum_mul(P3, P4, 2) +
?MODULE:sum_mul(P5, P6, 3) +
?MODULE:sum_mul(P5, P6, 4) +
?MODULE:sum_mul(P7, P8, 5) +
?MODULE:sum_mul(P9, P10, 6) +
?MODULE:sum_mul(P11, P12, 7) +
?MODULE:sum_mul(P13, P14, 8) +
?MODULE:sum_mul(P15, P16, 9) +
?MODULE:sum_mul(P17, P18, 10) +
?MODULE:sum_mul(P19, P20, 11),
{?MODULE:id(Sum), ?MODULE:id(Ref)}.

sum_mul(A, B, C) ->
(A + B) * C.

id(X) ->
X.

get_mf() ->
{?MODULE, f}.
6 changes: 6 additions & 0 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,13 @@ struct Test tests[] = {
#endif

TEST_CASE(float_decode),

TEST_CASE(test_utf8_atoms),

TEST_CASE(twentyone_param_function),
TEST_CASE(complex_list_match_xregs),
TEST_CASE(twentyone_param_fun),

// TEST CRASHES HERE: TEST_CASE(memlimit),

{ NULL, 0, false, false }
Expand Down

0 comments on commit 983544a

Please sign in to comment.