diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /.github/scripts/tests/test_linux_ccache_policy.py | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to '.github/scripts/tests/test_linux_ccache_policy.py')
| -rw-r--r-- | .github/scripts/tests/test_linux_ccache_policy.py | 189 |
1 files changed, 181 insertions, 8 deletions
diff --git a/.github/scripts/tests/test_linux_ccache_policy.py b/.github/scripts/tests/test_linux_ccache_policy.py index 42c97e01..4a6ff3d8 100644 --- a/.github/scripts/tests/test_linux_ccache_policy.py +++ b/.github/scripts/tests/test_linux_ccache_policy.py @@ -1,4 +1,5 @@ import pathlib +import re import unittest @@ -9,6 +10,32 @@ class LinuxCcachePolicyTests(unittest.TestCase): def read(self, relative_path): return (REPOSITORY / relative_path).read_text(encoding="utf-8") + def sanitizer_step(self, name): + action = self.read(".github/actions/build-linux-sanitizers/action.yml") + match = re.search( + rf"^ - name: {re.escape(name)}\n(?P<body>.*?)(?=^ - |\Z)", + action, + re.MULTILINE | re.DOTALL, + ) + self.assertIsNotNone(match, name) + return match.group("body") + + def armhf_job(self, name): + workflow = self.read(".github/workflows/build-linux.yml") + body = workflow.split(f"\n {name}:\n", 1)[1] + following = re.search(r"\n [A-Za-z0-9_-]+:\n", body) + return body[:following.start() + 1] if following else body + + def armhf_step(self, name, job="build-armhf"): + workflow = self.armhf_job(job) + match = re.search( + rf"^ - name: {re.escape(name)}\n(?P<body>.*?)(?=^ - |\Z)", + workflow, + re.MULTILINE | re.DOTALL, + ) + self.assertIsNotNone(match, name) + return match.group("body") + def assert_cache_tiers(self, text, prefix): primary = ( f"{prefix}${{{{ steps.image.outputs.ccache_compatibility_id }}}}-" @@ -42,6 +69,63 @@ class LinuxCcachePolicyTests(unittest.TestCase): action, ) + def test_sanitizer_save_requires_trusted_successful_build(self): + action = self.read(".github/actions/build-linux-sanitizers/action.yml") + save = self.sanitizer_step("Save sanitizer objects") + for condition in ( + "inputs.save_ccache == 'true'", + "github.ref == 'refs/heads/develop'", + "steps.image.outputs.recipe_match == 'true'", + "steps.ccache.outputs.cache-hit != 'true'", + ): + self.assertIn(condition, save) + self.assertNotIn("always()", save) + self.assertNotIn("!cancelled()", save) + self.assertIn("key: ${{ steps.ccache.outputs.cache-primary-key }}", save) + self.assertIn("path: ${{ steps.sanitizer.outputs.ccache_dir }}", save) + self.assertLess( + action.index("- name: Require sanitizer tests to pass"), + action.index("- name: Save sanitizer objects"), + ) + + def test_sanitizer_tests_remain_enabled_by_default(self): + workflow = self.read(".github/workflows/build-linux-sanitizers.yml") + action = self.read(".github/actions/build-linux-sanitizers/action.yml") + self.assertRegex( + workflow, + r" run_tests:\n(?: .*\n)*? type: boolean\n default: true", + ) + self.assertRegex( + action, + r' run_tests:\n(?: .*\n)*? default: "true"', + ) + self.assertIn("run_tests: ${{ inputs.run_tests }}", workflow) + self.assertIn("inputs.sanitizer == 'tsan' && 180 || 60", workflow) + + def test_build_only_sanitizer_keeps_test_targets_and_instrumentation(self): + configure = self.sanitizer_step("Configure sanitizer build") + self.assertIn("-DWSJT_ENABLE_TESTS=ON", configure) + self.assertIn("-DWSJT_ENABLE_GUI_SMOKE_TESTS=ON", configure) + for name in ( + "Configure sanitizer build", + "Build sanitizer targets", + "Verify sanitizer instrumentation", + ): + self.assertNotIn("inputs.run_tests", self.sanitizer_step(name)) + for name in ( + "Prepare test scratch directory", + "Run tests", + "Publish test summary", + "Upload test results", + "Require sanitizer tests to pass", + ): + with self.subTest(step=name): + self.assertIn("inputs.run_tests == 'true'", self.sanitizer_step(name)) + enforce = self.sanitizer_step("Require sanitizer tests to pass") + self.assertIn("always()", enforce) + self.assertIn('steps.ctest.outcome }}" != "success"', enforce) + self.assertIn("exit 1", enforce) + def test_sanitizer_cache_keeps_profile_and_generation(self): action = self.read(".github/actions/build-linux-sanitizers/action.yml") self.assert_cache_tiers( @@ -52,10 +136,6 @@ class LinuxCcachePolicyTests(unittest.TestCase): 'export CCACHE_COMPILERCHECK="${{ steps.image.outputs.ccache_compiler_check }}"', action, ) - self.assertIn( - "if: inputs.save_ccache == 'true' && steps.image.outputs.recipe_match == 'true' && steps.ccache.outputs.cache-hit != 'true'", - action, - ) def test_armhf_verifies_and_forwards_cache_identity(self): workflow = self.read(".github/workflows/build-linux.yml") @@ -72,7 +152,7 @@ class LinuxCcachePolicyTests(unittest.TestCase): workflow.count( "RUNTIME_IMAGE: ${{ needs.resolve-image.outputs.image_reference }}" ), - 2, + 4, ) self.assertIn("build-linux-armhf-cross.sh", workflow) self.assertIn("validate-linux-armhf-runtime.sh", workflow) @@ -83,16 +163,109 @@ class LinuxCcachePolicyTests(unittest.TestCase): self.assertIn("cross_recipe_match", workflow) self.assertIn("runtime_recipe_match", workflow) self.assertIn( - "if: inputs.save_ccache && steps.image.outputs.recipe_match == 'true' && steps.ccache.outputs.cache-hit != 'true'", + "if: inputs.save_ccache && (!inputs.armhf_build_only || github.ref == 'refs/heads/develop') && steps.image.outputs.recipe_match == 'true' && steps.ccache.outputs.cache-hit != 'true'", workflow, ) - def test_release_accepts_separately_promoted_armhf_recipe(self): + def test_armhf_build_only_preserves_compilation_audits_and_pair_verification(self): + workflow = self.read(".github/workflows/build-linux.yml") + self.assertEqual(len(re.findall( + r" armhf_build_only:\n(?: .*\n)*? type: boolean\n default: false", + workflow, + )), 2) + self.assertIn('if [ "$ARMHF_BUILD_ONLY" = true ] && [ "$ARCH" != armhf ]; then', workflow) + for name in ("Inspect ARMHF image pair", "Cross-build ARMHF binaries"): + self.assertNotIn("if:", self.armhf_step(name)) + compile_step = self.armhf_step("Cross-build ARMHF binaries") + self.assertIn("ARMHF_BUILD_ONLY: ${{ inputs.armhf_build_only }}", compile_step) + self.assertIn("-e ARMHF_BUILD_ONLY", compile_step) + script = self.read(".github/scripts/build-linux-armhf-cross.sh") + self.assertIn("-DWSJT_ENABLE_TESTS=ON", script) + skip_install = script.index('if [ "$ARMHF_BUILD_ONLY" = true ]; then', script.index("cmake --build")) + for audit in ("validate_linux_build_executables", ".github/scripts/audit-armhf-cross-build.sh"): + self.assertLess(script.index(audit), skip_install) + self.assertLess(skip_install, script.index("cmake --install")) + self.assertIn("exit 0", script[skip_install:script.index("cmake --install")]) + + def test_armhf_build_only_skips_runtime_and_artifact_steps(self): + test_job = self.armhf_job("test-armhf") + self.assertIn(" if: inputs.arch == 'armhf' && !inputs.armhf_build_only\n", test_job) + for name in ( + "Test and package on native ARMv7", "Publish armhf test summary", + "Upload armhf AppImage startup diagnostics", "Upload .deb", "Upload RPM", + "Upload AppImage", "Upload build artifacts", "Upload test results", + "Upload release tarballs", + ): + with self.subTest(step=name): + self.assertIn(f" - name: {name}\n", test_job) + self.assertNotIn(f" - name: {name}\n", self.armhf_job("build-armhf")) + for name in ("Pack ARMHF build tree", "Upload ARMHF build tree"): + with self.subTest(step=name): + self.assertIn("if: ${{ !inputs.armhf_build_only }}", self.armhf_step(name)) + + def test_armhf_runtime_runs_natively_on_an_arm_runner_from_the_cross_build_tree(self): + build_job = self.armhf_job("build-armhf") + test_job = self.armhf_job("test-armhf") + self.assertIn(" runs-on: ubuntu-24.04\n", build_job) + self.assertIn(" runs-on: ubuntu-24.04-arm\n", test_job) + self.assertIn(" needs: [resolve-image, build-armhf]\n", test_job) + self.assertNotIn("setup-qemu-action", test_job) + self.assertNotIn("validate-linux-armhf-runtime.sh", build_job) + self.assertIn("bash .github/scripts/validate-linux-armhf-runtime.sh", self.armhf_step("Test and package on native ARMv7", "test-armhf")) + pack = self.armhf_step("Pack ARMHF build tree") + self.assertIn( + "sudo tar --create --file armhf-build-tree.tar --exclude='wsjtx-build/*.o' --exclude='wsjtx-build/*.a' wsjtx-build AppDir\n", + pack, + ) + self.assertLess(build_job.index("- name: Save armhf ccache"), build_job.index("- name: Pack ARMHF build tree")) + for step in ("actions/checkout@", "docker/login-action@"): + self.assertIn(step, test_job) + self.assertLess(test_job.index("docker/login-action@"), test_job.index("- name: Require native 32-bit ARM execution")) + self.assertLess(test_job.index("- name: Require native 32-bit ARM execution"), test_job.index("- name: Download ARMHF build tree")) + preflight = self.armhf_step("Require native 32-bit ARM execution", "test-armhf") + self.assertIn("grep -Eq '^CPU op-mode\\(s\\):.*32-bit'", preflight) + self.assertIn("/proc/sys/fs/binfmt_misc/qemu-arm", preflight) + self.assertIn('docker run --rm --platform linux/arm/v7 "$RUNTIME_IMAGE" getconf LONG_BIT', preflight) + runtime_step = self.armhf_step("Test and package on native ARMv7", "test-armhf") + for fragment in ("docker run --rm --platform linux/arm/v7", '-v "${GITHUB_WORKSPACE}:/work"', "-w /work", "-e ARMHF_RUNTIME_PHASE"): + self.assertIn(fragment, runtime_step) + for name in ("Publish armhf test summary", "Upload test results"): + self.assertIn(" if: always()\n", self.armhf_step(name, "test-armhf")) + for name, artifact in ( + ("Upload .deb", "wsjtx-${{ inputs.version }}-linux-armhf-deb"), + ("Upload RPM", "wsjtx-${{ inputs.version }}-linux-armhf-rpm"), + ("Upload AppImage", "wsjtx-${{ inputs.version }}-linux-armhf-AppImage"), + ): + self.assertIn(f" name: {artifact}\n", self.armhf_step(name, "test-armhf")) + self.assertIn("name: armhf-build-tree\n", self.armhf_step("Upload ARMHF build tree")) + self.assertIn("name: armhf-build-tree\n", self.armhf_step("Download ARMHF build tree", "test-armhf")) + self.assertIn("tar --extract --file armhf-build-tree.tar", self.armhf_step("Unpack ARMHF build tree", "test-armhf")) + self.assertLess(test_job.index("- name: Unpack ARMHF build tree"), test_job.index("- name: Test and package on native ARMv7")) + runtime = self.read(".github/scripts/validate-linux-armhf-runtime.sh") + self.assertIn("ctest --parallel 3 --output-on-failure", runtime) + self.assertNotIn("--exclude-regex", runtime) + + def test_armhf_build_only_save_requires_trusted_successful_audits(self): + save = self.armhf_step("Save armhf ccache") + self.assertIn("(!inputs.armhf_build_only || github.ref == 'refs/heads/develop')", save) + self.assertIn("inputs.save_ccache", save) + self.assertIn("steps.image.outputs.recipe_match == 'true'", save) + self.assertIn("steps.ccache.outputs.cache-hit != 'true'", save) + self.assertIn("key: ${{ steps.ccache.outputs.cache-primary-key }}", save) + self.assertNotIn("always()", save) + self.assertNotIn("!cancelled()", save) + build_job = self.armhf_job("build-armhf") + self.assertLess(build_job.index("- name: Cross-build ARMHF binaries"), build_job.index("- name: Save armhf ccache")) + + def test_release_requires_pinned_armhf_pair_without_stale_recipe_fallback(self): workflow = self.read(".github/workflows/release.yml") armhf_job = workflow.split(" linux-armhf:\n", 1)[1].split( "\n windows:\n", 1 )[0] - self.assertIn("allow_stale_image: true", armhf_job) + self.assertNotIn("allow_stale_image: true", armhf_job) + self.assertIn("image_source: public-release", armhf_job) + self.assertIn("image_digest: ${{ needs.prepare.outputs.armhf_digest }}", armhf_job) + self.assertIn("armhf_cross_image_digest: ${{ needs.prepare.outputs.armhf_cross_digest }}", armhf_job) if __name__ == "__main__": |
