|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | +import tempfile |
| 5 | +import unittest |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | + |
| 9 | +PROJECT_ROOT = Path(__file__).resolve().parents[2] |
| 10 | + |
| 11 | + |
| 12 | +class BuildConfigurationTest(unittest.TestCase): |
| 13 | + def run_configure(self, *cmake_args: str) -> subprocess.CompletedProcess[str]: |
| 14 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 15 | + build_dir = Path(tmpdir) / "build" |
| 16 | + return subprocess.run( |
| 17 | + [ |
| 18 | + "cmake", |
| 19 | + "-S", |
| 20 | + str(PROJECT_ROOT), |
| 21 | + "-B", |
| 22 | + str(build_dir), |
| 23 | + "-G", |
| 24 | + "Ninja", |
| 25 | + *cmake_args, |
| 26 | + ], |
| 27 | + capture_output=True, |
| 28 | + text=True, |
| 29 | + check=False, |
| 30 | + ) |
| 31 | + |
| 32 | + def run_configure_and_build( |
| 33 | + self, |
| 34 | + target: str, |
| 35 | + *cmake_args: str, |
| 36 | + ) -> subprocess.CompletedProcess[str]: |
| 37 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 38 | + build_dir = Path(tmpdir) / "build" |
| 39 | + configure = subprocess.run( |
| 40 | + [ |
| 41 | + "cmake", |
| 42 | + "-S", |
| 43 | + str(PROJECT_ROOT), |
| 44 | + "-B", |
| 45 | + str(build_dir), |
| 46 | + "-G", |
| 47 | + "Ninja", |
| 48 | + *cmake_args, |
| 49 | + ], |
| 50 | + capture_output=True, |
| 51 | + text=True, |
| 52 | + check=False, |
| 53 | + ) |
| 54 | + if configure.returncode != 0: |
| 55 | + return configure |
| 56 | + |
| 57 | + return subprocess.run( |
| 58 | + [ |
| 59 | + "cmake", |
| 60 | + "--build", |
| 61 | + str(build_dir), |
| 62 | + "--target", |
| 63 | + target, |
| 64 | + "-j2", |
| 65 | + ], |
| 66 | + capture_output=True, |
| 67 | + text=True, |
| 68 | + check=False, |
| 69 | + ) |
| 70 | + |
| 71 | + def test_configure_succeeds_with_benchmarks_enabled_and_tests_disabled(self): |
| 72 | + result = self.run_configure( |
| 73 | + "-DCMAKE_BUILD_TYPE=Debug", |
| 74 | + "-DHPC_BUILD_TESTS=OFF", |
| 75 | + "-DHPC_BUILD_BENCHMARKS=ON", |
| 76 | + ) |
| 77 | + |
| 78 | + self.assertEqual(result.returncode, 0, msg=result.stdout + "\n" + result.stderr) |
| 79 | + |
| 80 | + def test_auto_vectorize_build_does_not_ignore_omp_simd_pragmas(self): |
| 81 | + result = self.run_configure_and_build( |
| 82 | + "auto_vectorize", |
| 83 | + "-DCMAKE_BUILD_TYPE=Debug", |
| 84 | + "-DHPC_BUILD_TESTS=OFF", |
| 85 | + "-DHPC_BUILD_BENCHMARKS=OFF", |
| 86 | + ) |
| 87 | + |
| 88 | + self.assertEqual(result.returncode, 0, msg=result.stdout + "\n" + result.stderr) |
| 89 | + combined_output = result.stdout + "\n" + result.stderr |
| 90 | + self.assertNotIn("ignoring '#pragma omp simd'", combined_output, msg=combined_output) |
| 91 | + |
| 92 | + def test_core_test_build_avoids_core_header_warnings(self): |
| 93 | + result = self.run_configure_and_build( |
| 94 | + "core_test", |
| 95 | + "-DCMAKE_BUILD_TYPE=Debug", |
| 96 | + "-DHPC_BUILD_TESTS=ON", |
| 97 | + "-DHPC_BUILD_BENCHMARKS=OFF", |
| 98 | + ) |
| 99 | + |
| 100 | + self.assertEqual(result.returncode, 0, msg=result.stdout + "\n" + result.stderr) |
| 101 | + combined_output = result.stdout + "\n" + result.stderr |
| 102 | + self.assertNotIn("-Winterference-size", combined_output, msg=combined_output) |
| 103 | + self.assertNotIn("shadows a previous local", combined_output, msg=combined_output) |
| 104 | + |
| 105 | + |
| 106 | +if __name__ == "__main__": |
| 107 | + unittest.main() |
0 commit comments