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

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