The derivedFrom
attribute in SVD is a powerful feature that allows reuse of elements (like registers, clusters, and
fields) across different parts of a peripheral definition. It is used to reference existing definitions and inherit
their attributes without having to redefine them. This reduces redundancy and helps maintain consistency within complex
device descriptions.
The derivedFrom
path resolving mechanism is crucial in determining how references are processed. Paths can vary in
complexity, ranging from simple names to more intricate, nested references within clusters. A robust parser
implementation must correctly interpret these paths, supporting multiple levels of hierarchy while handling any scope
ambiguities. Additionally, the parser should gracefully handle errors when the paths are incorrect, issuing clear
diagnostic messages to aid debugging.
According to this, the deriving
algorithm works as follows:
-
Initialization: - Split the deriving path (the string in the derivedFrom
attribute) by .
and store it in
array $P$. For example, if the path is x.y.z
, then $P_0 = ext{x}$, $P_1 = ext{y}$, and $P_2 = ext{z}$. - Set
index $i = 0$. - Store the deriving element (the element with the derivedFrom
attribute) in variable $D$. - Store the
deriving element $D$ in variable $C$ (i.e., $C = D$). - Get the parent of the current element $C$ and set it as the
current node (i.e., $C = C. ext{parent()}$).
-
Search in the current scope: - For each child of $C$, do the following: - Ignore the child if it is the same as
$D$, to not match the deriving element itself. - Check if the child’s name matches $P_i$. - If a match is found: 1.
Check if $P_{i+1}$ exists (i.e., there is a next element in the path). - If $P_{i+1}$ does not exist: - Verify if
the child has the same type as $D$ (e.g., both are registers): - If it does, the base element is found. Stop the
search. - If it does not, continue the algorithm (go to step 3). - If $P_{i+1}$ exists: - Increment $i$ (i.e.,
move to the next part of the path). - Set $C$ to the child element that matched $P_i$ and proceed to step 2 to continue
searching down the hierarchy.
-
Fallback search at the top level (peripherals): - If no match was found within the current scope, start searching
from the top-level container (referred to as peripherals
): - Set $C$ to the peripherals
container, which is the
container that holds all peripherals. - Set $i = 0$ (start over from the beginning of the path). - Repeat step 2 from
the peripherals
container: - Check if there is a child of $C$ that matches $P_i$. - Proceed with the same logic as in
step 2, following the path $P$.
-
Termination: - If the algorithm finds a match at any point, stop the search and return the base element. - If no
match is found after searching through both the local scope and the top-level container, conclude that the base element
could not be found.
In this chapter, we focus on test cases that validate the path resolving mechanism of derivedFrom
. Each test case
involves substituting the derivedFrom
path with multiple variations, and then testing whether the parser can correctly
process or reject each of these paths. Importantly, each test file is not a single test case; instead, each test file
contains exactly one derivedFrom
attribute, and multiple paths are tested against it. This approach allows us to
thoroughly validate path resolving in different scenarios using the same base SVD setup.
In the provided implementation examples, the pytest
parameterization feature is utilized to test these paths. Paths
that are expected to be valid and processable are not marked with pytest
's xmark, while paths that are expected to
raise errors are marked with pytest.mark.xfail
. Furthermore, test cases which are marked with pytest.mark.xfail
are
not processable with svdconv
, whereas the others can be processed with svdconv
if not statet otherwise.
test_test_setup_1
This test setup explores derivedFrom
path resolution within a single peripheral that contains nested
clusters. The setup verifies whether the parser can correctly resolve paths to registers located within
different levels of nested clusters. Additionally, it ensures that invalid paths are properly flagged as
errors.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue. This mimics
svdconv
's behavior.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"PeripheralA.ClusterA.ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ClusterA.ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralAA.ClusterA.ClusterB.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.ClusterAA.ClusterB.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.ClusterA.ClusterBB.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.ClusterA.ClusterB.RegisterAA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.ClusterB.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.ClusterA.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"ClusterB.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"ClusterA.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_1(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
This test setup explores `derivedFrom` path resolution within a single peripheral that contains nested
clusters. The setup verifies whether the parser can correctly resolve paths to registers located within
different levels of nested clusters. Additionally, it ensures that invalid paths are properly flagged as
errors.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue. This mimics
`svdconv`'s behavior.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_1.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 1
assert len(device.peripherals[0].registers_clusters) == 2
assert isinstance(device.peripherals[0].registers_clusters[0], Cluster)
assert device.peripherals[0].registers_clusters[0].name == "ClusterA"
assert len(device.peripherals[0].registers_clusters[0].registers_clusters) == 1
assert isinstance(device.peripherals[0].registers_clusters[0].registers_clusters[0], Cluster)
assert device.peripherals[0].registers_clusters[0].registers_clusters[0].name == "ClusterB"
assert len(device.peripherals[0].registers_clusters[0].registers_clusters[0].registers_clusters) == 1
registera = device.peripherals[0].registers_clusters[0].registers_clusters[0].registers_clusters[0]
assert isinstance(registera, Register)
assert registera.name == "RegisterA"
assert registera.address_offset == 0x0
assert registera.size == 32
assert len(registera.fields) == 1
assert registera.fields[0].name == "FieldA"
assert registera.fields[0].lsb == 0
assert registera.fields[0].msb == 0
assert isinstance(device.peripherals[0].registers_clusters[1], Register)
assert device.peripherals[0].registers_clusters[1].name == "RegisterB"
assert device.peripherals[0].registers_clusters[1].address_offset == 0x4
assert device.peripherals[0].registers_clusters[1].size == 32
assert len(device.peripherals[0].registers_clusters[1].fields) == 1
assert device.peripherals[0].registers_clusters[1].fields[0].name == "FieldA"
assert device.peripherals[0].registers_clusters[1].fields[0].lsb == 0
assert device.peripherals[0].registers_clusters[1].fields[0].msb == 0
|
SVD file: derivedfrom_path_resolving/test_setup_1.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_1</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<name>ClusterA</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<cluster>
<name>ClusterB</name>
<description>ClusterB description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldA</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</cluster>
</cluster>
<register derivedFrom="PATH">
<name>RegisterB</name>
<addressOffset>0x4</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_2
This test setup explores derivedFrom
path resolution within a single peripheral that contains nested
clusters and each element is named with the same name. Without the derivation, svdconv
would be able to
parse the file without any warnings or erros. However, svdconv
contains a known
bug, which prevents name
resolving, if a parent has the same name as the child. The setup verifies whether the parser can correctly
resolve paths to registers located within different levels of nested clusters, if they have the same names.
Additionally, it ensures that invalid paths are properly flagged as errors.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: no
Source code in tests/test_process/test_derived_from_path_resolving.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 | @pytest.mark.parametrize(
"path",
[
pytest.param( # can't be processed with svdconv
"SameA.SameA.SameA.SameA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param( # can't be processed with svdconv
"SameA.SameA.SameA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"SameA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"SameA.SameA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"SameA.SameA.SameA.SameA.SameA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_2(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
This test setup explores `derivedFrom` path resolution within a single peripheral that contains nested
clusters and each element is named with the same name. Without the derivation, `svdconv` would be able to
parse the file without any warnings or erros. However, `svdconv` contains a [known
bug](https://github.com/Open-CMSIS-Pack/devtools/issues/815#issuecomment-1495681319), which prevents name
resolving, if a parent has the same name as the child. The setup verifies whether the parser can correctly
resolve paths to registers located within different levels of nested clusters, if they have the same names.
Additionally, it ensures that invalid paths are properly flagged as errors.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** no
"""
file_name = "derivedfrom_path_resolving/test_setup_2.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 1
assert device.peripherals[0].name == "SameA"
assert len(device.peripherals[0].registers_clusters) == 2
assert isinstance(device.peripherals[0].registers_clusters[0], Cluster)
assert device.peripherals[0].registers_clusters[0].name == "SameA"
assert len(device.peripherals[0].registers_clusters[0].registers_clusters) == 1
assert isinstance(device.peripherals[0].registers_clusters[0].registers_clusters[0], Cluster)
assert device.peripherals[0].registers_clusters[0].registers_clusters[0].name == "SameA"
assert len(device.peripherals[0].registers_clusters[0].registers_clusters[0].registers_clusters) == 1
registera = device.peripherals[0].registers_clusters[0].registers_clusters[0].registers_clusters[0]
assert isinstance(registera, Register)
assert registera.name == "SameA"
assert registera.address_offset == 0x0
assert registera.size == 32
assert len(registera.fields) == 1
assert registera.fields[0].name == "SameA"
assert registera.fields[0].lsb == 0
assert registera.fields[0].msb == 0
assert isinstance(device.peripherals[0].registers_clusters[1], Register)
assert device.peripherals[0].registers_clusters[1].name == "RegisterB"
assert device.peripherals[0].registers_clusters[1].address_offset == 0x4
assert device.peripherals[0].registers_clusters[1].size == 32
assert len(device.peripherals[0].registers_clusters[1].fields) == 1
assert device.peripherals[0].registers_clusters[1].fields[0].name == "SameA"
assert device.peripherals[0].registers_clusters[1].fields[0].lsb == 0
assert device.peripherals[0].registers_clusters[1].fields[0].msb == 0
|
SVD file: derivedfrom_path_resolving/test_setup_2.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_2</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>SameA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<name>SameA</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<cluster>
<name>SameA</name>
<description>ClusterB description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>SameA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>SameA</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</cluster>
</cluster>
<register derivedFrom="PATH">
<name>RegisterB</name>
<addressOffset>0x4</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_3
In this test setup, the path ElementA.RegisterA
can be resolved in multiple valid ways. Depending on how the
algorithm is implemented, it could return RegisterA
located within the ElementA
peripheral or the
RegisterA
within PeripheralA
. Since the parser should implement the same algorithm as svdconv
, the
expected behavior is that RegisterA
within PeripheralA
is found. This is because the search process first
looks within the same scope, and if no match is found, it expands to all peripherals. Ultimately, RegisterB
should inherit from RegisterA
located in PeripheralA
, meaning it must include FieldB
instead of
FieldA
.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"ElementA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ElementA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_3(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
In this test setup, the path `ElementA.RegisterA` can be resolved in multiple valid ways. Depending on how the
algorithm is implemented, it could return `RegisterA` located within the `ElementA` peripheral or the
`RegisterA` within `PeripheralA`. Since the parser should implement the same algorithm as `svdconv`, the
expected behavior is that `RegisterA` within `PeripheralA` is found. This is because the search process first
looks within the same scope, and if no match is found, it expands to all peripherals. Ultimately, `RegisterB`
should inherit from `RegisterA` located in `PeripheralA`, meaning it must include `FieldB` instead of
`FieldA`.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_3.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 2
assert device.peripherals[1].name == "PeripheralA"
assert len(device.peripherals[1].registers_clusters) == 2
assert isinstance(device.peripherals[1].registers_clusters[1], Register)
assert device.peripherals[1].registers_clusters[1].name == "RegisterB"
assert len(device.peripherals[1].registers_clusters[1].fields) == 1
assert device.peripherals[1].registers_clusters[1].fields[0].name == "FieldB"
|
SVD file: derivedfrom_path_resolving/test_setup_3.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_3</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>ElementA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldA</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</registers>
</peripheral>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40002000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<name>ElementA</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldB</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</cluster>
<register derivedFrom="PATH">
<name>RegisterB</name>
<addressOffset>0x4</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_4
In this test setup, the path ElementA.RegisterA
can be resolved in multiple valid ways, similar to the
previous setup. However, this time there is an additional dim
configuration, which creates two clusters
ElementA
and ElementB
within PeripheralA
. Depending on how the algorithm is implemented, it could return
RegisterA
from either the ElementA
peripheral or of the ElementA
cluster within PeripheralA
. Since the
parser should follow the same resolution rules as svdconv
, the expected behavior is that RegisterA
within
PeripheralA
is found. The search should prioritize finding matches within the same scope first, and only
expand to all peripherals if no match is found. Ultimately, RegisterB
should inherit from RegisterA
within
PeripheralA
, and it must therefore include FieldB
instead of FieldA
.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"ElementA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ElementB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ElementA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_4(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
In this test setup, the path `ElementA.RegisterA` can be resolved in multiple valid ways, similar to the
previous setup. However, this time there is an additional `dim` configuration, which creates two clusters
`ElementA` and `ElementB` within `PeripheralA`. Depending on how the algorithm is implemented, it could return
`RegisterA` from either the `ElementA` peripheral or of the `ElementA` cluster within `PeripheralA`. Since the
parser should follow the same resolution rules as `svdconv`, the expected behavior is that `RegisterA` within
`PeripheralA` is found. The search should prioritize finding matches within the same scope first, and only
expand to all peripherals if no match is found. Ultimately, `RegisterB` should inherit from `RegisterA` within
`PeripheralA`, and it must therefore include `FieldB` instead of `FieldA`.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_4.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 2
assert device.peripherals[1].name == "PeripheralA"
assert len(device.peripherals[1].registers_clusters) == 3
assert isinstance(device.peripherals[1].registers_clusters[2], Register)
assert device.peripherals[1].registers_clusters[2].name == "RegisterB"
assert len(device.peripherals[1].registers_clusters[2].fields) == 1
assert device.peripherals[1].registers_clusters[2].fields[0].name == "FieldB"
|
SVD file: derivedfrom_path_resolving/test_setup_4.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_4</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>ElementA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldA</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</registers>
</peripheral>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40002000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<dim>2</dim>
<dimIncrement>0x4</dimIncrement>
<dimIndex>A,B</dimIndex>
<name>Element%s</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldB</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</cluster>
<register derivedFrom="PATH">
<name>RegisterB</name>
<addressOffset>0x8</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_5
Elements that use dim
can be referenced in two ways: either by their name before the dim
expansion (with
%s
within the name or [%s]
at the end) or by their resolved name after the dim
expansion. This test
setup examines both methods of referencing dim
-based elements. The test verifies whether the parser
correctly identifies paths using both the pre-expansion placeholder (Cluster%s
) and the fully expanded names
(ClusterA
, ClusterB
). Paths that correctly reference the target elements should be processed without
errors, while incorrect paths should trigger clear diagnostic messages. This setup ensures that the parser
handles dim
-expanded elements flexibly, similar to how svdconv
resolves these references.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"PeripheralA.Cluster%s.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralA.ClusterA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralA.ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_5(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
Elements that use `dim` can be referenced in two ways: either by their name before the `dim` expansion (with
`%s` within the name or `[%s]` at the end) or by their resolved name after the `dim` expansion. This test
setup examines both methods of referencing `dim`-based elements. The test verifies whether the parser
correctly identifies paths using both the pre-expansion placeholder (`Cluster%s`) and the fully expanded names
(`ClusterA`, `ClusterB`). Paths that correctly reference the target elements should be processed without
errors, while incorrect paths should trigger clear diagnostic messages. This setup ensures that the parser
handles `dim`-expanded elements flexibly, similar to how `svdconv` resolves these references.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_5.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 2
assert device.peripherals[1].name == "PeripheralB"
assert len(device.peripherals[1].registers_clusters) == 1
assert isinstance(device.peripherals[1].registers_clusters[0], Register)
assert device.peripherals[1].registers_clusters[0].name == "RegisterA"
assert len(device.peripherals[1].registers_clusters[0].fields) == 1
assert device.peripherals[1].registers_clusters[0].fields[0].name == "FieldA"
|
SVD file: derivedfrom_path_resolving/test_setup_5.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_5</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<dim>2</dim>
<dimIncrement>0x4</dimIncrement>
<dimIndex>A,B</dimIndex>
<name>Cluster%s</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldA</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
</field>
</fields>
</register>
</cluster>
</registers>
</peripheral>
<peripheral>
<name>PeripheralB</name>
<baseAddress>0x40002000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register derivedFrom="PATH">
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_6
This test setup examines how the parser handles resolving paths for enumerated values within nested clusters.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"PeripheralA.ClusterA.ClusterB.RegisterA.FieldA.FieldAEnumeratedValue",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ClusterA.ClusterB.RegisterA.FieldA.FieldAEnumeratedValue",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"ClusterB.RegisterA.FieldA.FieldAEnumeratedValue",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"RegisterA.FieldA.FieldAEnumeratedValue",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"FieldA.FieldAEnumeratedValue",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"FieldAEnumeratedValue",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_6(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
This test setup examines how the parser handles resolving paths for enumerated values within nested clusters.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_6.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 1
assert len(device.peripherals[0].registers_clusters) == 1
assert isinstance(device.peripherals[0].registers_clusters[0], Cluster)
assert device.peripherals[0].registers_clusters[0].name == "ClusterA"
assert len(device.peripherals[0].registers_clusters[0].registers_clusters) == 1
assert isinstance(device.peripherals[0].registers_clusters[0].registers_clusters[0], Cluster)
assert device.peripherals[0].registers_clusters[0].registers_clusters[0].name == "ClusterB"
assert len(device.peripherals[0].registers_clusters[0].registers_clusters[0].registers_clusters) == 1
registera = device.peripherals[0].registers_clusters[0].registers_clusters[0].registers_clusters[0]
assert isinstance(registera, Register)
assert registera.name == "RegisterA"
assert len(registera.fields) == 2
assert registera.fields[0].name == "FieldA"
assert len(registera.fields[0].enumerated_value_containers) == 1
assert registera.fields[0].enumerated_value_containers[0].name == "FieldAEnumeratedValue"
assert len(registera.fields[0].enumerated_value_containers[0].enumerated_values) == 2
assert registera.fields[1].name == "FieldB"
assert len(registera.fields[1].enumerated_value_containers) == 1
assert registera.fields[1].enumerated_value_containers[0].name == "FieldAEnumeratedValue"
assert len(registera.fields[1].enumerated_value_containers[0].enumerated_values) == 2
|
SVD file: derivedfrom_path_resolving/test_setup_6.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_6</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<name>ClusterA</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<cluster>
<name>ClusterB</name>
<description>ClusterB description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
<fields>
<field>
<name>FieldA</name>
<bitOffset>0</bitOffset>
<bitWidth>1</bitWidth>
<enumeratedValues>
<name>FieldAEnumeratedValue</name>
<usage>read-write</usage>
<enumeratedValue>
<name>0b0</name>
<description>Description for 0b0</description>
<value>0b0</value>
</enumeratedValue>
<enumeratedValue>
<name>0b1</name>
<description>Description for 0b1</description>
<value>0b1</value>
</enumeratedValue>
</enumeratedValues>
</field>
<field>
<name>FieldB</name>
<bitOffset>1</bitOffset>
<bitWidth>1</bitWidth>
<enumeratedValues derivedFrom="PATH">
</enumeratedValues>
</field>
</fields>
</register>
</cluster>
</cluster>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_7
This test setup focuses on how the parser resolves derivedFrom
paths when dealing with registers that have
alternateGroup
attributes. The alternateGroup
is used to group registers that can function as alternatives
to each other, and this test ensures that the parser correctly interprets and differentiates these alternate
groups during path resolution. In this setup, RegisterA
in PeripheralB
is marked with an alternateGroup
named RegisterX
, while the same-named register in PeripheralA
does not have this attribute. The goal is to
verify that when the parser encounters a path pointing to PeripheralB.RegisterA
, it can correctly identify
RegisterA
and handle the alternateGroup
reference. Paths that explicitly specify RegisterA_RegisterX
should resolve to PeripheralB.RegisterA
, reflecting its alternate group, while paths that point to
PeripheralA.RegisterA
should reference the original register without any alternate association. svdconv
can't resolve alternateGroup
paths, if they are named equal as a element outside of the alternate group. A
robust parser should be able to do so.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"PeripheralA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralC.RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralA.RegisterB",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
pytest.param(
"PeripheralB.RegisterB",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_7(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
This test setup focuses on how the parser resolves `derivedFrom` paths when dealing with registers that have
`alternateGroup` attributes. The `alternateGroup` is used to group registers that can function as alternatives
to each other, and this test ensures that the parser correctly interprets and differentiates these alternate
groups during path resolution. In this setup, `RegisterA` in `PeripheralB` is marked with an `alternateGroup`
named `RegisterX`, while the same-named register in `PeripheralA` does not have this attribute. The goal is to
verify that when the parser encounters a path pointing to `PeripheralB.RegisterA`, it can correctly identify
`RegisterA` and handle the `alternateGroup` reference. Paths that explicitly specify `RegisterA_RegisterX`
should resolve to `PeripheralB.RegisterA`, reflecting its alternate group, while paths that point to
`PeripheralA.RegisterA` should reference the original register without any alternate association. `svdconv`
can't resolve `alternateGroup` paths, if they are named equal as a element outside of the alternate group. A
robust parser should be able to do so.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_7.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 3
assert device.peripherals[2].name == "PeripheralC"
assert len(device.peripherals[2].registers_clusters) == 1
assert isinstance(device.peripherals[2].registers_clusters[0], Register)
assert device.peripherals[2].registers_clusters[0].name == "RegisterA"
assert device.peripherals[2].registers_clusters[0].description == "PeripheralA_RegisterA"
|
SVD file: derivedfrom_path_resolving/test_setup_7.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_7</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register>
<name>RegisterA</name>
<description>PeripheralA_RegisterA</description>
<addressOffset>0x0</addressOffset>
</register>
</registers>
</peripheral>
<peripheral derivedFrom="PeripheralA">
<name>PeripheralB</name>
<baseAddress>0x40002000</baseAddress>
<registers>
<register>
<name>RegisterA</name>
<description>PeripheralB_RegisterA</description>
<alternateGroup>RegisterX</alternateGroup>
<addressOffset>0x0</addressOffset>
</register>
</registers>
</peripheral>
<peripheral>
<name>PeripheralC</name>
<baseAddress>0x40003000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register derivedFrom="PATH">
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_8
This test setup examines how the parser resolves derivedFrom
references when inheritance cascades within
clusters, specifically focusing on paths that ultimately reference a register created through inheritance.
Here, RegisterA
is initially defined within ClusterA
. The second cluster, ClusterB
, inherits properties
from ClusterA
, effectively creating an inherited version of RegisterA
within ClusterB
. Thus, while
RegisterA
is not explicitly present in ClusterB
in the original SVD file, it becomes accessible there due
to inheritance.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"ClusterA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralA.ClusterA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralA.ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_8(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
This test setup examines how the parser resolves `derivedFrom` references when inheritance cascades within
clusters, specifically focusing on paths that ultimately reference a register created through inheritance.
Here, `RegisterA` is initially defined within `ClusterA`. The second cluster, `ClusterB`, inherits properties
from `ClusterA`, effectively creating an inherited version of `RegisterA` within `ClusterB`. Thus, while
`RegisterA` is not explicitly present in `ClusterB` in the original SVD file, it becomes accessible there due
to inheritance.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_8.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 1
assert len(device.peripherals[0].registers_clusters) == 3
assert device.peripherals[0].registers_clusters[2].name == "RegisterC"
assert device.peripherals[0].registers_clusters[2].address_offset == 0xC
assert device.peripherals[0].registers_clusters[2].size == 32
|
SVD file: derivedfrom_path_resolving/test_setup_8.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_8</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<cluster>
<name>ClusterA</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<addressOffset>0x0</addressOffset>
</register>
</cluster>
<cluster derivedFrom="ClusterA">
<name>ClusterB</name>
<description>ClusterB description</description>
<addressOffset>0x4</addressOffset>
<register>
<name>RegisterB</name>
<addressOffset>0x4</addressOffset>
</register>
</cluster>
<register derivedFrom="PATH">
<name>RegisterC</name>
<addressOffset>0xc</addressOffset>
</register>
</registers>
</peripheral>
</peripherals>
</device>
|
test_test_setup_9
Same as Test Setup 8, but with a forward reference.
Expected Outcome: Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
Processable with svdconv: partly
Source code in tests/test_process/test_derived_from_path_resolving.py
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647 | @pytest.mark.parametrize(
"path",
[
pytest.param(
"ClusterA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralA.ClusterA.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"PeripheralA.ClusterB.RegisterA",
marks=pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning"),
),
pytest.param(
"RegisterA",
marks=pytest.mark.xfail(strict=True, raises=ProcessException),
),
],
)
def test_test_setup_9(path: str, get_test_svd_file_content: Callable[[str], bytes]):
"""
Same as Test Setup 8, but with a forward reference.
**Expected Outcome:** Paths that correctly reference the target should be processed successfully. Invalid paths
should raise an error, and the parser should provide clear diagnostics indicating the issue.
**Processable with svdconv:** partly
"""
file_name = "derivedfrom_path_resolving/test_setup_9.svd"
file_content = get_test_svd_file_content(file_name)
file_content = file_content.replace(b"PATH", path.encode())
device = Process.from_xml_content(file_content).get_processed_device()
assert len(device.peripherals) == 1
assert len(device.peripherals[0].registers_clusters) == 3
assert device.peripherals[0].registers_clusters[2].name == "RegisterC"
assert device.peripherals[0].registers_clusters[2].description == "RegisterA description"
assert device.peripherals[0].registers_clusters[2].address_offset == 0xC
assert device.peripherals[0].registers_clusters[2].size == 32
|
SVD file: derivedfrom_path_resolving/test_setup_9.svd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 | <?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
<name>test_setup_9</name>
<version>1.0</version>
<description>Test_Example device</description>
<cpu>
<name>CM0</name>
<revision>r0p0</revision>
<endian>little</endian>
<mpuPresent>false</mpuPresent>
<fpuPresent>false</fpuPresent>
<nvicPrioBits>4</nvicPrioBits>
<vendorSystickConfig>false</vendorSystickConfig>
</cpu>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<peripherals>
<peripheral>
<name>PeripheralA</name>
<baseAddress>0x40001000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x1000</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register derivedFrom="PATH">
<name>RegisterC</name>
<addressOffset>0xc</addressOffset>
</register>
<cluster>
<name>ClusterA</name>
<description>ClusterA description</description>
<addressOffset>0x0</addressOffset>
<register>
<name>RegisterA</name>
<description>RegisterA description</description>
<addressOffset>0x0</addressOffset>
</register>
</cluster>
<cluster derivedFrom="ClusterA">
<name>ClusterB</name>
<description>ClusterB description</description>
<addressOffset>0x4</addressOffset>
<register>
<name>RegisterB</name>
<addressOffset>0x4</addressOffset>
</register>
</cluster>
</registers>
</peripheral>
</peripherals>
</device>
|