示例#1
0
def test_gdb(board_id=None):
    result = GdbTestResult()
    with MbedBoard.chooseBoard(board_id=board_id) as board:
        memory_map = board.target.getMemoryMap()
        ram_regions = [region for region in memory_map if region.type == 'ram']
        ram_region = ram_regions[0]
        rom_region = memory_map.getBootMemory()
        target_type = board.getTargetType()
        binary_file = os.path.join(parentdir, 'binaries',
                                   board.getTestBinary())
        if board_id is None:
            board_id = board.getUniqueID()
        test_clock = 10000000
        test_port = 3334
        error_on_invalid_access = True
        # Hardware breakpoints are not supported above 0x20000000 on
        # CortexM devices
        ignore_hw_bkpt_result = 1 if ram_region.start >= 0x20000000 else 0
        if target_type == "nrf51":
            # Override clock since 10MHz is too fast
            test_clock = 1000000
            # Reading invalid ram returns 0 or nrf51
            error_on_invalid_access = False

        # Program with initial test image
        board.flash.flashBinary(binary_file, rom_region.start)
        board.uninit(False)

    # Write out the test configuration
    test_params = {}
    test_params["rom_start"] = rom_region.start
    test_params["rom_length"] = rom_region.length
    test_params["ram_start"] = ram_region.start
    test_params["ram_length"] = ram_region.length
    test_params["invalid_start"] = 0xffff0000
    test_params["invalid_length"] = 0x1000
    test_params["expect_error_on_invalid_access"] = error_on_invalid_access
    test_params["ignore_hw_bkpt_result"] = ignore_hw_bkpt_result
    with open(TEST_PARAM_FILE, "wb") as f:
        f.write(json.dumps(test_params))

    # Run the test
    gdb = [PYTHON_GDB, "--command=gdb_script.py"]
    with open("output.txt", "wb") as f:
        program = Popen(gdb, stdin=PIPE, stdout=f, stderr=STDOUT)
        args = ['-p=%i' % test_port, "-f=%i" % test_clock, "-b=%s" % board_id]
        server = GDBServerTool()
        server.run(args)
        program.wait()

    # Read back the result
    with open(TEST_RESULT_FILE, "rb") as f:
        test_result = json.loads(f.read())

    # Print results
    if set(TEST_RESULT_KEYS).issubset(test_result):
        print("----------------Test Results----------------")
        print("HW breakpoint count: %s" % test_result["breakpoint_count"])
        print("Watchpoint count: %s" % test_result["watchpoint_count"])
        print("Average instruction step time: %s" %
              test_result["step_time_si"])
        print("Average single step time: %s" % test_result["step_time_s"])
        print("Average over step time: %s" % test_result["step_time_n"])
        print("Failure count: %i" % test_result["fail_count"])
        result.passed = test_result["fail_count"] == 0
    else:
        result.passed = False

    # Cleanup
    os.remove(TEST_RESULT_FILE)
    os.remove(TEST_PARAM_FILE)

    return result
示例#2
0
def test_gdb(board_id=None, n=0):
    temp_test_elf_name = None
    result = GdbTestResult()
    with ConnectHelper.session_with_chosen_probe(
            board_id=board_id, **get_session_options()) as session:
        board = session.board
        memory_map = board.target.getMemoryMap()
        ram_regions = [region for region in memory_map if region.type == 'ram']
        ram_region = ram_regions[0]
        rom_region = memory_map.getBootMemory()
        target_type = board.target_type
        binary_file = os.path.join(parentdir, 'binaries', board.test_binary)
        if board_id is None:
            board_id = board.unique_id
        test_clock = 10000000
        test_port = 3333 + n
        telnet_port = 4444 + n
        error_on_invalid_access = True
        # Hardware breakpoints are not supported above 0x20000000 on
        # CortexM devices
        ignore_hw_bkpt_result = 1 if ram_region.start >= 0x20000000 else 0
        if target_type in ("nrf51", "nrf52", "nrf52840"):
            # Override clock since 10MHz is too fast
            test_clock = 1000000
            # Reading invalid ram returns 0 or nrf51
            error_on_invalid_access = False
        if target_type == "ncs36510":
            # Override clock since 10MHz is too fast
            test_clock = 1000000

        # Program with initial test image
        board.flash.flashBinary(binary_file, rom_region.start)

    # Generate an elf from the binary test file.
    temp_test_elf_name = tempfile.mktemp('.elf')
    objcopyOutput = check_output([
        OBJCOPY, "-v", "-I", "binary", "-O", "elf32-littlearm", "-B", "arm",
        "-S", "--set-start",
        "0x%x" % rom_region.start, "--change-addresses",
        "0x%x" % rom_region.start, binary_file, temp_test_elf_name
    ],
                                 stderr=STDOUT)
    print(to_str_safe(objcopyOutput))
    # Need to escape backslashes on Windows.
    if sys.platform.startswith('win'):
        temp_test_elf_name = temp_test_elf_name.replace('\\', '\\\\')

    # Write out the test configuration
    test_params = {
        "test_port": test_port,
        "rom_start": rom_region.start,
        "rom_length": rom_region.length,
        "ram_start": ram_region.start,
        "ram_length": ram_region.length,
        "invalid_start": 0x3E000000,
        "invalid_length": 0x1000,
        "expect_error_on_invalid_access": error_on_invalid_access,
        "ignore_hw_bkpt_result": ignore_hw_bkpt_result,
        "test_elf": temp_test_elf_name,
    }
    test_param_filename = "test_params%d.txt" % n
    with open(test_param_filename, "w") as f:
        f.write(json.dumps(test_params))

    # Run the test
    gdb = [PYTHON_GDB, "-ex", "set $testn=%d" % n, "--command=gdb_script.py"]
    output_filename = "output_%s_%d.txt" % (board.target_type, n)
    with open(output_filename, "w") as f:
        program = Popen(gdb, stdin=PIPE, stdout=f, stderr=STDOUT)
        args = [
            '-p=%i' % test_port,
            "-f=%i" % test_clock,
            "-b=%s" % board_id,
            "-T=%i" % telnet_port, '-Oboard_config_file=test_boards.json'
        ]
        server = GDBServerTool()
        server.run(args)
        program.wait()

    # Read back the result
    test_result_filename = "test_results%d.txt" % n
    with open(test_result_filename, "r") as f:
        test_result = json.loads(f.read())

    # Print results
    if set(TEST_RESULT_KEYS).issubset(test_result):
        print("----------------Test Results----------------")
        print("HW breakpoint count: %s" % test_result["breakpoint_count"])
        print("Watchpoint count: %s" % test_result["watchpoint_count"])
        print("Average instruction step time: %s" %
              test_result["step_time_si"])
        print("Average single step time: %s" % test_result["step_time_s"])
        print("Average over step time: %s" % test_result["step_time_n"])
        print("Failure count: %i" % test_result["fail_count"])
        result.passed = test_result["fail_count"] == 0
    else:
        result.passed = False

    # Cleanup
    if temp_test_elf_name and os.path.exists(temp_test_elf_name):
        os.remove(temp_test_elf_name)
    os.remove(test_result_filename)
    os.remove(test_param_filename)

    return result
示例#3
0
def test_gdb(board_id=None):
    result = GdbTestResult()
    with MbedBoard.chooseBoard(board_id=board_id) as board:
        memory_map = board.target.getMemoryMap()
        ram_regions = [region for region in memory_map if region.type == "ram"]
        ram_region = ram_regions[0]
        rom_region = memory_map.getBootMemory()
        target_type = board.getTargetType()
        binary_file = os.path.join(parentdir, "binaries", board.getTestBinary())
        if board_id is None:
            board_id = board.getUniqueID()
        test_clock = 10000000
        test_port = 3334
        error_on_invalid_access = True
        # Hardware breakpoints are not supported above 0x20000000 on
        # CortexM devices
        ignore_hw_bkpt_result = 1 if ram_region.start >= 0x20000000 else 0
        if target_type == "nrf51":
            # Override clock since 10MHz is too fast
            test_clock = 1000000
            # Reading invalid ram returns 0 or nrf51
            error_on_invalid_access = False

        # Program with initial test image
        board.flash.flashBinary(binary_file, rom_region.start)
        board.uninit(False)

    # Write out the test configuration
    test_params = {}
    test_params["rom_start"] = rom_region.start
    test_params["rom_length"] = rom_region.length
    test_params["ram_start"] = ram_region.start
    test_params["ram_length"] = ram_region.length
    test_params["invalid_start"] = 0xFFFF0000
    test_params["invalid_length"] = 0x1000
    test_params["expect_error_on_invalid_access"] = error_on_invalid_access
    test_params["ignore_hw_bkpt_result"] = ignore_hw_bkpt_result
    with open(TEST_PARAM_FILE, "wb") as f:
        f.write(json.dumps(test_params))

    # Run the test
    gdb = [PYTHON_GDB, "--command=gdb_script.py"]
    with open("output.txt", "wb") as f:
        program = Popen(gdb, stdin=PIPE, stdout=f, stderr=STDOUT)
        args = ["-p=%i" % test_port, "-f=%i" % test_clock, "-b=%s" % board_id]
        server = GDBServerTool()
        server.run(args)
        program.wait()

    # Read back the result
    with open(TEST_RESULT_FILE, "rb") as f:
        test_result = json.loads(f.read())

    # Print results
    if set(TEST_RESULT_KEYS).issubset(test_result):
        print("----------------Test Results----------------")
        print("HW breakpoint count: %s" % test_result["breakpoint_count"])
        print("Watchpoint count: %s" % test_result["watchpoint_count"])
        print("Average instruction step time: %s" % test_result["step_time_si"])
        print("Average single step time: %s" % test_result["step_time_s"])
        print("Average over step time: %s" % test_result["step_time_n"])
        print("Failure count: %i" % test_result["fail_count"])
        result.passed = test_result["fail_count"] == 0
    else:
        result.passed = False

    # Cleanup
    os.remove(TEST_RESULT_FILE)
    os.remove(TEST_PARAM_FILE)

    return result
示例#4
0
def test_gdb(board_id=None):
    temp_test_elf_name = None
    result = GdbTestResult()
    with MbedBoard.chooseBoard(board_id=board_id) as board:
        memory_map = board.target.getMemoryMap()
        ram_regions = [region for region in memory_map if region.type == 'ram']
        ram_region = ram_regions[0]
        rom_region = memory_map.getBootMemory()
        target_type = board.getTargetType()
        binary_file = os.path.join(parentdir, 'binaries',
                                   board.getTestBinary())
        if board_id is None:
            board_id = board.getUniqueID()
        test_clock = 10000000
        test_port = 3334
        error_on_invalid_access = True
        # Hardware breakpoints are not supported above 0x20000000 on
        # CortexM devices
        ignore_hw_bkpt_result = 1 if ram_region.start >= 0x20000000 else 0
        if target_type == "nrf51":
            # Override clock since 10MHz is too fast
            test_clock = 1000000
            # Reading invalid ram returns 0 or nrf51
            error_on_invalid_access = False
        if target_type == "ncs36510":
            # Override clock since 10MHz is too fast
            test_clock = 1000000

        # Program with initial test image
        board.flash.flashBinary(binary_file, rom_region.start)
        board.uninit(False)

    # Generate an elf from the binary test file.
    temp_test_elf_name = tempfile.mktemp('.elf')
    check_call([
        OBJCOPY, "-v", "-I", "binary", "-O", "elf32-littlearm", "-B", "arm",
        "-S", "--set-start",
        "0x%x" % rom_region.start, binary_file, temp_test_elf_name
    ])
    # Need to escape backslashes on Windows.
    if sys.platform.startswith('win'):
        temp_test_elf_name = temp_test_elf_name.replace('\\', '\\\\')

    # Write out the test configuration
    test_params = {}
    test_params["rom_start"] = rom_region.start
    test_params["rom_length"] = rom_region.length
    test_params["ram_start"] = ram_region.start
    test_params["ram_length"] = ram_region.length
    test_params["invalid_start"] = 0x3E000000
    test_params["invalid_length"] = 0x1000
    test_params["expect_error_on_invalid_access"] = error_on_invalid_access
    test_params["ignore_hw_bkpt_result"] = ignore_hw_bkpt_result
    test_params["test_elf"] = temp_test_elf_name
    with open(TEST_PARAM_FILE, "w") as f:
        f.write(json.dumps(test_params))

    # Run the test
    gdb = [PYTHON_GDB, "--command=gdb_script.py"]
    with open("output.txt", "w") as f:
        program = Popen(gdb, stdin=PIPE, stdout=f, stderr=STDOUT)
        args = ['-p=%i' % test_port, "-f=%i" % test_clock, "-b=%s" % board_id]
        server = GDBServerTool()
        server.run(args)
        program.wait()

    # Read back the result
    with open(TEST_RESULT_FILE, "r") as f:
        test_result = json.loads(f.read())

    # Print results
    if set(TEST_RESULT_KEYS).issubset(test_result):
        print("----------------Test Results----------------")
        print("HW breakpoint count: %s" % test_result["breakpoint_count"])
        print("Watchpoint count: %s" % test_result["watchpoint_count"])
        print("Average instruction step time: %s" %
              test_result["step_time_si"])
        print("Average single step time: %s" % test_result["step_time_s"])
        print("Average over step time: %s" % test_result["step_time_n"])
        print("Failure count: %i" % test_result["fail_count"])
        result.passed = test_result["fail_count"] == 0
    else:
        result.passed = False

    # Cleanup
    if temp_test_elf_name and os.path.exists(temp_test_elf_name):
        os.remove(temp_test_elf_name)
    os.remove(TEST_RESULT_FILE)
    os.remove(TEST_PARAM_FILE)

    return result