|
| 1 | +""" |
| 2 | +peakrdl-python is a tool to generate Python Register Access Layer (RAL) from SystemRDL |
| 3 | +Copyright (C) 2021 - 2025 |
| 4 | +
|
| 5 | +This program is free software: you can redistribute it and/or modify |
| 6 | +it under the terms of the GNU General Public License as published by |
| 7 | +the Free Software Foundation, either version 3 of the License, or |
| 8 | +(at your option) any later version. |
| 9 | +
|
| 10 | +This program is distributed in the hope that it will be useful, |
| 11 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +GNU General Public License for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU General Public License |
| 16 | +along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | +
|
| 18 | +This package is intended to distributed as part of automatically generated code by the PeakRDL |
| 19 | +Python tool. It provide the base class common to both the async and non-async versions |
| 20 | +""" |
| 21 | +import unittest |
| 22 | +from abc import ABC |
| 23 | +from typing import Union, Optional |
| 24 | + |
| 25 | +from ..lib import FieldReadWrite, FieldReadOnly, FieldWriteOnly |
| 26 | +from ..lib import FieldEnumReadWrite, FieldEnumReadOnly, FieldEnumWriteOnly |
| 27 | +from ..lib import FieldAsyncReadOnly, FieldAsyncWriteOnly, FieldAsyncReadWrite |
| 28 | +from ..lib import FieldEnumAsyncReadOnly, FieldEnumAsyncWriteOnly, FieldEnumAsyncReadWrite |
| 29 | + |
| 30 | +class CommonTestBase(unittest.TestCase, ABC): |
| 31 | + """ |
| 32 | + Base Test class for the autogenerated register test to be used for for the async and |
| 33 | + non-async cases |
| 34 | + """ |
| 35 | + |
| 36 | + # pylint:disable-next=too-many-arguments |
| 37 | + def _single_field_property_test(self, *, |
| 38 | + fut: Union[FieldReadWrite, |
| 39 | + FieldReadOnly, |
| 40 | + FieldWriteOnly, |
| 41 | + FieldEnumReadWrite, |
| 42 | + FieldEnumReadOnly, |
| 43 | + FieldEnumWriteOnly, |
| 44 | + FieldAsyncReadOnly, |
| 45 | + FieldAsyncWriteOnly, |
| 46 | + FieldAsyncReadWrite, |
| 47 | + FieldEnumAsyncReadOnly, |
| 48 | + FieldEnumAsyncWriteOnly, |
| 49 | + FieldEnumAsyncReadWrite], |
| 50 | + lsb: int, |
| 51 | + msb: int, |
| 52 | + low: int, |
| 53 | + high: int, |
| 54 | + bitmask: int, |
| 55 | + inverse_bitmask: int, |
| 56 | + max_value: int, |
| 57 | + is_volatile: bool, |
| 58 | + default: Optional[int]) -> None: |
| 59 | + self.assertEqual(fut.lsb, lsb) |
| 60 | + self.assertEqual(fut.msb, msb) |
| 61 | + self.assertEqual(fut.low, low) |
| 62 | + self.assertEqual(fut.high, high) |
| 63 | + self.assertEqual(fut.bitmask, bitmask) |
| 64 | + self.assertEqual(fut.inverse_bitmask, inverse_bitmask) |
| 65 | + self.assertEqual(fut.max_value, max_value) |
| 66 | + self.assertEqual(fut.is_volatile, is_volatile) |
| 67 | + |
| 68 | + if default is None: |
| 69 | + self.assertIsNone(fut.default) |
| 70 | + else: |
| 71 | + if isinstance(fut, (FieldEnumReadWrite, |
| 72 | + FieldEnumReadOnly, |
| 73 | + FieldEnumWriteOnly, |
| 74 | + FieldEnumAsyncReadOnly, |
| 75 | + FieldEnumAsyncWriteOnly, |
| 76 | + FieldEnumAsyncReadWrite)): |
| 77 | + # pylint does not realise this is a class being returned rather than an object, so |
| 78 | + # is unhappy with the name |
| 79 | + # pylint:disable-next=invalid-name |
| 80 | + EnumCls = fut.enum_cls |
| 81 | + if default in [item.value for item in fut.enum_cls]: |
| 82 | + self.assertEqual(fut.default, EnumCls(default)) |
| 83 | + else: |
| 84 | + # this is a special case if the default value for the field does not map |
| 85 | + # to a legal value of the encoding |
| 86 | + self.assertIsNone(fut.default) |
| 87 | + else: |
| 88 | + self.assertEqual(fut.default, default) |
0 commit comments