]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: Prepare exit codes for automake
authorPhil Sutter <phil@nwl.cc>
Thu, 31 Aug 2023 10:44:55 +0000 (12:44 +0200)
committerPhil Sutter <phil@nwl.cc>
Thu, 11 Sep 2025 16:11:53 +0000 (18:11 +0200)
Make the test suite runners exit 77 when requiring root and running as
regular user, exit 99 for internal errors (unrelated to test cases) and
exit 1 (or any free non-zero value) to indicate test failures.

Signed-off-by: Phil Sutter <phil@nwl.cc>
tests/monitor/run-tests.sh
tests/py/nft-test.py
tests/shell/run-tests.sh

index 32b1b86e0cc6e9f363bc64b7b9bd62984ca5c696..44f21a285b17ce0e25736e93b032b76e64cb4651 100755 (executable)
@@ -12,18 +12,15 @@ err() {
        echo "$*" >&2
 }
 
-die() {
-       err "$*"
-       exit 1
-}
-
 if [ "$(id -u)" != "0" ] ; then
-       die "this requires root!"
+       err "this requires root!"
+       exit 77
 fi
 
 testdir=$(mktemp -d)
 if [ ! -d $testdir ]; then
-       die "Failed to create test directory"
+       err "Failed to create test directory"
+       exit 99
 fi
 trap 'rm -rf $testdir; $nft flush ruleset' EXIT
 
index 12c6174b01257ec68ea712d33442575b4ee3cd33..35b29fc90870b0519e50de50aa279f51e460ff8a 100755 (executable)
@@ -1527,7 +1527,7 @@ def main():
 
     if os.getuid() != 0:
         print("You need to be root to run this, sorry")
-        return
+        return 77
 
     if not args.no_netns and not spawn_netns():
         print_warning("cannot run in own namespace, connectivity might break")
@@ -1546,11 +1546,11 @@ def main():
     if check_lib_path and not os.path.exists(args.library):
         print("The nftables library at '%s' does not exist. "
               "You need to build the project." % args.library)
-        return
+        return 99
 
     if args.enable_schema and not args.enable_json:
         print_error("Option --schema requires option --json")
-        return
+        return 99
 
     global nftables
     nftables = Nftables(sofile = args.library)
@@ -1563,7 +1563,7 @@ def main():
         print_info("Log will be available at %s" % LOGFILE)
     except IOError:
         print_error("Cannot open log file %s" % LOGFILE)
-        return
+        return 99
 
     file_list = []
     if args.filenames:
@@ -1609,5 +1609,7 @@ def main():
                 print("%d test files, %d files passed, %d unit tests, " % (test_files, files_ok, tests))
                 print("%d error, %d warning" % (errors, warnings))
 
+    return errors != 0
+
 if __name__ == '__main__':
-    main()
+    sys.exit(main())
index 2d2e0ad146c80f0d0803e41eaa46cebf959806a3..46f523b962b134231de5d868ac02570d185576aa 100755 (executable)
@@ -96,7 +96,7 @@ _msg() {
                printf '%s\n' "$level: $*"
        fi
        if [ "$level" = E ] ; then
-               exit 1
+               exit 99
        fi
 }