Files
hakmem/verify_bench.sh

83 lines
2.2 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# verify_bench.sh - Verify benchmark binary is correctly linked with hakmem
# Usage: ./verify_bench.sh <binary>
set -e
BINARY="$1"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
if [ -z "$BINARY" ]; then
echo -e "${RED}Usage: $0 <binary>${NC}"
echo "Example: $0 ./bench_tiny"
exit 1
fi
if [ ! -f "$BINARY" ]; then
echo -e "${RED}❌ Binary not found: $BINARY${NC}"
exit 1
fi
echo -e "${YELLOW}Verifying: $BINARY${NC}"
echo ""
# Check 1: hakmem symbols
echo -n "Checking hakmem symbols... "
if nm "$BINARY" 2>/dev/null | grep -q "hak_tiny_alloc"; then
echo -e "${GREEN}✅ Found${NC}"
SYMBOLS_OK=1
else
echo -e "${RED}❌ NOT FOUND${NC}"
echo -e "${RED}ERROR: hakmem symbols not found - using system allocator!${NC}"
SYMBOLS_OK=0
fi
# Check 2: Binary size (heuristic)
echo -n "Checking binary size... "
TEXT_SIZE=$(size "$BINARY" 2>/dev/null | awk 'NR==2 {print $1}')
if [ -z "$TEXT_SIZE" ]; then
echo -e "${YELLOW}⚠️ Could not determine size${NC}"
SIZE_OK=1
elif [ "$TEXT_SIZE" -gt 50000 ]; then
echo -e "${GREEN}✅ OK ($TEXT_SIZE bytes)${NC}"
SIZE_OK=1
else
echo -e "${YELLOW}⚠️ Suspiciously small ($TEXT_SIZE bytes)${NC}"
echo -e "${YELLOW}Expected: > 50000 bytes (hakmem code included)${NC}"
SIZE_OK=0
fi
# Check 3: Symbol details
echo ""
echo "Symbol details:"
SYMBOL_COUNT=$(nm "$BINARY" 2>/dev/null | grep -c " hak_" || echo 0)
echo " hakmem symbols: $SYMBOL_COUNT"
if [ "$SYMBOL_COUNT" -gt 10 ]; then
echo -e " ${GREEN}✅ Many hakmem symbols found${NC}"
else
echo -e " ${YELLOW}⚠️ Few hakmem symbols (expected > 10)${NC}"
fi
# Summary
echo ""
echo "================================"
if [ "$SYMBOLS_OK" -eq 1 ] && [ "$SIZE_OK" -eq 1 ]; then
echo -e "${GREEN}✅ Verification PASSED: $BINARY${NC}"
echo -e "${GREEN}Safe to benchmark with hakmem${NC}"
exit 0
else
echo -e "${RED}❌ Verification FAILED: $BINARY${NC}"
echo -e "${RED}DO NOT use for benchmarking!${NC}"
echo ""
echo "Fix:"
echo " 1. make clean"
echo " 2. make bench_tiny # Use explicit Makefile target"
echo " 3. ./verify_bench.sh ./bench_tiny"
exit 1
fi