diff options
-rw-r--r-- | host/python/CMakeLists.txt | 1 | ||||
-rw-r--r-- | mpm/python/tests/eeprom_tests.py | 199 | ||||
-rw-r--r-- | mpm/python/tests/eeprom_tests/empty.eeprom | 0 | ||||
-rw-r--r-- | mpm/python/tests/eeprom_tests/legacy_mboard_v1.eeprom | bin | 0 -> 256 bytes | |||
-rw-r--r-- | mpm/python/tests/eeprom_tests/legacy_mboard_v2.eeprom | bin | 0 -> 256 bytes | |||
-rw-r--r-- | mpm/python/tests/eeprom_tests/legacy_mboard_v3.eeprom | bin | 0 -> 256 bytes | |||
-rw-r--r-- | mpm/python/tests/eeprom_tests/tlv_multiple.eeprom | bin | 0 -> 256 bytes | |||
-rw-r--r-- | mpm/python/tests/eeprom_tests/tlv_single.eeprom | bin | 0 -> 256 bytes | |||
-rw-r--r-- | mpm/python/tests/eeprom_tests/tlv_unknown_tagmap.eeprom | bin | 0 -> 256 bytes | |||
-rw-r--r-- | mpm/python/tests/eeprom_tests/tlv_wrong_maplen.eeprom | bin | 0 -> 256 bytes | |||
-rwxr-xr-x | mpm/python/tests/run_unit_tests.py | 2 |
11 files changed, 202 insertions, 0 deletions
diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt index 234870c5f..8f12e3f01 100644 --- a/host/python/CMakeLists.txt +++ b/host/python/CMakeLists.txt @@ -137,6 +137,7 @@ if(ENABLE_SIM) ${CMAKE_CURRENT_BINARY_DIR}/simulator/usrp_mpm/mpmtypes.py ${CMAKE_CURRENT_BINARY_DIR}/simulator/usrp_mpm/mpmutils.py ${CMAKE_CURRENT_BINARY_DIR}/simulator/usrp_mpm/prefs.py + ${CMAKE_CURRENT_BINARY_DIR}/simulator/usrp_mpm/tlv_eeprom.py ${CMAKE_CURRENT_BINARY_DIR}/simulator/usrp_mpm/rpc_server.py ${CMAKE_CURRENT_BINARY_DIR}/simulator/usrp_mpm/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/usrp_mpm) diff --git a/mpm/python/tests/eeprom_tests.py b/mpm/python/tests/eeprom_tests.py new file mode 100644 index 000000000..0fd69af84 --- /dev/null +++ b/mpm/python/tests/eeprom_tests.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python3 +# +# Copyright 2021 Ettus Research, a National Instruments Company +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +""" +TLV eeprom tests +""" + +import os +import struct +from base_tests import TestBase +import usrp_mpm.eeprom +import usrp_mpm.tlv_eeprom +from usrp_mpm.eeprom import MboardEEPROM +from usrp_mpm.periph_manager.base import PeriphManagerBase + +def get_eeprom_filename(name): + """ + location of EEPROM test file relative to test + """ + return os.path.join(os.path.dirname(__file__), "eeprom_tests", name) + +class TestEeprom(TestBase): + """ + Tests EEPROM readers of different versions. Each reader is expected to + return a dictionary with values read by the reader. The tests pass + the dictionary to _check_data which checks equality of all data as well as + that both dicts contain the same keys. + """ + + # tag map for tlv eeprom tests + tagmap = { + # typical board map + 0x42: usrp_mpm.tlv_eeprom.NamedStruct( + '< H H H 7s 1x', ['pid', 'rev', 'rev_compat', 'serial']), + # tow additional maps to test unpack of multiple maps in a single eeprom + 0x47: usrp_mpm.tlv_eeprom.NamedStruct( + '< B B H', ['byte1', 'byte2', 'short']), + 0x11: usrp_mpm.tlv_eeprom.NamedStruct( + '< L', ['long']) + } + magic = 0xCEF10F00 + + def _check_data(self, data, **kwargs): + #generic data check with kwargs containing key-value pairs + self.assertEqual(len(kwargs), len(data), + "test does not check all items " + "(Expected: %s Read: %s)" % + (kwargs.keys(), data.keys())) + for key, value in kwargs.items(): + self.assertTrue(key in data, "data does not contain %s" % key) + self.assertEqual(data[key], value, + "%s does not match. Expected: %s, Received: %s" % + (key, value, data[key])) + + def test_eeprom_legacy_minsize(self): + """ + check that empty eeprom files raises struct error + """ + self.assertRaises(struct.error, + usrp_mpm.eeprom.read_eeprom, + get_eeprom_filename("empty.eeprom"), + 0, + MboardEEPROM.eeprom_header_format, + MboardEEPROM.eeprom_header_keys, + PeriphManagerBase.dboard_eeprom_magic) + + def test_eeprom_mboard_v1(self): + """ + read valid v1 map + """ + keys = MboardEEPROM.eeprom_header_keys + (data, _) = usrp_mpm.eeprom.read_eeprom( + get_eeprom_filename("legacy_mboard_v1.eeprom"), + 0, + MboardEEPROM.eeprom_header_format, + keys, + PeriphManagerBase.mboard_eeprom_magic) + self._check_data( + data, + magic=PeriphManagerBase.mboard_eeprom_magic, + eeprom_version=1, + mcu_flags=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', + pid=0xDEAD, + rev=0xABCD, + serial=b"mbrd_v1", + mac_addresses=b'\x01\x02\x03\x04\x05\x06\x00\x00' + b'\x0f\x0e\r\x0c\x0b\n\x00\x00\x11' + b'"3DUf\x00\x00', + CRC=0x02CC50AA) + + def test_eeprom_mboard_v2(self): + """ + read valid v2 map + """ + (data, _) = usrp_mpm.eeprom.read_eeprom( + get_eeprom_filename("legacy_mboard_v2.eeprom"), + 0, + MboardEEPROM.eeprom_header_format, + MboardEEPROM.eeprom_header_keys, + PeriphManagerBase.mboard_eeprom_magic) + self._check_data( + data, + magic=PeriphManagerBase.mboard_eeprom_magic, + eeprom_version=2, + mcu_flags=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', + pid=0xDEAD, + rev=0xBEEF, + serial=b"mbrd_v2", + mac_eth0=b'\x01\x02\x03\x04\x05\x06', + dt_compat=0xD1C0, + mac_eth1=b'\x0f\x0e\r\x0c\x0b\n', + ec_compat=0xECC0, + mac_eth2=b'\x11"3DUf', + CRC=0x42097DAC) + + def test_eeprom_mboard_v3(self): + """ + read valid v3 map + """ + (data, _) = usrp_mpm.eeprom.read_eeprom( + get_eeprom_filename("legacy_mboard_v3.eeprom"), + 0, + MboardEEPROM.eeprom_header_format, + MboardEEPROM.eeprom_header_keys, + PeriphManagerBase.mboard_eeprom_magic) + self._check_data( + data, + magic=PeriphManagerBase.mboard_eeprom_magic, + eeprom_version=3, + mcu_flags=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', + pid=0xDEAD, + rev=0xBEEF, + serial=b"mbrd_v3", + mac_eth0=b'\x01\x02\x03\x04\x05\x06', + dt_compat=0xD1C0, + mac_eth1=b'\x0f\x0e\r\x0c\x0b\n', + ec_compat=0xECC0, + mac_eth2=b'\x11"3DUf', + rev_compat=0x4EC0, + CRC=0x2E52CB41) + + def test_eeprom_tlv_single(self): + """ + read eeprom with tag map + """ + (data, _) = usrp_mpm.tlv_eeprom.read_eeprom( + get_eeprom_filename("tlv_single.eeprom"), + self.tagmap, + self.magic) + self._check_data( + data, + rev=2, + rev_compat=2, + pid=0x410, + serial=b'3196D29') + + def test_eeprom_tlv_multiple(self): + """ + read eeprom with multiple tag maps + """ + (data, _) = usrp_mpm.tlv_eeprom.read_eeprom( + get_eeprom_filename("tlv_multiple.eeprom"), + self.tagmap, + self.magic) + self._check_data( + data, + rev=2, + rev_compat=2, + pid=0x410, + serial=b'3196D29', + byte1=0x08, + byte2=0x15, + short=0xEFBE, + long=0xBEBAFECA) + + def test_eeprom_tlv_unknown_tagmap(self): + """ + Check that reading unknown tag map ID leads to empty data map instead + of runtime error + """ + (data, _) = usrp_mpm.tlv_eeprom.read_eeprom( + get_eeprom_filename("tlv_unknown_tagmap.eeprom"), + self.tagmap, + self.magic) + self._check_data(data) + + def test_eeprom_tlv_unknown_wrong_maplen(self): + """ + Check that invalid map len results in TypeError + """ + self.assertRaises(TypeError, + usrp_mpm.tlv_eeprom.read_eeprom, + get_eeprom_filename("tlv_wrong_maplen.eeprom"), + self.tagmap, + self.magic) diff --git a/mpm/python/tests/eeprom_tests/empty.eeprom b/mpm/python/tests/eeprom_tests/empty.eeprom new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/mpm/python/tests/eeprom_tests/empty.eeprom diff --git a/mpm/python/tests/eeprom_tests/legacy_mboard_v1.eeprom b/mpm/python/tests/eeprom_tests/legacy_mboard_v1.eeprom Binary files differnew file mode 100644 index 000000000..92b15da2c --- /dev/null +++ b/mpm/python/tests/eeprom_tests/legacy_mboard_v1.eeprom diff --git a/mpm/python/tests/eeprom_tests/legacy_mboard_v2.eeprom b/mpm/python/tests/eeprom_tests/legacy_mboard_v2.eeprom Binary files differnew file mode 100644 index 000000000..87ccecaba --- /dev/null +++ b/mpm/python/tests/eeprom_tests/legacy_mboard_v2.eeprom diff --git a/mpm/python/tests/eeprom_tests/legacy_mboard_v3.eeprom b/mpm/python/tests/eeprom_tests/legacy_mboard_v3.eeprom Binary files differnew file mode 100644 index 000000000..b201ea087 --- /dev/null +++ b/mpm/python/tests/eeprom_tests/legacy_mboard_v3.eeprom diff --git a/mpm/python/tests/eeprom_tests/tlv_multiple.eeprom b/mpm/python/tests/eeprom_tests/tlv_multiple.eeprom Binary files differnew file mode 100644 index 000000000..531896f11 --- /dev/null +++ b/mpm/python/tests/eeprom_tests/tlv_multiple.eeprom diff --git a/mpm/python/tests/eeprom_tests/tlv_single.eeprom b/mpm/python/tests/eeprom_tests/tlv_single.eeprom Binary files differnew file mode 100644 index 000000000..3dc264427 --- /dev/null +++ b/mpm/python/tests/eeprom_tests/tlv_single.eeprom diff --git a/mpm/python/tests/eeprom_tests/tlv_unknown_tagmap.eeprom b/mpm/python/tests/eeprom_tests/tlv_unknown_tagmap.eeprom Binary files differnew file mode 100644 index 000000000..ee57dbd56 --- /dev/null +++ b/mpm/python/tests/eeprom_tests/tlv_unknown_tagmap.eeprom diff --git a/mpm/python/tests/eeprom_tests/tlv_wrong_maplen.eeprom b/mpm/python/tests/eeprom_tests/tlv_wrong_maplen.eeprom Binary files differnew file mode 100644 index 000000000..704adff36 --- /dev/null +++ b/mpm/python/tests/eeprom_tests/tlv_wrong_maplen.eeprom diff --git a/mpm/python/tests/run_unit_tests.py b/mpm/python/tests/run_unit_tests.py index 88ea1a805..c563804ae 100755 --- a/mpm/python/tests/run_unit_tests.py +++ b/mpm/python/tests/run_unit_tests.py @@ -12,6 +12,7 @@ import sys import argparse from sys_utils_tests import TestNet from mpm_utils_tests import TestMpmUtils +from eeprom_tests import TestEeprom import importlib.util if importlib.util.find_spec("xmlrunner"): @@ -21,6 +22,7 @@ TESTS = { '__all__': { TestNet, TestMpmUtils, + TestEeprom, }, 'n3xx': set(), } |