diff options
author | Toni Jones <toni.jones@ni.com> | 2019-03-05 11:09:12 -0600 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-03-26 15:15:05 -0700 |
commit | 8b080a8a14e943e998b9c301106456e41d176207 (patch) | |
tree | 721757e55b073c28fd89892d1d074ecd689a0f54 /mpm/python/tests/run_unit_tests.py | |
parent | 0e0a30595479d1ebd589355a7ee77968e6e927a4 (diff) | |
download | uhd-8b080a8a14e943e998b9c301106456e41d176207.tar.gz uhd-8b080a8a14e943e998b9c301106456e41d176207.tar.bz2 uhd-8b080a8a14e943e998b9c301106456e41d176207.zip |
cmake: Add unit testing framework to MPM
Add unit testing framework to MPM which can be run by calling
"make test". The testing is done using the built in unittest Python
module. Tests can be run on a dev machine or on the USRP itself when
compiling natively.
Diffstat (limited to 'mpm/python/tests/run_unit_tests.py')
-rwxr-xr-x | mpm/python/tests/run_unit_tests.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/mpm/python/tests/run_unit_tests.py b/mpm/python/tests/run_unit_tests.py new file mode 100755 index 000000000..d7c288aaa --- /dev/null +++ b/mpm/python/tests/run_unit_tests.py @@ -0,0 +1,64 @@ +# +# Copyright 2019 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +""" +USRP MPM Python Unit testing framework +""" + +import unittest +import sys +from sys_utils_tests import TestNet + +TESTS = { + '__all__': {TestNet}, + 'n3xx': set(), +} + +def get_test_suite(device_name=''): + """ + Gets a test suite (collection of test cases) which is relevant for + the specified device. + """ + # A collection of test suites, generated by test loaders, which will + # be later combined + test_suite_list = [] + test_loader = unittest.TestLoader() + + # Combine generic and device specific tests + test_cases = TESTS.get('__all__') | TESTS.get(device_name, set()) + for case in test_cases: + new_suite = test_loader.loadTestsFromTestCase(case) + for test in new_suite: + # Set up test case class for a specific device. + # Each test uses a different test case instance. + if (hasattr(test, 'set_device_name')) and (device_name != ''): + test.set_device_name(device_name) + test_suite_list.append(new_suite) + + # Individual test suites are combined into a master test suite + test_suite = unittest.TestSuite(test_suite_list) + return test_suite + +def run_tests(device_name=''): + """ + Executes the unit tests specified by the test suite. + This should be called from CMake. + """ + test_result = unittest.TestResult() + test_runner = unittest.TextTestRunner(verbosity=2) + test_result = test_runner.run(get_test_suite(device_name)) + return test_result + +def main(): + if len(sys.argv) >= 2: + mpm_device_name = sys.argv[1] + else: + mpm_device_name = '' + + if not run_tests(mpm_device_name).wasSuccessful(): + sys.exit(-1) + +if __name__ == "__main__": + main() |