Skip to content

test_application_of_default_values

This feature includes tests that verify the parser correctly applies default values to properties not explicitly defined in the SVD file. It ensures the parser adheres to the SVD standard by assigning the appropriate predefined defaults.

test_custom_register_properties_on_device_level

This test ensures that the default values are overwritten if custom values are specified in a processed SVD file on device level.

Expected Outcome: The device is processed correctly, with custom register properties specified at the device level overriding the default values. The register size is set to 16 bits, the access type is WRITE_ONLY, the protection type is SECURE, the reset value is 0xDEADBEEF, and the reset mask is 0xDEADC0DE.

Processable with svdconv: yes

Source code in tests/test_process/test_application_of_default_values.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning")
def test_custom_register_properties_on_device_level(get_processed_device_from_testfile: Callable[[str], Device]):
    """
    This test ensures that the default values are overwritten if custom values are specified in a processed SVD
    file on device level.

    **Expected Outcome:** The device is processed correctly, with custom register properties specified at the device
    level overriding the default values. The register size is set to 16 bits, the access type is `WRITE_ONLY`, the
    protection type is `SECURE`, the reset value is `0xDEADBEEF`, and the reset mask is `0xDEADC0DE`.

    **Processable with svdconv:** yes
    """

    device = get_processed_device_from_testfile(
        "application_of_default_values/custom_register_properties_on_device_level.svd"
    )

    assert device.size == 16
    assert device.access == AccessType.WRITE_ONLY
    assert device.protection == ProtectionStringType.SECURE
    assert device.reset_value == 0xDEADBEEF
    assert device.reset_mask == 0xDEADC0DE
SVD file: application_of_default_values/custom_register_properties_on_device_level.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
<?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>custom_register_properties_on_device_level</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>
  <size>16</size>
  <access>write-only</access>
  <protection>s</protection>
  <resetValue>0xDEADBEEF</resetValue>
  <resetMask>0xDEADC0DE</resetMask>
  <peripherals>
    <peripheral>
      <name>PeripheralA</name>
      <version>1.0</version>
      <baseAddress>0x40001000</baseAddress>
      <addressBlock>
        <offset>0x0</offset>
        <size>0x1000</size>
        <usage>registers</usage>
      </addressBlock>
      <registers>
        <register>
          <name>RegisterA</name>
          <addressOffset>0x0</addressOffset>
        </register>
      </registers>
    </peripheral>
  </peripherals>
</device>

test_default_register_properties_on_device_level

Although not stated in the SVD specification, svdconv assigns default values to size (32), access (read- write), resetValue (0x0), and resetMask (0xFFFFFFFF). This test ensures that the default values are set if they are not specified in a processed SVD file.

Expected Outcome: The device is processed correctly, with default register properties applied at the device level. The register size is set to 32 bits, the access type is READ_WRITE, the protection type is ANY, the reset value is 0x0, and the reset mask is 0xFFFFFFFF.

Processable with svdconv: yes

Source code in tests/test_process/test_application_of_default_values.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@pytest.mark.filterwarnings("error::svdsuite.process.ProcessWarning")
def test_default_register_properties_on_device_level(get_processed_device_from_testfile: Callable[[str], Device]):
    """
    Although not stated in the SVD specification, `svdconv` assigns default values to size (32), access (read-
    write), resetValue (0x0), and resetMask (0xFFFFFFFF). This test ensures that the default values are set if
    they are not specified in a processed SVD file.

    **Expected Outcome:** The device is processed correctly, with default register properties applied at the device
    level. The register size is set to 32 bits, the access type is `READ_WRITE`, the protection type is `ANY`, the
    reset value is `0x0`, and the reset mask is `0xFFFFFFFF`.

    **Processable with svdconv:** yes
    """

    device = get_processed_device_from_testfile(
        "application_of_default_values/default_register_properties_on_device_level.svd"
    )

    assert device.size == 32
    assert device.access == AccessType.READ_WRITE
    assert device.protection == ProtectionStringType.ANY
    assert device.reset_value == 0x0
    assert device.reset_mask == 0xFFFFFFFF
SVD file: application_of_default_values/default_register_properties_on_device_level.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
<?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>default_register_properties_on_device_level</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>
      <version>1.0</version>
      <baseAddress>0x40001000</baseAddress>
      <addressBlock>
        <offset>0x0</offset>
        <size>0x1000</size>
        <usage>registers</usage>
      </addressBlock>
      <registers>
        <register>
          <name>RegisterA</name>
          <addressOffset>0x0</addressOffset>
        </register>
      </registers>
    </peripheral>
  </peripherals>
</device>