Skip to content

Commit

Permalink
fix: Ommit append option when running in user mode with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemek Recha committed Dec 4, 2023
1 parent 9d2bd75 commit 0d9e2d4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/qemu_runner/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ def _yield_args():
yield layer.general.kernel

if layer.general.kernel_cmdline:
yield '-append'
yield layer.general.kernel_cmdline
if not layer.general.mode or layer.general.mode == Mode.System:
yield '-append'
yield layer.general.kernel_cmdline
else:
args = layer.general.kernel_cmdline.split()
for arg in args:
yield arg

return list(_yield_args())
4 changes: 4 additions & 0 deletions tests/test_layer_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
Layer(GeneralSettings(engine='my-engine', kernel='abc.elf', kernel_cmdline='a b c')),
['my-engine', '-kernel', 'abc.elf', '-append', 'a b c']
),
(
Layer(GeneralSettings(engine='my-engine', kernel='abc.elf', mode=Mode.User, kernel_cmdline='a b c')),
['my-engine', 'abc.elf', 'a', 'b', 'c']
),
(
Layer(
GeneralSettings(engine='my-engine', halted=True, gdb=True, kernel='abc.elf', kernel_cmdline='a b c'),
Expand Down
42 changes: 42 additions & 0 deletions tests/test_runner_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,48 @@ def test_runner_flow_no_args(tmp_path: Path, test_layer: Path):
'-kernel', str(tmp_path / 'abc.elf'),
]

@pytest.fixture()
def test_user_mode_layer(tmp_path: Path) -> Path:
with open(tmp_path / 'test-layer', 'w') as f:
f.write("""
[general]
engine = qemu-aarch64
mode = user
[L]
@ = /some/path
""")

return tmp_path / 'test-layer'


def test_runner_flow_user_mode(tmp_path: Path, test_user_mode_layer: Path):
engine = place_echo_args(tmp_path / 'qemu' / 'qemu-aarch64')

run_make_runner('-l', test_user_mode_layer, '-o', tmp_path / 'test.pyz', cwd=tmp_path)
with with_cwd(tmp_path):
cmdline = capture_runner_cmdline(tmp_path / 'test.pyz', 'abc.elf', 'arg1', 'arg2')

assert cmdline == [
engine,
'-L', '/some/path',
str(tmp_path / 'abc.elf'),
'arg1', 'arg2'
]

def test_runner_flow_no_args(tmp_path: Path, test_user_mode_layer: Path):
engine = place_echo_args(tmp_path / 'qemu' / 'qemu-aarch64')

run_make_runner('-l', test_user_mode_layer, '-o', tmp_path / 'test.pyz', cwd=tmp_path)
with with_cwd(tmp_path):
cmdline = capture_runner_cmdline(tmp_path / 'test.pyz', 'abc.elf')

assert cmdline == [
engine,
'-L', '/some/path',
str(tmp_path / 'abc.elf')
]


def assert_arg_set_in_cmdline(arg_set: List[str], cmdline: List[str]):
if len(arg_set) == 1:
Expand Down

0 comments on commit 0d9e2d4

Please sign in to comment.