diff options
author | Sverker Eriksson <[email protected]> | 2015-11-13 16:50:33 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2016-04-07 18:41:47 +0200 |
commit | 9c80b9ec06fc0ca89dcc8d797a2dbc408a162098 (patch) | |
tree | 00920702806a31febc140ebca3850622a93836ff /lib/erl_interface/test | |
parent | bf0bf9cf009fa8ccc7fc364fdbbdeb6f491efe43 (diff) | |
download | otp-9c80b9ec06fc0ca89dcc8d797a2dbc408a162098.tar.gz otp-9c80b9ec06fc0ca89dcc8d797a2dbc408a162098.tar.bz2 otp-9c80b9ec06fc0ca89dcc8d797a2dbc408a162098.zip |
erl_interface: Support 32-bit creation for pid,port,refs
Diffstat (limited to 'lib/erl_interface/test')
4 files changed, 74 insertions, 56 deletions
diff --git a/lib/erl_interface/test/all_SUITE_data/ei_runner.c b/lib/erl_interface/test/all_SUITE_data/ei_runner.c index 2b0d6c856a..e9b4b2de57 100644 --- a/lib/erl_interface/test/all_SUITE_data/ei_runner.c +++ b/lib/erl_interface/test/all_SUITE_data/ei_runner.c @@ -255,12 +255,17 @@ do_report(file, line, ok) * Erlang side. */ -void do_fail(char* file, int line, char* reason) +void do_fail(const char* file, int line, const char* reason, ...) { + va_list ap; char sbuf[2048]; + char* sp = sbuf; - sbuf[0] = 'f'; - sprintf(sbuf+1, "%s, line %d: %s", file, line, reason); + *sp++ = 'f'; + sp += sprintf(sp, "%s, line %d: ", file, line); + va_start(ap, reason); + sp += vsprintf(sp, reason, ap); + va_end(ap); reply(sbuf, 1+strlen(sbuf+1)); } diff --git a/lib/erl_interface/test/all_SUITE_data/ei_runner.h b/lib/erl_interface/test/all_SUITE_data/ei_runner.h index 62997d00a0..ca01a1d3ed 100644 --- a/lib/erl_interface/test/all_SUITE_data/ei_runner.h +++ b/lib/erl_interface/test/all_SUITE_data/ei_runner.h @@ -52,10 +52,11 @@ void free_packet(char*); */ #define fail(reason) do_fail(__FILE__, __LINE__, reason) +#define fail1(reason, a1) do_fail(__FILE__, __LINE__, reason, a1) #define report(ok) do_report(__FILE__, __LINE__, ok) void do_report(char* file, int line, int ok); -void do_fail(char* file, int line, char* reason); +void do_fail(const char* file, int line, const char* reason, ...); void send_buffer(char* buf, int size); void message(char* format, ...); diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE.erl b/lib/erl_interface/test/ei_decode_encode_SUITE.erl index a3d0ca0576..14aee76500 100644 --- a/lib/erl_interface/test/ei_decode_encode_SUITE.erl +++ b/lib/erl_interface/test/ei_decode_encode_SUITE.erl @@ -89,17 +89,16 @@ test_ei_decode_encode(Config) when is_list(Config) -> TXPort = mk_port(ThisNode, 268435455), TXRef = mk_ref(ThisNode, [262143, 4294967295, 4294967295]), - OtherNode = {gurka@sallad, 2}, - OXPid = mk_pid(OtherNode, 32767, 8191), - OXPort = mk_port(OtherNode, 268435455), - OXRef = mk_ref(OtherNode, [262143, 4294967295, 4294967295]), - send_rec(P, TXPid), send_rec(P, TXPort), send_rec(P, TXRef), - send_rec(P, OXPid), - send_rec(P, OXPort), - 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), @@ -176,6 +175,9 @@ get_binary(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, @@ -197,51 +199,62 @@ 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 when is_pid(Pid) -> - Pid; - {'EXIT', {badarg, _}} -> - exit({badarg, mk_pid, [{NodeNameExt, Creation}, Number, Serial]}); - Other -> - exit({unexpected_binary_to_term_result, Other}) + pid_tag(Creation), + NodeNameExt, + uint32_be(Number), + uint32_be(Serial), + enc_creation(Creation)])) of + Pid when is_pid(Pid) -> + Pid; + {'EXIT', {badarg, _}} -> + exit({badarg, mk_pid, [{NodeNameExt, Creation}, Number, Serial]}); + Other -> + 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, - NodeNameExt, - uint32_be(Number), - uint8(Creation)])) of - Port when is_port(Port) -> - Port; - {'EXIT', {badarg, _}} -> - exit({badarg, mk_port, [{NodeNameExt, Creation}, Number]}); - Other -> - exit({unexpected_binary_to_term_result, Other}) + port_tag(Creation), + NodeNameExt, + uint32_be(Number), + enc_creation(Creation)])) of + Port when is_port(Port) -> + Port; + {'EXIT', {badarg, _}} -> + exit({badarg, mk_port, [{NodeNameExt, Creation}, Number]}); + Other -> + 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) -> <<?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), - is_integer(Number) -> + is_integer(Creation), + Creation =< 3, + is_integer(Number) -> case catch binary_to_term(list_to_binary([?VERSION_MAGIC, ?REFERENCE_EXT, NodeNameExt, @@ -258,20 +271,20 @@ mk_ref({NodeNameExt, Creation}, Numbers) when is_binary(NodeNameExt), is_integer(Creation), is_list(Numbers) -> case catch binary_to_term(list_to_binary([?VERSION_MAGIC, - ?NEW_REFERENCE_EXT, - uint16_be(length(Numbers)), - NodeNameExt, - uint8(Creation), - lists:map(fun (N) -> - uint32_be(N) - end, - Numbers)])) of - Ref when is_reference(Ref) -> - Ref; - {'EXIT', {badarg, _}} -> - exit({badarg, mk_ref, [{NodeNameExt, Creation}, Numbers]}); - Other -> - exit({unexpected_binary_to_term_result, Other}) + ref_tag(Creation), + uint16_be(length(Numbers)), + NodeNameExt, + enc_creation(Creation), + lists:map(fun (N) -> + uint32_be(N) + end, + Numbers)])) of + Ref when is_reference(Ref) -> + Ref; + {'EXIT', {badarg, _}} -> + exit({badarg, mk_ref, [{NodeNameExt, Creation}, Numbers]}); + Other -> + exit({unexpected_binary_to_term_result, Other}) end. diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c index 4b0201ca0b..58b2dc1671 100644 --- a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c +++ b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c @@ -240,7 +240,7 @@ void decode_encode(struct Type** tv, int nobj) if (err != -1) { fail("decode returned non zero but not -1"); } else { - fail("decode returned non zero"); + fail1("decode '%s' returned non zero", t->name); } return; } @@ -491,12 +491,11 @@ TESTCASE(test_ei_decode_encode) decode_encode_big(&big_type); /* Test large node containers... */ - decode_encode_one(&pid_type); - decode_encode_one(&port_type); - decode_encode_one(&ref_type); - decode_encode_one(&pid_type); - decode_encode_one(&port_type); - decode_encode_one(&ref_type); + for (i=0; i<6; i++) { + decode_encode_one(&pid_type); + decode_encode_one(&port_type); + decode_encode_one(&ref_type); + } /* Unicode atoms */ for (i=0; i<24; i++) { |