diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 58bcd85..2744404 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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 \ No newline at end of file + run: tox diff --git a/src/qemu_runner/layer.py b/src/qemu_runner/layer.py index ad4c453..762972a 100644 --- a/src/qemu_runner/layer.py +++ b/src/qemu_runner/layer.py @@ -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 @@ -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]: @@ -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( @@ -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: diff --git a/tests/test_layer_cmdline.py b/tests/test_layer_cmdline.py index 1d70edb..b65633c 100644 --- a/tests/test_layer_cmdline.py +++ b/tests/test_layer_cmdline.py @@ -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') @@ -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'] diff --git a/tests/test_layer_parsing.py b/tests/test_layer_parsing.py index a70c703..a65c341 100644 --- a/tests/test_layer_parsing.py +++ b/tests/test_layer_parsing.py @@ -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'), [ @@ -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]