Revamp Python regression tests suite (#2022)
* Fix Python regression test suite (partial) * Fix Python regression test suite * Add a test for mapping at high addresses * Add ctl tests
This commit is contained in:
@@ -1,34 +1,64 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from os.path import dirname, basename, isfile
|
||||
import glob
|
||||
|
||||
# Find all unittest type in this directory and run it.
|
||||
|
||||
class RegressTest(unittest.TestCase):
|
||||
pass
|
||||
"""Regress test case dummy class.
|
||||
"""
|
||||
|
||||
|
||||
def __setup_logger(name):
|
||||
"""Set up a unified logger for all tests.
|
||||
"""
|
||||
|
||||
instance = logging.getLogger(name)
|
||||
instance.propagate = False
|
||||
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter('[%(levelname)s] %(message)s')
|
||||
|
||||
if not instance.hasHandlers():
|
||||
handler.setFormatter(formatter)
|
||||
instance.addHandler(handler)
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
logger = __setup_logger('UnicornRegress')
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
unittest.main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
directory = dirname(__file__)
|
||||
if directory == '':
|
||||
directory = '.'
|
||||
modules = glob.glob(directory+"/*.py")
|
||||
__all__ = [ basename(f)[:-3] for f in modules if isfile(f)]
|
||||
suite = unittest.TestSuite()
|
||||
|
||||
for module in __all__:
|
||||
m = __import__(module)
|
||||
for cl in dir(m):
|
||||
try:
|
||||
realcl = getattr(m,cl)
|
||||
if issubclass(realcl, unittest.TestCase):
|
||||
suite.addTest(realcl())
|
||||
except Exception as e:
|
||||
pass
|
||||
logger.info('starting discovery')
|
||||
|
||||
# Find all unittest type in this directory and run it.
|
||||
directory = os.path.dirname(__file__) or '.'
|
||||
pyfiles = glob.glob(directory + '/*.py')
|
||||
modules = [os.path.splitext(os.path.basename(f))[0] for f in pyfiles if os.path.isfile(f) and f != __file__]
|
||||
|
||||
logger.info('%d test modules found', len(modules))
|
||||
|
||||
for mname in modules:
|
||||
try:
|
||||
module = __import__(mname)
|
||||
except ImportError as ex:
|
||||
logger.error('could not load %s: %s is missing', mname, ex.name)
|
||||
else:
|
||||
tests = unittest.defaultTestLoader.loadTestsFromModule(module)
|
||||
suite.addTests(tests)
|
||||
|
||||
logger.debug('found %d test cases in %s', tests.countTestCases(), mname)
|
||||
|
||||
logger.info('%d test cases were added', suite.countTestCases())
|
||||
|
||||
unittest.TextTestRunner().run(suite)
|
||||
|
||||
Reference in New Issue
Block a user