aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/test/ei_decode_encode_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erl_interface/test/ei_decode_encode_SUITE.erl')
-rw-r--r--lib/erl_interface/test/ei_decode_encode_SUITE.erl262
1 files changed, 115 insertions, 147 deletions
diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE.erl b/lib/erl_interface/test/ei_decode_encode_SUITE.erl
index 57d5031d9d..570a91e2da 100644
--- a/lib/erl_interface/test/ei_decode_encode_SUITE.erl
+++ b/lib/erl_interface/test/ei_decode_encode_SUITE.erl
@@ -24,34 +24,15 @@
-include_lib("common_test/include/ct.hrl").
-include("ei_decode_encode_SUITE_data/ei_decode_encode_test_cases.hrl").
--export(
- [
- all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
- init_per_group/2,end_per_group/2,
- test_ei_decode_encode/1
- ]).
+-export([all/0, suite/0,
+ test_ei_decode_encode/1]).
-suite() -> [{ct_hooks,[ts_install_cth]}].
+suite() ->
+ [{ct_hooks,[ts_install_cth]}].
all() ->
[test_ei_decode_encode].
-groups() ->
- [].
-
-init_per_suite(Config) ->
- Config.
-
-end_per_suite(_Config) ->
- ok.
-
-init_per_group(_GroupName, Config) ->
- Config.
-
-end_per_group(_GroupName, Config) ->
- Config.
-
-
%% ---------------------------------------------------------------------------
% NOTE: these types have no meaning on the C side so we pass them
@@ -60,20 +41,19 @@ end_per_group(_GroupName, Config) ->
%% ######################################################################## %%
-test_ei_decode_encode(suite) -> [];
test_ei_decode_encode(Config) when is_list(Config) ->
- ?line P = runner:start(?test_ei_decode_encode),
+ P = runner:start(?test_ei_decode_encode),
Fun = fun (X) -> {X,true} end,
Pid = self(),
Port = case os:type() of
- {win32,_} ->
- open_port({spawn,"sort"},[]);
- {unix, darwin} ->
- open_port({spawn,"/usr/bin/true"},[]);
- _ ->
- open_port({spawn,"/bin/true"},[])
- end,
+ {win32,_} ->
+ open_port({spawn,"sort"},[]);
+ {unix, darwin} ->
+ open_port({spawn,"/usr/bin/true"},[]);
+ _ ->
+ open_port({spawn,"/bin/true"},[])
+ end,
Ref = make_ref(),
Trace = {1,2,3,self(),4}, % FIXME how to construct?!
@@ -86,47 +66,46 @@ test_ei_decode_encode(Config) when is_list(Config) ->
BigLargeB = 1 bsl 11112 + BigSmallB,
BigLargeC = BigSmallA * BigSmallB * BigSmallC * BigSmallA,
- ?line send_rec(P, Fun),
- ?line send_rec(P, Pid),
- ?line send_rec(P, Port),
- ?line send_rec(P, Ref),
- ?line send_rec(P, Trace),
+ send_rec(P, Fun),
+ send_rec(P, Pid),
+ send_rec(P, Port),
+ send_rec(P, Ref),
+ send_rec(P, Trace),
% bigs
- ?line send_rec(P, BigSmallA),
- ?line send_rec(P, BigSmallB),
- ?line send_rec(P, BigSmallC),
-
- ?line send_rec(P, BigLargeA),
- ?line send_rec(P, BigLargeB),
- ?line send_rec(P, BigLargeC),
+ send_rec(P, BigSmallA),
+ send_rec(P, BigSmallB),
+ send_rec(P, BigSmallC),
+
+ send_rec(P, BigLargeA),
+ send_rec(P, BigLargeB),
+ send_rec(P, BigLargeC),
%% Test large node containers...
- ?line ThisNode = {node(), erlang:system_info(creation)},
- ?line TXPid = mk_pid(ThisNode, 32767, 8191),
- ?line TXPort = mk_port(ThisNode, 268435455),
- ?line TXRef = mk_ref(ThisNode, [262143, 4294967295, 4294967295]),
+ ThisNode = {node(), erlang:system_info(creation)},
+ TXPid = mk_pid(ThisNode, 32767, 8191),
+ TXPort = mk_port(ThisNode, 268435455),
+ TXRef = mk_ref(ThisNode, [262143, 4294967295, 4294967295]),
- ?line OtherNode = {gurka@sallad, 2},
- ?line OXPid = mk_pid(OtherNode, 32767, 8191),
- ?line OXPort = mk_port(OtherNode, 268435455),
- ?line OXRef = mk_ref(OtherNode, [262143, 4294967295, 4294967295]),
+ send_rec(P, TXPid),
+ send_rec(P, TXPort),
+ send_rec(P, TXRef),
- ?line send_rec(P, TXPid),
- ?line send_rec(P, TXPort),
- ?line send_rec(P, TXRef),
- ?line send_rec(P, OXPid),
- ?line send_rec(P, OXPort),
- ?line send_rec(P, OXRef),
+ [begin OtherNode = {gurka@sallad, Creation},
+ send_rec(P, mk_pid(OtherNode, 32767, 8191)),
+ send_rec(P, mk_port(OtherNode, 268435455)),
+ send_rec(P, mk_ref(OtherNode, [262143, 4294967295, 4294967295])),
+ void
+ end || Creation <- [1, 2, 3, 4, 16#adec0ded]],
%% Unicode atoms
[begin send_rec(P, Atom),
- send_rec(P, mk_pid({Atom,1}, 23434, 3434)),
- send_rec(P, mk_port({Atom,1}, 2343434)),
- send_rec(P, mk_ref({Atom,1}, [262143, 8723648, 24097245])),
- void
+ send_rec(P, mk_pid({Atom,1}, 23434, 3434)),
+ send_rec(P, mk_port({Atom,1}, 2343434)),
+ send_rec(P, mk_ref({Atom,1}, [262143, 8723648, 24097245])),
+ void
end || Atom <- unicode_atom_data()],
send_rec(P, {}),
@@ -137,7 +116,7 @@ test_ei_decode_encode(Config) when is_list(Config) ->
send_rec(P, #{key => value}),
send_rec(P, maps:put(Port, Ref, #{key => value, key2 => Pid})),
- ?line runner:recv_eot(P),
+ runner:recv_eot(P),
ok.
@@ -146,29 +125,27 @@ test_ei_decode_encode(Config) when is_list(Config) ->
% We read two packets for each test, the ei_decode_encode and ei_x_decode_encode version....
send_rec(P, Term) when is_port(P) ->
- %%?t:format("Testing: ~p~n", [Term]),
P ! {self(), {command, term_to_binary(Term)}},
{_B,Term} = get_buf_and_term(P).
-
get_buf_and_term(P) ->
B = get_binaries(P),
case B of
- <<131>> ->
- io:format("(got single magic, no content)\n",[]),
- {B,'$$magic$$'};
- <<131,_>> ->
- T = binary_to_term(B),
- io:format("~w\n~w\n(got magic)\n",[B,T]),
- {B,T};
- _ ->
- B1 = list_to_binary([131,B]), % No magic, add
- T = binary_to_term(B1),
- %io:format("~w\n~w\n(got no magic)\n",[B,T]),
- {B,T}
+ <<131>> ->
+ io:format("(got single magic, no content)\n",[]),
+ {B,'$$magic$$'};
+ <<131,_>> ->
+ T = binary_to_term(B),
+ io:format("~w\n~w\n(got magic)\n",[B,T]),
+ {B,T};
+ _ ->
+ B1 = list_to_binary([131,B]), % No magic, add
+ T = binary_to_term(B1),
+ %io:format("~w\n~w\n(got no magic)\n",[B,T]),
+ {B,T}
end.
-
+
get_binaries(P) ->
B1 = get_binary(P),
@@ -177,40 +154,17 @@ get_binaries(P) ->
get_binary(P) ->
case runner:get_term(P) of
- {bytes,L} ->
- B = list_to_binary(L),
- %%io:format("~w\n",[L]),
-% For strange reasons <<131>> show up as <>....
-% io:format("~w\n",[B]),
- B;
- Other ->
- Other
+ {bytes,L} ->
+ B = list_to_binary(L),
+ %%io:format("~w\n",[L]),
+ % For strange reasons <<131>> show up as <>....
+ % io:format("~w\n",[B]),
+ B;
+ Other ->
+ Other
end.
%%
-
-% We use our own get_term()
-
-get_term(P) ->
- case runner:get_term(P) of
- {bytes,[131]} ->
- io:format("(got single magic, no content)\n",[]),
- '$$magic$$';
- {bytes,[131,L]} ->
- B = list_to_binary(L),
- T = binary_to_term(B),
- io:format("~w\n~w\n(got magic)\n",[L,T]),
- T;
- {bytes,L} ->
- B = list_to_binary([131,L]),
- T = binary_to_term(B),
- io:format("~w\n~w\n(got no magic)\n",[L,T]),
- T;
- Other ->
- Other
- end.
-
-%%
%% Node container constructor functions
%%
@@ -221,6 +175,9 @@ get_term(P) ->
-define(PORT_EXT, 102).
-define(PID_EXT, 103).
-define(NEW_REFERENCE_EXT, 114).
+-define(NEW_PID_EXT, $X).
+-define(NEW_PORT_EXT, $Y).
+-define(NEWER_REFERENCE_EXT, $Z).
uint32_be(Uint) when is_integer(Uint), 0 =< Uint, Uint < 1 bsl 32 ->
[(Uint bsr 24) band 16#ff,
@@ -242,18 +199,22 @@ uint8(Uint) when is_integer(Uint), 0 =< Uint, Uint < 1 bsl 8 ->
uint8(Uint) ->
exit({badarg, uint8, [Uint]}).
+pid_tag(Creation) when Creation =< 3 -> ?PID_EXT;
+pid_tag(_Creation) -> ?NEW_PID_EXT.
+enc_creation(Creation) when Creation =< 3 -> uint8(Creation);
+enc_creation(Creation) -> uint32_be(Creation).
mk_pid({NodeName, Creation}, Number, Serial) when is_atom(NodeName) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_pid({NodeNameExt, Creation}, Number, Serial);
mk_pid({NodeNameExt, Creation}, Number, Serial) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PID_EXT,
- NodeNameExt,
- uint32_be(Number),
- uint32_be(Serial),
- uint8(Creation)])) of
+ pid_tag(Creation),
+ NodeNameExt,
+ uint32_be(Number),
+ uint32_be(Serial),
+ enc_creation(Creation)])) of
Pid when is_pid(Pid) ->
Pid;
{'EXIT', {badarg, _}} ->
@@ -262,15 +223,18 @@ mk_pid({NodeNameExt, Creation}, Number, Serial) ->
exit({unexpected_binary_to_term_result, Other})
end.
+port_tag(Creation) when Creation =< 3 -> ?PORT_EXT;
+port_tag(_Creation) -> ?NEW_PORT_EXT.
+
mk_port({NodeName, Creation}, Number) when is_atom(NodeName) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_port({NodeNameExt, Creation}, Number);
mk_port({NodeNameExt, Creation}, Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PORT_EXT,
+ port_tag(Creation),
NodeNameExt,
uint32_be(Number),
- uint8(Creation)])) of
+ enc_creation(Creation)])) of
Port when is_port(Port) ->
Port;
{'EXIT', {badarg, _}} ->
@@ -279,34 +243,38 @@ mk_port({NodeNameExt, Creation}, Number) ->
exit({unexpected_binary_to_term_result, Other})
end.
+ref_tag(Creation) when Creation =< 3 -> ?NEW_REFERENCE_EXT;
+ref_tag(_Creation) -> ?NEWER_REFERENCE_EXT.
+
mk_ref({NodeName, Creation}, Numbers) when is_atom(NodeName),
- is_integer(Creation),
- is_list(Numbers) ->
+ is_integer(Creation),
+ is_list(Numbers) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_ref({NodeNameExt, Creation}, Numbers);
mk_ref({NodeNameExt, Creation}, [Number]) when is_binary(NodeNameExt),
is_integer(Creation),
+ Creation =< 3,
is_integer(Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?REFERENCE_EXT,
- NodeNameExt,
- uint32_be(Number),
- uint8(Creation)])) of
- Ref when is_reference(Ref) ->
- Ref;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_ref, [{NodeNameExt, Creation}, [Number]]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ ?REFERENCE_EXT,
+ NodeNameExt,
+ uint32_be(Number),
+ uint8(Creation)])) of
+ Ref when is_reference(Ref) ->
+ Ref;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_ref, [{NodeNameExt, Creation}, [Number]]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end;
mk_ref({NodeNameExt, Creation}, Numbers) when is_binary(NodeNameExt),
- is_integer(Creation),
- is_list(Numbers) ->
+ is_integer(Creation),
+ is_list(Numbers) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?NEW_REFERENCE_EXT,
+ ref_tag(Creation),
uint16_be(length(Numbers)),
NodeNameExt,
- uint8(Creation),
+ enc_creation(Creation),
lists:map(fun (N) ->
uint32_be(N)
end,
@@ -333,10 +301,10 @@ unicode_atom_data() ->
uc_atup(lists:seq(65500, 65754)),
uc_atup(lists:seq(65500, 65563))
| lists:map(fun (N) ->
- Pow2 = (1 bsl N),
- uc_atup(lists:seq(Pow2 - 127, Pow2 + 127))
- end,
- lists:seq(7, 20))
+ Pow2 = (1 bsl N),
+ uc_atup(lists:seq(Pow2 - 127, Pow2 + 127))
+ end,
+ lists:seq(7, 20))
].
uc_atup(ATxt) ->
@@ -346,33 +314,33 @@ string_to_atom(String) ->
Utf8List = string_to_utf8_list(String),
Len = length(Utf8List),
TagLen = case Len < 256 of
- true -> [119, Len];
- false -> [118, Len bsr 8, Len band 16#ff]
- end,
+ true -> [119, Len];
+ false -> [118, Len bsr 8, Len band 16#ff]
+ end,
binary_to_term(list_to_binary([131, TagLen, Utf8List])).
string_to_utf8_list([]) ->
[];
string_to_utf8_list([CP|CPs]) when is_integer(CP),
- 0 =< CP,
- CP =< 16#7F ->
+ 0 =< CP,
+ CP =< 16#7F ->
[CP | string_to_utf8_list(CPs)];
string_to_utf8_list([CP|CPs]) when is_integer(CP),
- 16#80 =< CP,
- CP =< 16#7FF ->
+ 16#80 =< CP,
+ CP =< 16#7FF ->
[16#C0 bor (CP bsr 6),
16#80 bor (16#3F band CP)
| string_to_utf8_list(CPs)];
string_to_utf8_list([CP|CPs]) when is_integer(CP),
- 16#800 =< CP,
- CP =< 16#FFFF ->
+ 16#800 =< CP,
+ CP =< 16#FFFF ->
[16#E0 bor (CP bsr 12),
16#80 bor (16#3F band (CP bsr 6)),
16#80 bor (16#3F band CP)
| string_to_utf8_list(CPs)];
string_to_utf8_list([CP|CPs]) when is_integer(CP),
- 16#10000 =< CP,
- CP =< 16#10FFFF ->
+ 16#10000 =< CP,
+ CP =< 16#10FFFF ->
[16#F0 bor (CP bsr 18),
16#80 bor (16#3F band (CP bsr 12)),
16#80 bor (16#3F band (CP bsr 6)),