Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyocd/subcommands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class CommonOptions:
CONNECT_GROUP.add_argument("-W", "--no-wait", action="store_true",
help="Do not wait for a probe to be connected if none are available.")
CONNECT_GROUP.add_argument("-M", "--connect", dest="connect_mode", metavar="MODE",
choices=("halt", "pre-reset", "under-reset", "attach"),
help="Select connect mode from one of (halt, pre-reset, under-reset, attach).")

@classmethod
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
VECTOR_CATCH_CHAR_MAP,
convert_session_options,
)
from pyocd.__main__ import PyOCDTool
from pyocd.core.target import Target
from pyocd.target import normalise_target_type_name
from pyocd.subcommands.commander_cmd import CommanderSubcommand
Expand All @@ -45,6 +46,27 @@ def test_exit_code(self, monkeypatch, exit_code):
commander.assert_called_once_with(args, None)
commander.return_value.run.assert_called_once_with()

@pytest.mark.parametrize("command", ["commander", "erase", "load", "gdbserver", "info", "reset", "rtt", "run"])
class TestConnectMode:
@pytest.mark.parametrize("mode", ["under_reset", "asdf"])
def test_reject_invalid_mode(self, command, mode, capsys):
parser = PyOCDTool().build_parser()
with pytest.raises(SystemExit) as error:
parser.parse_args([command, "--connect", mode])
assert error.value.code == 2
diagnostic = capsys.readouterr().err
assert "invalid choice" in diagnostic
assert mode in diagnostic
assert "under-reset" in diagnostic

def test_supported_modes_and_default(self, command):
parser = PyOCDTool().build_parser()
assert parser.parse_args([command]).connect_mode is None
for mode in ("halt", "pre-reset", "under-reset", "attach"):
assert parser.parse_args([command, "--connect", mode]).connect_mode == mode
assert parser.parse_args([command, "-M", mode]).connect_mode == mode


class TestSplitCommandLine(object):
def test_split(self):
assert split_command_line('foo') == ['foo']
Expand Down