vpp/test/discover_tests.py
Klement Sekera 31da2e3031 Revert "Revert "ipsec: VPP-1316 calculate IP/TCP/UDP inner checksums""
This reverts commit e0d2bd6bd7fc59c0c6ac48195d7f825dc99bfd91.

Change-Id: If491e16f9ea66b2493a6a7c7f3c684ed585f8f51
Signed-off-by: Klement Sekera <ksekera@cisco.com>
2018-06-24 22:53:37 +02:00

58 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python
import sys
import os
import unittest
import importlib
import argparse
def discover_tests(directory, callback):
do_insert = True
for _f in os.listdir(directory):
f = "%s/%s" % (directory, _f)
if os.path.isdir(f):
discover_tests(f, callback)
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" or name.startswith("Template"):
continue
for method in dir(cls):
if not callable(getattr(cls, method)):
continue
if method.startswith("test_"):
callback(_f, cls, method)
def print_callback(file_name, cls, method):
print("%s.%s.%s" % (file_name, cls.__name__, method))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Discover VPP unit tests")
parser.add_argument("-d", "--dir", action='append', type=str,
help="directory containing test files "
"(may be specified multiple times)")
args = parser.parse_args()
if args.dir is None:
args.dir = "."
suite = unittest.TestSuite()
for d in args.dir:
discover_tests(d, print_callback)