All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Hamilton <adhamilt@gmail.com>
To: grub-devel@gnu.org
Cc: Andrew Hamilton <adhamilt@gmail.com>
Subject: [PATCH v2 1/2] tests: Add net_test for network commands
Date: Sat, 31 Aug 2024 22:31:07 -0500	[thread overview]
Message-ID: <20240901033108.144171-2-adhamilt@gmail.com> (raw)
In-Reply-To: <20240901033108.144171-1-adhamilt@gmail.com>

diff --git a/Makefile.util.def b/Makefile.util.def
index 0f74a1680..9ed211bc5 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -1131,6 +1131,12 @@ script = {
   common = tests/cdboot_test.in;
 };
 
+script = {
+  testcase = nonnative;
+  name = net_test;
+  common = tests/net_test.in;
+};
+
 script = {
   testcase = nonnative;
   name = netboot_test;
diff --git a/tests/net_test.in b/tests/net_test.in
new file mode 100644
index 000000000..de5d8a821
--- /dev/null
+++ b/tests/net_test.in
@@ -0,0 +1,187 @@
+#! @BUILD_SHEBANG@
+# This test is intended to perform basic tests of the "net" commands
+# by providing command line inputs and checking command console output.
+
+set -e
+
+. "@builddir@/grub-core/modinfo.sh"
+
+set -e
+
+if [ "$EUID" = "" ] ; then
+  EUID=$(id -u)
+fi
+
+# Define some variables to be used if different platforms have different
+# interfaces / etc.
+net_dev=""
+net_dev_mac=""
+net_addr=""
+net_addr2=""
+net_addr_ip6=""
+net_addr_ip6_exp=""
+net_route_subnet6=""
+net_gw_subnet=""
+net_gw_addr=""
+net_route_subnet=""
+echo "${grub_modinfo_target_cpu}-${grub_modinfo_platfomr}"
+case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
+    # PLATFORM: emu works when run as root to create the tap device
+    *-emu)
+        if [ "$EUID" != 0 ] ; then
+           echo "not root; cannot test net_test"
+           exit 99
+        fi
+	net_dev="emu0"
+	net_dev_mac="00:01:02:03:04:05"
+	net_addr="169.254.45.2"
+	net_addr2="169.254.46.2"
+	net_addr_ip6="fe80::bca3:3bdf:ba9B:ba9a"
+	net_addr_ip6_exp="fe80:0:0:0:bca3:3bdf:ba9b:ba9a"
+	net_route_subnet6="fe80:0:0:0:0:0:0:0/32"
+	net_gw_subnet="169.254.60.1/24"
+	net_gw_addr="169.254.45.1"
+	net_route_subnet="169.254.0.0/16"
+        ;;
+    # Others are untested (wasn't able to figure out how to get a
+    # network card in Qemu with Grub)
+    # FIXME:
+    *)
+        exit 77;;
+esac
+
+# TC1: The default state should be one card exists
+expected="$net_dev $net_dev_mac"
+output="$(echo 'net_ls_cards' | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC2: The default state should be no address defined
+expected=""
+output="$(echo 'net_ls_addr' | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC3: The default state should be no DNS defined
+expected=""
+output="$(echo 'net_ls_dns' | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC4: The default state should be no routes defined
+expected=""
+output="$(echo 'net_ls_routes' | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC5: Add an addr to the card
+expected="if1 $net_dev_mac $net_addr 
+if1:local $net_route_subnet if1"
+command="net_add_addr if1 $net_dev $net_addr; net_ls_addr; net_ls_routes"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC6: Test removing the addr and associated route update
+expected=""
+command="net_add_addr if1 $net_dev $net_addr; net_del_addr if1; net_ls_routes; \
+net_ls_addr"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC7: Test adding two interfaces then removing one
+expected="if:2 $net_dev_mac 169.254.46.2 
+if:2:local $net_route_subnet if:2"
+command="net_add_addr if:1 $net_dev $net_addr; net_add_addr if:2 $net_dev \
+$net_addr2 ; net_del_addr if:1; net_ls_addr; net_ls_routes"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC8: Test adding a route with a gateway
+expected="INTERFACE_1 00:01:02:03:04:05 169.254.45.2 
+IFACE1_ROUTE $net_gw_subnet gw $net_gw_addr
+INTERFACE_1:local $net_route_subnet INTERFACE_1"
+command="net_add_addr INTERFACE_1 $net_dev $net_addr; net_add_route \
+IFACE1_ROUTE $net_gw_subnet gw $net_gw_addr; net_ls_addr; net_ls_routes"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC9: Test timeout case for IP6 autoconf
+expected="error: couldn't send network packet.
+error: couldn't send network packet.
+error: couldn't send network packet.
+error: couldn't send network packet.
+error: couldn't send network packet.
+error: couldn't send network packet.
+error: couldn't autoconfigure emu0."
+command="net_ipv6_autoconf"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC10: Test setting a VLAN
+expected="if1 $net_dev_mac $net_addr vlan1"
+command="net_add_addr if1 $net_dev $net_addr; net_set_vlan if1 1; \
+net_ls_addr"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC11: Test setting another VLAN
+expected="if1 $net_dev_mac $net_addr vlan4"
+command="net_add_addr if1 $net_dev $net_addr; net_set_vlan if1 4; \
+net_ls_addr"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC12: Test setting up an IPv6 address
+#  I'm not sure if manually adding a route for the link local should be
+#  required...
+expected="if1 $net_dev_mac $net_addr_ip6_exp 
+if1:local $net_route_subnet6 if1"
+command="net_add_addr if1 $net_dev $net_addr_ip6; net_add_route \
+if1:local $net_route_subnet6 if1; net_ls_addr; net_ls_routes"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
+
+# TC13: Test adding IPV6 address, route, then removing the interface
+#  I'm not sure if manually adding a route for the link local should be
+#  required...
+expected=""
+command="net_add_addr if1 $net_dev $net_addr_ip6; net_add_route \
+if1:local $net_route_subnet6 if1;  net_del_addr if1; net_ls_routes; \
+net_ls_addr"
+output="$(echo "$command" | @builddir@/grub-shell)"
+if [ "$output" != "$expected" ]; then
+  printf "Line: $LINENO, Actual: >%s<\nExpected: >%s<\n" "$output" "$expected"
+  exit 1;
+fi
-- 
2.39.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2024-09-01  3:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-01  3:31 [PATCH v2 0/2] Delete Net Routes for Deleted Interfaces Andrew Hamilton
2024-09-01  3:31 ` Andrew Hamilton [this message]
2024-09-01  3:31 ` [PATCH v2 2/2] net/net: Delete " Andrew Hamilton
2024-10-03 14:04 ` [PATCH v2 0/2] Delete Net " Andrew Hamilton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240901033108.144171-2-adhamilt@gmail.com \
    --to=adhamilt@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.