File 2431-kernel-test-Add-simple-test-case-for-prim_net-if_nam.patch of Package erlang
From 1521ff60b14713bb9cc95b66be1dc4eac8071e06 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Thu, 19 Jun 2025 10:48:51 +0200
Subject: [PATCH 11/14] [kernel|test] Add simple test case for
prim_net:if_name2index/2
OTP-19674
---
lib/kernel/test/prim_net_SUITE.erl | 44 ++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/lib/kernel/test/prim_net_SUITE.erl b/lib/kernel/test/prim_net_SUITE.erl
index 4f7d1e76a3..ff4c07476a 100644
--- a/lib/kernel/test/prim_net_SUITE.erl
+++ b/lib/kernel/test/prim_net_SUITE.erl
@@ -74,7 +74,8 @@
get_adapters_addresses/1,
get_if_entry/1,
get_interface_info/1,
- get_ip_address_table/1
+ get_ip_address_table/1,
+ if_name2index/1
]).
@@ -109,7 +110,9 @@ misc_cases() ->
get_adapters_addresses,
get_if_entry,
get_interface_info,
- get_ip_address_table
+ get_ip_address_table,
+
+ if_name2index
].
@@ -634,6 +637,43 @@ giat_verify_result([#{index := Idx, addr := Addr} | Tab], Addr0)
giat_verify_result(Tab, Addr).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Make sure we can handle any argument
+
+if_name2index(_Config) when is_list(_Config) ->
+ ?TT(?SECS(10)),
+ tc_try(?FUNCTION_NAME,
+ fun() -> ok end,
+ fun() ->
+ try
+ ok = do_if_name2index()
+ catch
+ error:notsup = NOTSUP ->
+ skip(NOTSUP)
+ end
+ end).
+
+do_if_name2index() ->
+ %% First, pick something that we know exist:
+ case prim_net:if_names() of
+ {ok, [{Idx,If}|_]} ->
+ {ok, Idx} = prim_net:if_name2index(If),
+ ok;
+ {error, Reason} ->
+ %% This should not really fail...
+ ?P("Failed to get a success name to try: "
+ "~n Reason: ~p", [Reason]),
+ ok
+ end,
+ {error, einval} = prim_net:if_name2index("flipp-flopp-on-concrete"),
+ {error, enxio} = prim_net:if_name2index("flipp-flopp"),
+ {error, einval} = prim_net:if_name2index(["flipp-flopp"]),
+ {error, einval} = prim_net:if_name2index(['flipp-flopp']),
+ {error, enxio} = prim_net:if_name2index([1,2,3,4]),
+ {error, einval} = prim_net:if_name2index("flipp-" ++ [555] ++ "-flopp"),
+ ok.
+
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% not_supported(What) ->
--
2.43.0