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

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