From 77fc614916c1afa506fccb0ff2e5260aae8608b6 Mon Sep 17 00:00:00 2001 From: Jeremy Johnson Date: Mon, 4 Sep 2023 17:04:21 +0100 Subject: Add desc.json schema validation with compliance/data_gen extensions Rename scripts utlities to tosa_* such as tosa_json2numpy Signed-off-by: Jeremy Johnson Change-Id: Ie8d584e2afb189fb74cf96b39590c7c27444ba14 --- verif/tests/test_schemavalidation.py | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 verif/tests/test_schemavalidation.py (limited to 'verif') 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) -- cgit v1.2.1