aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2019-07-17 14:06:25 +0200
committerMicael Karlberg <[email protected]>2019-07-17 15:02:44 +0200
commitc1faea0e9e663d2d69a75f519d8f671419e6e226 (patch)
tree9e144be994749759e675d56f10aed5c039e33985 /erts
parent96ef9b4a7e97b906a08350e8a7805856b0307cdb (diff)
downloadotp-c1faea0e9e663d2d69a75f519d8f671419e6e226.tar.gz
otp-c1faea0e9e663d2d69a75f519d8f671419e6e226.tar.bz2
otp-c1faea0e9e663d2d69a75f519d8f671419e6e226.zip
[esock|test] Add test case for socket option 'debug'
The test case must either be run with a user that has CAP_NET_ADMIN capability or by root. Otherwise the test case will be skipped (eacces). OTP-15904
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/test/socket_SUITE.erl128
1 files changed, 122 insertions, 6 deletions
diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl
index ff12ef66a3..8921cdde04 100644
--- a/erts/emulator/test/socket_SUITE.erl
+++ b/erts/emulator/test/socket_SUITE.erl
@@ -125,6 +125,7 @@
api_opt_sock_acceptfilter/1,
api_opt_sock_bindtodevice/1,
api_opt_sock_broadcast/1,
+ api_opt_sock_debug/1,
api_opt_ip_add_drop_membership/1,
%% *** API Operation Timeout ***
@@ -787,7 +788,8 @@ api_options_socket_cases() ->
api_opt_sock_acceptconn,
api_opt_sock_acceptfilter,
api_opt_sock_bindtodevice,
- api_opt_sock_broadcast
+ api_opt_sock_broadcast,
+ api_opt_sock_debug
].
api_options_ip_cases() ->
@@ -9165,7 +9167,7 @@ api_opt_sock_broadcast() ->
end
end},
#{desc => "[socket 1] UDP socket sockname",
- cmd => fun(#{sock1 := Sock, sa1 := skip} = _State) ->
+ cmd => fun(#{sa1 := skip} = _State) ->
?SEV_IPRINT("SKIP limited broadcast test"),
ok;
(#{sock1 := Sock} = _State) ->
@@ -9310,8 +9312,7 @@ api_opt_sock_broadcast() ->
?SEV_SLEEP(?SECS(1)),
#{desc => "[socket 3] try send to limited broadcast address",
- cmd => fun(#{sock3 := Sock,
- sa1 := skip} = _State) ->
+ cmd => fun(#{sa1 := skip} = _State) ->
?SEV_IPRINT("SKIP limited broadcast test"),
ok;
(#{sock3 := Sock,
@@ -9331,8 +9332,7 @@ api_opt_sock_broadcast() ->
end
end},
#{desc => "[socket 1] try recv",
- cmd => fun(#{sock1 := Sock,
- sa1 := skip} = _State) ->
+ cmd => fun(#{sa1 := skip} = _State) ->
?SEV_IPRINT("SKIP limited broadcast test"),
ok;
(#{sock1 := Sock} = _State) ->
@@ -9421,6 +9421,119 @@ api_opt_sock_broadcast() ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Tests the socket option debug.
+%% Only allowed for processes with the CAP_NET_ADMIN capability or an
+%% effective user ID of 0.
+%% Since we never run the test as root (I hope), this test will
+%% most likely be skipped (unless we give the test user CAP_NET_ADMIN
+%% capability).
+
+api_opt_sock_debug(suite) ->
+ [];
+api_opt_sock_debug(doc) ->
+ [];
+api_opt_sock_debug(_Config) when is_list(_Config) ->
+ ?TT(?SECS(10)),
+ tc_try(api_opt_sock_debug,
+ fun() -> has_support_sock_debug() end,
+ fun() -> api_opt_sock_debug() end).
+
+
+api_opt_sock_debug() ->
+ Opt = debug,
+ Set = fun(S, Val) when is_integer(Val) ->
+ socket:setopt(S, socket, Opt, Val)
+ end,
+ Get = fun(S) ->
+ socket:getopt(S, socket, Opt)
+ end,
+
+ TesterSeq =
+ [
+ #{desc => "which local address",
+ cmd => fun(#{domain := Domain} = State) ->
+ case ?LIB:which_local_host_info(Domain) of
+ {ok, #{name := Name,
+ addr := Addr,
+ broadaddr := BAddr}} ->
+ ?SEV_IPRINT("local host info: "
+ "~n Name: ~p"
+ "~n Addr: ~p"
+ "~n Broadcast Addr: ~p",
+ [Name, Addr, BAddr]),
+ LSA = #{family => Domain,
+ addr => Addr},
+ BSA = #{family => Domain,
+ addr => BAddr},
+ {ok, State#{lsa => LSA,
+ bsa => BSA}};
+ {error, _} = ERROR ->
+ ERROR
+ end
+ end},
+
+ #{desc => "create UDP socket",
+ cmd => fun(#{domain := Domain} = State) ->
+ case socket:open(Domain, dgram, udp) of
+ {ok, Sock} ->
+ {ok, State#{sock => Sock}};
+ {error, _} = ERROR ->
+ ERROR
+ end
+ end},
+ #{desc => "Get current debug value",
+ cmd => fun(#{sock := Sock} = State) ->
+ case Get(Sock) of
+ {ok, Debug} when is_integer(Debug) ->
+ ?SEV_IPRINT("Success: ~p", [Debug]),
+ {ok, State#{debug => Debug}};
+ {error, Reason} = ERROR ->
+ ?SEV_EPRINT("Unexpected failure: ~p",
+ [Reason]),
+ ERROR
+ end
+ end},
+ #{desc => "Try enable socket debug",
+ cmd => fun(#{sock := Sock, debug := Debug} = _State) ->
+ case Set(Sock, Debug + 1) of
+ ok ->
+ ?SEV_IPRINT("Expected Success"),
+ ok;
+ {error, eacces = Reason} ->
+ ?SEV_EPRINT("NO ACCESS => SKIP"),
+ {skip, Reason};
+ {error, Reason} = ERROR ->
+ ?SEV_EPRINT("Unexpected Failure: ~p",
+ [Reason]),
+ ERROR
+ end
+ end},
+
+ %% *** Termination ***
+ #{desc => "close UDP socket",
+ cmd => fun(#{sock := Sock} = State0) ->
+ socket:close(Sock),
+ State1 = maps:remove(sock, State0),
+ {ok, State1}
+ end},
+
+ %% *** We are done ***
+ ?SEV_FINISH_NORMAL
+ ],
+
+ Domain = inet,
+
+ i("start tester evaluator"),
+ InitState = #{domain => Domain},
+ Tester = ?SEV_START("tester", TesterSeq, InitState),
+
+ i("await evaluator(s)"),
+ ok = ?SEV_AWAIT_FINISH([Tester]).
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
%% Tests that the add_mambership and drop_membership ip options work.
%% We create one server and two clients. The server only send messages,
%% the clients only receives messages.
@@ -28171,6 +28284,9 @@ has_support_sock_broadcast() ->
not_supported({broadcast, Reason})
end.
+has_support_sock_debug() ->
+ has_support_socket_option_sock(debug).
+
has_support_ip_add_membership() ->
has_support_socket_option_ip(add_membership).