Blame SOURCES/0012-tests-json_echo-Support-testing-host-binaries.patch

911625
From 0eb301a3f50fb70cb78d955692f3feea1ad8095e Mon Sep 17 00:00:00 2001
911625
From: Phil Sutter <psutter@redhat.com>
911625
Date: Wed, 12 Feb 2020 22:35:27 +0100
911625
Subject: [PATCH] tests: json_echo: Support testing host binaries
911625
911625
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1754047
911625
Upstream Status: nftables commit 106b1f2b93f82
911625
911625
commit 106b1f2b93f82784c18dd5e312bbf88e6c02a5b8
911625
Author: Phil Sutter <phil@nwl.cc>
911625
Date:   Fri Jan 10 11:19:42 2020 +0100
911625
911625
    tests: json_echo: Support testing host binaries
911625
911625
    Support -H/--host option to use host's libnftables.so.1. Alternatively
911625
    users may specify a custom library path via -l/--library option.
911625
911625
    Signed-off-by: Phil Sutter <phil@nwl.cc>
911625
---
911625
 tests/json_echo/run-test.py | 23 +++++++++++++++++++----
911625
 1 file changed, 19 insertions(+), 4 deletions(-)
911625
911625
diff --git a/tests/json_echo/run-test.py b/tests/json_echo/run-test.py
911625
index fa7d69a..36a377a 100755
911625
--- a/tests/json_echo/run-test.py
911625
+++ b/tests/json_echo/run-test.py
911625
@@ -4,6 +4,7 @@ from __future__ import print_function
911625
 import sys
911625
 import os
911625
 import json
911625
+import argparse
911625
 
911625
 TESTS_PATH = os.path.dirname(os.path.abspath(__file__))
911625
 sys.path.insert(0, os.path.join(TESTS_PATH, '../../py/'))
911625
@@ -13,12 +14,26 @@ from nftables import Nftables
911625
 # Change working directory to repository root
911625
 os.chdir(TESTS_PATH + "/../..")
911625
 
911625
-if not os.path.exists('src/.libs/libnftables.so'):
911625
-    print("The nftables library does not exist. "
911625
-          "You need to build the project.")
911625
+parser = argparse.ArgumentParser(description='Run JSON echo tests')
911625
+parser.add_argument('-H', '--host', action='store_true',
911625
+                    help='Run tests against installed libnftables.so.1')
911625
+parser.add_argument('-l', '--library', default=None,
911625
+                    help='Path to libntables.so, overrides --host')
911625
+args = parser.parse_args()
911625
+
911625
+check_lib_path = True
911625
+if args.library is None:
911625
+    if args.host:
911625
+        args.library = 'libnftables.so.1'
911625
+        check_lib_path = False
911625
+    else:
911625
+        args.library = 'src/.libs/libnftables.so.1'
911625
+
911625
+if check_lib_path and not os.path.exists(args.library):
911625
+    print("Library not found at '%s'." % args.library)
911625
     sys.exit(1)
911625
 
911625
-nftables = Nftables(sofile = 'src/.libs/libnftables.so')
911625
+nftables = Nftables(sofile = args.library)
911625
 nftables.set_echo_output(True)
911625
 
911625
 # various commands to work with
911625
-- 
8ff5ad
2.31.1
911625