#!/bin/sh
set -euo pipefail

TMPDIR=$(mktemp -d)
cd "$TMPDIR"

# ---------------------------------------------------------------------------
# TEST 1 — hipify-clang smoke (no CUDA required)
# Just verify the binary starts and reports an LLVM version.
# ---------------------------------------------------------------------------
echo "[TEST 1] hipify-clang --version..."

VERSION=$(/usr/bin/hipify-clang --version 2>&1 || true)
if echo "$VERSION" | grep -q "LLVM"; then
  echo "[TEST 1] PASS: $VERSION"
else
  echo "[TEST 1] FAIL: unexpected output: $VERSION" >&2
  exit 1
fi

# ---------------------------------------------------------------------------
# TEST 2 — hipify-perl smoke (no CUDA required)
# Verify that a CUDA include is rewritten to its HIP equivalent.
# ---------------------------------------------------------------------------
echo "[TEST 2] hipify-perl include translation..."

cat > sample_perl.cu <<'EOF'
#include <cuda_runtime.h>
int main() { return 0; }
EOF

/usr/bin/hipify-perl sample_perl.cu > sample_perl.hip.cu

if grep -q "hip/hip_runtime.h" sample_perl.hip.cu; then
  echo "[TEST 2] PASS: cuda_runtime.h -> hip/hip_runtime.h"
else
  echo "[TEST 2] FAIL: expected hip/hip_runtime.h in output" >&2
  cat sample_perl.hip.cu >&2
  exit 1
fi

echo "All hipify smoke tests passed."
exit 0
