From cca9ce398e092e8348cff05a1392e6b00b588c7d Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Wed, 17 Dec 2025 06:31:15 +0900 Subject: [PATCH] test: Phase 100 mutable accumulator LLVM EXE smoke MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add phase100_mutable_accumulator_llvm_exe.sh - Plugin gating via Phase 97 pattern (dlopen cache → build-all) - Numeric output validation (same SSOT as VM smoke) - Regression: phase94 pass (phase97 has pre-existing issue) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../phase100_mutable_accumulator_llvm_exe.sh | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tools/smokes/v2/profiles/integration/apps/phase100_mutable_accumulator_llvm_exe.sh diff --git a/tools/smokes/v2/profiles/integration/apps/phase100_mutable_accumulator_llvm_exe.sh b/tools/smokes/v2/profiles/integration/apps/phase100_mutable_accumulator_llvm_exe.sh new file mode 100644 index 00000000..8e24024d --- /dev/null +++ b/tools/smokes/v2/profiles/integration/apps/phase100_mutable_accumulator_llvm_exe.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# Phase 100 P2.1 - Mutable Accumulator (LLVM EXE backend) +# Tests: out = out + ch (string accumulator) and count = count + 1 (integer accumulator) + +source "$(dirname "$0")/../../../lib/test_runner.sh" +export SMOKES_USE_PYVM=0 +require_env || exit 2 + +# LLVM availability checks (graceful SKIP) +if ! command -v llvm-config-18 &> /dev/null; then + test_skip "llvm-config-18 not found"; exit 0 +fi + +if ! "$NYASH_BIN" --help 2>&1 | grep -q "llvm"; then + test_skip "hakorune --backend llvm not available"; exit 0 +fi + +if ! python3 -c "import llvmlite" 2>/dev/null; then + test_skip "Python llvmlite not found"; exit 0 +fi + +# Note: This fixture doesn't actually use FileBox/MapBox plugins, +# but we follow the Phase 97 plugin gating pattern for consistency +FILEBOX_SO="$NYASH_ROOT/plugins/nyash-filebox-plugin/libnyash_filebox_plugin.so" +MAPBOX_SO="$NYASH_ROOT/plugins/nyash-map-plugin/libnyash_map_plugin.so" + +check_plugins() { + python3 - "$FILEBOX_SO" "$MAPBOX_SO" <<'PY' +import ctypes +import os +import sys +names = ["FileBox", "MapBox"] +paths = sys.argv[1:] +failures = [] +for name, path in zip(names, paths): + if not os.path.isfile(path): + failures.append(f"[plugin/missing] {name}: {path}") + continue + try: + ctypes.CDLL(path) + except Exception as e: # noqa: BLE001 + failures.append(f"[plugin/dlopen] {name}: {path} ({e})") +if failures: + print("\n".join(failures)) + sys.exit(1) +print("OK") +PY +} + +echo "[INFO] Checking plugin artifacts (FileBox/MapBox)" +if ! CHECK_OUTPUT=$(check_plugins 2>&1); then + echo "$CHECK_OUTPUT" + echo "[INFO] Missing/broken plugin detected, running build-all (FileBox/MapBox)" + BUILD_LOG="/tmp/phase100_mutable_accumulator_plugin_build.log" + if ! bash "$NYASH_ROOT/tools/plugins/build-all.sh" nyash-filebox-plugin nyash-map-plugin >"$BUILD_LOG" 2>&1; then + echo "[FAIL] tools/plugins/build-all.sh failed for FileBox/MapBox" + tail -n 80 "$BUILD_LOG" + exit 1 + fi + if ! CHECK_OUTPUT=$(check_plugins 2>&1); then + echo "$CHECK_OUTPUT" + echo "[FAIL] Plugin artifacts still missing or unloadable after build-all" + tail -n 80 "$BUILD_LOG" + exit 1 + fi +fi + +mkdir -p "$NYASH_ROOT/tmp" + +INPUT_HAKO="$NYASH_ROOT/apps/tests/phase100_mutable_accumulator_min.hako" +OUTPUT_EXE="$NYASH_ROOT/tmp/phase100_mutable_accumulator_min" + +echo "[INFO] Building: $INPUT_HAKO → $OUTPUT_EXE" + +BUILD_LOG="/tmp/phase100_mutable_accumulator_build.log" +if ! env NYASH_DISABLE_PLUGINS=0 "$NYASH_ROOT/tools/build_llvm.sh" "$INPUT_HAKO" -o "$OUTPUT_EXE" 2>&1 | tee "$BUILD_LOG"; then + echo "[FAIL] build_llvm.sh failed" + tail -n 80 "$BUILD_LOG" + exit 1 +fi + +if [ ! -x "$OUTPUT_EXE" ]; then + echo "[FAIL] Executable not created or not executable: $OUTPUT_EXE" + ls -la "$OUTPUT_EXE" 2>/dev/null || echo "File does not exist" + exit 1 +fi + +echo "[INFO] Executing: $OUTPUT_EXE" + +set +e +OUTPUT=$(timeout "${RUN_TIMEOUT_SECS:-10}" env NYASH_DISABLE_PLUGINS=0 "$OUTPUT_EXE" 2>&1) +EXIT_CODE=$? +set -e + +if [ "$EXIT_CODE" -ne 0 ]; then + echo "[FAIL] Execution failed with exit code $EXIT_CODE" + echo "$OUTPUT" | tail -n 80 + exit 1 +fi + +# Extract numeric output only (same SSOT as VM smoke test) +CLEAN=$(printf "%s\n" "$OUTPUT" | grep -E '^[0-9]+$' | head -n 1 | tr -d '\r') +EXPECTED="3" + +echo "[INFO] CLEAN output:" +echo "$CLEAN" + +if [ "$CLEAN" = "$EXPECTED" ]; then + test_pass "phase100_mutable_accumulator_llvm_exe: output matches expected (3)" +else + echo "[FAIL] Output mismatch" + echo "[INFO] Raw output (tail):" + echo "$OUTPUT" | tail -n 80 + echo "[INFO] Expected:" + printf "%s\n" "$EXPECTED" + exit 1 +fi