Beispiel #1
0
def test_packing_and_unpacking():
    for width in [1,2]:
        min_value = -(2 ** (16 * width) / 2)
        max_value = -min_value - 1
        edge_cases = [min_value, max_value, -1, 0, 1]
        sample = random.sample(xrange(min_value, max_value), 10000)
        for i in itertools.chain(edge_cases, sample):
            packed = util.pack_value(i, width)
            unpacked = util.unpack_values(packed)
            nose.assert_equal(i, unpacked)
Beispiel #2
0
    def _expand_register_value(self, addr, value):
        """Returns a dict of register addresses to register values.

        A40 registers can have register values greater than 2 bytes.  In which
        case the value is split across contiguous registers.

        This function takes a register address; looks up how wide it expects the
        value to be; and returns a mapping of register addresses to values.
        """
        assert addr in _ALL_REGISTERS
        width = _ALL_REGISTERS[addr]

        to_return = {}
        for i, value in enumerate(util.pack_value(value, width)):
            to_return[addr + i] = value

        return to_return