From a7be68a4d77791bbe02c37f7ad8ae60b02e5679e Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Tue, 9 Oct 2018 11:31:32 -0500 Subject: Test the Python C JSON extension The C JSON parser was added quite a while ago, but unless you configure with --enable-shared and have the Python 2/3 development libraries installed, and the resulting python-ovs module installed, 'make check' won't actually test it. This patch changes Python-based tests to run from the $builddir/python directory and makes the tests configurable to use both JSON backends. There are some unicode failures in the C JSON extension that I left unfixed in this patch to make it easy to show run the new tests on broken code. The next patch in this set works around the issue. Signed-off-by: Terry Wilson Signed-off-by: Ben Pfaff Acked-by: Lucas Alvares Gomes --- tests/test-ovsdb.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'tests/test-ovsdb.py') diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index 14491a2e9..b99109dc2 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -23,6 +23,7 @@ import uuid import ovs.db.idl import ovs.db.schema import ovs.db.types +import ovs.json import ovs.ovsuuid import ovs.poller import ovs.stream @@ -815,14 +816,20 @@ The following options are also available: def main(argv): try: - options, args = getopt.gnu_getopt(argv[1:], 't:h', + options, args = getopt.gnu_getopt(argv[1:], 't:h:j:', ['timeout', - 'help']) + 'help', 'json-parser']) except getopt.GetoptError as geo: sys.stderr.write("%s: %s\n" % (ovs.util.PROGRAM_NAME, geo.msg)) sys.exit(1) timeout = None + # Save the old version to detect whether we support the C Parser + # but then override to the Python parser because it is always available + # and is the historical default + ORIG_PARSER = ovs.json.PARSER + ovs.json.PARSER = ovs.json.PARSER_PY + for key, value in options: if key in ['-h', '--help']: usage() @@ -834,6 +841,17 @@ def main(argv): except TypeError: raise error.Error("value %s on -t or --timeout is not at " "least 1" % value) + elif key in ['-j', '--json-parser']: + if value == "python": + ovs.json.PARSER = ovs.json.PARSER_PY + elif value in ('C', 'c'): + if ORIG_PARSER != ovs.json.PARSER_C: + raise error.Error("C parser selected, but not compiled") + else: + ovs.json.PARSER = ovs.json.PARSER_C + else: + raise error.Error( + "invalid option: %s, json-parser must be 'C' or json") else: sys.exit(0) -- cgit v1.2.1