Пример #1
0
    def test_invalid_address_memory_read(self, device):
        """Tests an Error is raised when trying to access invalid memory for
        memory read"""
        INVALID_ADDRESS = 0xFFFFFFFF
        NUM_BYTES = 4

        with pytest.raises(tiflash.TIFlashError):
            tiflash.memory_read(INVALID_ADDRESS, NUM_BYTES,
                            serno=device['serno'],
                            connection=device['connection'],
                            devicetype=device['devicetype'])
def _data_(con, sn, sval, fval, cnt, prt, infinite=True, width=16):
    active = True
    while active:
        try:

            time.sleep(1)

            buf = tiflash.memory_read(address=0x51020000,
                                      num_bytes=sval * fval * cnt,
                                      ccs=_meta_['ccs'],
                                      serno=sn,
                                      connection=con,
                                      fresh=True)

        except Exception as e:
            print_log(e, sys._getframe())
            break

        if verbose:
            tmp = dec2hex(buf)
            frames = split(tmp, sval * fval * 2)  # two chars
            for frame in frames:
                print('')
                tmp = split(frame, width * sval)
                for line in tmp:
                    print(' '.join(split(line, sval)))

        if infinite:
            send_config(prt, None, None)

        active = infinite
Пример #3
0
    def test_basic_memory_read_multiple_bytes(self, device):
        """Tests simple memory read of multiple bytes"""
        result = tiflash.memory_read(ADDRESS, 4,
                            serno=device['serno'],
                            connection=device['connection'],
                            devicetype=device['devicetype'])

        assert len(result) == 4
Пример #4
0
    def test_basic_memory_read_single_byte(self, tdev):
        """Tests simple memory read"""
        result = tiflash.memory_read(tdev['read-address'],
                                     1,
                                     serno=tdev['serno'],
                                     connection=tdev['connection'],
                                     devicetype=tdev['devicetype'])

        assert len(result) == 1
Пример #5
0
def _data_(con, sn, sval, fval, cnt, prt, infinite=True, width=16):

    time.sleep(1)

    active = True

    while active:

        try:

            print_log(
                'read memory: address={}, bytes={}, frames={}'.format(
                    hex(_meta_['add']), sval * fval * cnt, cnt),
                sys._getframe())

            buf = tiflash.memory_read(address=_meta_['add'],
                                      num_bytes=sval * fval * cnt,
                                      ccs=_meta_['ccs'],
                                      serno=sn,
                                      connection=con,
                                      fresh=True,
                                      devicetype=_meta_['typ'])

        except Exception as e:
            print_log(e, sys._getframe())
            break

        buffer = []

        tmp = dec2hex(buf)
        frames = split(tmp, sval * fval * 2)  # two chars per byte
        for frame in frames:
            buffer.append('')
            tmp = split(frame, width * sval)
            for line in tmp:
                buffer.append(' '.join(split(line, sval)))

        chunk = '\n'.join(buffer)
        _pipe_(chunk)

        if verbose:
            print(chunk, file=sys.stdout, flush=True)

        if infinite:
            send_config(prt, None, None)
            time.sleep(0.5)

        active = infinite
Пример #6
0
def handle_memory(args):
    """Helper function for handling 'memory' command"""
    session_args = get_session_args(args)

    if args.cmd == 'memory-read':
        try:
            result = tiflash.memory_read(args.address, args.num_bytes, args.page,
                **session_args)
            if args.hex:
                result = [ hex(h) for h in result ]
            print(result)
        except Exception as e:
            __exit_with_error(e)
    elif args.cmd == 'memory-write':
        try:
            result = tiflash.memory_write(args.address, args.data, args.page,
                **session_args)
        except Exception as e:
            __exit_with_error(e)
Пример #7
0
    def test_basic_memory_read_and_check_byte_values(self, device):
        """Tests memory read and checks for correct byte values. This test is
        device specific."""

        if "memaddr" not in device.keys() or \
            "memval" not in device.keys():
            pytest.skip("Need to add memval and memaddr fields in \
                setup.cfg for device: %s" % device['devicetype'])

        addr = int(device['memaddr'], 0)
        answer = device['memval'].split(',')
        answer = [ int(d, 0) for d in answer ]
        result = tiflash.memory_read(addr, len(answer),
                            serno=device['serno'],
                            connection=device['connection'],
                            devicetype=device['devicetype'])

        assert len(result) == len(answer)
        assert result == answer