Skip to content

Commit

Permalink
Merge pull request #9 from pszem0c/user-more-runner
Browse files Browse the repository at this point in the history
feat: Add option to skip kernel option name
  • Loading branch information
Novakov authored Nov 29, 2023
2 parents cd969e9 + 15316e3 commit bc80628
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
tests:
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags')
if: (github.event_name == 'push' || github.event_name == 'pull_request') && !startsWith(github.ref, 'refs/tags')
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -24,4 +24,4 @@ jobs:
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
run: tox
19 changes: 17 additions & 2 deletions src/qemu_runner/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
from dataclasses import dataclass, replace
from pathlib import Path
from typing import List, Sequence, Dict, Protocol, Optional, Iterable
from enum import IntEnum

from .argument import Argument, ArgumentValue, build_command_line_for_argument
from .variable_resolution import VariableResolver, resolve_no_variables, append_resolver, make_resolver_from_dict


class Mode(IntEnum):
System = 0
User = 1

@dataclass(frozen=True)
class GeneralSettings:
engine: str = ''
mode: Optional[Mode] = None
kernel: Optional[str] = None
kernel_cmdline: Optional[str] = None
halted: Optional[bool] = None
Expand Down Expand Up @@ -46,12 +52,13 @@ def apply_general() -> GeneralSettings:
return replace(
self._general,
engine=other.engine if other.engine != '' else self._general.engine,
mode=other.mode if other.mode else None,
kernel=other.kernel if other.kernel != '' else self._general.kernel,
kernel_cmdline=' '.join(cmdline) if cmdline else None,
halted=other.halted if other.halted is not None else self._general.halted,
gdb=other.gdb if other.gdb is not None else self._general.gdb,
gdb_dev=other.gdb_dev if other.gdb_dev is not None else self._general.gdb_dev,
memory=other.memory if other.memory is not None else self._general.memory
memory=other.memory if other.memory is not None else self._general.memory,
)

def apply_arguments() -> Iterable[Argument]:
Expand Down Expand Up @@ -157,6 +164,13 @@ def read_general_settings() -> GeneralSettings:
if 'memory' in section:
result = replace(result, memory=section['memory'])

if 'mode' in section:
mode = section['mode']
if mode != 'system' and mode != 'user':
raise Exception('Possible mode values: system, user')
result = replace(result, mode=Mode[mode.capitalize()])


return result

return Layer(
Expand Down Expand Up @@ -215,7 +229,8 @@ def _yield_args():
yield '-s'

if layer.general.kernel:
yield '-kernel'
if not layer.general.mode or layer.general.mode == Mode.System:
yield '-kernel'
yield layer.general.kernel

if layer.general.kernel_cmdline:
Expand Down
6 changes: 5 additions & 1 deletion tests/test_layer_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from qemu_runner.argument import Argument
from qemu_runner.layer import Layer, build_command_line, GeneralSettings
from qemu_runner.layer import Layer, build_command_line, GeneralSettings, Mode

MY_ENGINE = GeneralSettings(engine='my-engine')

Expand Down Expand Up @@ -38,6 +38,10 @@
Layer(GeneralSettings(engine='my-engine', kernel='abc.elf')),
['my-engine', '-kernel', 'abc.elf']
),
(
Layer(GeneralSettings(engine='my-engine', kernel='abc.elf', mode=Mode.User)),
['my-engine', 'abc.elf']
),
(
Layer(GeneralSettings(engine='my-engine', kernel='abc.elf', kernel_cmdline='a b c')),
['my-engine', '-kernel', 'abc.elf', '-append', 'a b c']
Expand Down
11 changes: 10 additions & 1 deletion tests/test_layer_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from qemu_runner.argument import Argument
from qemu_runner.layer import Layer, GeneralSettings, parse_layer
from qemu_runner.layer import Layer, GeneralSettings, parse_layer, Mode


@pytest.mark.parametrize(('text', 'expected'), [
Expand All @@ -30,6 +30,15 @@
""",
Layer(general=GeneralSettings(engine='my-engine', kernel='my-kernel.elf', kernel_cmdline='a b c'))
),
(
"""
[general]
engine = my-engine
kernel = my-kernel.elf
mode = user
""",
Layer(general=GeneralSettings(engine='my-engine', kernel='my-kernel.elf', mode=Mode.User))
),
(
"""
[general]
Expand Down

0 comments on commit bc80628

Please sign in to comment.