Debian Codegraph @

tests/test_cmake_dispatch.sh

raw
1 #!/bin/bash
2 # Test that the CMake build produces a portable binary with runtime
3 # SIMD dispatch, matching the Makefile build's multi-ISA compilation.
4 set -e
5
6 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7 PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
8 cd "$PROJECT_DIR"
9
10 BUILD_DIR="/tmp/abpoa_cmake_dispatch_$$"
11 trap "rm -rf $BUILD_DIR" EXIT
12
13 ERRORS=0
14
15 # Build via CMake
16 if ! cmake -B "$BUILD_DIR" -S . -DCMAKE_BUILD_TYPE=Release >/dev/null 2>&1; then
17 echo "FAIL: cmake configure failed"
18 ERRORS=$((ERRORS + 1))
19 fi
20
21 if [ $ERRORS -eq 0 ]; then
22 if ! cmake --build "$BUILD_DIR" -j$(sysctl -n hw.logicalcpu 2>/dev/null || nproc 2>/dev/null || echo 4) >/dev/null 2>&1; then
23 echo "FAIL: cmake build failed"
24 ERRORS=$((ERRORS + 1))
25 fi
26 fi
27
28 if [ $ERRORS -gt 0 ]; then
29 echo "$ERRORS cmake dispatch errors"
30 exit 1
31 fi
32
33 # Find the library
34 CMAKE_LIB=$(find "$BUILD_DIR" -name 'libabpoa.a' | head -1)
35 if [ -z "$CMAKE_LIB" ]; then
36 echo "FAIL: libabpoa.a not found"
37 exit 1
38 fi
39
40 SYMBOLS=$(nm -g "$CMAKE_LIB" 2>/dev/null | grep " T " | awk '{print $3}' | sed 's/^_//')
41
42 ARCH=$(uname -m)
43 if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
44 # Check for per-ISA dispatch symbols (x86 only)
45 for sym in simd_sse2_abpoa_align_sequence_to_subgraph \
46 simd_sse41_abpoa_align_sequence_to_subgraph \
47 simd_avx2_abpoa_align_sequence_to_subgraph \
48 simd_avx512_abpoa_align_sequence_to_subgraph \
49 simd_abpoa_align_sequence_to_subgraph \
50 simd_abpoa_align_sequence_to_graph; do
51 if ! echo "$SYMBOLS" | grep -qx "$sym"; then
52 echo "FAIL: dispatch symbol '$sym' not found in CMake-built library"
53 ERRORS=$((ERRORS + 1))
54 fi
55 done
56 else
57 # Non-x86: just verify the generic align symbols are present
58 for sym in simd_abpoa_align_sequence_to_subgraph \
59 simd_abpoa_align_sequence_to_graph; do
60 if ! echo "$SYMBOLS" | grep -qx "$sym"; then
61 echo "FAIL: dispatch symbol '$sym' not found in CMake-built library"
62 ERRORS=$((ERRORS + 1))
63 fi
64 done
65 fi
66
67 # Compare output with Makefile reference
68 CMAKE_BIN=$(find "$BUILD_DIR" -name 'abpoa' -type f -exec test -x {} \; -print | head -1)
69 if [ -z "$CMAKE_BIN" ]; then
70 echo "FAIL: abpoa binary not found in CMake build"
71 ERRORS=$((ERRORS + 1))
72 else
73 if ! "$CMAKE_BIN" test_data/seq.fa 2>/dev/null | diff -q - tests/ref_consensus.txt >/dev/null 2>&1; then
74 echo "FAIL: CMake binary output differs from Makefile reference (consensus)"
75 ERRORS=$((ERRORS + 1))
76 fi
77
78 if ! "$CMAKE_BIN" test_data/seq.fa -a1 2>/dev/null | diff -q - tests/ref_msa.txt >/dev/null 2>&1; then
79 echo "FAIL: CMake binary output differs from Makefile reference (MSA)"
80 ERRORS=$((ERRORS + 1))
81 fi
82
83 if ! "$CMAKE_BIN" test_data/heter.fa -d2 2>/dev/null | diff -q - tests/ref_heter.txt >/dev/null 2>&1; then
84 echo "FAIL: CMake binary output differs from Makefile reference (heter)"
85 ERRORS=$((ERRORS + 1))
86 fi
87 fi
88
89 if [ $ERRORS -gt 0 ]; then
90 echo "$ERRORS cmake dispatch errors"
91 exit 1
92 fi
93
94 echo "CMake SIMD dispatch build works correctly"
95 exit 0