Skip to content

Commit 89158ca

Browse files
authored
Merge pull request #201 from krcb197/200-sparse-enumeration-generates-excessive-test-time
Fix sparse enumeration generates excessive test time
2 parents 29c5ea7 + 348f1aa commit 89158ca

3 files changed

Lines changed: 64 additions & 10 deletions

File tree

src/peakrdl_python/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
1818
Variables that describes the peakrdl-python Package
1919
"""
20-
__version__ = "1.2.1rc3"
20+
__version__ = "1.2.1rc4"

src/peakrdl_python/templates/addrmap_tb.py.jinja

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class {{fq_block_name}}_single_access({{top_node.inst_name}}_TestCase): # type:
467467

468468
{% if asyncoutput %}await {%endif %}self.dut.{{'.'.join(get_python_path_segments(node))}}.write(field_value) # type: ignore[union-attr]
469469

470-
{% if (((node.high+1) - node.low) < (node.parent.size*8)) and (node.parent.has_sw_readable) %}
470+
{% if (node.width < (node.parent.size*8)) and (node.parent.has_sw_readable) %}
471471
read_callback_mock.assert_called_once_with(
472472
addr={{node.parent.absolute_address}},
473473
width={{node.parent.size * 8}},
@@ -556,14 +556,17 @@ class {{fq_block_name}}_single_access({{top_node.inst_name}}_TestCase): # type:
556556
accesswidth=self.dut.{{'.'.join(get_python_path_segments(node))}}.parent_register.accesswidth) # type: ignore[union-attr]
557557
{% endfor %}
558558

559-
{% if node.get_property('encode').__len__() < (2**((node.high+1) - node.low)) %}
560-
# check that other values of the field int
561-
# that don't appear in the enum generate an
562-
# error
563-
for field_value in range(0, {{get_field_max_value_hex_string(node)}}+1):
564-
if field_value in [{%- for value_of_enum_needed in node.get_property('encode') -%}{{value_of_enum_needed.value}}{% if not loop.last %}, {% endif %}{%- endfor %}]:
565-
# legal int value of the eunm so no test is needed
566-
continue
559+
{# only run this if there are field values that are not part of the enum #}
560+
{% if node.get_property('encode').__len__() < (2**node.width) %}
561+
# check that other values of the field int that don't appear in the enum generate
562+
# an error
563+
{% if node.width <= 8 %}
564+
{# for enumerated fields of up to 8 bit all combinations can be exhaustively tested #}
565+
for field_value in set(range({{get_field_max_value_hex_string(node)}}+1)) - { {%- for value_of_enum_needed in node.get_property('encode') -%}{{value_of_enum_needed.value}}{% if not loop.last %}, {% endif %}{%- endfor %} }:
566+
{% else %}
567+
{# for enumerated fields of with larger sizes look for up to 100 illegal values #}
568+
for field_value in { random.randint(0, {{get_field_max_value_hex_string(node)}}+1) for _ in range(100) } - { {%- for value_of_enum_needed in node.get_property('encode') -%}{{value_of_enum_needed.value}}{% if not loop.last %}, {% endif %}{%- endfor %} }:
569+
{% endif %}
567570
with self.assertRaises(ValueError):
568571
read_callback_mock.reset_mock()
569572
random_reg_value = random.randrange(0, {{get_reg_max_value_hex_string(node.parent)}} + 1)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Testcase for a spare enumeration that caused an issue for excessive test times
3+
*/
4+
5+
enum block_validity {
6+
erased = 0xFFFF_FFFF { name = "Erased"; };
7+
invalid = 0x0 { name = "Invalid"; };
8+
valid = 0xDEAD_BEEF { name = "Valid"; };
9+
};
10+
11+
enum block_validity_short {
12+
erased = 0x7F { name = "Erased"; };
13+
invalid = 0x0 { name = "Invalid"; };
14+
valid = 0x5A { name = "Valid"; };
15+
};
16+
17+
enum block_validity_very_short {
18+
erased = 0x7 { name = "Erased"; };
19+
invalid = 0x0 { name = "Invalid"; };
20+
valid = 0x5 { name = "Valid"; };
21+
};
22+
23+
addrmap sparse_enum_issue_200 {
24+
25+
reg {
26+
default sw = rw;
27+
regwidth = 128;
28+
field { encode = block_validity; sw=rw; fieldwidth=32; } valid_rw;
29+
field { encode = block_validity; sw=r; fieldwidth=32; } valid_r;
30+
field { encode = block_validity; sw=w; fieldwidth=32; } valid_w;
31+
field { encode = block_validity_short; sw=rw; fieldwidth=7; } valid_short_rw;
32+
field { encode = block_validity_short; sw=r; fieldwidth=7; } valid_short_r;
33+
field { encode = block_validity_short; sw=w; fieldwidth=7; } valid_short_w;
34+
field { encode = block_validity_very_short; sw=rw; fieldwidth=3; } valid_very_short_rw;
35+
field { encode = block_validity_very_short; sw=r; fieldwidth=3; } valid_very_short_r;
36+
field { encode = block_validity_very_short; sw=w; fieldwidth=3; } valid_very_short_w;
37+
} block_valid_rw;
38+
39+
reg {
40+
default sw = r;
41+
regwidth = 128;
42+
field { encode = block_validity; sw=r; fieldwidth=32; } valid_r;
43+
} block_valid_r;
44+
45+
reg {
46+
default sw = w;
47+
regwidth = 128;
48+
field { encode = block_validity; sw=w; fieldwidth=32; } valid_w;
49+
} block_valid_w;
50+
51+
};

0 commit comments

Comments
 (0)