forked from geissdoerfer/shepherd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.