コード例 #1
0
def test_initialises_sterm(mock_sterm, mock_serial):
    port = "tty.1111"
    baud = "9600"

    terminal.run(port, baud)

    mock_sterm.assert_called_once_with(mock_serial(), echo=True)
コード例 #2
0
def test_initialises_serial_port(mock_sterm, mock_serial):
    port = "tty.1111"
    baud = 9600

    terminal.run(port, baud)

    mock_serial.assert_called_once_with(port=port, baudrate=str(baud))
コード例 #3
0
def test_closes_sterm_after_keyboard_interrupt(mock_sterm, mock_serial):
    mock_sterm().join.side_effect = (KeyboardInterrupt(), None)
    terminal.run("tty.122", 9600)

    mock_sterm().close.assert_called_once()
コード例 #4
0
def test_closes_sterm_after_exception(mock_sterm, mock_serial):
    mock_sterm().join.side_effect = (Exception(), None)
    with pytest.raises(Exception):
        terminal.run("tty.122", 9600)

    mock_sterm().close.assert_called_once()
コード例 #5
0
def test_closes_sterm(mock_sterm, mock_serial):
    terminal.run("tty.122", 9600)

    mock_sterm().close.assert_called_once()
コード例 #6
0
def test_joins_tx_thread_after_keyboard_interrupt(mock_sterm, mock_serial):
    mock_sterm().join.side_effect = (KeyboardInterrupt(), None)

    terminal.run("tty.122", 9600)

    mock_sterm().join.assert_called_with()
コード例 #7
0
def test_joins_tx_and_rx_threads(mock_sterm, mock_serial):
    terminal.run("tty.122", 9600)

    mock_sterm().join.assert_any_call(True)
コード例 #8
0
def test_starts_sterm_thread(mock_sterm, mock_serial):
    terminal.run("tty.122", 9600)

    mock_sterm().start.assert_called_once()
コード例 #9
0
ファイル: build.py プロジェクト: wernerlewis/mbed-tools
def build(
    program_path: str,
    profile: str,
    toolchain: str = "",
    mbed_target: str = "",
    clean: bool = False,
    flash: bool = False,
    hex_file: bool = False,
    sterm: bool = False,
    baudrate: int = 9600,
    mbed_os_path: str = None,
    custom_targets_json: str = None,
) -> None:
    """Configure and build an Mbed project using CMake and Ninja.

    If the CMake configuration step has already been run previously (i.e a CMake build tree exists), then just try to
    build the project immediately using Ninja.

    Args:
       program_path: Path to the Mbed project.
       mbed_os_path: The path to the local Mbed OS directory.
       profile: The Mbed build profile (debug, develop or release).
       custom_targets_json: Path to custom_targets.json.
       toolchain: The toolchain to use for the build.
       mbed_target: The name of the Mbed target to build for.
       clean: Perform a clean build.
       flash: Flash the binary onto a device.
       hex_file: Use hex file, this option should be used with '-f/--flash' option.
       sterm: Open a serial terminal to the connected target.
       baudrate: Change the serial baud rate (ignored unless --sterm is also given).
    """
    _validate_target_and_toolchain_args(mbed_target, toolchain)
    mbed_target, target_id = _get_target_id(mbed_target)

    cmake_build_subdir = pathlib.Path(mbed_target.upper(), profile.lower(),
                                      toolchain.upper())
    if mbed_os_path is None:
        program = MbedProgram.from_existing(pathlib.Path(program_path),
                                            cmake_build_subdir)
    else:
        program = MbedProgram.from_existing(pathlib.Path(program_path),
                                            cmake_build_subdir,
                                            pathlib.Path(mbed_os_path))
    build_tree = program.files.cmake_build_dir
    if clean and build_tree.exists():
        shutil.rmtree(build_tree)

    click.echo("Configuring project and generating build system...")
    if custom_targets_json is not None:
        program.files.custom_targets_json = pathlib.Path(custom_targets_json)
    generate_config(mbed_target.upper(), toolchain, program)
    generate_build_system(program.root, build_tree, profile)

    click.echo("Building Mbed project...")
    build_project(build_tree)

    if flash or sterm:
        if target_id is not None or sterm:
            devices = [find_connected_device(mbed_target, target_id)]
        else:
            devices = find_all_connected_devices(mbed_target)

    if flash:
        for dev in devices:
            flashed_path = flash_binary(dev.mount_points[0].resolve(),
                                        program.root, build_tree, mbed_target,
                                        hex_file)
        click.echo(
            f"Copied {str(flashed_path.resolve())} to {len(devices)} device(s)."
        )
    elif hex_file:
        click.echo(
            "'--hex-file' option should be used with '-f/--flash' option")

    if sterm:
        dev = devices[0]
        if dev.serial_port is None:
            raise click.ClickException(
                f"The connected device {dev.mbed_board.board_name} does not have an associated serial port."
                " Reconnect the device and try again.")

        terminal.run(dev.serial_port, baudrate)
コード例 #10
0
ファイル: sterm.py プロジェクト: wernerlewis/mbed-tools
def sterm(port: str, baudrate: int, echo: str, mbed_target: str) -> None:
    """Launches a serial terminal to a connected device."""
    if port is None:
        port = _find_target_serial_port_or_default(mbed_target)

    terminal.run(port, baudrate, echo=True if echo == "on" else False)
コード例 #11
0
ファイル: build.py プロジェクト: rwalton-arm/mbed-tools
def build(
    program_path: str,
    build_type: str,
    toolchain: str = "",
    mbed_target: str = "",
    clean: bool = False,
    flash: bool = False,
    hex_file: bool = False,
    sterm: bool = False,
    baudrate: int = 9600,
    mbed_os_path: str = None,
) -> None:
    """Configure and build an Mbed project using CMake and Ninja.

    If the project has already been configured and contains '.mbedbuild/mbed_config.cmake', this command will skip the
    Mbed configuration step and invoke CMake.

    If the CMake configuration step has already been run previously (i.e a CMake build tree exists), then just try to
    build the project immediately using Ninja.

    Args:
       program_path: Path to the Mbed project.
       mbed_os_path: the path to the local Mbed OS directory
       build_type: The Mbed build profile (debug, develop or release).
       toolchain: The toolchain to use for the build.
       mbed_target: The name of the Mbed target to build for.
       clean: Perform a clean build.
       flash: Flash the binary onto a device.
       hex_file: Use hex file, this option should be used with '-f/--flash' option.
       sterm: Open a serial terminal to the connected target.
       baudrate: Change the serial baud rate (ignored unless --sterm is also given).
    """
    if mbed_os_path is None:
        program = MbedProgram.from_existing(pathlib.Path(program_path))
    else:
        program = MbedProgram.from_existing(pathlib.Path(program_path),
                                            pathlib.Path(mbed_os_path))
    mbed_config_file = program.files.cmake_config_file
    build_tree = program.files.cmake_build_dir
    if clean and build_tree.exists():
        shutil.rmtree(build_tree)

    if any([
            not mbed_config_file.exists(), not build_tree.exists(),
            mbed_target, toolchain
    ]):
        click.echo("Configuring project and generating build system...")
        _validate_target_and_toolchain_args(mbed_target, toolchain)
        generate_config(mbed_target.upper(), toolchain, program)
        generate_build_system(program.root, build_tree, build_type)

    click.echo("Building Mbed project...")
    build_project(build_tree)

    if flash or sterm:
        dev = find_connected_device(mbed_target)

    if flash:
        flash_binary(dev.mount_points[0].resolve(), program.root, build_tree,
                     mbed_target, hex_file)
    elif hex_file:
        click.echo(
            "'--hex-file' option should be used with '-f/--flash' option")

    if sterm:
        if dev.serial_port is None:
            raise click.ClickException(
                f"The connected device {dev.mbed_board.board_name} does not have an associated serial port."
                " Reconnect the device and try again.")

        terminal.run(dev.serial_port, baudrate)