Esempio n. 1
0
 def test_ram(record_speed=False, width=8):
     print("\n\n------ TEST RAM READ / WRITE SPEED [%s] ------" %
           test_config)
     test_addr = ram_start
     test_size = ram_size
     data = [randrange(1, 50) for x in range(test_size)]
     start = time()
     if width == 8:
         target.write_memory_block8(test_addr, data)
     elif width == 32:
         target.write_memory_block32(
             test_addr, conversion.byte_list_to_u32le_list(data))
     target.flush()
     stop = time()
     diff = stop - start
     if diff == 0:
         print("Unexpected ram write elapsed time of 0!")
         write_speed = 0
     else:
         write_speed = test_size / diff
     if record_speed:
         result.write_speed = write_speed
     print("Writing %i byte took %.3f seconds: %.3f B/s" %
           (test_size, diff, write_speed))
     start = time()
     if width == 8:
         block = target.read_memory_block8(test_addr, test_size)
     elif width == 32:
         block = conversion.u32le_list_to_byte_list(
             target.read_memory_block32(test_addr, test_size // 4))
     target.flush()
     stop = time()
     diff = stop - start
     if diff == 0:
         print("Unexpected ram read elapsed time of 0!")
         read_speed = 0
     else:
         read_speed = test_size / diff
     if record_speed:
         result.read_speed = read_speed
     print("Reading %i byte took %.3f seconds: %.3f B/s" %
           (test_size, diff, read_speed))
     error = False
     if len(block) != len(data):
         error = True
         print("ERROR: read length (%d) != write length (%d)!" %
               (len(block), len(data)))
     if not error:
         for i in range(len(block)):
             if (block[i] != data[i]):
                 error = True
                 print("ERROR: 0x%X, 0x%X, 0x%X!!!" %
                       ((addr + i), block[i], data[i]))
     if error:
         print("TEST FAILED")
     else:
         print("TEST PASSED")
     return not error
Esempio n. 2
0
 def test_u32leListToByteList(self):
     data = [
         0x03020100,
         0x07060504,
         0x0B0A0908,
         0x0F0E0D0C,
         0x13121110,
         0x17161514,
         0x1B1A1918,
         0x1F1E1D1C,
     ]
     assert u32le_list_to_byte_list(data) == list(range(32))
Esempio n. 3
0
 def test_u32leListToByteList(self):
     data = [
         0x03020100,
         0x07060504,
         0x0B0A0908,
         0x0F0E0D0C,
         0x13121110,
         0x17161514,
         0x1B1A1918,
         0x1F1E1D1C,
     ]
     assert u32le_list_to_byte_list(data) == list(range(32))
Esempio n. 4
0
 def test_ram(record_speed=False, width=8):
     print("\n\n------ TEST RAM READ / WRITE SPEED [%s] ------" % test_config)
     test_addr = ram_start
     test_size = ram_size
     data = [randrange(1, 50) for x in range(test_size)]
     start = time()
     if width == 8:
         target.write_memory_block8(test_addr, data)
     elif width == 32:
         target.write_memory_block32(test_addr, conversion.byte_list_to_u32le_list(data))
     target.flush()
     stop = time()
     diff = stop - start
     if diff == 0:
         print("Unexpected ram write elapsed time of 0!")
         write_speed = 0
     else:
         write_speed = test_size / diff
     if record_speed:
         result.write_speed = write_speed
     print("Writing %i byte took %.3f seconds: %.3f B/s" % (test_size, diff, write_speed))
     start = time()
     if width == 8:
         block = target.read_memory_block8(test_addr, test_size)
     elif width == 32:
         block = conversion.u32le_list_to_byte_list(target.read_memory_block32(test_addr, test_size // 4))
     target.flush()
     stop = time()
     diff = stop - start
     if diff == 0:
         print("Unexpected ram read elapsed time of 0!")
         read_speed = 0
     else:
         read_speed = test_size / diff
     if record_speed:
         result.read_speed = read_speed
     print("Reading %i byte took %.3f seconds: %.3f B/s" % (test_size, diff, read_speed))
     error = False
     if len(block) != len(data):
         error = True
         print("ERROR: read length (%d) != write length (%d)!" % (len(block), len(data)))
     if not error:
         for i in range(len(block)):
             if (block[i] != data[i]):
                 error = True
                 print("ERROR: 0x%X, 0x%X, 0x%X!!!" % ((addr + i), block[i], data[i]))
     if error:
         print("TEST FAILED")
     else:
         print("TEST PASSED")
     return not error
Esempio n. 5
0
 def test_rom(record_speed=False, width=8):
     print("\n\n------ TEST ROM READ SPEED [%s] ------" % test_config)
     test_addr = rom_start
     test_size = rom_size
     start = time()
     if width == 8:
         block = target.read_memory_block8(test_addr, test_size)
     elif width == 32:
         block = conversion.u32le_list_to_byte_list(target.read_memory_block32(test_addr, test_size // 4))
     target.flush()
     stop = time()
     diff = stop - start
     if diff == 0:
         print("Unexpected rom read elapsed time of 0!")
         read_speed = 0
     else:
         read_speed = test_size / diff
     if record_speed:
         result.rom_read_speed = read_speed
     print("Reading %i byte took %.3f seconds: %.3f B/s" % (test_size, diff, read_speed))
     print("TEST PASSED")
     return True
Esempio n. 6
0
 def test_rom(record_speed=False, width=8):
     print("\n\n------ TEST ROM READ SPEED [%s] ------" % test_config)
     test_addr = rom_start
     test_size = rom_size
     start = time()
     if width == 8:
         block = target.read_memory_block8(test_addr, test_size)
     elif width == 32:
         block = conversion.u32le_list_to_byte_list(
             target.read_memory_block32(test_addr, test_size // 4))
     target.flush()
     stop = time()
     diff = stop - start
     if diff == 0:
         print("Unexpected rom read elapsed time of 0!")
         read_speed = 0
     else:
         read_speed = test_size / diff
     if record_speed:
         result.rom_read_speed = read_speed
     print("Reading %i byte took %.3f seconds: %.3f B/s" %
           (test_size, diff, read_speed))
     print("TEST PASSED")
     return True
Esempio n. 7
0
def debug_context_test(board_id):
    with ConnectHelper.session_with_chosen_probe(unique_id=board_id, **get_session_options()) as session:
        board = session.board
        target = session.target

        test_params = get_target_test_params(session)
        session.probe.set_clock(test_params['test_clock'])

        memory_map = target.get_memory_map()
        boot_region = memory_map.get_boot_memory()
        ram_region = memory_map.get_default_region_of_type(MemoryType.RAM)
        ram_base = ram_region.start
        binary_file = get_test_binary_path(board.test_binary)
        gdb_test_binary_file = os.path.join(PYOCD_DIR, GDB_TEST_BIN)

        # Read the gdb test binary file.
        with open(gdb_test_binary_file, "rb") as f:
            gdb_test_binary_data = list(bytearray(f.read()))

        # Read the test binary file.
        with open(binary_file, "rb") as f:
            test_binary_data = bytearray(f.read())
        test_binary_data_length = len(test_binary_data)

        # Generate ELF file from the binary test file.
        temp_test_elf_name = binary_to_elf_file(binary_file, boot_region.start)

        test_pass_count = 0
        test_count = 0
        result = DebugContextTestResult()

        target.reset_and_halt()

        # Reproduce a gdbserver failure.
        print("\n------ Test 1: Mem cache ------")

        ctx = target.get_target_context()

        print("Writing gdb test binary")
        ctx.write_memory_block8(ram_base, gdb_test_binary_data)

        print("Reading first chunk")
        data = ctx.read_memory_block8(ram_base, 64)
        if data == gdb_test_binary_data[:64]:
            test_pass_count += 1
            print("TEST PASSED")
        else:
            print("TEST FAILED")
        test_count += 1

        print("Reading N chunks")
        did_pass = True
        for n in range(8):
            offset = 0x7e + (4 * n)
            data = ctx.read_memory_block8(ram_base + offset, 4)
            if data == gdb_test_binary_data[offset:offset + 4]:
                test_pass_count += 1
            else:
                did_pass = False
            test_count += 1
        if did_pass:
            print("TEST PASSED")
        else:
            print("TEST FAILED")

        # Force a memory cache clear.
        target.step()

        # ELF reader test goals:
        # 1. Verify correct data is read without accessing the target memory.
        # 2. Test null interval failure.
        #
        print("\n------ Test 2: ELF reader ------")

        # Set the elf on the target, which will add a context to read from the elf.
        target.elf = temp_test_elf_name
        ctx = target.get_target_context()

        print("Check that ElfReaderContext was created")
        if isinstance(ctx, ElfReaderContext):
            test_pass_count += 1
            print("TEST PASSED")
        else:
            print("TEST FAILED")
        test_count += 1

        # Program the test binary.
        print("Programming test binary to boot memory")
        FileProgrammer(session).program(binary_file, base_address=boot_region.start)

        with mock.patch.object(target.selected_core, 'read_memory_block32') as read_block32_mock:
            test_len = min(4096, test_binary_data_length)
            print("Reading %d bytes of test binary from context." % test_len)
            data = ctx.read_memory_block32(boot_region.start, test_len // 4)
            data = conversion.u32le_list_to_byte_list(data)
            if same(data, test_binary_data[:test_len]):
                print("PASSED: expected data returned")
                test_pass_count += 1
            else:
                print("FAILED: unexpected data")
            test_count += 1

            # Verify the target memory wasn't accessed.
            try:
                read_block32_mock.assert_not_called()
            except AssertionError:
                print("FAILED: target memory was accessed")
            else:
                print("PASSED: target memory was not accessed")
                test_pass_count += 1
            test_count += 1

        print("\nTest Summary:")
        print("Pass count %i of %i tests" % (test_pass_count, test_count))
        if test_pass_count == test_count:
            print("DEBUG CONTEXT TEST PASSED")
        else:
            print("DEBUG CONTEXT TEST FAILED")

        # Clean up.
        target.reset()

        result.passed = test_count == test_pass_count
        return result
Esempio n. 8
0
 def write_memory_block32(self, addr, data):
     return self.write_memory_block8(addr, conversion.u32le_list_to_byte_list(data))
Esempio n. 9
0
 def write_memory_block32(self, addr, data):
     return self.write_memory_block8(addr, conversion.u32le_list_to_byte_list(data))