Esempio n. 1
0
    def test_register_set_bit_in_second_byte(self) -> None:
        r = MIIRegister(3, 4)
        r.set_bit(10, True)
        assert r.as_bytes()[0] == 0
        assert r.as_bytes()[1] == 0b0000_0100
        assert r.get_byte(0) == r.as_bytes()[0]
        assert r.get_byte(1) == r.as_bytes()[1]
        assert r.get_bit(0) == 0
        assert r.get_bit(1) == 0
        assert r.get_bit(9) == 0
        assert r.get_bit(10) == 1
        assert r.get_bit(11) == 0
        assert r.get_bit(15) == 0

        assert r.as_number() == 0b0000_0100_0000_0000
        assert r.as_number(signed=True) == 0b0000_0100_0000_0000
Esempio n. 2
0
    def test_register_reset_bit(self) -> None:
        r = MIIRegister(3, 4)
        r.set_bit(2, True)
        r.set_bit(2, False)
        assert r.as_bytes()[0] == 0
        assert r.as_bytes()[1] == 0
        assert r.get_byte(0) == r.as_bytes()[0]
        assert r.get_byte(1) == r.as_bytes()[1]
        assert r.get_bit(0) == 0
        assert r.get_bit(1) == 0
        assert r.get_bit(2) == 0
        assert r.get_bit(3) == 0
        assert r.get_bit(15) == 0

        assert r.as_number() == 0
        assert r.as_number(signed=True) == 0
Esempio n. 3
0
    def test_register_set_bit_in_first_byte(self) -> None:
        r = MIIRegister(3, 4)
        r.set_bit(0, True)
        assert r.address.phy == 3
        assert r.address.mii == 4
        assert len(r.as_bytes()) == 2
        assert r.as_bytes()[0] == 1
        assert r.as_bytes()[1] == 0
        assert r.get_byte(0) == 1
        assert r.get_byte(1) == 0
        assert r.get_bit(0) == 1
        assert r.get_bit(1) == 0
        assert r.get_bit(8) == 0
        assert r.get_bit(15) == 0

        assert r.as_number() == 1
        assert r.as_number(signed=True) == 1
        assert r.is_default()
Esempio n. 4
0
 def test_register_set_bit_as_signed(self) -> None:
     r = MIIRegister(3, 4)
     r.set_bit(15, True)
     assert r.as_number() == pow(2, 15)
     assert r.as_number(signed=True) == -pow(2, 15)