diff --git a/tests/README.md b/tests/README.md index 8c8268ff1..2d16c2b8c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -28,7 +28,7 @@ Go to your "everest-core/**tests**" folder and execute *pytest*: ```bash cd ~/checkout/everest-workspace/everest-core/tests -pytest-3 -s ./core_tests/startup_tests.py --path .. --junitxml=results.xml +pytest --everest-prefix ../build/dist core_tests/*.py framework_tests/*.py ``` After execution a "results.xml" file should be available in the "everest-core/**tests**" folder, which details the current test results. diff --git a/tests/conftest.py b/tests/conftest.py index b5cdc069f..6cac93ee4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,29 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest +# Copyright Pionix GmbH and Contributors to EVerest + +from pathlib import Path +import pytest -import os def pytest_addoption(parser): parser.addoption("--everest-prefix", action="store", default="../build/dist", help="everest prefix path; default = '../build/dist'") + + +def pytest_configure(config): + everest_prefix = config.getoption('--everest-prefix') + everest_config_path = Path(everest_prefix) / 'etc/everest' + if not everest_config_path.exists(): + return + everest_configs = [path for path in everest_config_path.iterdir( + ) if path.name.startswith('config-') and path.name.endswith('.yaml')] + pytest.everest_configs = {} + pytest.everest_configs['params'] = [] + pytest.everest_configs['ids'] = [] + for config_path in everest_configs: + config_id = config_path.stem + if config_id == 'config-sil-gen-pm' or config_id == 'config-test-cpp-error-handling': + # skip + continue + pytest.everest_configs['params'].append(config_path) + pytest.everest_configs['ids'].append(config_id) diff --git a/tests/core_tests/config_tests.py b/tests/core_tests/config_tests.py new file mode 100644 index 000000000..2b39f4576 --- /dev/null +++ b/tests/core_tests/config_tests.py @@ -0,0 +1,60 @@ + +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright Pionix GmbH and Contributors to EVerest + +from copy import deepcopy +import logging +import os +from pathlib import Path +import pty +import pytest +from tempfile import mkdtemp +from typing import Dict + +from everest.testing.core_utils.fixtures import * +from everest.testing.core_utils.everest_core import EverestCore + +from everest.testing.core_utils import EverestConfigAdjustmentStrategy + + +class EverestCoreConfigSilGenPmConfigurationAdjustment(EverestConfigAdjustmentStrategy): + def __init__(self): + self.temporary_directory = mkdtemp() + self.serial_port_0, self.serial_port_1 = pty.openpty() + # FIXME: cleanup socket after test + self.serial_port_0_name = os.ttyname(self.serial_port_0) + + def adjust_everest_configuration(self, everest_config: Dict): + adjusted_config = deepcopy(everest_config) + + adjusted_config["active_modules"]["serial_comm_hub"]["config_implementation"]["main"]["serial_port"] = self.serial_port_0_name + + return adjusted_config + + +@pytest.mark.everest_core_config('config-sil-gen-pm.yaml') +@pytest.mark.everest_config_adaptions(EverestCoreConfigSilGenPmConfigurationAdjustment()) +@pytest.mark.asyncio +async def test_start_config_sil_gen_pm(everest_core: EverestCore): + logging.info(">>>>>>>>> test_start_config_sil_gen_pm <<<<<<<<<") + + everest_core.start() + + +class TestConfigsInDirectory: + @pytest.fixture(params=pytest.everest_configs['params'], ids=pytest.everest_configs['ids']) + def core_config(self, request) -> EverestEnvironmentCoreConfiguration: + everest_prefix = Path(request.config.getoption("--everest-prefix")) + + everest_config_path = request.param + + return EverestEnvironmentCoreConfiguration( + everest_core_path=everest_prefix, + template_everest_config_path=everest_config_path, + ) + + @pytest.mark.asyncio + async def test_config(self, everest_core: EverestCore): + logging.info(">>>>>>>>> test_config <<<<<<<<<") + everest_core.start() diff --git a/tests/pytest.ini b/tests/pytest.ini index 7204f927a..c6aea78b6 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -4,3 +4,4 @@ log_level=debug asyncio_mode=strict markers = everest_core_config: marks tests using a specific config (deselect with '-m "not everest_core_config"') + everest_config_adaptions: modify config for a specific testcase