def test_logic_bit_or(): r = Logic(0) | Bit(1) assert type(r) == Logic assert r == Logic(1) r = Bit(1) | Logic(0) assert type(r) == Logic assert r == Logic(1)
def test_logic_int_conversions(): assert int(Logic("0")) == 0 assert int(Logic("1")) == 1 with pytest.raises(ValueError): int(Logic("X")) with pytest.raises(ValueError): int(Logic("Z"))
def test_logic_bit_and(): r = Logic(0) & Bit(1) assert type(r) == Logic assert r == Logic(0) r = Bit(1) & Logic(0) assert type(r) == Logic assert r == Logic(0)
def test_logic_bool_conversions(): assert bool(Logic("1")) is True assert bool(Logic("0")) is False with pytest.raises(ValueError): bool(Logic("X")) with pytest.raises(ValueError): bool(Logic("Z"))
def test_logic_bit_xor(): r = Logic(0) ^ Bit(1) assert type(r) == Logic assert r == Logic(1) r = Bit(0) ^ Logic(0) assert type(r) == Logic assert r == Logic(0)
async def wait_for_signal(self, signal, value): self.log.debug(f"wait_for_signal: {signal._name} value {value}") await ReadOnly() while self.in_reset or Logic(signal.value.binstr) != Logic(value): await RisingEdge(self.clock) await ReadOnly() self.log.debug(f"wait_for_signal: {signal._name} value {value} return") await NextTimeStep()
def test_bit_logic_conversions(): Logic(Bit(0)) Logic(Bit(1)) Bit(Logic(0)) Bit(Logic(1)) with pytest.raises(ValueError): Bit(Logic("X")) with pytest.raises(ValueError): Bit(Logic("Z"))
def test_logic_array_constructor(): LogicArray([False, 1, "X", Logic("Z")]) l = LogicArray("01XZ") assert all(isinstance(v, Logic) for v in l) with pytest.raises(ValueError): LogicArray([object()]) assert LogicArray(0) == LogicArray("0") assert LogicArray(0xA7) == LogicArray("10100111") assert LogicArray(-1) == LogicArray("1") assert LogicArray(10, Range(5, "downto", 0)) == LogicArray("001010") assert LogicArray(-2, Range(5, "downto", 0)) == LogicArray("111110") with pytest.raises(ValueError): LogicArray(10, Range(1, "to", 3)) with pytest.raises(TypeError): LogicArray(object()) with pytest.raises(ValueError): LogicArray("101010", Range(0, 'to', 0))
def test_logic_default_value(): assert Logic() == Logic("X")
def test_logic_bit_hashability(): s = {Logic("0"), Logic("1"), Logic("X"), Logic("Z"), Bit("0"), Bit("1")} assert len(s) == 4
def test_logic_bit_equality(): assert Logic(0) == Bit(0) assert Logic(1) == Bit(1)
def test_logic_conversions(): l = Logic("0") assert Logic("l") == l assert Logic("L") == l assert Logic(0) == l assert Logic(False) == l assert Logic(Logic("0")) == l l = Logic("1") assert Logic(1) == l assert Logic(True) == l assert Logic("h") == l assert Logic("H") == l assert Logic(Logic("1")) == l l = Logic("X") assert Logic("x") == l assert Logic("w") == l assert Logic("W") == l assert Logic("u") == l assert Logic("U") == l assert Logic("-") == l assert Logic(Logic("X")) == l l = Logic("Z") assert Logic("z") == l assert Logic(Logic("Z")) == l for value in ("j", 2, object()): with pytest.raises(ValueError): Logic(value)
def test_logic_equality(): assert Logic(0) == Logic("0") assert Logic(0) != Logic("X") assert Logic(0) != object()
def test_bit_identity(): assert Bit(0) is Bit(False) assert Bit(Logic(1)) is Bit("1")
def test_logic_identity(): assert Logic(0) is Logic(False) assert Logic("1") is Logic(1) assert Logic("X") is Logic("x") assert Logic("z") is Logic("Z")
def test_logic_str_conversions(): assert str(Logic("0")) == "0" assert str(Logic("1")) == "1" assert str(Logic("X")) == "X" assert str(Logic("Z")) == "Z"
def test_logic_xor(): # will not be exhaustive assert (Logic("1") ^ Logic(True)) == Logic(0) assert (Logic(1) ^ Logic("X")) == Logic("X") assert (Logic(1) ^ Logic(False)) == Logic(1) with pytest.raises(TypeError): Logic(1) ^ () with pytest.raises(TypeError): () ^ Logic(1)
def test_logic_repr(): assert eval(repr(Logic("0"))) == Logic("0") assert eval(repr(Logic("1"))) == Logic("1") assert eval(repr(Logic("X"))) == Logic("X") assert eval(repr(Logic("Z"))) == Logic("Z")
def test_logic_or(): # will not be exhaustive assert Logic("1") | Logic("Z") == Logic("1") assert Logic(0) | Logic("0") == Logic(0) assert Logic("X") | Logic("Z") == Logic("X") with pytest.raises(TypeError): 8 | Logic(0) with pytest.raises(TypeError): Logic(0) | 8
def test_logic_and(): # will not be exhaustive assert Logic("0") & Logic("Z") == Logic(0) assert Logic(1) & Logic("1") == Logic(1) assert Logic("X") & Logic("Z") == Logic("X") with pytest.raises(TypeError): Logic("1") & 8 with pytest.raises(TypeError): 8 & Logic("1")
def test_logic_invert(): assert ~Logic(0) == Logic(1) assert ~Logic(1) == Logic(0) assert ~Logic("X") == Logic("X") assert ~Logic("Z") == Logic("X")
async def test_assign_Logic(dut): dut.stream_in_ready.value = Logic("X") await Timer(1, "ns") assert dut.stream_in_ready.value.binstr.lower() == "x" with pytest.raises(ValueError): dut.stream_in_data.value = Logic("U") # not the correct size