diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2023-09-04 17:04:21 +0100 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2023-09-07 16:04:07 +0000 |
commit | 77fc614916c1afa506fccb0ff2e5260aae8608b6 (patch) | |
tree | a3b68a8c2375311f65446710e0e960c784f76dc3 /verif/tests | |
parent | 7021ef064f7daeca260bb1f1bd61b5bbc6473aa5 (diff) | |
download | reference_model-77fc614916c1afa506fccb0ff2e5260aae8608b6.tar.gz |
Add desc.json schema validation with compliance/data_gen extensions
Rename scripts utlities to tosa_* such as tosa_json2numpy
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: Ie8d584e2afb189fb74cf96b39590c7c27444ba14
Diffstat (limited to 'verif/tests')
-rw-r--r-- | verif/tests/test_schemavalidation.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/verif/tests/test_schemavalidation.py b/verif/tests/test_schemavalidation.py new file mode 100644 index 0000000..1ecd3ee --- /dev/null +++ b/verif/tests/test_schemavalidation.py @@ -0,0 +1,102 @@ +"""Tests for schemavalidation.py.""" +# Copyright (c) 2023, ARM Limited. +# SPDX-License-Identifier: Apache-2.0 +import pytest +import schemavalidation.schemavalidation as sch +from jsonschema.exceptions import ValidationError + + +def test_schemavalidation_full_fail(): + json = {} + + sv = sch.TestDescSchemaValidator() + with pytest.raises(ValidationError) as excinfo: + sv.validate_config(json) + info = str(excinfo.value).split("\n") + assert info[0] == "'tosa_file' is a required property" + + +def test_schemavalidation_compliance_fail(): + json = {"version": "v"} + + sv = sch.TestDescSchemaValidator() + with pytest.raises(ValidationError) as excinfo: + sv.validate_config(json, sch.TD_SCHEMA_COMPLIANCE) + info = str(excinfo.value).split("\n") + assert info[0] == "'tensors' is a required property" + + +def test_schemavalidation_data_gen_fail(): + json = {"version": "v", "tensors": {"input": {}}} + + sv = sch.TestDescSchemaValidator() + with pytest.raises(ValidationError) as excinfo: + sv.validate_config(json, sch.TD_SCHEMA_DATA_GEN) + info = str(excinfo.value).split("\n") + assert info[0] == "'generator' is a required property" + + +def test_schemavalidation_full_minimal(): + json = { + "tosa_file": "file", + "ifm_name": ["name1", "name2"], + "ifm_file": ["file1", "file2"], + "ofm_name": ["name1", "name2"], + "ofm_file": ["file1", "file2"], + } + + sv = sch.TestDescSchemaValidator() + sv.validate_config(json) + + +def test_schemavalidation_full_unexpected(): + json = { + "tosa_file": "file", + "ifm_name": ["name1", "name2"], + "ifm_file": ["file1", "file2"], + "ofm_name": ["name1", "name2"], + "ofm_file": ["file1", "file2"], + "unexpected_property": 1, + } + + sv = sch.TestDescSchemaValidator() + with pytest.raises(ValidationError) as excinfo: + sv.validate_config(json) + info = str(excinfo.value).split("\n") + assert ( + info[0] + == "Additional properties are not allowed ('unexpected_property' was unexpected)" + ) + + +def test_schemavalidation_compliance_minimal(): + json = { + "version": "v", + "tensors": { + "output": { + "mode": "mode", + } + }, + } + + sv = sch.TestDescSchemaValidator() + sv.validate_config(json, sch.TD_SCHEMA_COMPLIANCE) + + +def test_schemavalidation_data_gen_minimal(): + json = { + "version": "v", + "tensors": { + "input": { + "generator": "generator", + "data_type": "type", + "input_type": "constant", + "shape": [], + "op": "name", + "input_pos": 0, + } + }, + } + + sv = sch.TestDescSchemaValidator() + sv.validate_config(json, sch.TD_SCHEMA_DATA_GEN) |