summaryrefslogtreecommitdiffstats
path: root/test/run_tests.py
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2017-03-16 09:14:59 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2017-03-22 10:48:26 +0000
commit993e0edf4e8078d10ddd5efa8156d62ce8f9d0c5 (patch)
tree146fcedb0160e61a826881d39202a12e759773d1 /test/run_tests.py
parentfa80f2e421e7e85f429437aad2da9971a2a60a24 (diff)
make test: support out-of-tree tests
env EXTERN_TESTS="/path/to/extra/tests" make test causes to run the default test set and tests collected from test_*.py files under subtree specified in EXTERN_TESTS. Change-Id: I58c5471dd6010730278a5b47d4318737d920bc28 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/run_tests.py')
-rw-r--r--test/run_tests.py51
1 files changed, 50 insertions, 1 deletions
diff --git a/test/run_tests.py b/test/run_tests.py
index 8f2174b1463..39b093685da 100644
--- a/test/run_tests.py
+++ b/test/run_tests.py
@@ -1,12 +1,61 @@
#!/usr/bin/env python
+import sys
import os
import unittest
+import argparse
+import importlib
from framework import VppTestRunner
+
+def add_from_dir(suite, directory):
+ do_insert = True
+ for _f in os.listdir(directory):
+ f = "%s/%s" % (directory, _f)
+ if os.path.isdir(f):
+ add_from_dir(suite, f)
+ continue
+ if not os.path.isfile(f):
+ continue
+ if do_insert:
+ sys.path.insert(0, directory)
+ do_insert = False
+ if not _f.startswith("test_") or not _f.endswith(".py"):
+ continue
+ name = "".join(f.split("/")[-1].split(".")[:-1])
+ if name in sys.modules:
+ raise Exception("Duplicate test module `%s' found!" % name)
+ module = importlib.import_module(name)
+ for name, cls in module.__dict__.items():
+ if not isinstance(cls, type):
+ continue
+ if not issubclass(cls, unittest.TestCase):
+ continue
+ if name == "VppTestCase":
+ continue
+ for method in dir(cls):
+ if not callable(getattr(cls, method)):
+ continue
+ if method.startswith("test_"):
+ suite.addTest(cls(method))
+
if __name__ == '__main__':
try:
verbose = int(os.getenv("V", 0))
except:
verbose = 0
- unittest.main(testRunner=VppTestRunner, module=None, verbosity=verbose)
+
+ parser = argparse.ArgumentParser(description="VPP unit tests")
+ parser.add_argument("-f", "--failfast", action='count',
+ help="fast failure flag")
+ parser.add_argument("-d", "--dir", action='append', type=str,
+ help="directory containing test files "
+ "(may be specified multiple times)")
+ args = parser.parse_args()
+ failfast = True if args.failfast == 1 else False
+
+ suite = unittest.TestSuite()
+ for d in args.dir:
+ print("Adding tests from directory tree %s" % d)
+ add_from_dir(suite, d)
+ VppTestRunner(verbosity=verbose, failfast=failfast).run(suite)