Skip to content

Commit 7af3060

Browse files
committed
Add primitive topic handling for mcap files
Signed-off-by: Pierre R. Mai <pmai@pmsf.de>
1 parent aedf301 commit 7af3060

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

qc_ositrace/checks/deserialization/deserialization_checker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def run_checks(config: Configuration, result: Result) -> None:
6868
try:
6969
try:
7070
trace = OSITrace(
71-
config.get_config_param("InputFile"), config.get_config_param("osiType")
71+
config.get_config_param("InputFile"),
72+
config.get_config_param("osiType"),
73+
False,
74+
config.get_config_param("osiTopic"),
7275
)
7376
except Exception as e:
7477
logging.error(f"Error reading input file: {e}")

qc_ositrace/checks/osirules/osirules_checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,12 @@ def run_checks(config: Configuration, result: Result) -> None:
469469

470470
try:
471471
try:
472-
trace = OSITrace(config.get_config_param("InputFile"), expected_type_name)
472+
trace = OSITrace(
473+
config.get_config_param("InputFile"),
474+
expected_type_name,
475+
False,
476+
config.get_config_param("osiTopic"),
477+
)
473478
except Exception as e:
474479
logging.error(f"Error reading input file: {e}")
475480
raise RuntimeError(f"Error reading input file: {e}") from e

qc_ositrace/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def args_entrypoint() -> argparse.Namespace:
2828
type=pathlib.Path,
2929
help="Path to the input OSI Trace file.",
3030
)
31+
parser.add_argument(
32+
"--osiTopic",
33+
type=str,
34+
help="Channel topic of a multi-trace OSI Trace file to select.",
35+
)
3136
parser.add_argument(
3237
"--osiType",
3338
type=str,
@@ -101,6 +106,9 @@ def main():
101106
logging.info("Setting input file: %s", args.input_file)
102107
config.set_config_param("InputFile", str(args.input_file))
103108

109+
if args.osiTopic:
110+
logging.info("Setting OSI Topic: %s", args.osiTopic)
111+
config.set_config_param("osiTopic", args.osiTopic)
104112
if args.osiType:
105113
logging.info("Setting OSI Type: %s", args.osiType)
106114
config.set_config_param("osiType", args.osiType)

tests/test_deserialization_checks.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
from typing import List
66

7+
from qc_ositrace.checks.deserialization.deserialization_constants import (
8+
CHECKER_ID as deserialization_checker_id,
9+
)
710
from qc_baselib import IssueSeverity
811

912
from test_setup import *
@@ -58,3 +61,36 @@ def test_deserialization_expected_version(
5861
launch_main(monkeypatch)
5962
check_issues(rule_uid, issue_count, issue_severity)
6063
cleanup_files()
64+
65+
66+
@pytest.mark.parametrize(
67+
"target_file,target_topic,target_type,target_version,issue_count",
68+
[
69+
("360", "MySensorView", "SensorView", "3.5.0", 547),
70+
("360", "MySensorView", "SensorView", "3.6.0", 0),
71+
("360", "Foo", "SensorView", "3.6.0", -1),
72+
],
73+
)
74+
def test_deserialization_mcap_topic(
75+
target_file: str,
76+
target_topic: str,
77+
target_type: str,
78+
target_version: str,
79+
issue_count: int,
80+
monkeypatch,
81+
) -> None:
82+
base_path = "tests/data/deserialization_expected_version/"
83+
target_file_name = f"deserialization_expected_version_{target_file}.mcap"
84+
rule_uid = "asam.net:osi:3.0.0:deserialization.expected_version"
85+
issue_severity = IssueSeverity.ERROR
86+
87+
target_file_path = os.path.join(base_path, target_file_name)
88+
create_test_config(
89+
target_file_path, target_type, target_version, None, target_topic
90+
)
91+
launch_main(monkeypatch)
92+
if issue_count < 0:
93+
check_failure(deserialization_checker_id)
94+
else:
95+
check_issues(rule_uid, issue_count, issue_severity)
96+
cleanup_files()

tests/test_setup.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
from typing import Optional
55

6+
from contextlib import suppress
7+
68
import qc_ositrace.main as main
79

810
from qc_ositrace import constants
9-
from qc_baselib import Configuration, Result, IssueSeverity
11+
from qc_baselib import Configuration, Result, IssueSeverity, StatusType
1012

1113
CONFIG_FILE_PATH = "bundle_config.xml"
1214
REPORT_FILE_PATH = "osi_bundle_report.xqar"
@@ -17,6 +19,7 @@ def create_test_config(
1719
target_file_type: str,
1820
target_file_version: Optional[str] = None,
1921
target_file_rules: Optional[str] = None,
22+
target_file_topic: Optional[str] = None,
2023
):
2124
test_config = Configuration()
2225
test_config.set_config_param(name="InputFile", value=target_file_path)
@@ -25,6 +28,8 @@ def create_test_config(
2528
test_config.set_config_param(name="osiVersion", value=target_file_version)
2629
if target_file_rules is not None:
2730
test_config.set_config_param(name="osiRulesFile", value=target_file_rules)
31+
if target_file_topic is not None:
32+
test_config.set_config_param(name="osiTopic", value=target_file_topic)
2833
test_config.register_checker_bundle(checker_bundle_name=constants.BUNDLE_NAME)
2934
test_config.set_checker_bundle_param(
3035
checker_bundle_name=constants.BUNDLE_NAME,
@@ -47,6 +52,14 @@ def check_issues(rule_uid: str, issue_count: int, severity: IssueSeverity):
4752
assert issue.level == severity
4853

4954

55+
def check_failure(checker_id: str):
56+
result = Result()
57+
result.load_from_file(REPORT_FILE_PATH)
58+
59+
status = result.get_checker_status(checker_id)
60+
assert status == StatusType.ERROR
61+
62+
5063
def launch_main(monkeypatch):
5164
monkeypatch.setattr(
5265
sys,
@@ -61,5 +74,6 @@ def launch_main(monkeypatch):
6174

6275

6376
def cleanup_files():
64-
os.remove(REPORT_FILE_PATH)
65-
os.remove(CONFIG_FILE_PATH)
77+
with suppress(Exception):
78+
os.remove(REPORT_FILE_PATH)
79+
os.remove(CONFIG_FILE_PATH)

0 commit comments

Comments
 (0)