From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

Enhance scripts/test.py to pass extra arguments to run.py

This patch enhances scripts/test.py to allow passing
extra arguments to run.py. This allows executing running
unit tests with different than default parameters.

See examples below how to run tests with different
virtio configuration:

./scripts/test.py --run_options '--virtio legacy'
./scripts/test.py --run_options '--virtio modern'
./scripts/test.py --run_options '--virtio modern -S'

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
Message-Id: <20190209043102.21408-1-jwkozac...@gmail.com>

---
diff --git a/scripts/test.py b/scripts/test.py
--- a/scripts/test.py
+++ b/scripts/test.py
@@ -57,6 +57,7 @@ def run_test(test):

     start = time.time()
     try:
+        test.set_run_py_args(run_py_args)
         test.run()
     except:
         sys.stdout.write("Test %s FAILED\n" % test.name)
@@ -75,7 +76,7 @@ def run_tests_in_single_instance():
     run(filter(lambda test: not isinstance(test, TestRunnerTest), tests))

     blacklist_tests = ' '.join(blacklist)
-    args = ["-s", "-e", "/testrunner.so -b %s" % (blacklist_tests)]
+ args = run_py_args + ["-s", "-e", "/testrunner.so -b %s" % (blacklist_tests)]
     if subprocess.call(["./scripts/run.py"] + args):
         exit(1)

@@ -182,6 +183,11 @@ def main():
parser.add_argument("-s", "--single", action="store_true", help="run as much tests as possible in a single OSv instance") parser.add_argument("-n", "--nfs", action="store_true", help="run nfs test in a single OSv instance") parser.add_argument("--name", action="store", help="run all tests whose names match given regular expression") + parser.add_argument("--run_options", action="store", help="pass extra options to run.py")
     cmdargs = parser.parse_args()
     set_verbose_output(cmdargs.verbose)
+    if cmdargs.run_options != None:
+        run_py_args = cmdargs.run_options.split()
+    else:
+        run_py_args = []
     main()
diff --git a/scripts/tests/testing.py b/scripts/tests/testing.py
--- a/scripts/tests/testing.py
+++ b/scripts/tests/testing.py
@@ -16,6 +16,10 @@ class TestFailed(Exception):
 class Test(object):
     def __init__(self, name):
         self.name = name
+        self.run_py_args = []
+
+    def set_run_py_args(self, args):
+        self.run_py_args = args

     def run(self):
         pass
@@ -26,7 +30,7 @@ def __init__(self, name, command):
         self.command = command

     def run(self):
-        run_command_in_guest(self.command).join()
+ run_command_in_guest(self.command, run_py_args=self.run_py_args).join()

 class test(Test):
     """
@@ -182,7 +186,7 @@ def run_command_in_guest(command, **kwargs):

 class Guest(SupervisedProcess):
def __init__(self, args, forward=[], hold_with_poweroff=False, show_output_on_error=True,
-                 scan_for_failed_to_load_object_error=True):
+ scan_for_failed_to_load_object_error=True, run_py_args=[]):

         run_script = os.path.join(osv_base, "scripts/run.py")

@@ -197,7 +201,7 @@ def __init__(self, args, forward=[], hold_with_poweroff=False, show_output_on_er

         args.extend(['--unsafe-cache'])

-        SupervisedProcess.__init__(self, [run_script] + args,
+        SupervisedProcess.__init__(self, [run_script] + run_py_args + args,
             show_output=_verbose_output,
             show_output_on_error=show_output_on_error,
scan_for_failed_to_load_object_error=scan_for_failed_to_load_object_error)

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to