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