diff options
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/test/socket_SUITE.erl | 163 |
1 files changed, 111 insertions, 52 deletions
diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index c83b3f0022..92dd5e7097 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -88,7 +88,11 @@ %% Internal exports %% -export([]). - +-record(ev, {name :: string(), + pid :: pid(), + mref :: reference()}). +-type ev() :: #ev{}. +-define(MKEV(N,P,R), #ev{name = N, pid = P, mref = R}). -type initial_evaluator_state() :: map(). -type evaluator_state() :: term(). -type command_fun() :: @@ -109,6 +113,10 @@ -define(SLEEP(T), receive after T -> ok end). +-define(MINS(M), timer:minutes(M)). +-define(SECS(S), timer:seconds(S)). + +-define(TT(T), ct:timetrap(T)). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -164,6 +172,8 @@ api_op_with_timeout_cases() -> api_to_connect_tcp6, api_to_accept_tcp4, api_to_accept_tcp6, + api_to_maccept_tcp4, + api_to_maccept_tcp6, api_to_send_tcp4, api_to_send_tcp6, api_to_sendto_udp4, @@ -263,6 +273,7 @@ api_b_open_and_close_udp4(suite) -> api_b_open_and_close_udp4(doc) -> []; api_b_open_and_close_udp4(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), tc_try(api_b_open_and_close_udp4, fun() -> InitState = #{domain => inet, @@ -281,6 +292,7 @@ api_b_open_and_close_tcp4(suite) -> api_b_open_and_close_tcp4(doc) -> []; api_b_open_and_close_tcp4(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), tc_try(api_b_open_and_close_tcp4, fun() -> InitState = #{domain => inet, @@ -392,6 +404,7 @@ api_b_sendto_and_recvfrom_udp4(suite) -> api_b_sendto_and_recvfrom_udp4(doc) -> []; api_b_sendto_and_recvfrom_udp4(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), tc_try(api_b_sendto_and_recvfrom_udp4, fun() -> Send = fun(Sock, Data, Dest) -> @@ -416,6 +429,7 @@ api_b_sendmsg_and_recvmsg_udp4(suite) -> api_b_sendmsg_and_recvmsg_udp4(doc) -> []; api_b_sendmsg_and_recvmsg_udp4(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), tc_try(api_b_sendmsg_and_recvmsg_udp4, fun() -> Send = fun(Sock, Data, Dest) -> @@ -530,6 +544,7 @@ api_b_send_and_recv_tcp4(suite) -> api_b_send_and_recv_tcp4(doc) -> []; api_b_send_and_recv_tcp4(_Config) when is_list(_Config) -> + ?TT(?SECS(10)), tc_try(api_b_send_and_recv_tcp4, fun() -> Send = fun(Sock, Data) -> @@ -554,6 +569,7 @@ api_b_sendmsg_and_recvmsg_tcp4(suite) -> api_b_sendmsg_and_recvmsg_tcp4(doc) -> []; api_b_sendmsg_and_recvmsg_tcp4(_Config) when is_list(_Config) -> + ?TT(?SECS(10)), tc_try(api_b_sendmsg_and_recvmsg_tcp4, fun() -> Send = fun(Sock, Data) -> @@ -710,10 +726,10 @@ api_b_send_and_recv_tcp(InitState) -> ], i("start server evaluator"), - Server = evaluator_start("server", ServerSeq, InitState), - i("await server (~p) port", [Server]), + #ev{pid = Pid} = Server = evaluator_start("server", ServerSeq, InitState), + i("await server (~p) port", [Pid]), SPort = receive - {server_port, Server, Port} -> + {server_port, Pid, Port} -> Port end, i("start client evaluator"), @@ -739,6 +755,7 @@ api_opt_simple_otp_options(suite) -> api_opt_simple_otp_options(doc) -> []; api_opt_simple_otp_options(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), tc_try(api_opt_simple_otp_options, fun() -> api_opt_simple_otp_options() end). @@ -999,6 +1016,7 @@ api_opt_simple_otp_controlling_process(suite) -> api_opt_simple_otp_controlling_process(doc) -> []; api_opt_simple_otp_controlling_process(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), tc_try(api_opt_simple_otp_controlling_process, fun() -> api_opt_simple_otp_controlling_process() end). @@ -1220,22 +1238,24 @@ api_opt_simple_otp_controlling_process() -> i("start tcp (stream) socket"), ClientInitState1 = #{}, - Client1 = evaluator_start("tcp-client", ClientSeq, ClientInitState1), + #ev{pid = Pid1} = Client1 = evaluator_start("tcp-client", + ClientSeq, ClientInitState1), TesterInitState1 = #{domain => inet, type => stream, protocol => tcp, - client => Client1}, + client => Pid1}, Tester1 = evaluator_start("tcp-tester", TesterSeq, TesterInitState1), i("await tcp evaluator"), ok = await_evaluator_finish([Tester1, Client1]), i("start udp (dgram) socket"), ClientInitState2 = #{}, - Client2 = evaluator_start("udp-client", ClientSeq, ClientInitState2), + #ev{pid = Pid2} = Client2 = evaluator_start("udp-client", + ClientSeq, ClientInitState2), TesterInitState2 = #{domain => inet, type => dgram, protocol => udp, - client => Client2}, + client => Pid2}, Tester2 = evaluator_start("udp-tester", TesterSeq, TesterInitState2), i("await udp evaluator"), ok = await_evaluator_finish([Tester2, Client2]). @@ -1261,6 +1281,7 @@ api_to_connect_tcp4(doc) -> api_to_connect_tcp4(_Config) when is_list(_Config) -> tc_try(api_to_connect_tcp4, fun() -> + ?TT(?SECS(10)), InitState = #{domain => inet, timeout => 5000}, ok = api_to_connect_tcp(InitState) end). @@ -1278,6 +1299,7 @@ api_to_connect_tcp6(_Config) when is_list(_Config) -> tc_try(api_to_connect_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), InitState = #{domain => inet6, timeout => 5000}, ok = api_to_connect_tcp(InitState) end). @@ -1505,7 +1527,7 @@ api_to_connect_tcp(InitState) -> Server = evaluator_start("server", ServerSeq, ServerInitState), i("create tester evaluator"), - TesterInitState = InitState#{server => Server}, + TesterInitState = InitState#{server => Server#ev.pid}, Tester = evaluator_start("tester", TesterSeq, TesterInitState), i("await evaluator(s)"), @@ -1555,6 +1577,7 @@ api_to_accept_tcp4(doc) -> api_to_accept_tcp4(_Config) when is_list(_Config) -> tc_try(api_to_accept_tcp4, fun() -> + ?TT(?SECS(10)), InitState = #{domain => inet, timeout => 5000}, ok = api_to_accept_tcp(InitState) end). @@ -1572,6 +1595,7 @@ api_to_accept_tcp6(_Config) when is_list(_Config) -> tc_try(api_to_accept_tcp4, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), InitState = #{domain => inet6, timeout => 5000}, ok = api_to_accept_tcp(InitState) end). @@ -2073,23 +2097,26 @@ api_to_maccept_tcp(InitState) -> i("create prim-acceptor evaluator"), PrimAInitState = InitState, - PrimAcceptor = evaluator_start("prim-acceptor", - PrimAcceptorSeq, PrimAInitState), + #ev{pid = PPid} = PrimAcceptor = evaluator_start("prim-acceptor", + PrimAcceptorSeq, + PrimAInitState), i("create sec-acceptor 1 evaluator"), SecAInitState1 = maps:remove(domain, InitState), - SecAcceptor1 = evaluator_start("sec-acceptor-1", - SecAcceptorSeq, SecAInitState1), - + #ev{pid = SPid1} = SecAcceptor1 = evaluator_start("sec-acceptor-1", + SecAcceptorSeq, + SecAInitState1), + i("create sec-acceptor 2 evaluator"), SecAInitState2 = SecAInitState1, - SecAcceptor2 = evaluator_start("sec-acceptor-2", - SecAcceptorSeq, SecAInitState2), + #ev{pid = SPid2} = SecAcceptor2 = evaluator_start("sec-acceptor-2", + SecAcceptorSeq, + SecAInitState2), i("create tester evaluator"), - TesterInitState = #{prim_acceptor => PrimAcceptor, - sec_acceptor1 => SecAcceptor1, - sec_acceptor2 => SecAcceptor2}, + TesterInitState = #{prim_acceptor => PPid, + sec_acceptor1 => SPid1, + sec_acceptor2 => SPid2}, Tester = evaluator_start("tester", TesterSeq, TesterInitState), i("await evaluator(s)"), @@ -2238,6 +2265,7 @@ api_to_recv_tcp4(doc) -> api_to_recv_tcp4(_Config) when is_list(_Config) -> tc_try(api_to_recv_tcp4, fun() -> + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recv(Sock, 0, To) end, InitState = #{domain => inet, recv => Recv, @@ -2260,6 +2288,7 @@ api_to_recv_tcp6(_Config) when is_list(_Config) -> not_yet_implemented(), case socket:supports(ipv6) of true -> + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recv(Sock, 0, To) end, @@ -2630,14 +2659,18 @@ api_to_receive_tcp(InitState) -> i("start server evaluator"), ServerInitState = InitState, - Server = evaluator_start("server", ServerSeq, ServerInitState), + #ev{pid = SPid} = Server = evaluator_start("server", + ServerSeq, + ServerInitState), i("start client evaluator"), ClientInitState = InitState, - Client = evaluator_start("client", ClientSeq, ClientInitState), + #ev{pid = CPid} = Client = evaluator_start("client", + ClientSeq, + ClientInitState), i("start tester evaluator"), - TesterInitState = #{server => Server, client => Client}, + TesterInitState = #{server => SPid, client => CPid}, Tester = evaluator_start("tester", TesterSeq, TesterInitState), i("await evaluator(s)"), @@ -2656,6 +2689,7 @@ api_to_recvfrom_udp4(doc) -> api_to_recvfrom_udp4(_Config) when is_list(_Config) -> tc_try(api_to_recvfrom_udp4, fun() -> + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recvfrom(Sock, 0, To) end, InitState = #{domain => inet, recv => Recv, @@ -2676,6 +2710,7 @@ api_to_recvfrom_udp6(_Config) when is_list(_Config) -> tc_try(api_to_recvfrom_udp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recvfrom(Sock, 0, To) end, InitState = #{domain => inet6, recv => Recv, @@ -2772,6 +2807,7 @@ api_to_recvmsg_udp4(doc) -> api_to_recvmsg_udp4(_Config) when is_list(_Config) -> tc_try(api_to_recvmsg_udp4, fun() -> + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recvmsg(Sock, To) end, InitState = #{domain => inet, recv => Recv, @@ -2792,6 +2828,7 @@ api_to_recvmsg_udp6(_Config) when is_list(_Config) -> tc_try(api_to_recvmsg_udp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recvmsg(Sock, To) end, InitState = #{domain => inet6, recv => Recv, @@ -2811,6 +2848,7 @@ api_to_recvmsg_tcp4(doc) -> api_to_recvmsg_tcp4(_Config) when is_list(_Config) -> tc_try(api_to_recvmsg_tcp4, fun() -> + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recvmsg(Sock, To) end, InitState = #{domain => inet, recv => Recv, @@ -2831,6 +2869,7 @@ api_to_recvmsg_tcp6(_Config) when is_list(_Config) -> tc_try(api_to_recvmsg_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock, To) -> socket:recvmsg(Sock, To) end, InitState = #{domain => inet6, recv => Recv, @@ -2861,6 +2900,7 @@ sc_cpe_socket_cleanup_tcp4(_Config) when is_list(_Config) -> tc_try(sc_cpe_socket_cleanup_tcp4, fun() -> %% not_yet_implemented(), + ?TT(?SECS(5)), InitState = #{domain => inet, type => stream, protocol => tcp}, @@ -2881,6 +2921,7 @@ sc_cpe_socket_cleanup_tcp6(_Config) when is_list(_Config) -> tc_try(sc_cpe_socket_cleanup_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(5)), InitState = #{domain => inet6, type => stream, protocol => tcp}, @@ -2900,6 +2941,7 @@ sc_cpe_socket_cleanup_udp4(doc) -> sc_cpe_socket_cleanup_udp4(_Config) when is_list(_Config) -> tc_try(sc_cpe_socket_cleanup_udp4, fun() -> + ?TT(?SECS(5)), InitState = #{domain => inet, type => dgram, protocol => udp}, @@ -2921,6 +2963,7 @@ sc_cpe_socket_cleanup_udp6(_Config) when is_list(_Config) -> tc_try(sc_cpe_socket_cleanup_udp6, fun() -> not_yet_implemented(), + ?TT(?SECS(5)), InitState = #{domain => inet6, type => dgram, protocol => udp}, @@ -3058,10 +3101,10 @@ sc_cpe_socket_cleanup(InitState) -> ], i("start (socket) owner evaluator"), - Owner = evaluator_start("owner", OwnerSeq, InitState), + #ev{pid = Pid} = Owner = evaluator_start("owner", OwnerSeq, InitState), i("start tester evaluator"), - TesterInitState = #{owner => Owner}, + TesterInitState = #{owner => Pid}, Tester = evaluator_start("tester", TesterSeq, TesterInitState), i("await evaluator"), @@ -3088,7 +3131,7 @@ sc_lc_recv_response_tcp4(doc) -> sc_lc_recv_response_tcp4(_Config) when is_list(_Config) -> tc_try(sc_lc_recv_response_tcp4, fun() -> - %% not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recv(Sock) end, InitState = #{domain => inet, type => stream, @@ -3111,6 +3154,7 @@ sc_lc_recv_response_tcp6(_Config) when is_list(_Config) -> tc_try(sc_lc_recv_response_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recv(Sock) end, InitState = #{domain => inet6, type => stream, @@ -3646,20 +3690,26 @@ sc_lc_receive_response_tcp(InitState) -> i("start acceptor evaluator"), AccInitState = InitState, - Acceptor = evaluator_start("acceptor", AcceptorSeq, AccInitState), + #ev{pid = APid} = Acceptor = evaluator_start("acceptor", + AcceptorSeq, + AccInitState), i("start handler evaluator"), HandlerInitState = #{recv => maps:get(recv, InitState)}, - Handler = evaluator_start("handler", HandlerSeq, HandlerInitState), + #ev{pid = HPid} = Handler = evaluator_start("handler", + HandlerSeq, + HandlerInitState), i("start client evaluator"), ClientInitState = InitState, - Client = evaluator_start("client", ClientSeq, ClientInitState), + #ev{pid = CPid} = Client = evaluator_start("client", + ClientSeq, + ClientInitState), i("start tester evaluator"), - TesterInitState = #{acceptor => Acceptor, - handler => Handler, - client => Client}, + TesterInitState = #{acceptor => APid, + handler => HPid, + client => CPid}, Tester = evaluator_start("tester", TesterSeq, TesterInitState), i("await evaluator"), @@ -3680,6 +3730,7 @@ sc_rc_recv_response_tcp4(_Config) when is_list(_Config) -> tc_try(sc_rc_recv_response_tcp4, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recv(Sock) end, InitState = #{domain => inet, type => stream, @@ -3702,6 +3753,7 @@ sc_rc_recv_response_tcp6(_Config) when is_list(_Config) -> tc_try(sc_rc_recv_response_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recv(Sock) end, InitState = #{domain => inet6, type => stream, @@ -3730,6 +3782,7 @@ sc_lc_recvmsg_response_tcp4(doc) -> sc_lc_recvmsg_response_tcp4(_Config) when is_list(_Config) -> tc_try(sc_lc_recvmsg_response_tcp4, fun() -> + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recvmsg(Sock) end, InitState = #{domain => inet, type => stream, @@ -3752,6 +3805,7 @@ sc_lc_recvmsg_response_tcp6(_Config) when is_list(_Config) -> tc_try(sc_recvmsg_response_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recvmsg(Sock) end, InitState = #{domain => inet6, type => stream, @@ -3774,6 +3828,7 @@ sc_rc_recvmsg_response_tcp4(_Config) when is_list(_Config) -> tc_try(sc_rc_recvmsg_response_tcp4, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recvmsg(Sock) end, InitState = #{domain => inet, type => stream, @@ -3796,6 +3851,7 @@ sc_rc_recvmsg_response_tcp6(_Config) when is_list(_Config) -> tc_try(sc_rc_recvmsg_response_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), Recv = fun(Sock) -> socket:recvmsg(Sock) end, InitState = #{domain => inet6, type => stream, @@ -3820,6 +3876,7 @@ sc_lc_acceptor_response_tcp4(_Config) when is_list(_Config) -> tc_try(sc_lc_acceptor_response_tcp4, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), InitState = #{domain => inet, type => stream, protocol => tcp}, @@ -3842,6 +3899,7 @@ sc_lc_acceptor_response_tcp6(_Config) when is_list(_Config) -> tc_try(sc_lc_acceptor_response_tcp6, fun() -> not_yet_implemented(), + ?TT(?SECS(10)), InitState = #{domain => inet, type => stream, protocol => tcp}, @@ -3899,18 +3957,17 @@ which_addr2(Domain, [_|IFO]) -> %% will be used as exit reason. %% A successful command shall evaluate to ok | {ok, NewState} --spec evaluator_start(Name, Seq, Init) -> {Pid, MRef} when +-spec evaluator_start(Name, Seq, Init) -> ev() when Name :: string(), Seq :: [command()], - Init :: initial_evaluator_state(), - Pid :: pid(), - MRef :: reference(). + Init :: initial_evaluator_state(). evaluator_start(Name, Seq, Init) when is_list(Name) andalso is_list(Seq) andalso (Seq =/= []) -> Init2 = Init#{parent => self()}, - {Pid, _} = erlang:spawn_monitor(fun() -> evaluator_init(Name, Seq, Init2) end), - Pid. + {Pid, MRef} = erlang:spawn_monitor( + fun() -> evaluator_init(Name, Seq, Init2) end), + ?MKEV(Name, Pid, MRef). evaluator_init(Name, Seq, Init) -> put(sname, Name), @@ -3949,24 +4006,26 @@ await_evaluator_finish([], Fails) -> await_evaluator_finish(Evs, Fails) -> receive {'DOWN', _MRef, process, Pid, normal} -> - case lists:delete(Pid, Evs) of - Evs -> + case lists:keysearch(Pid, #ev.pid, Evs) of + {value, #ev{name = Name}} -> + i("evaluator '~s' (~p) success", [Name, Pid]), + NewEvs = lists:keydelete(Pid, #ev.pid, Evs), + await_evaluator_finish(NewEvs, Fails); + false -> i("unknown process ~p died (normal)", [Pid]), - await_evaluator_finish(Evs, Fails); - NewEvs -> - i("evaluator ~p success", [Pid]), - await_evaluator_finish(NewEvs, Fails) - end; + await_evaluator_finish(Evs, Fails) + end; {'DOWN', _MRef, process, Pid, Reason} -> - case lists:delete(Pid, Evs) of - Evs -> + case lists:keysearch(Pid, #ev.pid, Evs) of + {value, #ev{name = Name}} -> + i("evaluator '~s' (~p) failed", [Name, Pid]), + NewEvs = lists:keydelete(Pid, #ev.pid, Evs), + await_evaluator_finish(NewEvs, [{Pid, Reason}|Fails]); + false -> i("unknown process ~p died: " - "~n ~p", [Pid, Reason]), - await_evaluator_finish(Evs, Fails); - NewEvs -> - i("Evaluator ~p failed", [Pid]), - await_evaluator_finish(NewEvs, [{Pid, Reason}|Fails]) - end + "~n ~p", [Pid, Reason]), + await_evaluator_finish(Evs, Fails) + end end. |