Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:26
erlang
0252-esock-test-Add-simple-test-case.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0252-esock-test-Add-simple-test-case.patch of Package erlang
From 7327a3462c826487040824caf88f2d99f7da1b09 Mon Sep 17 00:00:00 2001 From: Micael Karlberg <bmk@erlang.org> Date: Wed, 10 Apr 2024 11:16:36 +0200 Subject: [PATCH 2/2] [esock|test] Add simple test case OTP-19063 --- lib/kernel/test/socket_SUITE.erl | 172 ++++++++++++++++++++++++++++++- 1 file changed, 170 insertions(+), 2 deletions(-) diff --git a/lib/kernel/test/socket_SUITE.erl b/lib/kernel/test/socket_SUITE.erl index 57610e438c..2af48f3904 100644 --- a/lib/kernel/test/socket_SUITE.erl +++ b/lib/kernel/test/socket_SUITE.erl @@ -749,7 +749,8 @@ otp16359_maccept_tcpL/1, otp18240_accept_mon_leak_tcp4/1, otp18240_accept_mon_leak_tcp6/1, - otp18635/1 + otp18635/1, + otp19063/1 ]). @@ -2353,7 +2354,8 @@ tickets_cases() -> [ {group, otp16359}, {group, otp18240}, - otp18635 + otp18635, + otp19063 ]. otp16359_cases() -> @@ -51875,6 +51877,164 @@ do_otp18635(_) -> Result. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%% This test case is to verify recv on UDP with timeout zero (0) on Windows. +otp19063(Config) when is_list(Config) -> + ?TT(?SECS(10)), + tc_try(?FUNCTION_NAME, + fun() -> + %% is_windows(), + has_support_ipv4() + end, + fun() -> + InitState = #{}, + ok = do_otp19063(InitState) + end). + + +do_otp19063(_) -> + Parent = self(), + + ?P("Get \"proper\" local socket address"), + LSA0 = which_local_socket_addr(inet), + LSA = LSA0#{port => 0}, + + + + %% --- recv --- + + ?P("[recv] - create (listen) socket"), + {ok, LSock1} = socket:open(inet, stream), + + ?P("[recv] bind (listen) socket to: " + "~n ~p", [LSA]), + ok = socket:bind(LSock1, LSA), + + ?P("[recv] make listen socket"), + ok = socket:listen(LSock1), + + ?P("[recv] get sockname for listen socket"), + {ok, SA1} = socket:sockname(LSock1), + + ?P("[recv] attempt a nowait-accept"), + {Tag, Handle} = + case socket:accept(LSock1, nowait) of + {select, {select_info, _, SH}} -> + {select, SH}; + {completion, {completion_info, _, CH}} -> + {completion, CH} + end, + + ?P("[recv] spawn the connector process"), + {Connector, MRef} = + spawn_monitor( + fun() -> + ?P("[connector] try create socket"), + {ok, CSock1} = socket:open(inet, stream), + ?P("[connector] bind socket to: " + "~n ~p", [LSA]), + ok = socket:bind(CSock1, LSA), + ?P("[connector] try connect: " + "~n (server) ~p", [SA1]), + ok = socket:connect(CSock1, SA1), + ?P("[connector] connected - inform parent"), + Parent ! {self(), connected}, + ?P("[connector] await termination command"), + receive + {Parent, terminate} -> + ?P("[connector] terminate - close socket"), + (catch socket:close(CSock1)), + exit(normal) + end + end), + + ?P("[recv] await (connection-) confirmation from connector (~p)", + [Connector]), + receive + {Connector, connected} -> + ?P("[recv] connector connected"), + ok + end, + + ?P("[recv] receive the accepted socket"), + ASock1 = + receive + {'$socket', LSock1, completion, {Handle, {ok, AS}}} + when (Tag =:= completion) -> + AS; + {'$socket', LSock1, completion, {Handle, {error, Reason1C}}} + when (Tag =:= completion) -> + exit({accept_failed, Reason1C}); + {'$socket', LSock1, select, Handle} -> + case socket:accept(LSock1, nowait) of + {ok, AS} -> + AS; + {error, Reason1S} -> + exit({accept_failed, Reason1S}) + end + end, + + ?SLEEP(?SECS(1)), + + ?P("[recv] try read"), + case socket:recv(ASock1, 0, 0) of + {error, timeout} -> + ok; + Any1 -> + ?P("Unexpected result: ~p", [Any1]), + exit({unexpected_recv_result, Any1}) + end, + + + %% --- recvfrom --- + + ?P("[recvfrom} create socket"), + {ok, Sock2} = socket:open(inet, dgram), + + ?P("[recvfrom} bind socket to: " + "~n ~p", [LSA]), + ok = socket:bind(Sock2, LSA), + + ?SLEEP(?SECS(1)), + + ?P("[recvfrom] try read"), + {error, timeout} = socket:recvfrom(Sock2, 1024, 0), + + + %% --- recvmsg --- + + ?P("[recvmsg] create socket"), + {ok, Sock3} = socket:open(inet, dgram), + + ?P("[recvmsg] bind socket to: " + "~n ~p", [LSA]), + ok = socket:bind(Sock3, LSA), + + ?SLEEP(?SECS(1)), + + ?P("[recvmsg] try read"), + {error, timeout} = socket:recvmsg(Sock3, 0), + + + ?P("cleanup"), + + Connector ! {self(), terminate}, + receive + {'DOWN', MRef, process, Connector, _} -> + ?P("connector terminated"), + ok + end, + _ = socket:close(ASock1), + _ = socket:close(LSock1), + _ = socket:close(Sock2), + _ = socket:close(Sock3), + + ?P("done"), + + ok. + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sock_open(Domain, Type, Proto) -> @@ -52333,6 +52493,14 @@ is_not_windows() -> ok end. +%% is_windows() -> +%% case os:type() of +%% {win32, nt} -> +%% ok; +%% _ -> +%% skip("This does not work on *non* Windows") +%% end. + is_not_platform(Platform, PlatformStr) when is_atom(Platform) andalso is_list(PlatformStr) -> case os:type() of -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor