diff options
author | Lars Amsel <lars.amsel@ni.com> | 2021-06-04 08:27:50 +0200 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-06-10 12:01:53 -0500 |
commit | 2a575bf9b5a4942f60e979161764b9e942699e1e (patch) | |
tree | 2f0535625c30025559ebd7494a4b9e7122550a73 /mpm/python/tests/components_tests.py | |
parent | e17916220cc955fa219ae37f607626ba88c4afe3 (diff) | |
download | uhd-2a575bf9b5a4942f60e979161764b9e942699e1e.tar.gz uhd-2a575bf9b5a4942f60e979161764b9e942699e1e.tar.bz2 uhd-2a575bf9b5a4942f60e979161764b9e942699e1e.zip |
uhd: Add support for the USRP X410
Co-authored-by: Lars Amsel <lars.amsel@ni.com>
Co-authored-by: Michael Auchter <michael.auchter@ni.com>
Co-authored-by: Martin Braun <martin.braun@ettus.com>
Co-authored-by: Paul Butler <paul.butler@ni.com>
Co-authored-by: Cristina Fuentes <cristina.fuentes-curiel@ni.com>
Co-authored-by: Humberto Jimenez <humberto.jimenez@ni.com>
Co-authored-by: Virendra Kakade <virendra.kakade@ni.com>
Co-authored-by: Lane Kolbly <lane.kolbly@ni.com>
Co-authored-by: Max Köhler <max.koehler@ni.com>
Co-authored-by: Andrew Lynch <andrew.lynch@ni.com>
Co-authored-by: Grant Meyerhoff <grant.meyerhoff@ni.com>
Co-authored-by: Ciro Nishiguchi <ciro.nishiguchi@ni.com>
Co-authored-by: Thomas Vogel <thomas.vogel@ni.com>
Diffstat (limited to 'mpm/python/tests/components_tests.py')
-rw-r--r-- | mpm/python/tests/components_tests.py | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/mpm/python/tests/components_tests.py b/mpm/python/tests/components_tests.py new file mode 100644 index 000000000..120b89121 --- /dev/null +++ b/mpm/python/tests/components_tests.py @@ -0,0 +1,114 @@ +# +# Copyright 2020 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +""" +Tests the components classes (currently ZynqComponents) +""" + +from usrp_mpm.components import ZynqComponents +from base_tests import TestBase + +import copy +import os.path +import tempfile +import unittest + +class TestZynqComponents(TestBase): + """ + Test functions of the ZynqComponents class + """ + + _testcase_input = '// mpm_version foo_current_version 1.10\n' \ + '// mpm_version foo_oldest_compatible_version 1.5\n' \ + '// mpm_version bar_current_version 1.2\n' \ + '// mpm_version bar_oldest_compatible_version 1.0\n' \ + '// mpm_version baz_current_version 1.2.3\n' \ + '// mpm_version baz_oldest_compatible_version 1.0.0\n' \ + '// mpm_version zack 2.0\n' \ + '// mpm_version zack_oldest_compatible_version 1.0\n' \ + '// mpm_other_tag noname_current_version 1.2.3\n' \ + '// other comment\n' + + _testcase_result = { + 'bar': {'current': (1, 2), 'oldest': (1,0)}, + 'baz': {'current': (1, 2, 3), 'oldest': (1,0,0)}, + 'foo': {'current': (1, 10), 'oldest': (1, 5)}, + 'zack': {'current': (2, 0), 'oldest': (1,0)}, + } + + def _write_dts_file_from_test_cases(self, content): + """ Write content to a temporary .dts file """ + f = tempfile.NamedTemporaryFile(mode="w+", suffix=".dts") + expected = {} + f.write(content) + f.flush() + return f + + def test_parse_dts_version_info_from_file(self): + """ Test function ZynqComponents._parse_dts_version_info_from_file """ + f = self._write_dts_file_from_test_cases(self._testcase_input) + expected = self._testcase_result + result = ZynqComponents._parse_dts_version_info_from_file(f.name) + self.assertEqual(result, expected) + + def test_verify_compatibility(self): + """ Test function ZynqComponents._verify_compatibility """ + class _log_dummy(): + def _dummy(self, *args): + pass + trace = _dummy + info = _dummy + warning = _dummy + error = _dummy + + f = self._write_dts_file_from_test_cases(self._testcase_input) + compatibility = self._testcase_result + for version_type in ['current', 'oldest']: + for case in ['normal', 'smaller_mpm_minor', 'bigger_mpm_minor', + 'smaller_mpm_major', 'bigger_mpm_major', 'component_missing', + 'additional_component']: + compatibility_testcase = copy.deepcopy(compatibility) + foo_major, foo_minor = compatibility['foo'][version_type] + if case == 'normal': + compatibility_testcase['foo'][version_type] = (foo_major, foo_minor) + error_expected = None + elif case == 'smaller_mpm_minor': + compatibility_testcase['foo'][version_type] = (foo_major, foo_minor-1) + error_expected = None + elif case == 'bigger_mpm_minor': + compatibility_testcase['foo'][version_type] = (foo_major, foo_minor+1) + error_expected = None + elif case == 'smaller_mpm_major': + compatibility_testcase['foo'][version_type] = (foo_major-1, foo_minor) + if version_type == 'oldest': + error_expected = None + else: + error_expected = RuntimeError() + elif case == 'bigger_mpm_major': + compatibility_testcase['foo'][version_type] = (foo_major+1, foo_minor) + if version_type == 'oldest': + error_expected = RuntimeError() + else: + error_expected = None + elif case == 'component_missing': + del compatibility_testcase['foo'] + error_expected = None + elif case == 'additional_component': + compatibility_testcase['newcomp'] = {version_type: (2, 10)} + error_expected = None + update_dict = { + 'compatibility': compatibility_testcase, + 'check_dts_for_compatibility': True, + } + filebasename, _ = os.path.splitext(f.name) + try: + self._zynqcomponents = ZynqComponents() + self._zynqcomponents.log = _log_dummy() + self._zynqcomponents._verify_compatibility(filebasename, update_dict) + error = None + except RuntimeError as r: + error = r + self.assertEqual(error.__class__, error_expected.__class__, + f"Unexpected result for test case {case} (version type: {version_type})") |