Skip to content

Commit

Permalink
add programmer tests and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
orgua committed Mar 31, 2023
1 parent 8f1bb32 commit 71d798d
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 3 deletions.
6 changes: 3 additions & 3 deletions software/python-package/shepherd/sysfs_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ def write_programmer_ctrl(
pin_tck: int,
pin_tdio: int,
pin_dir_tdio: int,
pin_tdo: Optional[int] = None,
pin_tms: Optional[int] = None,
pin_dir_tms: Optional[int] = None,
pin_tdo: int = 0,
pin_tms: int = 0,
pin_dir_tms: int = 0,
):
args = locals()
for num, attribute in enumerate(prog_attribs):
Expand Down
175 changes: 175 additions & 0 deletions software/python-package/tests/test_cli_programmer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
from pathlib import Path
from shepherd.cli import cli

import pytest

from shepherd import CalibrationData


@pytest.fixture
def firmware_example():
here = Path(__file__).absolute()
name = "firmware_nrf52_powered.hex"
return here.parent / name


@pytest.fixture
def firmware_empty(tmp_path):
store_path = tmp_path / "firmware_null.hex"
with open(store_path, "w") as f:
pass
return store_path


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_minimal(shepherd_up, cli_runner, firmware_example):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--simulate",
str(firmware_example),
],
)
assert res.exit_code == 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_swd_explicit(shepherd_up, cli_runner, firmware_example):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--sel_a",
"--voltage", "2.0",
"--speed", "600000",
"--target", "nrf52",
"--prog1",
"--simulate",
str(firmware_example),
],
)
assert res.exit_code == 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_sbw_explicit(shepherd_up, cli_runner, firmware_example):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--sel_b",
"--voltage", "1.5",
"--speed", "300000",
"--target", "msp430",
"--prog2",
"--simulate",
str(firmware_example),
],
)
assert res.exit_code == 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_file_defective_a(shepherd_up, cli_runner, firmware_empty):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--simulate",
str(firmware_empty),
],
)
assert res.exit_code != 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_file_defective_b(shepherd_up, cli_runner, tmp_path):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--simulate",
str(tmp_path), # Directory
],
)
assert res.exit_code != 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_file_defective_c(shepherd_up, cli_runner, tmp_path):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--simulate",
str(tmp_path / "file_abc.bin"), # non_existing file
],
)
assert res.exit_code != 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_datarate_invalid_a(shepherd_up, cli_runner, firmware_example):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--speed", "2000000",
"--simulate",
str(firmware_example),
],
)
assert res.exit_code != 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_datarate_invalid_b(shepherd_up, cli_runner, firmware_example):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--speed", "0",
"--simulate",
str(firmware_example),
],
)
assert res.exit_code != 0


@pytest.mark.hardware
@pytest.mark.timeout(60)
def test_cli_program_target_invalid(shepherd_up, cli_runner, firmware_example):
res = cli_runner.invoke(
cli,
[
"-vvv",
"programmer",
"--target", "arduino",
"--simulate",
str(firmware_example),
],
)
assert res.exit_code != 0


# not testable ATM (through CLI)
# - fail pins 3x (pin_num is identical)
# - fail wrong target (internally, fail in kModule)
# - datasize > mem_size

0 comments on commit 71d798d

Please sign in to comment.