diff --git a/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_no_snippets.yaml b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_no_snippets.yaml new file mode 100644 index 0000000..6de7350 --- /dev/null +++ b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_no_snippets.yaml @@ -0,0 +1,21 @@ +desc: "Integration test Zephyr snippets" +min_ver: "0.22" + + +components: + dom0: + default: true + build-dir: "ZEPHYR_BUILD_DIR" + sources: + - type: west + url: "https://github.com/xen-troops/aos_core_zephyr.git" + rev: "zephyr-v3.6.0" + + builder: + type: zephyr + board: "rcar_spider" + target: aos_core_zephyr + work_dir: build + + target_images: + - "build/zephyr/zephyr.bin" diff --git a/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_one_snippet.yaml b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_one_snippet.yaml new file mode 100644 index 0000000..f633f25 --- /dev/null +++ b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_one_snippet.yaml @@ -0,0 +1,28 @@ +desc: "Integration test Zephyr snippets" +min_ver: "0.22" + + +components: + dom0: + default: true + build-dir: "ZEPHYR_BUILD_DIR" + sources: + - type: west + url: "https://github.com/xen-troops/aos_core_zephyr.git" + rev: "zephyr-v3.6.0" + + builder: + type: zephyr + board: "rcar_spider" + target: aos_core_zephyr + work_dir: build + + snippets: + - "xen_dom0" + + additional_deps: + - "dep_1" + - "dep_2" + + target_images: + - "build/zephyr/zephyr.bin" diff --git a/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_snippet_and_shield.yaml b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_snippet_and_shield.yaml new file mode 100644 index 0000000..435cb66 --- /dev/null +++ b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_snippet_and_shield.yaml @@ -0,0 +1,31 @@ +desc: "Integration test Zephyr snippets" +min_ver: "0.22" + + +components: + dom0: + default: true + build-dir: "ZEPHYR_BUILD_DIR" + sources: + - type: west + url: "https://github.com/xen-troops/aos_core_zephyr.git" + rev: "zephyr-v3.6.0" + + builder: + type: zephyr + board: "rcar_spider" + target: aos_core_zephyr + work_dir: build + + shields: + - "xen_dom0" + + snippets: + - "xen_dom0" + + additional_deps: + - "dep_1" + - "dep_2" + + target_images: + - "build/zephyr/zephyr.bin" diff --git a/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_two_snippets.yaml b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_two_snippets.yaml new file mode 100644 index 0000000..c7b540a --- /dev/null +++ b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/resources/zephyr_builder_with_two_snippets.yaml @@ -0,0 +1,29 @@ +desc: "Integration test Zephyr snippets" +min_ver: "0.22" + + +components: + dom0: + default: true + build-dir: "ZEPHYR_BUILD_DIR" + sources: + - type: west + url: "https://github.com/xen-troops/aos_core_zephyr.git" + rev: "zephyr-v3.6.0" + + builder: + type: zephyr + board: "rcar_spider" + target: aos_core_zephyr + work_dir: build + + snippets: + - "xen_dom0" + - "xen_dom1" + + additional_deps: + - "dep_1" + - "dep_2" + + target_images: + - "build/zephyr/zephyr.bin" diff --git a/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/test_zephyr_snippets_support.py b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/test_zephyr_snippets_support.py new file mode 100644 index 0000000..b4c4890 --- /dev/null +++ b/tests/integration_tests/zephyr_builder/test_zephyr_snippets_support/test_zephyr_snippets_support.py @@ -0,0 +1,85 @@ +import subprocess +import pytest +import os +import tempfile +import re +@pytest.mark.integration +def test_zephyr_one_snippet(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/zephyr_builder_with_one_snippet.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode == 0, ("The return code is equal to '0'") + + with open(tmp_dir + "/build.ninja") as f: + ninja_file = f.read() + assert re.search(r"west build .*(\$\n)?.* \$snippets .*", ninja_file) is not None, "Snippets paremeter present" + assert "snippets = -S xen_dom0" in ninja_file + +@pytest.mark.integration +def test_zephyr_two_snippets(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/zephyr_builder_with_two_snippets.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode == 0, ("The return code is equal to '0'") + + with open(tmp_dir + "/build.ninja") as f: + ninja_file = f.read() + assert re.search(r"west build .*(\$\n)?.* \$snippets .*", ninja_file) is not None, "Snippets paremeter present" + assert "snippets = -S xen_dom0 -S xen_dom1" in ninja_file + +@pytest.mark.integration +def test_zephyr_snippet_and_shield(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/zephyr_builder_with_snippet_and_shield.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode != 0, ("The return code is not equal to '0'") + assert "Both shields and snippets are specified, only one of them is allowed" in result.stderr, \ + ("The expected error message") + +@pytest.mark.integration +def test_zephyr_no_snippets(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/zephyr_builder_with_no_snippets.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode == 0, ("The return code is equal to '0'") + + with open(tmp_dir + "/build.ninja") as f: + ninja_file = f.read() + print(ninja_file) + print(re.search(r"snippets = $", ninja_file, re.M)) + assert re.search(r"snippets = $", ninja_file, re.M) is not None, "Snippets paremeter not present" + +if __name__ == "__main__": + pytest.main([__file__])