File: test_05_base_classes.py

package info (click to toggle)
pyuvm 4.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 992 kB
  • sloc: python: 8,662; makefile: 238; vhdl: 206; sh: 7
file content (287 lines) | stat: -rw-r--r-- 6,281 bytes parent folder | download
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
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
164
165
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
246
247
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
import copy

import pytest

from pyuvm import *

pytestmark = pytest.mark.usefixtures("initialize_pyuvm")


class my_object(uvm_object):
    def __init__(self, name=""):
        super().__init__(name)
        self.val = 5

    def __eq__(self, other):
        if type(other) is type(self):
            return self.val == other.val

    __hash__: None  # type: ignore[assignment]

    def __str__(self):
        return "Hello"

    def do_copy(self, other):
        self.val = other.val


def test_basic_creation():
    """
    15.3
    Tests whether the factory gets populated and whether it can be used.
    """
    uvf = uvm_factory()
    mof = uvf.fd.classes["my_object"]("factory")
    moi = my_object("name")
    assert type(mof) is type(moi)


# Testing specification


def test_seeding():
    """
    5.3.3.1 get_uvm_seeding
    5.3.3.2 set_uvm_seeding
    5.3.3.3 reseed
    """
    mo = my_object("mo")
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.get_uvm_seeding()
    with pytest.raises(error_classes.UVMNotImplemented):
        _ = mo.set_uvm_seeding(1)
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.reseed()


def test_identification():
    """
    5.3.4
    :return:
    """
    nameless = my_object()
    assert len(nameless.get_name()) == 0
    moe = my_object("moe")
    # 5.3.4.2
    name = moe.get_name()
    assert "moe" == name
    # 5.3.4.1
    moe.set_name("curly")
    name = moe.get_name()
    assert "curly" == name
    moe.set_name("larry")
    # 5.3.4.3
    name = moe.get_full_name()
    assert "larry" == name
    # 5.3.4.4
    moe_id = moe.get_inst_id()
    assert id(moe) == moe_id
    # 5.3.4.5 not implemented
    with pytest.raises(error_classes.UsePythonMethod):
        moe.get_type()
    # 5.3.4.6 not implemented
    with pytest.raises(error_classes.UsePythonMethod):
        moe.get_object_type()
    # 5.3.4.7
    assert "my_object" == moe.get_type_name()


def test_creation():
    """
    5.3.5
    :return:
    """
    mo = my_object("mo")
    # 5.3.5.1
    new_mo = mo.create("new_mo")
    assert "new_mo" == new_mo.get_name()
    assert type(new_mo) is type(mo)
    # 5.3.5.2
    mo.val = 5
    cln_mo = copy.deepcopy(mo)
    assert mo.__eq__(cln_mo)


def test_printing():
    """
    5.3.6
    :return:
    """
    mo = my_object("mo")
    # 5.3.6.1
    with pytest.raises(error_classes.UsePythonMethod):
        mo.print()
    # 5.3.6.2
    with pytest.raises(error_classes.UsePythonMethod):
        mo.sprint()
    assert "Hello" == mo.convert2string()


def test_recording():
    """
    5.3.7
    :return:
    """
    mo = my_object("mo")
    # 5.3.7.1
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.record()
    # 5.3.7.2
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.do_record()


def test_copying():
    """
    5.3.8
    :return:
    """
    mo = my_object("mo")
    rhs = my_object("rhs")
    # 5.3.8.1
    mo.copy(rhs)
    # 5.3.8.2
    assert mo.val == rhs.val


def test_comparing():
    """
    5.3.9
    :return:
    """
    mo = my_object("mo")
    rhs = my_object("rhs")
    # 5.3.9.1
    assert mo.compare(rhs)
    # 5.3.9.2
    assert mo.do_compare(rhs)


def test_packing():
    """
    5.3.10
    :return:
    """
    mo = my_object("mo")
    # 5.3.10.1
    with pytest.raises(error_classes.UsePythonMethod):
        mo.pack()
    with pytest.raises(error_classes.UsePythonMethod):
        mo.pack_bytes()
    with pytest.raises(error_classes.UsePythonMethod):
        mo.pack_ints()
    with pytest.raises(error_classes.UsePythonMethod):
        mo.pack_longints()
    # 5.3.10.2
    with pytest.raises(error_classes.UsePythonMethod):
        mo.do_pack()


def test_unpacking():
    """
    5.3.11
    :return:
    """
    mo = my_object("mo")
    # 5.3.10.1
    with pytest.raises(error_classes.UsePythonMethod):
        mo.unpack()
    with pytest.raises(error_classes.UsePythonMethod):
        mo.unpack_bytes()
    with pytest.raises(error_classes.UsePythonMethod):
        mo.unpack_ints()
    with pytest.raises(error_classes.UsePythonMethod):
        mo.unpack_longints()
    # 5.3.11.2

    with pytest.raises(error_classes.UsePythonMethod):
        mo.do_unpack()


def test_configuration():
    """
    5.3.12
    :return:
    """
    mo = my_object("mo")
    # 5.3.12.1
    with pytest.raises(error_classes.UsePythonMethod):
        mo.set_local()


def test_field_operations():
    """
    5.3.13
    :return:
    """
    mo = my_object("mo")
    with pytest.raises(error_classes.UsePythonMethod):
        mo.do_execute_op(None)


def test_active_policy():
    """
    5.3.14
    :return:
    """
    mo = my_object("mo")
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.push_active_policy()
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.pop_active_policy()
    with pytest.raises(error_classes.UVMNotImplemented):
        mo.get_active_policy()


def test_create():
    """
    5.3.5 This needs to be further implemented to include the factory
    """
    mo = my_object("first")
    mo2 = mo.create("second")
    assert mo == mo2


def test_uvm_transaction_creation():
    """
    5.4.2.1
    5.4.2.14
    5.4.2.15
    :return:
    """
    tr = uvm_transaction()
    assert 0 == len(tr.get_name())
    assert not tr.get_initiator()
    uc = uvm_component("uc", None)
    tr.set_initiator(uc)
    assert uc == tr.get_initiator()


def test_transaction_recording():
    """
    5.4.2 all methods
    :return:
    """
    tr = uvm_transaction()
    with pytest.raises(error_classes.UVMNotImplemented):
        tr.get_tr_handle()
    with pytest.raises(error_classes.UVMNotImplemented):
        tr.enable_recording()
    with pytest.raises(error_classes.UVMNotImplemented):
        tr.disable_recording()
    with pytest.raises(error_classes.UVMNotImplemented):
        tr.is_recording_enabled()
    with pytest.raises(error_classes.UVMNotImplemented):
        tr.is_active()
    with pytest.raises(error_classes.UVMNotImplemented):
        tr.get_event_pool()
    tr.get_accept_time()
    tr.get_begin_time()
    tr.get_end_time()


def test_clone():
    orig = my_object("orig")
    clone = orig.clone()
    assert id(orig) != id(clone)
    assert orig.val == clone.val