diff options
author | Micael Karlberg <[email protected]> | 2019-05-29 12:10:56 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-05-29 12:10:56 +0200 |
commit | e628d2cdf8953b8692e6b9ac0265c20bfce4b21d (patch) | |
tree | e151e1ce6545d92a483a531cbef01936ab04b73a /lib/snmp/test/snmp_test_lib.erl | |
parent | 36e61f1e23bf06664206aaba1848e36440a36e4a (diff) | |
download | otp-e628d2cdf8953b8692e6b9ac0265c20bfce4b21d.tar.gz otp-e628d2cdf8953b8692e6b9ac0265c20bfce4b21d.tar.bz2 otp-e628d2cdf8953b8692e6b9ac0265c20bfce4b21d.zip |
[snmp|test] Improved IPv6 test checks
Improve the checks for if/when we shall run the IPv6
test cases.
OTP-15764
Diffstat (limited to 'lib/snmp/test/snmp_test_lib.erl')
-rw-r--r-- | lib/snmp/test/snmp_test_lib.erl | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl index 9fab1a5c56..42f710e4cd 100644 --- a/lib/snmp/test/snmp_test_lib.erl +++ b/lib/snmp/test/snmp_test_lib.erl @@ -25,7 +25,9 @@ -export([hostname/0, hostname/1, localhost/0, localhost/1, os_type/0, sz/1, display_suite_info/1]). --export([non_pc_tc_maybe_skip/4, os_based_skip/1]). +-export([non_pc_tc_maybe_skip/4, os_based_skip/1, + has_support_ipv6/0, has_support_ipv6/1, + is_ipv6_host/0, is_ipv6_host/1]). -export([fix_data_dir/1, init_suite_top_dir/2, init_group_top_dir/2, init_testcase_top_dir/2, lookup/2, @@ -52,11 +54,12 @@ hostname() -> hostname(node()). hostname(Node) -> - from($@, atom_to_list(Node)). - -from(H, [H | T]) -> T; -from(H, [_ | T]) -> from(H, T); -from(_H, []) -> []. + case string:tokens(atom_to_list(Node), [$@]) of + [_, Host] -> + Host; + _ -> + [] + end. %% localhost() -> %% {ok, Ip} = snmp_misc:ip(net_adm:localhost()), @@ -78,7 +81,9 @@ localhost(Family) -> {error, Reason1} -> fail({getifaddrs, Reason1}, ?MODULE, ?LINE) end; - {ok, {0, _, _, _, _, _, _, _}} when (Family =:= inet6) -> + {ok, {A1, _, _, _, _, _, _, _}} when (Family =:= inet6) andalso + ((A1 =:= 0) orelse + (A1 =:= 16#fe80)) -> %% Ouch, we need to use something else case inet:getifaddrs() of {ok, IfList} -> @@ -270,8 +275,47 @@ os_based_skip_check(OsName, OsNames) -> _ -> false end. + + +%% A basic test to check if current host supports IPv6 +has_support_ipv6() -> + case inet:gethostname() of + {ok, Hostname} -> + has_support_ipv6(Hostname); + _ -> + false + end. + +has_support_ipv6(Hostname) -> + case inet:getaddr(Hostname, inet6) of + {ok, Addr} when (size(Addr) =:= 8) andalso + (element(1, Addr) =/= 0) andalso + (element(1, Addr) =/= 16#fe80) -> + true; + {ok, _} -> + false; + {error, _} -> + false + end. +is_ipv6_host() -> + case inet:gethostname() of + {ok, Hostname} -> + is_ipv6_host(Hostname); + {error, _} -> + false + end. + +is_ipv6_host(Hostname) -> + case ct:require(ipv6_hosts) of + ok -> + lists:member(list_to_atom(Hostname), ct:get_config(ipv6_hosts)); + _ -> + false + end. + + %% ---------------------------------------------------------------- %% Test suite utility functions %% |