Files
hakorune/tools/smokes/v2/lib/test_runner.sh

247 lines
7.8 KiB
Bash
Raw Normal View History

#!/bin/bash
# test_runner.sh - 中核実行器(強制使用)
# スモークテストv2の核心ライブラリ
# set -eは使わない個々のテストが失敗しても全体を続行するため
set -uo pipefail
# ルート/バイナリ検出CWDに依存しない実行を保証
if [ -z "${NYASH_ROOT:-}" ]; then
export NYASH_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../.." && pwd)"
fi
export NYASH_BIN="${NYASH_BIN:-$NYASH_ROOT/target/release/nyash}"
# グローバル変数
export SMOKES_V2_LIB_LOADED=1
export SMOKES_START_TIME=$(date +%s.%N)
export SMOKES_TEST_COUNT=0
export SMOKES_PASS_COUNT=0
export SMOKES_FAIL_COUNT=0
# 色定義(重複回避)
if [ -z "${RED:-}" ]; then
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly NC='\033[0m' # No Color
fi
# ログ関数
log_info() {
echo -e "${BLUE}[INFO]${NC} $*" >&2
}
log_success() {
echo -e "${GREEN}[PASS]${NC} $*" >&2
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*" >&2
}
log_error() {
echo -e "${RED}[FAIL]${NC} $*" >&2
}
# 環境チェック(必須)
require_env() {
local required_tools=("cargo" "grep" "jq")
local missing_tools=()
for tool in "${required_tools[@]}"; do
if ! command -v "$tool" &> /dev/null; then
missing_tools+=("$tool")
fi
done
if [ ${#missing_tools[@]} -ne 0 ]; then
log_error "Required tools missing: ${missing_tools[*]}"
log_error "Please install missing tools and try again"
return 1
fi
# Nyash実行ファイル確認
if [ ! -f "$NYASH_BIN" ]; then
log_error "Nyash executable not found at $NYASH_BIN"
log_error "Please run 'cargo build --release' first (in $NYASH_ROOT)"
return 1
fi
log_info "Environment check passed"
return 0
}
# プラグイン整合性チェック(必須)
preflight_plugins() {
# プラグインマネージャーが存在する場合は実行
if [ -f "$(dirname "${BASH_SOURCE[0]}")/plugin_manager.sh" ]; then
source "$(dirname "${BASH_SOURCE[0]}")/plugin_manager.sh"
check_plugin_integrity || return 1
else
log_warn "Plugin manager not found, skipping plugin checks"
fi
return 0
}
# テスト実行関数
run_test() {
local test_name="$1"
local test_func="$2"
((SMOKES_TEST_COUNT++))
local start_time=$(date +%s.%N)
log_info "Running test: $test_name"
if $test_func; then
local end_time=$(date +%s.%N)
local duration=$(echo "$end_time - $start_time" | bc -l)
log_success "$test_name (${duration}s)"
((SMOKES_PASS_COUNT++))
return 0
else
local end_time=$(date +%s.%N)
local duration=$(echo "$end_time - $start_time" | bc -l)
log_error "$test_name (${duration}s)"
((SMOKES_FAIL_COUNT++))
return 1
fi
}
# Nyash実行ヘルパーRust VM
run_nyash_vm() {
local program="$1"
shift
local USE_PYVM="${SMOKES_USE_PYVM:-0}"
# -c オプションの場合は一時ファイル経由で実行
if [ "$program" = "-c" ]; then
local code="$1"
shift
local tmpfile="/tmp/nyash_test_$$.nyash"
echo "$code" > "$tmpfile"
# プラグイン初期化メッセージを除外
NYASH_VM_USE_PY="$USE_PYVM" NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 "$NYASH_BIN" "$tmpfile" "$@" 2>&1 | \
feat: GC機能復活&VM整理&json_native調査完了 ## 🎉 ChatGPT×Claude協働成果 - ✅ **GC機能復活**: vm-legacy削除で失われたGC機能を新実装で復活 - GCメトリクス追跡システム実装(alloc/collect/pause計測) - 3種類のGCモード対応(counting/mark_sweep/generational) - host_handles.rsでハンドル管理復活 - ✅ **VM整理とエイリアス追加**: 混乱していた名前を整理 - MirInterpreter = NyashVm = VM のエイリアス統一 - vm-legacyとインタープリターの違いを明確化 - 壊れていたvm.rsの互換性修復 - ✅ **スモークテスト整理**: v2構造でプラグイン/コア分離 - plugins/ディレクトリにプラグインテスト移動 - gc_metrics.sh, gc_mode_off.sh, async_await.sh追加 - _ensure_fixture.shでプラグイン事前ビルド確認 ## 📊 json_native調査結果 - **現状**: 25%完成(配列/オブジェクトパース未実装) - **将来性**: 並行処理でyyjson超えの可能性大 - 100KB以上のJSONで2-10倍速の可能性 - Nyash ABI実装後はゼロコピー最適化 - **判断**: 現時点では置換不可、将来の大きな足場 ## 🔍 技術的発見 - vm-legacy = 完全なVM実装(GC付き)だった - MirInterpreter = 現在のRust VM(712行、Arc使用) - 200行簡易JSONは既に削除済み(存在しない) ChatGPT爆速修復×Claude詳細調査の完璧な協働! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 23:27:59 +09:00
grep -v "^\[UnifiedBoxRegistry\]" | grep -v "^\[FileBox\]" | grep -v "^Net plugin:" | grep -v "^\[.*\] Plugin" | \
grep -v "Using builtin StringBox" | grep -v "Phase 15.5: Everything is Plugin" | grep -v "cargo build -p nyash-string-plugin" | \
grep -v "^\[plugin-loader\] backend=" | grep -v "^\[using\] ctx:" | \
grep -v "^🔌 plugin host initialized" | grep -v "^✅ plugin host fully configured" | \
grep -v "^🚀 Nyash VM Backend - Executing file:"
local exit_code=${PIPESTATUS[0]}
rm -f "$tmpfile"
return $exit_code
else
# プラグイン初期化メッセージを除外
NYASH_VM_USE_PY="$USE_PYVM" NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 "$NYASH_BIN" "$program" "$@" 2>&1 | \
feat: GC機能復活&VM整理&json_native調査完了 ## 🎉 ChatGPT×Claude協働成果 - ✅ **GC機能復活**: vm-legacy削除で失われたGC機能を新実装で復活 - GCメトリクス追跡システム実装(alloc/collect/pause計測) - 3種類のGCモード対応(counting/mark_sweep/generational) - host_handles.rsでハンドル管理復活 - ✅ **VM整理とエイリアス追加**: 混乱していた名前を整理 - MirInterpreter = NyashVm = VM のエイリアス統一 - vm-legacyとインタープリターの違いを明確化 - 壊れていたvm.rsの互換性修復 - ✅ **スモークテスト整理**: v2構造でプラグイン/コア分離 - plugins/ディレクトリにプラグインテスト移動 - gc_metrics.sh, gc_mode_off.sh, async_await.sh追加 - _ensure_fixture.shでプラグイン事前ビルド確認 ## 📊 json_native調査結果 - **現状**: 25%完成(配列/オブジェクトパース未実装) - **将来性**: 並行処理でyyjson超えの可能性大 - 100KB以上のJSONで2-10倍速の可能性 - Nyash ABI実装後はゼロコピー最適化 - **判断**: 現時点では置換不可、将来の大きな足場 ## 🔍 技術的発見 - vm-legacy = 完全なVM実装(GC付き)だった - MirInterpreter = 現在のRust VM(712行、Arc使用) - 200行簡易JSONは既に削除済み(存在しない) ChatGPT爆速修復×Claude詳細調査の完璧な協働! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 23:27:59 +09:00
grep -v "^\[UnifiedBoxRegistry\]" | grep -v "^\[FileBox\]" | grep -v "^Net plugin:" | grep -v "^\[.*\] Plugin" | \
grep -v "Using builtin StringBox" | grep -v "Phase 15.5: Everything is Plugin" | grep -v "cargo build -p nyash-string-plugin" | \
grep -v "^\[plugin-loader\] backend=" | grep -v "^\[using\] ctx:" | \
grep -v "^🔌 plugin host initialized" | grep -v "^✅ plugin host fully configured" | \
grep -v "^🚀 Nyash VM Backend - Executing file:"
return ${PIPESTATUS[0]}
fi
}
# Nyash実行ヘルパーLLVM
run_nyash_llvm() {
local program="$1"
shift
# -c オプションの場合は一時ファイル経由で実行
if [ "$program" = "-c" ]; then
local code="$1"
shift
local tmpfile="/tmp/nyash_test_$$.nyash"
echo "$code" > "$tmpfile"
# プラグイン初期化メッセージを除外
NYASH_VM_USE_PY=0 NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 "$NYASH_BIN" --backend llvm "$tmpfile" "$@" 2>&1 | \
grep -v "^\[FileBox\]" | grep -v "^Net plugin:" | grep -v "^\[.*\] Plugin"
local exit_code=${PIPESTATUS[0]}
rm -f "$tmpfile"
return $exit_code
else
# プラグイン初期化メッセージを除外
NYASH_VM_USE_PY=0 NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 "$NYASH_BIN" --backend llvm "$program" "$@" 2>&1 | \
grep -v "^\[FileBox\]" | grep -v "^Net plugin:" | grep -v "^\[.*\] Plugin"
return ${PIPESTATUS[0]}
fi
}
# シンプルテスト補助(スクリプト互換)
test_pass() { log_success "$1"; return 0; }
test_fail() { log_error "$1 ${2:-}"; return 1; }
test_skip() { log_warn "SKIP $1 ${2:-}"; return 0; }
# 出力比較ヘルパー
compare_outputs() {
local expected="$1"
local actual="$2"
local test_name="$3"
if [ "$expected" = "$actual" ]; then
return 0
else
log_error "$test_name output mismatch:"
log_error " Expected: $expected"
log_error " Actual: $actual"
return 1
fi
}
# 結果サマリー出力
print_summary() {
local end_time=$(date +%s.%N)
local total_duration=$(echo "$end_time - $SMOKES_START_TIME" | bc -l)
echo ""
echo "==============================================="
echo "Smoke Test Summary"
echo "==============================================="
echo "Total tests: $SMOKES_TEST_COUNT"
echo "Passed: $SMOKES_PASS_COUNT"
echo "Failed: $SMOKES_FAIL_COUNT"
echo "Duration: ${total_duration}s"
echo ""
if [ $SMOKES_FAIL_COUNT -eq 0 ]; then
log_success "All tests passed! ✨"
return 0
else
log_error "$SMOKES_FAIL_COUNT test(s) failed"
return 1
fi
}
# JSON出力関数
output_json() {
local profile="${1:-unknown}"
local end_time=$(date +%s.%N)
local total_duration=$(echo "$end_time - $SMOKES_START_TIME" | bc -l)
cat << EOF
{
"profile": "$profile",
"total": $SMOKES_TEST_COUNT,
"passed": $SMOKES_PASS_COUNT,
"failed": $SMOKES_FAIL_COUNT,
"duration": $total_duration,
"timestamp": "$(date -Iseconds)",
"success": $([ $SMOKES_FAIL_COUNT -eq 0 ] && echo "true" || echo "false")
}
EOF
}
# JUnit XML出力関数
output_junit() {
local profile="${1:-unknown}"
local end_time=$(date +%s.%N)
local total_duration=$(echo "$end_time - $SMOKES_START_TIME" | bc -l)
cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="smokes_$profile" tests="$SMOKES_TEST_COUNT" failures="$SMOKES_FAIL_COUNT" time="$total_duration">
<!-- Individual test cases would be added by specific test scripts -->
</testsuite>
EOF
}