From cc553264b4a6e06377b34c06858f75f3a17319de Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 19 Dec 2018 13:04:28 +0100 Subject: [socket-nif] Fixed OpenBSD config The macro (define) IPTOS_MINCOST does not exist on OpenBSD 6.3. OTP-14831 --- erts/emulator/nifs/common/socket_nif.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'erts') diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 80903c487f..6dcd4ae623 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -15198,9 +15198,11 @@ char* encode_cmsghdr_data_ip(ErlNifEnv* env, case IPTOS_RELIABILITY: *eCMsgHdrData = esock_atom_reliability; break; +#if defined(IPTOS_MINCOST) case IPTOS_MINCOST: *eCMsgHdrData = esock_atom_mincost; break; +#endif default: *eCMsgHdrData = MKUI(env, tos); break; @@ -15467,9 +15469,11 @@ BOOLEAN_T decode_ip_tos(ErlNifEnv* env, ERL_NIF_TERM eVal, int* val) } else if (COMPARE(eVal, esock_atom_reliability) == 0) { *val = IPTOS_RELIABILITY; result = TRUE; +#if defined(IPTOS_MINCOST) } else if (COMPARE(eVal, esock_atom_mincost) == 0) { *val = IPTOS_MINCOST; result = TRUE; +#endif } else { *val = -1; result = FALSE; @@ -15781,9 +15785,11 @@ ERL_NIF_TERM encode_ip_tos(ErlNifEnv* env, int val) result = esock_make_ok2(env, esock_atom_reliability); break; +#if defined(IPTOS_MINCOST) case IPTOS_MINCOST: result = esock_make_ok2(env, esock_atom_mincost); break; +#endif default: result = esock_make_ok2(env, MKI(env, val)); -- cgit v1.2.3 From ff3ce49e25ea150c0637bcb584cffdd88e560e5b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 19 Dec 2018 18:06:03 +0100 Subject: [socket-nif|test] Updated test case api_b_open_and_close The test case tried to validate the (socket option) protocol, which is not actually available on OpenBSD. So, add a check if the option is supported. OTP-14831 --- erts/emulator/test/socket_SUITE.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'erts') diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index 9ad15f06dc..f77eb5502c 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -1444,11 +1444,20 @@ api_b_open_and_close(InitState) -> end}, #{desc => "get protocol", cmd => fun(#{socket := Sock} = State) -> - Res = socket:getopt(Sock, socket, protocol), - {ok, {State, Res}} + case socket:supports(options, socket, protocol) of + true -> + Res = socket:getopt(Sock, socket, protocol), + {ok, {State, Res}}; + false -> + {ok, {State, not_supported}} + end end}, #{desc => "validate protocol", - cmd => fun({#{protocol := Protocol} = State, {ok, Protocol}}) -> + cmd => fun({State, not_supported}) -> + ?SEV_IPRINT("socket option 'protocol' " + "not supported"), + {ok, State}; + ({#{protocol := Protocol} = State, {ok, Protocol}}) -> {ok, State}; ({#{protocol := ExpProtocol}, {ok, Protocol}}) -> {error, {unexpected_type, ExpProtocol, Protocol}}; -- cgit v1.2.3 From 5cb57ba153b9febfca17f90166791e104262615e Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 21 Dec 2018 12:16:44 +0100 Subject: [socket-nif|test] Buffer set and adjusted traffic ping-pong iterations Handle (rcv and snd) buffer set failure. The number of iterations (message exchanges) that the traffic ping-cases has been adjusted down (by a factor of 10). Also, improve skip'ing. OTP-14831 --- erts/emulator/test/socket_SUITE.erl | 54 ++++++++++++++++++++++------ erts/emulator/test/socket_test_evaluator.erl | 14 ++++++-- 2 files changed, 56 insertions(+), 12 deletions(-) (limited to 'erts') diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index f77eb5502c..3adda52e1e 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -18,7 +18,14 @@ %% %CopyrightEnd% %% +%% Run the entire test suite: %% ts:run(emulator, socket_SUITE, [batch]). +%% +%% Run a specific group: +%% ts:run(emulator, socket_SUITE, {group, foo}, [batch]). +%% +%% Run a specific test case: +%% ts:run(emulator, socket_SUITE, foo, [batch]). -module(socket_SUITE). @@ -433,9 +440,9 @@ -define(TPP_MEDIUM, lists:flatten(lists:duplicate(1024, ?TPP_SMALL))). -define(TPP_LARGE, lists:flatten(lists:duplicate(1024, ?TPP_MEDIUM))). --define(TPP_SMALL_NUM, 100000). --define(TPP_MEDIUM_NUM, 100000). --define(TPP_LARGE_NUM, 1000). +-define(TPP_SMALL_NUM, 10000). +-define(TPP_MEDIUM_NUM, 1000). +-define(TPP_LARGE_NUM, 100). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -2736,6 +2743,7 @@ api_to_connect_tcp(InitState) -> end}, #{desc => "create node", cmd => fun(#{host := Host} = State) -> + ?SEV_IPRINT("try create node on ~p", [Host]), case start_node(Host, client) of {ok, Node} -> ?SEV_IPRINT("client node ~p started", @@ -9475,14 +9483,34 @@ traffic_ping_pong_sendmsg_and_recvmsg_tcp(InitState) -> traffic_ping_pong_send_and_receive_tcp(#{msg := Msg} = InitState) -> Fun = fun(Sock) -> {ok, RcvSz} = socket:getopt(Sock, socket, rcvbuf), + ?SEV_IPRINT("RcvBuf is ~p (needs atleast ~p)", + [RcvSz, 16+size(Msg)]), if (RcvSz < size(Msg)) -> - ok = socket:setopt(Sock, socket, rcvbuf, 1024+size(Msg)); + case socket:setopt(Sock, + socket, rcvbuf, 1024+size(Msg)) of + ok -> + ok; + {error, enobufs} -> + skip({failed_change, rcvbuf}); + {error, Reason1} -> + ?FAIL({rcvbuf, Reason1}) + end; true -> ok end, {ok, SndSz} = socket:getopt(Sock, socket, sndbuf), + ?SEV_IPRINT("SndBuf is ~p (needs atleast ~p)", + [SndSz, 16+size(Msg)]), if (SndSz < size(Msg)) -> - ok = socket:setopt(Sock, socket, sndbuf, 1024+size(Msg)); + case socket:setopt(Sock, + socket, sndbuf, 1024+size(Msg)) of + ok -> + ok; + {error, enobufs} -> + skip({failed_change, sndbuf}); + {error, Reason2} -> + ?FAIL({sndbuf, Reason2}) + end; true -> ok end, @@ -9924,7 +9952,7 @@ traffic_ping_pong_send_and_receive_tcp2(InitState) -> Result2 = erlang:delete_element(1, Result), {ok, State#{server_result => Result2}}; {ok, BadResult} -> - ?SEV_EPRINT("bad sever result: " + ?SEV_EPRINT("bad server result: " "~n ~p", [BadResult]), {error, {invalid_server_result, BadResult}}; {error, _} = ERROR -> @@ -10166,10 +10194,10 @@ tpp_tcp_client_await_continue(Parent, Slogan) -> ?SEV_IPRINT("await continue (~p)", [Slogan]), case ?SEV_AWAIT_CONTINUE(Parent, parent, Slogan) of ok -> - %% ?SEV_IPRINT("continue (~p): ok", [Slogan]), + ?SEV_IPRINT("continue (~p): ok", [Slogan]), ok; {ok, Data} -> - %% ?SEV_IPRINT("continue (~p): ok with data", [Slogan]), + ?SEV_IPRINT("continue (~p): ok with data", [Slogan]), Data; {error, Reason} -> ?SEV_EPRINT("continue (~p): error" @@ -16526,7 +16554,11 @@ sock_close(Sock) -> local_host() -> try net_adm:localhost() of Host when is_list(Host) -> - list_to_atom(Host) + %% Convert to shortname if long + case string:tokens(Host, [$.]) of + [H|_] -> + list_to_atom(H) + end catch C:E:S -> erlang:raise(C, E, S) @@ -16546,7 +16578,9 @@ which_local_addr(Domain) -> which_addr(_Domain, []) -> ?FAIL(no_address); -which_addr(Domain, [{Name, IFO}|_IFL]) when (Name =/= "lo") -> +which_addr(Domain, [{"lo" ++ _, _}|IFL]) -> + which_addr(Domain, IFL); +which_addr(Domain, [{_Name, IFO}|_IFL]) -> which_addr2(Domain, IFO); which_addr(Domain, [_|IFL]) -> which_addr(Domain, IFL). diff --git a/erts/emulator/test/socket_test_evaluator.erl b/erts/emulator/test/socket_test_evaluator.erl index deea7e5d36..fe6a6ff70a 100644 --- a/erts/emulator/test/socket_test_evaluator.erl +++ b/erts/emulator/test/socket_test_evaluator.erl @@ -130,6 +130,10 @@ loop(ID, [#{desc := Desc, "~n Reason: ~p", [ID, Reason]), exit({command_failed, ID, Reason, State}) catch + throw:{skip, R} = E:_ -> + eprint("command ~w skip: " + "~n Skip Reason: ~p", [ID, R]), + exit(E); C:E:S -> eprint("command ~w crashed: " "~n Class: ~p" @@ -150,6 +154,8 @@ await_finish(Evs) -> await_finish([], []) -> ok; await_finish([], Fails) -> + ?SEV_EPRINT("Fails: " + "~n ~p", [Fails]), Fails; await_finish(Evs, Fails) -> receive @@ -443,8 +449,12 @@ await(ExpPid, Name, Announcement, Slogan, OtherPids) ok; {Announcement, Pid, Slogan, Extra} when (Pid =:= ExpPid) -> {ok, Extra}; + {'DOWN', _, process, Pid, {skip, SkipReason}} when (Pid =:= ExpPid) -> + iprint("Unexpected SKIP from ~w (~p): " + "~n ~p", [Name, Pid, SkipReason]), + ?LIB:skip({Name, SkipReason}); {'DOWN', _, process, Pid, Reason} when (Pid =:= ExpPid) -> - eprint("Unexpected DOWN regarding ~w ~p: " + eprint("Unexpected DOWN from ~w (~p): " "~n ~p", [Name, Pid, Reason]), {error, {unexpected_exit, Name}}; {'DOWN', _, process, OtherPid, Reason} -> @@ -476,7 +486,7 @@ pi(Pid, Item) -> check_down(Pid, DownReason, Pids) -> case lists:keymember(Pid, 1, Pids) of {value, {_, Name}} -> - eprint("Unexpected DOWN regarding ~w ~p: " + eprint("Unexpected DOWN from ~w (~p): " "~n ~p", [Name, Pid, DownReason]), {error, {unexpected_exit, Name}}; false -> -- cgit v1.2.3