| 1 |
#!/bin/bash |
| 2 |
# Test that SIMDMalloc/SIMDFree are portable across platforms. |
| 3 |
# The implementation must: |
| 4 |
# 1. Have an MSVC path with _aligned_malloc/_aligned_free |
| 5 |
# 2. Not use a bare free() macro for SIMDFree |
| 6 |
# 3. Compile and produce correct alignment on this platform |
| 7 |
set -e |
| 8 |
|
| 9 |
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 10 |
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 11 |
cd "$PROJECT_DIR" |
| 12 |
|
| 13 |
SIMD_H="src/simd_instruction.h" |
| 14 |
ERRORS=0 |
| 15 |
|
| 16 |
if ! grep -q '_MSC_VER' "$SIMD_H"; then |
| 17 |
echo "FAIL: $SIMD_H has no MSVC (_MSC_VER) code path" |
| 18 |
ERRORS=$((ERRORS + 1)) |
| 19 |
fi |
| 20 |
|
| 21 |
if ! grep -q '_aligned_malloc' "$SIMD_H"; then |
| 22 |
echo "FAIL: $SIMD_H does not use _aligned_malloc for MSVC" |
| 23 |
ERRORS=$((ERRORS + 1)) |
| 24 |
fi |
| 25 |
|
| 26 |
if ! grep -q '_aligned_free' "$SIMD_H"; then |
| 27 |
echo "FAIL: $SIMD_H does not use _aligned_free for MSVC" |
| 28 |
ERRORS=$((ERRORS + 1)) |
| 29 |
fi |
| 30 |
|
| 31 |
if grep -q '#define SIMDFree.*free' "$SIMD_H"; then |
| 32 |
echo "FAIL: SIMDFree is still a bare free() macro" |
| 33 |
ERRORS=$((ERRORS + 1)) |
| 34 |
fi |
| 35 |
|
| 36 |
# Compile and run the alignment verification test |
| 37 |
if [ -f tests/test_aligned_alloc.c ]; then |
| 38 |
ARCH=$(uname -m) |
| 39 |
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then |
| 40 |
EXTRA_DEFS="" |
| 41 |
else |
| 42 |
EXTRA_DEFS="-DUSE_SIMDE -DSIMDE_ENABLE_NATIVE_ALIASES" |
| 43 |
fi |
| 44 |
if gcc -march=native $EXTRA_DEFS tests/test_aligned_alloc.c -I src -I include \ |
| 45 |
-o /tmp/test_aligned_alloc 2>/tmp/test_aligned_alloc.err; then |
| 46 |
if ! /tmp/test_aligned_alloc; then |
| 47 |
echo "FAIL: aligned allocation test failed at runtime" |
| 48 |
ERRORS=$((ERRORS + 1)) |
| 49 |
fi |
| 50 |
else |
| 51 |
echo "FAIL: test_aligned_alloc.c does not compile" |
| 52 |
cat /tmp/test_aligned_alloc.err |
| 53 |
ERRORS=$((ERRORS + 1)) |
| 54 |
fi |
| 55 |
rm -f /tmp/test_aligned_alloc /tmp/test_aligned_alloc.err |
| 56 |
fi |
| 57 |
|
| 58 |
if [ $ERRORS -gt 0 ]; then |
| 59 |
echo "$ERRORS portable allocation errors" |
| 60 |
exit 1 |
| 61 |
fi |
| 62 |
|
| 63 |
echo "Portable allocation checks passed" |
| 64 |
exit 0 |