scripts: tests: sanitycheck: Add testcases for schema validation.
test_sanitycheck.py: Add testcases for correct & incorrect
testcase/platform yaml schemas.
Signed-off-by: Aastha Grover <aastha.grover@intel.com>
diff --git a/scripts/tests/sanitycheck/test_data/platform_correct_schema.yaml b/scripts/tests/sanitycheck/test_data/platform_correct_schema.yaml
new file mode 100755
index 0000000..a93ece4
--- /dev/null
+++ b/scripts/tests/sanitycheck/test_data/platform_correct_schema.yaml
@@ -0,0 +1,4 @@
+testing:
+ ignore_tags:
+ - correct_schema_1
+ - correct_schema_2
diff --git a/scripts/tests/sanitycheck/test_data/platform_incorrect_schema.yaml b/scripts/tests/sanitycheck/test_data/platform_incorrect_schema.yaml
new file mode 100755
index 0000000..da9a33b
--- /dev/null
+++ b/scripts/tests/sanitycheck/test_data/platform_incorrect_schema.yaml
@@ -0,0 +1,4 @@
+test:
+ ignore_tags:
+ - incorrect_schema_1
+ - incorrect_schema_2
diff --git a/scripts/tests/sanitycheck/test_data/testcase_incorrect_schema.yaml b/scripts/tests/sanitycheck/test_data/testcase_incorrect_schema.yaml
new file mode 100755
index 0000000..779f53e
--- /dev/null
+++ b/scripts/tests/sanitycheck/test_data/testcase_incorrect_schema.yaml
@@ -0,0 +1,4 @@
+test:
+ testing.incorrect_schema:
+ tag: demo incorrect_tag
+ platform_exclude: demo_board_1
diff --git a/scripts/tests/sanitycheck/test_sanitycheck.py b/scripts/tests/sanitycheck/test_sanitycheck.py
new file mode 100644
index 0000000..11906dc
--- /dev/null
+++ b/scripts/tests/sanitycheck/test_sanitycheck.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020 Intel Corporation
+#
+# SPDX-License-Identifier: Apache-2.0
+"""
+This test file contains foundational testcases for Sanitycheck tool
+"""
+
+import os
+import sys
+import pytest
+
+ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
+sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/sanity_chk"))
+
+import scl
+from sanitylib import SanityConfigParser
+
+def test_yamlload():
+ """ Test to check if loading the non-existent files raises the errors """
+ filename = 'testcase_nc.yaml'
+ with pytest.raises(FileNotFoundError):
+ scl.yaml_load(filename)
+
+
+@pytest.mark.parametrize("filename, schema",
+ [("testcase_correct_schema.yaml", "testcase-schema.yaml"),
+ ("platform_correct_schema.yaml", "platform-schema.yaml")])
+def test_correct_schema(filename, schema, test_data):
+ """ Test to validate the testcase schema"""
+ filename = test_data + filename
+ schema = scl.yaml_load(ZEPHYR_BASE +'/scripts/sanity_chk/' + schema)
+ data = SanityConfigParser(filename, schema)
+ data.load()
+ assert data
+
+
+@pytest.mark.parametrize("filename, schema",
+ [("testcase_incorrect_schema.yaml", "testcase-schema.yaml"),
+ ("platform_incorrect_schema.yaml", "platform-schema.yaml")])
+def test_incorrect_schema(filename, schema, test_data):
+ """ Test to validate the exception is raised for incorrect testcase schema"""
+ filename = test_data + filename
+ schema = scl.yaml_load(ZEPHYR_BASE +'/scripts/sanity_chk/' + schema)
+ with pytest.raises(Exception) as exception:
+ scl.yaml_load_verify(filename, schema)
+ assert str(exception.value) == "Schema validation failed"