Skip to content

Commit

Permalink
Fix SAMM regressions
Browse files Browse the repository at this point in the history
Also adding some tests

Signed-off-by: Erik Jaegervall <[email protected]>
  • Loading branch information
erikbosch committed Oct 24, 2024
1 parent 6fb0625 commit 70e5ef8
Show file tree
Hide file tree
Showing 8 changed files with 601 additions and 13 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ var/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Expand Down
6 changes: 3 additions & 3 deletions src/vss_tools/exporters/samm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def __setup_environment(output_namespace, vspec_version, split_depth: int) -> No
cfg.init(output_namespace, vspec_version, split_depth)

global VSSConcepts
VSSConcepts = importlib.import_module("vss_tools.vspec.exporters.samm.helpers.samm_concepts").VSSConcepts
VSSConcepts = importlib.import_module("vss_tools.exporters.samm.helpers.samm_concepts").VSSConcepts

global vss_helper
vss_helper = importlib.import_module("vss_tools.vspec.exporters.samm.helpers.vss_helper")
vss_helper = importlib.import_module("vss_tools.exporters.samm.helpers.vss_helper")

global ttl_helper
ttl_helper = importlib.import_module("vss_tools.vspec.exporters.samm.helpers.ttl_helper")
ttl_helper = importlib.import_module("vss_tools.exporters.samm.helpers.ttl_helper")


# TODO: Currently this is a workaround to read the Vehicle.VersionVSS, which is provided from COVESA/VSS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
@prefix : <urn:samm:com.covesa.vss.spec:1.0.0#> .
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:A a samm:Aspect ;
samm:events () ;
samm:operations () ;
samm:preferredName "A"@en ;
samm:properties ( :a ) .

:a a samm:Property ;
samm:characteristic :ACharacteristic ;
samm:preferredName "A"@en .

:double a samm:Property ;
samm:characteristic :DoubleCharacteristic ;
samm:preferredName "Double"@en .

:float a samm:Property ;
samm:characteristic :FloatCharacteristic ;
samm:preferredName "Float"@en .

:int16 a samm:Property ;
samm:characteristic :Int16Characteristic ;
samm:preferredName "Int16"@en .

:int32 a samm:Property ;
samm:characteristic :Int32Characteristic ;
samm:preferredName "Int32"@en .

:int64 a samm:Property ;
samm:characteristic :Int64Characteristic ;
samm:preferredName "Int64"@en .

:int8 a samm:Property ;
samm:characteristic :Int8Characteristic ;
samm:preferredName "Int8"@en .

:isBoolean a samm:Property ;
samm:characteristic :IsBooleanCharacteristic ;
samm:preferredName "Is Boolean"@en .

:uInt16 a samm:Property ;
samm:characteristic :UInt16Characteristic ;
samm:preferredName "U Int16"@en .

:uInt32 a samm:Property ;
samm:characteristic :UInt32Characteristic ;
samm:preferredName "U Int32"@en .

:uInt64 a samm:Property ;
samm:characteristic :UInt64Characteristic ;
samm:preferredName "U Int64"@en .

:uInt8 a samm:Property ;
samm:characteristic :UInt8Characteristic ;
samm:preferredName "U Int8"@en .

:ACharacteristic a samm:Characteristic ;
samm:dataType :AEntity ;
samm:description """
VSS path : A
Description: Branch A."""@en ;
samm:name "ACharacteristic" .

:AEntity a samm:Entity ;
samm:properties ( [ samm:property :uInt8; samm:payloadName "uInt8" ] [ samm:property :int8; samm:payloadName "int8" ] [ samm:property :uInt16; samm:payloadName "uInt16" ] [ samm:property :int16; samm:payloadName "int16" ] [ samm:property :uInt32; samm:payloadName "uInt32" ] [ samm:property :int32; samm:payloadName "int32" ] [ samm:property :uInt64; samm:payloadName "uInt64" ] [ samm:property :int64; samm:payloadName "int64" ] [ samm:property :isBoolean; samm:payloadName "isBoolean" ] [ samm:property :float; samm:payloadName "float" ] [ samm:property :double; samm:payloadName "double" ] ) .

:DoubleCharacteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:double ;
samm:description """
VSS path : A.Double
Description: A double.
Unit : km"""@en .

:FloatCharacteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:float ;
samm:description """
VSS path : A.Float
Description: A float.
Unit : km"""@en .

:Int16Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:short ;
samm:description """
VSS path : A.Int16
Description: An int16.
Unit : km"""@en .

:Int32Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:int ;
samm:description """
VSS path : A.Int32
Description: An int32
Unit : km"""@en .

:Int64Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:long ;
samm:description """
VSS path : A.Int64
Description: An int64
Unit : km"""@en .

:Int8Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:byte ;
samm:description """
VSS path : A.Int8
Description: An int8.
Unit : km"""@en .

:IsBooleanCharacteristic a samm:Characteristic ;
samm:dataType xsd:boolean ;
samm:description """
VSS path : A.IsBoolean
Description: A boolean"""@en .

:UInt16Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:unsignedShort ;
samm:description """
VSS path : A.UInt16
Description: A uint16.
Unit : km"""@en .

:UInt32Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:unsignedShort ;
samm:description """
VSS path : A.UInt32
Description: A uint32.
Unit : km"""@en .

:UInt64Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:unsignedLong ;
samm:description """
VSS path : A.UInt64
Description: A uint64.
Unit : km"""@en .

:UInt8Characteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:unsignedByte ;
samm:description """
VSS path : A.UInt8
Description: A uint8.
Unit : km"""@en .


13 changes: 9 additions & 4 deletions tests/vspec/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
HERE = Path(__file__).resolve().parent
TEST_UNITS = HERE / "test_units.yaml"
TEST_QUANT = HERE / "test_quantities.yaml"
DEFAULT_TEST_FILE = "test.vspec"


def default_directories() -> list:
directories = []
for path in HERE.iterdir():
if path.is_dir():
if list(path.rglob("*.vspec")):
if list(path.rglob(DEFAULT_TEST_FILE)):
# Exclude directories with custom made python file
if not list(path.rglob("*.py")):
directories.append(path)
Expand All @@ -35,21 +36,25 @@ def idfn(directory: pathlib.PosixPath):


def run_exporter(directory, exporter, tmp_path):
vspec = directory / "test.vspec"
vspec = directory / DEFAULT_TEST_FILE
types = directory / "types.vspec"
output = tmp_path / f"out.{exporter}"
expected = directory / f"expected.{exporter}"
if not expected.exists():
# If you want find directory/exporter combinations not yet covered enable the assert
# assert False, f"Folder {expected} not found"
return
cmd = f"vspec export {exporter} -u {TEST_UNITS} -q {TEST_QUANT} --vspec {vspec} "
if types.exists():
cmd += f" --types {types}"
if exporter in ["apigear"]:
cmd += f" --output-dir {output}"
elif exporter in ["samm"]:
cmd += f" --target-folder {output}"
else:
cmd += f" --output {output}"
subprocess.run(cmd.split(), check=True)
if exporter in ["apigear"]:
if exporter in ["apigear", "samm"]:
dcmp = filecmp.dircmp(output, expected)
assert not (dcmp.diff_files or dcmp.left_only or dcmp.right_only)
else:
Expand All @@ -60,7 +65,7 @@ def run_exporter(directory, exporter, tmp_path):
def test_exporters(directory, tmp_path):
# Run all "supported" exporters, i.e. not those in contrib
# Exception is "binary", as it is assumed output may vary depending on target
exporters = ["apigear", "json", "jsonschema", "ddsidl", "csv", "yaml", "franca", "graphql", "go"]
exporters = ["apigear", "json", "jsonschema", "ddsidl", "csv", "yaml", "franca", "graphql", "go", "samm"]

for exporter in exporters:
run_exporter(directory, exporter, tmp_path)
16 changes: 16 additions & 0 deletions tests/vspec/test_instances/expected.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package vss

type A struct {
B B
}
type B struct {
Row1 BI1
Row2 BI1
}
type BI1 struct {
Left BI2
Right BI2
}
type BI2 struct {
C int8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@prefix : <urn:samm:com.covesa.vss.spec:1.0.0#> .
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .

:A a samm:Aspect ;
samm:events () ;
samm:operations () ;
samm:preferredName "A"@en ;
samm:properties ( :a ) .

:a a samm:Property ;
samm:characteristic :ACharacteristic ;
samm:preferredName "A"@en .

:ACharacteristic a samm:Characteristic ;
samm:dataType :AEntity ;
samm:description """
VSS path : A
Description: Branch A."""@en ;
samm:name "ACharacteristic" .

:AEntity a samm:Entity ;
samm:properties ( [ samm:property :b; samm:payloadName "b" ] ) .


Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@prefix : <urn:samm:com.covesa.vss.spec:1.0.0#> .
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:B a samm:Aspect ;
samm:events () ;
samm:operations () ;
samm:preferredName "B"@en ;
samm:properties ( :b ) .

:b a samm:Property ;
samm:characteristic :BInstanceSingleEntity ;
samm:preferredName "B"@en .

:bRow1 a samm:Property ;
samm:characteristic :BRowSingleEntity ;
samm:preferredName "B Row1"@en .

:bRow2 a samm:Property ;
samm:characteristic :BRowSingleEntity ;
samm:preferredName "B Row2"@en .

:bRowLeft a samm:Property ;
samm:characteristic :BCharacteristic ;
samm:preferredName "B Row Left"@en .

:bRowRight a samm:Property ;
samm:characteristic :BCharacteristic ;
samm:preferredName "B Row Right"@en .

:c a samm:Property ;
samm:characteristic :CCharacteristic ;
samm:preferredName "C"@en .

:BEntity a samm:Entity ;
samm:properties ( [ samm:property :c; samm:payloadName "c" ] ) .

:BInstanceEntity a samm:Entity ;
samm:properties ( [ samm:property :bRow1; samm:optional true; samm:payloadName "row1" ] [ samm:property :bRow2; samm:optional true; samm:payloadName "row2" ] ) .

:BInstanceSingleEntity a samm-c:SingleEntity ;
samm:dataType :BInstanceEntity ;
samm:name "BInstance" ;
samm:preferredName "B Instance"@en .

:BRowEntity a samm:Entity ;
samm:properties ( [ samm:property :bRowLeft; samm:optional true; samm:payloadName "left" ] [ samm:property :bRowRight; samm:optional true; samm:payloadName "right" ] ) .

:CCharacteristic a samm-c:Measurement ;
samm-c:unit unit:kilometre ;
samm:dataType xsd:byte ;
samm:description """
VSS path : A.B.C
Description: This description will also exist multiple times.
Comment : As well as this comment.
Unit : km"""@en .

:BCharacteristic a samm:Characteristic ;
samm:dataType :BEntity ;
samm:description """
VSS path : A.B
Description: This description will be duplicated.
Comment : This comment will be duplicated"""@en ;
samm:name "BCharacteristic" .

:BRowSingleEntity a samm-c:SingleEntity ;
samm:dataType :BRowEntity ;
samm:name "BRow" ;
samm:preferredName "B Row"@en .


Loading

0 comments on commit 70e5ef8

Please sign in to comment.