forked from UCSBarchlab/PyRTL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wire.py
More file actions
615 lines (508 loc) · 21.9 KB
/
test_wire.py
File metadata and controls
615 lines (508 loc) · 21.9 KB
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
288
289
290
291
292
293
294
295
296
297
298
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
353
354
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
407
408
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
477
478
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
542
543
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
import unittest
import pyrtl
from pyrtl import wire
class TestWireVector(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def test_wirevector_length(self):
x = pyrtl.WireVector(1)
y = pyrtl.WireVector(13)
self.assertEqual(len(x), 1)
self.assertEqual(len(y), 13)
def test_basic_assignment(self):
x = pyrtl.WireVector(1)
y = pyrtl.WireVector(1)
y <<= x
def test_unset_bitwidth(self):
x = pyrtl.Input()
y = pyrtl.WireVector(1)
with self.assertRaises(pyrtl.PyrtlError):
y <<= x
def test_assign_to_value(self):
x = pyrtl.WireVector(1)
y = 1337
with self.assertRaises(TypeError):
y <<= x
def test_zero_extend(self):
pass
def test_sign_extend(self):
pass
def test_truncating(self):
pass
def test_rename(self):
block = pyrtl.working_block()
w = pyrtl.WireVector(1, "test1")
self.assertIn("test1", block.wirevector_by_name)
self.assertIn(w, block.wirevector_set)
w.name = "testJohn"
self.assertNotIn("test1", block.wirevector_by_name)
self.assertIn("testJohn", block.wirevector_by_name)
self.assertIn(w, block.wirevector_set)
class TestWireVectorNames(unittest.TestCase):
def is_valid_str(self, s):
return wire.next_tempvar_name(s) == s
def test_invalid_name(self):
self.assertFalse(self.is_valid_str(''))
with self.assertRaises(pyrtl.PyrtlError):
self.is_valid_str('clock')
def test_valid_names(self):
self.assertTrue(self.is_valid_str('xxx'))
self.assertTrue(self.is_valid_str('h'))
self.assertTrue(self.is_valid_str(' '))
self.assertTrue(self.is_valid_str('#$)(*&#@_+!#)('))
def check_name_setter(self, ns):
"""test name setter in wire.py.
Keyword arguments:
ns -- new name of WireVector to be set
"""
test = pyrtl.WireVector(1, 'test')
test.name = ns
self.assertTrue(test.name == ns)
def test_invalid_name_setter(self):
"""test invalid name data types and expect PyrtlError."""
with self.assertRaises(pyrtl.PyrtlError):
self.check_name_setter(24)
with self.assertRaises(pyrtl.PyrtlError):
self.check_name_setter(True)
with self.assertRaises(pyrtl.PyrtlError):
self.check_name_setter(3.14)
def test_valid_name_setter(self):
"""test string names and expect no error."""
self.check_name_setter('24')
self.check_name_setter(str(24))
self.check_name_setter('twenty_four')
class TestWireVectorFail(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def test_undef_wirevector_length(self):
x = pyrtl.WireVector()
with self.assertRaises(pyrtl.PyrtlError):
y = len(x)
def test_bad_bitwidth(self):
with self.assertRaises(pyrtl.PyrtlError):
x = pyrtl.WireVector(bitwidth='happy')
with self.assertRaises(pyrtl.PyrtlError):
x = pyrtl.WireVector(bitwidth=-1)
with self.assertRaises(pyrtl.PyrtlError):
x = pyrtl.WireVector(bitwidth=0)
y = pyrtl.WireVector(1)
with self.assertRaises(pyrtl.PyrtlError):
x = pyrtl.WireVector(y)
def test_no_immed_operators(self):
x = pyrtl.WireVector(bitwidth=3)
with self.assertRaises(pyrtl.PyrtlError):
x &= 2
with self.assertRaises(pyrtl.PyrtlError):
x ^= 2
with self.assertRaises(pyrtl.PyrtlError):
x += 2
with self.assertRaises(pyrtl.PyrtlError):
x -= 2
with self.assertRaises(pyrtl.PyrtlError):
x *= 2
def test_sign_and_zero_extend_only_increase_bitwidth(self):
x = pyrtl.WireVector(bitwidth=3)
with self.assertRaises(pyrtl.PyrtlError):
x.zero_extended(2)
def test_truncate_only_reduces_bitwidth(self):
x = pyrtl.WireVector(bitwidth=3)
with self.assertRaises(pyrtl.PyrtlError):
x.truncate(5)
def test_truncate_only_takes_integers(self):
x = pyrtl.WireVector(bitwidth=3)
y = pyrtl.WireVector(bitwidth=3)
with self.assertRaises(pyrtl.PyrtlError):
x.truncate(y)
class TestWirevectorSlicing(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def invalid_empty_slice(self, bitwidth, slice):
w = pyrtl.Input(bitwidth)
with self.assertRaises(pyrtl.PyrtlError):
x = w[slice]
def invalid_slice_index(self, bitwidth, slice):
w = pyrtl.Input(bitwidth)
with self.assertRaises(IndexError):
x = w[slice]
def valid_slice(self, bitwidth, slice):
w = pyrtl.Input(bitwidth)
x = w[slice]
def test_wire_wo_bitwidth_fails(self):
w = pyrtl.WireVector()
with self.assertRaises(pyrtl.PyrtlError):
x = w[2]
with self.assertRaises(pyrtl.PyrtlError):
x = w[3:5]
def test_valid_indicies(self):
self.valid_slice(4, 2)
self.valid_slice(4, 0)
self.valid_slice(4, -1)
pyrtl.working_block().sanity_check()
def test_valid_slices(self):
self.valid_slice(8, slice(6))
self.valid_slice(8, slice(1, 4))
self.valid_slice(8, slice(1, 8)) # Yes, supplying a end index out of bounds is valid python
self.valid_slice(8, slice(1, 2, 2))
self.valid_slice(8, slice(1, 4, 2))
self.valid_slice(8, slice(7, 1, -2))
self.valid_slice(8, slice(-2))
self.valid_slice(8, slice(-6, -2, 3))
pyrtl.working_block().sanity_check()
def test_invalid_indicies(self):
self.invalid_slice_index(4, 5)
self.invalid_slice_index(4, -5)
def test_invalid_slices(self):
self.invalid_empty_slice(8, slice(1, 1))
self.invalid_empty_slice(8, slice(7, 1))
self.invalid_empty_slice(8, slice(-1, 1, 2))
class TestInput(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def test_no_connection_to_inputs(self):
x = pyrtl.WireVector(1)
y = pyrtl.Input(1)
with self.assertRaises(pyrtl.PyrtlError):
y <<= x
class TestRegister(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
self.r = pyrtl.Register(bitwidth=3)
def test_connection_small(self):
self.r.next <<= pyrtl.Const(1, bitwidth=3)
def test_connection_unspec_width(self):
self.r.next <<= pyrtl.Const(1)
def test_connection_raw(self):
self.r.next <<= 1
def test_connection_large(self):
self.r.next <<= pyrtl.Const(202)
def test_register_assignment(self):
with self.assertRaises(pyrtl.PyrtlError):
self.r.next = 1
def test_logic_operations(self):
with self.assertRaises(pyrtl.PyrtlError):
a = (self.r or True)
def test_register_assignment_not_next(self):
with self.assertRaises(pyrtl.PyrtlError):
self.r <<= 1
@unittest.skip("I don't think this is fixable")
def test_assign_next(self):
# I really don't know how we can fix this - John
w = pyrtl.WireVector(bitwidth=1)
with self.assertRaises(pyrtl.PyrtlError):
a = self.r.next
def test_connect_next(self):
w = pyrtl.WireVector(bitwidth=1)
with self.assertRaises(pyrtl.PyrtlError):
w <<= self.r.next
def test_next_logic_operations(self):
with self.assertRaises(pyrtl.PyrtlError):
a = (self.r.next or True)
def test_reset_value_is_none(self):
self.assertIsNone(self.r.reset_value)
def test_reset_value_is_correct(self):
r = pyrtl.Register(4, reset_value=1)
self.assertEqual(r.reset_value, 1)
def test_reset_value_as_string(self):
r = pyrtl.Register(4, reset_value="2'd1")
self.assertEqual(r.reset_value, 1)
def test_invalid_reset_value_too_large(self):
with self.assertRaises(pyrtl.PyrtlError):
r = pyrtl.Register(4, reset_value=16)
def test_invalid_reset_value_too_large_as_string(self):
with self.assertRaises(pyrtl.PyrtlError):
r = pyrtl.Register(4, reset_value="5'd16")
def test_negative_reset_value(self):
r = pyrtl.Register(4, reset_value=-4)
self.assertEqual(
pyrtl.helperfuncs.val_to_signed_integer(r.reset_value, r.bitwidth),
-4
)
def test_negative_reset_value_as_string(self):
r = pyrtl.Register(4, reset_value="-4'd1")
self.assertEqual(
pyrtl.helperfuncs.val_to_signed_integer(r.reset_value, r.bitwidth),
-1
)
def test_invalid_negative_reset_value_as_string(self):
with self.assertRaises(pyrtl.PyrtlError):
r = pyrtl.Register(2, reset_value="-4'd1")
def test_extending_negative_reset_value_as_string(self):
r = pyrtl.Register(4, reset_value="-3'd3")
self.assertEqual(
pyrtl.helperfuncs.val_to_signed_integer(r.reset_value, r.bitwidth),
-3
)
def test_invalid_reset_value_not_an_integer(self):
with self.assertRaises(pyrtl.PyrtlError):
r = pyrtl.Register(4, reset_value='hello')
# -------------------------------------------------------------------
class TestConst(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def test_integers(self):
self.check_const(1, 1, 1)
self.check_const(5, 5, 3)
self.check_const(1, 1, 5, bitwidth=5)
self.check_const(0, 0b0, 1)
self.check_const(0, 0b0, 1, signed=True)
self.check_const(1, 0b01, 2, signed=True)
self.check_const(2, 0b010, 3, signed=True)
self.check_const(3, 0b011, 3, signed=True)
self.check_const(4, 0b0100, 4, signed=True)
self.check_const(5, 0b0101, 4, signed=True)
def test_neg_integers(self):
self.check_const(-1, 0b11111, 5, bitwidth=5)
self.check_const(-2, 0b110, 3, bitwidth=3)
self.check_const(-5, 0b1011, 4, bitwidth=4)
self.check_const(-1, 0b1, 1, signed=True)
self.check_const(-2, 0b10, 2, signed=True)
self.check_const(-3, 0b101, 3, signed=True)
self.check_const(-4, 0b100, 3, signed=True)
self.check_const(-5, 0b1011, 4, signed=True)
def test_too_big(self):
self.assert_bad_const(5, 2)
def test_invalid_bitwidth(self):
self.assert_bad_const(1, 0)
self.assert_bad_const(1, -1)
def test_bad_neg_integers(self):
# check that bitwidth is required
self.assert_bad_const(-4)
self.assert_bad_const(-4, 2)
def test_string(self):
self.check_const("1'1", 1, 1)
self.check_const("5'3", 3, 5)
self.check_const("5'b11", 3, 5)
self.check_const("-5'b11", 29, 5)
self.check_const("16'xff", 0xff, 16)
self.check_const("17'xff", 0xff, 17)
self.check_const("16'hff", 0xff, 16)
self.check_const("17'hff", 0xff, 17)
self.check_const("5'b011", 3, 5)
self.check_const("5'b0_11", 3, 5)
self.check_const("5'02_1", 21, 5)
self.check_const("16'HFF", 0xff, 16)
def test_bad_string(self):
self.assert_bad_const("1")
self.assert_bad_const("-1")
self.assert_bad_const("1bx")
self.assert_bad_const("1ba")
self.assert_bad_const("1'bx")
self.assert_bad_const("1'z0")
self.assert_bad_const("1'ba")
self.assert_bad_const("1'b10")
self.assert_bad_const("4'h12")
self.assert_bad_const("-'h1")
self.assert_bad_const("-2'b10")
self.assert_bad_const("1'-b10")
self.assert_bad_const("-1'b10")
self.assert_bad_const("5'b111111'")
self.assert_bad_const("'")
self.assert_bad_const("'1")
self.assert_bad_const("1'")
def test_bool(self):
self.check_const(True, 1, 1)
self.check_const(False, 0, 1, bitwidth=1)
def test_badbool(self):
self.assert_bad_const(False, bitwidth=2)
self.assert_bad_const(True, bitwidth=0)
def test_badtype(self):
self.assert_bad_const(pyrtl.Const(123))
self.assert_bad_const([])
def test_assignment(self):
with self.assertRaises(pyrtl.PyrtlError):
c = pyrtl.Const(4)
c <<= 3
def test_named(self):
block = pyrtl.working_block()
c = pyrtl.Const(20, name="archid")
self.assertIn("archid", block.wirevector_by_name)
self.assertIn(c, block.wirevector_set)
self.assertEqual(c.val, 20)
c.name = "vendorid"
self.assertNotIn("archid", block.wirevector_by_name)
self.assertIn("vendorid", block.wirevector_by_name)
self.assertIn(c, block.wirevector_set)
self.assertEqual(c.val, 20)
def check_const(self, val_in, expected_val, expected_bitwidth, **kargs):
c = pyrtl.Const(val_in, **kargs)
self.assertEqual(c.val, expected_val)
self.assertEqual(c.bitwidth, expected_bitwidth)
def assert_bad_const(self, *args, **kwargs):
with self.assertRaises(pyrtl.PyrtlError):
c = pyrtl.Const(*args, **kwargs)
class TestOutput(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def test_assign_output(self):
o = pyrtl.Output(1)
w = pyrtl.WireVector(1)
with self.assertRaises(pyrtl.PyrtlInternalError):
w <<= o
def test_log_op_output(self):
o = pyrtl.Output(1)
w = pyrtl.WireVector(1)
with self.assertRaises(pyrtl.PyrtlInternalError):
x = w & o
def test_slice_output(self):
o = pyrtl.Output(2)
with self.assertRaises(pyrtl.PyrtlInternalError):
x = o[0]
class TestKeepingCallStack(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
@classmethod
def tearDownClass(cls):
pyrtl.set_debug_mode(False)
def test_no_call_stack(self):
pyrtl.set_debug_mode(False)
wire = pyrtl.WireVector()
with self.assertRaises(AttributeError):
call_stack = wire.init_call_stack
def test_get_call_stack(self):
pyrtl.set_debug_mode(True)
wire = pyrtl.WireVector()
call_stack = wire.init_call_stack
self.assertIsInstance(call_stack, list)
class TestWrappedWireVector(unittest.TestCase):
def setUp(self):
pyrtl.reset_working_block()
def test_attr(self):
reg = pyrtl.Register(bitwidth=1, name='reg')
wrapped_reg = pyrtl.wire.WrappedWireVector(reg)
# Check __setattr__ forwarding.
wrapped_reg.next <<= True
# Check __getattr__ forwarding.
self.assertEqual(wrapped_reg.bitwidth, 1)
self.assertEqual(wrapped_reg.name, 'reg')
sim = pyrtl.Simulation()
sim.step(provided_inputs={})
self.assertEqual(sim.inspect('reg'), False)
sim.step(provided_inputs={})
self.assertEqual(sim.inspect('reg'), True)
def test_ops(self):
# Check special method forwarding.
for a_val in range(16):
for b_val in range(16):
pyrtl.reset_working_block()
a = pyrtl.Const(bitwidth=4, val=a_val)
wrapped_a = pyrtl.wire.WrappedWireVector(a)
b = pyrtl.Const(bitwidth=4, val=b_val)
wrapped_b = pyrtl.wire.WrappedWireVector(b)
self.assertEqual(hash(a), hash(wrapped_a))
self.assertEqual(str(a), str(wrapped_a))
self.assertEqual(len(a), len(wrapped_a))
a_and_b = pyrtl.wire.WireVector(name='a_and_b', bitwidth=4)
a_and_b <<= wrapped_a & wrapped_b
a_rand_b = pyrtl.wire.WireVector(name='a_rand_b', bitwidth=4)
a_rand_b <<= wrapped_a.val & wrapped_b
a_or_b = pyrtl.wire.WireVector(name='a_or_b', bitwidth=4)
a_or_b <<= wrapped_a | wrapped_b
a_ror_b = pyrtl.wire.WireVector(name='a_ror_b', bitwidth=4)
a_ror_b <<= wrapped_a.val | wrapped_b
a_xor_b = pyrtl.wire.WireVector(name='a_xor_b', bitwidth=4)
a_xor_b <<= wrapped_a ^ wrapped_b
a_rxor_b = pyrtl.wire.WireVector(name='a_rxor_b', bitwidth=4)
a_rxor_b <<= wrapped_a.val ^ wrapped_b
a_add_b = pyrtl.wire.WireVector(name='a_add_b', bitwidth=5)
a_add_b <<= wrapped_a + wrapped_b
a_radd_b = pyrtl.wire.WireVector(name='a_radd_b', bitwidth=5)
a_radd_b <<= wrapped_a.val + wrapped_b
a_sub_b = pyrtl.wire.WireVector(name='a_sub_b', bitwidth=4)
a_sub_b <<= wrapped_a - wrapped_b
a_rsub_b = pyrtl.wire.WireVector(name='a_rsub_b', bitwidth=4)
a_rsub_b <<= wrapped_a.val - wrapped_b
a_mul_b = pyrtl.wire.WireVector(name='a_mul_b', bitwidth=8)
a_mul_b <<= wrapped_a * wrapped_b
a_rmul_b = pyrtl.wire.WireVector(name='a_rmul_b', bitwidth=8)
a_rmul_b <<= wrapped_a.val * wrapped_b
a_lt_b = pyrtl.wire.WireVector(name='a_lt_b', bitwidth=1)
a_lt_b <<= wrapped_a < wrapped_b
a_le_b = pyrtl.wire.WireVector(name='a_le_b', bitwidth=1)
a_le_b <<= wrapped_a <= wrapped_b
a_eq_b = pyrtl.wire.WireVector(name='a_eq_b', bitwidth=1)
a_eq_b <<= wrapped_a == wrapped_b
a_ne_b = pyrtl.wire.WireVector(name='a_ne_b', bitwidth=1)
a_ne_b <<= wrapped_a != wrapped_b
a_gt_b = pyrtl.wire.WireVector(name='a_gt_b', bitwidth=1)
a_gt_b <<= wrapped_a > wrapped_b
a_ge_b = pyrtl.wire.WireVector(name='a_ge_b', bitwidth=1)
a_ge_b <<= wrapped_a >= wrapped_b
a_invert = pyrtl.wire.WireVector(name='a_invert', bitwidth=4)
a_invert <<= ~wrapped_a
a_high = pyrtl.wire.WireVector(name='a_high', bitwidth=2)
a_high <<= wrapped_a[2:4]
a_low = pyrtl.wire.WireVector(name='a_low', bitwidth=2)
a_low <<= wrapped_a[0:2]
x = pyrtl.WireVector(name='x', bitwidth=4)
wrapped_x = pyrtl.wire.WrappedWireVector(x)
wrapped_x <<= a_val
self.assertEqual(type(wrapped_x), pyrtl.wire.WrappedWireVector)
sim = pyrtl.Simulation()
sim.step(provided_inputs={})
self.assertEqual(sim.inspect('a_and_b'), a.val & b.val)
self.assertEqual(sim.inspect('a_rand_b'), a.val & b.val)
self.assertEqual(sim.inspect('a_or_b'), a.val | b.val)
self.assertEqual(sim.inspect('a_ror_b'), a.val | b.val)
self.assertEqual(sim.inspect('a_xor_b'), a.val ^ b.val)
self.assertEqual(sim.inspect('a_rxor_b'), a.val ^ b.val)
self.assertEqual(sim.inspect('a_add_b'), a.val + b.val)
self.assertEqual(sim.inspect('a_radd_b'), a.val + b.val)
# Mask with 0xF to convert from signed to unsigned value.
self.assertEqual(sim.inspect('a_sub_b'), (a.val - b.val) & 0xF)
self.assertEqual(sim.inspect('a_rsub_b'), (a.val - b.val) & 0xF)
self.assertEqual(sim.inspect('a_mul_b'), a.val * b.val)
self.assertEqual(sim.inspect('a_rmul_b'), a.val * b.val)
self.assertEqual(sim.inspect('a_lt_b'), a.val < b.val)
self.assertEqual(sim.inspect('a_le_b'), a.val <= b.val)
self.assertEqual(sim.inspect('a_eq_b'), a.val == b.val)
self.assertEqual(sim.inspect('a_ne_b'), a.val != b.val)
self.assertEqual(sim.inspect('a_gt_b'), a.val > b.val)
self.assertEqual(sim.inspect('a_ge_b'), a.val >= b.val)
# Mask with 0xF to convert from signed to unsigned value.
self.assertEqual(sim.inspect('a_invert'), ~a.val & 0xF)
self.assertEqual(sim.inspect('a_high'), a.val >> 2)
self.assertEqual(sim.inspect('a_low'), a.val & 0x3)
self.assertEqual(sim.inspect('x'), a.val)
def test_conditional_assignment(self):
# Check forwarding for __ior__, __enter__, __exit__.
select = pyrtl.Input(name='select', bitwidth=1)
wrapped_select = pyrtl.wire.WrappedWireVector(select)
x = pyrtl.WireVector(name='x', bitwidth=4)
wrapped_x = pyrtl.wire.WrappedWireVector(x)
with pyrtl.conditional_assignment:
with wrapped_select:
wrapped_x |= 0xA
with ~wrapped_select:
wrapped_x |= 0xB
self.assertEqual(type(wrapped_x), pyrtl.wire.WrappedWireVector)
sim = pyrtl.Simulation()
sim.step(provided_inputs={select: True})
self.assertEqual(sim.inspect('x'), 0xA)
sim.step(provided_inputs={select: False})
self.assertEqual(sim.inspect('x'), 0xB)
def test_exceptions(self):
# Check forwarding for special methods that throw exceptions.
a = pyrtl.Const(bitwidth=4, val=0xA)
wrapped_a = pyrtl.wire.WrappedWireVector(a)
b = pyrtl.Const(bitwidth=4, val=0xB)
wrapped_b = pyrtl.wire.WrappedWireVector(b)
with self.assertRaises(pyrtl.PyrtlError):
bool(wrapped_a)
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a &= wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a ^= wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a += wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a -= wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a *= wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a << wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a >> wrapped_b
with self.assertRaises(pyrtl.PyrtlError):
wrapped_a % wrapped_b
if __name__ == "__main__":
unittest.main()