Skip to content

Commit

Permalink
Add tests that simply run all (SIL) configs in everest-core/config (#437
Browse files Browse the repository at this point in the history
)

* Add tests that simply run all (SIL) configs in everest-core/config
* Remove obsolete config-hil.yaml
* Restrict config tests to files following the config-*.yaml convention
* Fix pytest invocation example
* Do not set pytest.everest_configs if directory doesn't exist
* Skip test config

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
Co-authored-by: Andreas Heinrich <[email protected]>
  • Loading branch information
hikinggrass and andistorm authored Feb 9, 2024
1 parent 49ea0bf commit 3d4792c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 23 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
60 changes: 60 additions & 0 deletions tests/core_tests/config_tests.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3d4792c

Please sign in to comment.