Skip to content

Commit f0dafe7

Browse files
authored
Merge pull request #283 from krcb197/272-split-into-the-lib_test-base-classes-into-classes-per-type-of-thing
272 split into the lib test base classes into classes per type of thing
2 parents c6f1923 + 2b6121a commit f0dafe7

13 files changed

Lines changed: 2702 additions & 2422 deletions

src/peakrdl_python/lib_test/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
This package is intended to distributed as part of automatically generated code by the PeakRDL
1919
Python tool. It provides a set of base test classes to reduce the size of the auto generated code
2020
"""
21-
from .base_reg_test_class import LibTestBase
22-
from .async_reg_base_test_class import AsyncLibTestBase
21+
from .test_class import LibTestBase
22+
from .async_test_class import AsyncLibTestBase
2323

2424
from .utilities import reverse_bits
2525

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 Lesser General Public License as
7+
published by the Free Software Foundation, either version 3 of
8+
the License, or (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 Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser 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 for the autogenerated tests
20+
"""
21+
# this module is very similar to the non-async version, a lot of code has been put into common
22+
# methods but it did not make sense to do everything as it would destroy readability
23+
# pylint:disable=duplicate-code
24+
25+
import unittest
26+
from abc import ABC, abstractmethod
27+
28+
from ._common_base_test_class import CommonTestBase
29+
30+
class AsyncLibTestCommon(unittest.IsolatedAsyncioTestCase, CommonTestBase, ABC):
31+
"""
32+
Base Test class for the autogenerated register test when in async mode
33+
"""
34+
35+
# The following may look odd by a second layer of indirection is required to effectively patch
36+
# the read and write within tests
37+
38+
# pylint:disable=missing-function-docstring
39+
40+
async def outer_read_callback(self, addr: int, width: int, accesswidth: int) -> int:
41+
return await self.read_callback(addr=addr,
42+
width=width,
43+
accesswidth=accesswidth)
44+
45+
@abstractmethod
46+
async def read_callback(self, addr: int, width: int, accesswidth: int) -> int:
47+
...
48+
49+
async def outer_write_callback(self, addr: int,
50+
width: int, accesswidth: int,
51+
data: int) -> None:
52+
return await self.write_callback(addr=addr,
53+
width=width,
54+
accesswidth=accesswidth,
55+
data=data)
56+
57+
@abstractmethod
58+
async def write_callback(self, addr: int, width: int, accesswidth: int, data: int) -> None:
59+
...
60+
61+
# pylint:enable=missing-function-docstring
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 Lesser General Public License as
7+
published by the Free Software Foundation, either version 3 of
8+
the License, or (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 Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
This package is intended to distributed as part of automatically generated code by the PeakRDL
22+
Python tool. It provide the base class for the autogenerated tests
23+
"""
24+
from abc import ABC, abstractmethod
25+
26+
from ._common_base_test_class import CommonTestBase
27+
28+
29+
class LibTestCommon(CommonTestBase, ABC):
30+
"""
31+
Base Test class for the autogenerated register test when in non-async mode
32+
"""
33+
34+
# The following may look odd by a second layer of indirection is required to effectively patch
35+
# the read and write within tests
36+
37+
# pylint:disable=missing-function-docstring
38+
39+
def outer_read_callback(self, addr: int, width: int, accesswidth: int) -> int:
40+
return self.read_callback(addr=addr, width=width, accesswidth=accesswidth)
41+
42+
@abstractmethod
43+
def read_callback(self, addr: int, width: int, accesswidth: int) -> int:
44+
...
45+
46+
def outer_write_callback(self, addr: int, width: int, accesswidth: int, data: int) -> None:
47+
return self.write_callback(addr=addr, width=width, accesswidth=accesswidth, data=data)
48+
49+
@abstractmethod
50+
def write_callback(self, addr: int, width: int, accesswidth: int, data: int) -> None:
51+
...
52+
53+
# pylint:enable=missing-function-docstring

0 commit comments

Comments
 (0)