Skip to content

rw_test

Read Write Test.

Functions:

  • rw_test

    Performs read-write tests using random or default values.

  • rw_test_base

    Base function to perform read-write tests on a given register.

  • walking_ones_test

    Performs walking ones test on the registers.

  • walking_zeros_test

    Performs walking zeros test on the registers.

rw_test async

rw_test(
    RAL,
    foreground_write=True,
    foreground_read=True,
    count=10,
    default_value=None,
    verbose=False,
)

Performs read-write tests using random or default values.

Parameters:

  • RAL (RAL_Test) –

    Instance of RAL model generated using peakrdl_cocotb_ralgen.

  • foreground_write (bool, default: True ) –

    If True, use foreground write; otherwise, use background write.

  • foreground_read (bool, default: True ) –

    If True, use foreground read; otherwise, use background read.

  • count (int, default: 10 ) –

    Number of read-write operations to perform per register.

  • default_value (int, default: None ) –

    If provided, this value is used for writes; otherwise, random values are used.

  • verbose (bool, default: False ) –

    If True, logs the results of each operation.

Source code in src/peakrdl_cocotb_ralgen/testcases/rw_test.py
 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
async def rw_test(
    RAL,
    foreground_write=True,
    foreground_read=True,
    count=10,
    default_value=None,
    verbose=False,
):
    """Performs read-write tests using random or default values.

    Params:
        RAL (RAL_Test): Instance of RAL model generated using peakrdl_cocotb_ralgen.
        foreground_write (bool): If True, use foreground write; otherwise, use background write.
        foreground_read (bool): If True, use foreground read; otherwise, use background read.
        count (int): Number of read-write operations to perform per register.
        default_value (int): If provided, this value is used for writes; otherwise, random values are used.
        verbose (bool): If True, logs the results of each operation.
    """
    test_type = "RW"
    for key, reg in RAL.masks.items():
        if "rw" in reg["disable"]:
            continue

        for _ in range(count):
            wrval = (
                default_value
                if default_value is not None
                else random.randint(0, 2 ** reg["regwidth"])
            )
            await rw_test_base(
                RAL,
                key,
                reg,
                wrval,
                foreground_write,
                foreground_read,
                test_type,
                verbose,
            )

rw_test_base async

rw_test_base(
    RAL: Any,
    key: str,
    reg: dict,
    wrval: int,
    foreground_write: bool,
    foreground_read: bool,
    test_type: str,
    verbose: bool,
)

Base function to perform read-write tests on a given register.

Parameters:

  • RAL (Any) –

    The RAL instance, required for background operations.

  • key (str) –

    Key or identifier for the register.

  • reg (dict) –

    Register metadata containing width and masks.

  • wrval (int) –

    The value to write to the register.

  • foreground_write (bool) –

    If True, use foreground write; otherwise, use background write.

  • foreground_read (bool) –

    If True, use foreground read; otherwise, use background read.

  • test_type (str) –

    The test type which calls the base function.

  • verbose (bool) –

    If True, logs the read-write results.

Raises:

  • AssertionError

    If the actual value read does not match the expected value.

Source code in src/peakrdl_cocotb_ralgen/testcases/rw_test.py
 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
async def rw_test_base(
    RAL: Any,
    key: str,
    reg: dict,
    wrval: int,
    foreground_write: bool,
    foreground_read: bool,
    test_type: str,
    verbose: bool,
):
    """Base function to perform read-write tests on a given register.

    Params:
        RAL: The RAL instance, required for background operations.
        key (str): Key or identifier for the register.
        reg (dict): Register metadata containing width and masks.
        wrval (int): The value to write to the register.
        foreground_write (bool): If True, use foreground write; otherwise, use background write.
        foreground_read (bool): If True, use foreground read; otherwise, use background read.
        test_type (str): The test type which calls the base function.
        verbose (bool): If True, logs the read-write results.

    Raises:
        AssertionError: If the actual value read does not match the expected value.
    """
    r = RAL.ifc
    addr = reg["address"]
    donttest = reg["donttest"]
    wmask = reg["write_mask"]
    rmask = reg["read_mask"]

    expected = wrval & ~donttest & wmask & rmask

    if foreground_write:
        await r.write(addr, reg["width"], reg["width"], wrval)
    else:
        for sighash in reg["signals"]:
            RAL.background.write(
                sighash,
                (wrval >> sighash["low"])
                & int("1" * (sighash["high"] - sighash["low"] + 1), 2),
            )

    if foreground_read:
        rv = await r.read(addr, reg["width"], reg["width"])
    else:
        rv = 0
        for sighash in reg["signals"]:
            rv |= RAL.background.read(sighash) << sighash["low"]

    actual = rv & ~donttest & wmask

    assert (
        actual == expected
    ), f"{key}:: Read Write Written {wrval:x}, actual(Read) {actual:x}, Expected {expected:x}, wrMask {wmask:x}, rdmask {rmask:x}, donttest = {donttest:x}"

    if verbose:
        logger.info(
            f"Test {test_type}: {key} wval {wrval:x} rv {rv:x} expected {expected:x} actual {actual:x}",
        )

walking_ones_test async

walking_ones_test(
    RAL,
    foreground_write=True,
    foreground_read=True,
    verbose=False,
)

Performs walking ones test on the registers.

Parameters:

  • RAL (RAL_Test) –

    Instance of RAL model generated using peakrdl_cocotb_ralgen.

  • verbose (bool, default: False ) –

    If True, logs the results of each operation.

  • foreground_write (bool, default: True ) –

    If True, use foreground write; otherwise, use background write.

  • foreground_read (bool, default: True ) –

    If True, use foreground read; otherwise, use background read.

Source code in src/peakrdl_cocotb_ralgen/testcases/rw_test.py
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
async def walking_ones_test(
    RAL,
    foreground_write=True,
    foreground_read=True,
    verbose=False,
):
    """Performs walking ones test on the registers.

    Params:
        RAL (RAL_Test): Instance of RAL model generated using peakrdl_cocotb_ralgen.
        verbose (bool): If True, logs the results of each operation.
        foreground_write (bool): If True, use foreground write; otherwise, use background write.
        foreground_read (bool): If True, use foreground read; otherwise, use background read.
    """
    test_type = "Walking Ones"
    for key, reg in RAL.masks.items():
        if "rw" in reg["disable"]:
            continue

        reg_width = reg["regwidth"]

        for bit in range(reg_width):
            wrval = 1 << bit
            await rw_test_base(
                RAL,
                key,
                reg,
                wrval,
                foreground_write,
                foreground_read,
                test_type,
                verbose,
            )

walking_zeros_test async

walking_zeros_test(
    RAL,
    foreground_write=True,
    foreground_read=True,
    verbose=False,
)

Performs walking zeros test on the registers.

Parameters:

  • RAL (RAL_Test) –

    Instance of RAL model generated using peakrdl_cocotb_ralgen.

  • verbose (bool, default: False ) –

    If True, logs the results of each operation.

  • foreground_write (bool, default: True ) –

    If True, use foreground write; otherwise, use background write.

  • foreground_read (bool, default: True ) –

    If True, use foreground read; otherwise, use background read.

Source code in src/peakrdl_cocotb_ralgen/testcases/rw_test.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
async def walking_zeros_test(
    RAL,
    foreground_write=True,
    foreground_read=True,
    verbose=False,
):
    """Performs walking zeros test on the registers.

    Params:
        RAL (RAL_Test): Instance of RAL model generated using peakrdl_cocotb_ralgen.
        verbose (bool): If True, logs the results of each operation.
        foreground_write (bool): If True, use foreground write; otherwise, use background write.
        foreground_read (bool): If True, use foreground read; otherwise, use background read.
    """
    test_type = "Walking Zeros"
    for key, reg in RAL.masks.items():
        if "rw" in reg["disable"]:
            continue

        reg_width = reg["regwidth"]

        for bit in range(reg_width):
            wrval = ~(1 << bit) & (2 ** reg["regwidth"] - 1)
            await rw_test_base(
                RAL,
                key,
                reg,
                wrval,
                foreground_write,
                foreground_read,
                test_type,
                verbose,
            )