Пример #1
0
def parallel_test():
    """Test that devices can be found and opened in parallel"""
    device_list = DAPAccess.get_connected_devices()
    id_list = [device.get_unique_id() for device in device_list]
    id_list.sort()

    if len(id_list) < 2:
        print("Need at least 2 boards to run the parallel test")
        exit(-1)

    # Goal of this file is to test that:
    # -The process of listing available boards does not interfere
    #  with other processes enumerating, opening, or using boards
    # -Opening and using a board does not interfere with another process
    #  processes which is enumerating, opening, or using boards as
    # long as that is not the current board

    print("Listing board from multiple threads at the same time")
    args_list = [(id_list, ) for _ in range(5)]
    run_in_parallel(list_boards, args_list)

    print("Listing board from multiple processes at the same time")
    run_in_processes(list_boards, args_list)

    print("Opening same board from multiple threads at the same time")
    device = DAPAccess.get_device(id_list[0])
    device.open()
    open_already_opened(id_list[0])
    args_list = [(id_list[0], ) for _ in range(5)]
    run_in_parallel(open_already_opened, args_list)
    device.close()

    print("Opening same board from multiple processes at the same time")
    device = DAPAccess.get_device(id_list[0])
    device.open()
    open_already_opened(id_list[0])
    args_list = [(id_list[0], ) for _ in range(5)]
    run_in_processes(open_already_opened, args_list)
    device.close()

    print("Opening different boards from different threads")
    args_list = [(board_id, ) for board_id in id_list]
    run_in_parallel(search_and_lock, args_list)

    print("Opening different boards from different processes")
    run_in_processes(search_and_lock, args_list)

    print("Test passed")
Пример #2
0
def parallel_test():
    """Test that devices can be found and opened in parallel"""
    device_list = DAPAccess.get_connected_devices()
    id_list = [device.get_unique_id() for device in device_list]
    id_list.sort()

    if len(id_list) < 2:
        print("Need at least 2 boards to run the parallel test")
        exit(-1)

    # Goal of this file is to test that:
    # -The process of listing available boards does not interfere
    #  with other processes enumerating, opening, or using boards
    # -Opening and using a board does not interfere with another process
    #  processes which is enumerating, opening, or using boards as
    # long as that is not the current board

    print("Listing board from multiple threads at the same time")
    args_list = [(id_list,) for _ in range(5)]
    run_in_parallel(list_boards, args_list)

    print("Listing board from multiple processes at the same time")
    run_in_processes(list_boards, args_list)

    print("Opening same board from multiple threads at the same time")
    device = DAPAccess.get_device(id_list[0])
    device.open()
    open_already_opened(id_list[0])
    args_list = [(id_list[0],) for _ in range(5)]
    run_in_parallel(open_already_opened, args_list)
    device.close()

    print("Opening same board from multiple processes at the same time")
    device = DAPAccess.get_device(id_list[0])
    device.open()
    open_already_opened(id_list[0])
    args_list = [(id_list[0],) for _ in range(5)]
    run_in_processes(open_already_opened, args_list)
    device.close()

    print("Opening different boards from different threads")
    args_list = [(board_id,) for board_id in id_list]
    run_in_parallel(search_and_lock, args_list)

    print("Opening different boards from different processes")
    run_in_processes(search_and_lock, args_list)

    print("Test passed")
Пример #3
0
def open_already_opened(board_id):
    """Open a device that is already open to verify it gives an error"""
    device = DAPAccess.get_device(board_id)
    try:
        device.open()
        assert False
    except DAPAccess.DeviceError:
        pass
Пример #4
0
def search_and_lock(board_id):
    """Repeatedly lock a board with the given ID"""
    for _ in range(0, 20):
        device = DAPAccess.get_device(board_id)
        device.open()
        device.close()
        with ConnectHelper.session_with_chosen_probe(unique_id=board_id):
            pass
Пример #5
0
def open_already_opened(board_id):
    """Open a device that is already open to verify it gives an error"""
    device = DAPAccess.get_device(board_id)
    try:
        device.open()
        assert False
    except DAPAccess.DeviceError:
        pass
Пример #6
0
def search_and_lock(board_id):
    """Repeatedly lock a board with the given ID"""
    for _ in range(0, 20):
        device = DAPAccess.get_device(board_id)
        device.open()
        device.close()
        with ConnectHelper.session_with_chosen_probe(unique_id=board_id):
            pass
Пример #7
0
def list_boards(id_list):
    """List all connected DAPLink boards repeatedly

    Assert that they are the same as the id list passed in.
    """
    for _ in range(0, 20):
        device_list = DAPAccess.get_connected_devices()
        found_id_list = [device.get_unique_id() for device in device_list]
        found_id_list.sort()
        assert id_list == found_id_list, "Expected %s, got %s" % \
            (id_list, found_id_list)
Пример #8
0
def list_boards(id_list):
    """List all connected DAPLink boards repeatedly

    Assert that they are the same as the id list passed in.
    """
    for _ in range(0, 20):
        device_list = DAPAccess.get_connected_devices()
        found_id_list = [device.get_unique_id() for device in device_list]
        found_id_list.sort()
        assert id_list == found_id_list, "Expected %s, got %s" % \
            (id_list, found_id_list)
Пример #9
0
            for c in failed_commands:
                print(" - '" + c + "'")
        if test_pass_count == test_count:
            print("COMMANDS TEST SCRIPT PASSED")
        else:
            print("COMMANDS TEST SCRIPT FAILED")

        target.reset()

        result.passed = test_count == test_pass_count
        return result


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='pyOCD commands test')
    parser.add_argument('-d',
                        '--debug',
                        action="store_true",
                        help='Enable debug logging')
    parser.add_argument('-u', '--uid', help='Debug probe unique ID')
    parser.add_argument("-da",
                        "--daparg",
                        dest="daparg",
                        nargs='+',
                        help="Send setting to DAPAccess layer.")
    args = parser.parse_args()
    level = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=level)
    DAPAccess.set_args(args.daparg)
    commands_test(args.uid)
Пример #10
0
            test_pass_count += 1
        else:
            print("TEST FAILED")
        test_count += 1

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

        target.reset()

        result.passed = test_count == test_pass_count
        return result

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='pyOCD flash loader test')
    parser.add_argument('-d', '--debug', action="store_true", help='Enable debug logging')
    parser.add_argument("-da", "--daparg", dest="daparg", nargs='+', help="Send setting to DAPAccess layer.")
    args = parser.parse_args()
    level = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=level)
    DAPAccess.set_args(args.daparg)
    # Set to debug to print some of the decisions made while flashing
    session = ConnectHelper.session_with_chosen_probe(open_session=False, **get_session_options())
    test = FlashLoaderTest()
    result = [test.run(session.board)]