Bash · 18991 bytes Raw Blame History
1 #!/bin/bash
2 # =====================================
3 # Comprehensive Memory Pool Test Bench
4 # =====================================
5 # Tests all aspects of Phase 6 memory pooling implementation
6 # Ensures pooling behaves exactly as designed with no subtleties
7
8 # Colors for output
9 RED='\033[0;31m'
10 GREEN='\033[0;32m'
11 YELLOW='\033[1;33m'
12 BLUE='\033[0;34m'
13 CYAN='\033[0;36m'
14 NC='\033[0m'
15
16 # Test counters
17 PASSED=0
18 FAILED=0
19 WARNINGS=0
20
21 # Test configuration
22 SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
23 FORTSH_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
24 FORTSH_POOLED="$FORTSH_DIR/bin/fortsh"
25 FORTSH_TRADITIONAL="$FORTSH_DIR/bin/fortsh_traditional"
26 TEST_WORK_DIR="/tmp/memory_pool_test_$$"
27
28 # Create work directory
29 mkdir -p "$TEST_WORK_DIR"
30 cd "$TEST_WORK_DIR" || exit 1
31
32 # Cleanup on exit
33 cleanup() {
34 rm -rf "$TEST_WORK_DIR"
35 cd "$FORTSH_DIR" || exit 1
36 }
37 trap cleanup EXIT INT TERM
38
39 # Test result functions
40 pass() {
41 printf "${GREEN}✓ PASS${NC}: %s\n" "$1"
42 PASSED=$((PASSED + 1))
43 }
44
45 fail() {
46 printf "${RED}✗ FAIL${NC}: %s\n" "$1"
47 if [ -n "$2" ]; then
48 printf " Details: %s\n" "$2"
49 fi
50 FAILED=$((FAILED + 1))
51 }
52
53 warn() {
54 printf "${YELLOW}⚠ WARN${NC}: %s\n" "$1"
55 if [ -n "$2" ]; then
56 printf " Details: %s\n" "$2"
57 fi
58 WARNINGS=$((WARNINGS + 1))
59 }
60
61 section() {
62 printf "\n${BLUE}==========================================\n"
63 printf "%s\n" "$1"
64 printf "==========================================${NC}\n"
65 }
66
67 subsection() {
68 printf "\n${CYAN}--- %s ---${NC}\n" "$1"
69 }
70
71 # =====================================
72 # 1. BUILD VALIDATION
73 # =====================================
74 section "1. BUILD VALIDATION"
75
76 subsection "Building pooled version"
77 cd "$FORTSH_DIR" || exit 1
78 make clean > /dev/null 2>&1
79 if make > /dev/null 2>&1; then
80 pass "Pooled build successful"
81 cp bin/fortsh "$FORTSH_POOLED"
82 else
83 fail "Pooled build failed"
84 exit 1
85 fi
86
87 subsection "Building traditional version"
88 make clean > /dev/null 2>&1
89 if make NO_MEMPOOL=1 > /dev/null 2>&1; then
90 pass "Traditional build successful"
91 cp bin/fortsh "$FORTSH_TRADITIONAL"
92 else
93 fail "Traditional build failed"
94 exit 1
95 fi
96
97 # Verify binaries exist
98 if [ ! -x "$FORTSH_POOLED" ]; then
99 fail "Pooled binary not found"
100 exit 1
101 fi
102
103 if [ ! -x "$FORTSH_TRADITIONAL" ]; then
104 fail "Traditional binary not found"
105 exit 1
106 fi
107
108 cd "$TEST_WORK_DIR" || exit 1
109
110 # =====================================
111 # 2. BASIC FUNCTIONALITY TESTS
112 # =====================================
113 section "2. BASIC FUNCTIONALITY COMPARISON"
114
115 subsection "Command execution"
116 POOLED_OUT=$("$FORTSH_POOLED" -c "echo 'test output'" 2>&1)
117 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "echo 'test output'" 2>&1)
118
119 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
120 pass "Identical output for basic command"
121 else
122 fail "Different outputs" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
123 fi
124
125 subsection "Variable expansion"
126 POOLED_OUT=$("$FORTSH_POOLED" -c 'X=hello; echo "$X world"' 2>&1)
127 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c 'X=hello; echo "$X world"' 2>&1)
128
129 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
130 pass "Identical variable expansion"
131 else
132 fail "Different variable expansion" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
133 fi
134
135 subsection "Parameter expansion"
136 POOLED_OUT=$("$FORTSH_POOLED" -c 'VAR=foo.bar.baz; echo "${VAR##*.}"' 2>&1)
137 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c 'VAR=foo.bar.baz; echo "${VAR##*.}"' 2>&1)
138
139 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
140 pass "Identical parameter expansion"
141 else
142 fail "Different parameter expansion" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
143 fi
144
145 # =====================================
146 # 3. MODULE-SPECIFIC TESTS
147 # =====================================
148 section "3. MODULE-SPECIFIC POOLING TESTS"
149
150 subsection "Parser Module"
151 # Test token parsing with various complexities
152 TEST_CMD='echo "test" | grep test && X=$((5+3)); [ $X -eq 8 ] && echo "pass"'
153 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
154 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
155
156 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
157 pass "Parser: Complex tokenization"
158 else
159 fail "Parser: Different tokenization" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
160 fi
161
162 subsection "Expansion Module"
163 # Test complex expansions
164 TEST_CMD='A=hello; B=world; C=${A}_${B}; echo "${C^^}"'
165 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
166 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
167
168 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
169 pass "Expansion: Complex string operations"
170 else
171 fail "Expansion: Different results" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
172 fi
173
174 subsection "Executor Module"
175 # Test command execution with large output
176 TEST_CMD='for i in $(seq 1 100); do echo "Line $i of output"; done | wc -l'
177 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1 | tr -d ' ')
178 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1 | tr -d ' ')
179
180 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
181 pass "Executor: Large buffer handling"
182 else
183 fail "Executor: Different buffer behavior" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
184 fi
185
186 subsection "Variables Module"
187 # Test variable arrays and functions
188 TEST_CMD='arr=(a b c d e); func() { echo "$@"; }; func "${arr[@]}"'
189 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
190 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
191
192 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
193 pass "Variables: Array and function handling"
194 else
195 fail "Variables: Different behavior" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
196 fi
197
198 subsection "Builtins Module"
199 # Test cd and printenv
200 TEST_CMD='cd /tmp && pwd && TEST_VAR=pooltest printenv TEST_VAR'
201 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
202 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
203
204 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
205 pass "Builtins: cd and printenv"
206 else
207 fail "Builtins: Different behavior" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
208 fi
209
210 # =====================================
211 # 4. READLINE BUFFER TESTS
212 # =====================================
213 section "4. READLINE BUFFER VALIDATION"
214
215 subsection "Interactive editing simulation"
216 # Test with echo piped to simulate input
217 echo "echo test" | "$FORTSH_POOLED" > pooled_interactive.out 2>&1
218 echo "echo test" | "$FORTSH_TRADITIONAL" > trad_interactive.out 2>&1
219
220 # Remove prompt variations
221 sed 's/fortsh\$ //g' pooled_interactive.out > pooled_clean.out
222 sed 's/fortsh\$ //g' trad_interactive.out > trad_clean.out
223
224 if diff -q pooled_clean.out trad_clean.out > /dev/null 2>&1; then
225 pass "Readline: Interactive behavior consistent"
226 else
227 fail "Readline: Different interactive behavior"
228 fi
229
230 # =====================================
231 # 5. STRESS TESTS
232 # =====================================
233 section "5. STRESS AND EDGE CASE TESTS"
234
235 subsection "Rapid allocation/deallocation"
236 # Create a script that rapidly allocates/deallocates
237 cat > stress_test.sh << 'EOF'
238 for i in {1..100}; do
239 X="String_$i"
240 Y="${X}_modified"
241 Z="${Y%%_*}"
242 unset X Y Z
243 done
244 echo "Stress test complete"
245 EOF
246
247 POOLED_OUT=$("$FORTSH_POOLED" < stress_test.sh 2>&1 | grep "Stress test complete")
248 TRAD_OUT=$("$FORTSH_TRADITIONAL" < stress_test.sh 2>&1 | grep "Stress test complete")
249
250 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
251 pass "Stress: Rapid allocation/deallocation"
252 else
253 fail "Stress: Different behavior under load"
254 fi
255
256 subsection "Large string operations"
257 # Test with very large strings
258 TEST_CMD='LARGE=$(printf "X%.0s" {1..1000}); echo "${#LARGE}"'
259 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
260 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
261
262 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
263 pass "Stress: Large string handling"
264 else
265 fail "Stress: Different large string behavior" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
266 fi
267
268 subsection "Nested expansions"
269 # Test deeply nested expansions with variable indirection (deterministic)
270 TEST_CMD='V=world; X="\$V"; Y="\$X"; eval eval echo "$Y"'
271 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
272 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
273
274 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
275 pass "Stress: Nested expansions"
276 else
277 fail "Stress: Different nested expansion behavior" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
278 fi
279
280 # =====================================
281 # 6. MEMORY LEAK DETECTION
282 # =====================================
283 section "6. MEMORY LEAK DETECTION"
284
285 subsection "Checking for leaks with valgrind (if available)"
286 if command -v valgrind > /dev/null 2>&1; then
287 # Run a simple command under valgrind
288 valgrind --leak-check=full --error-exitcode=1 "$FORTSH_POOLED" -c "echo test" > valgrind.out 2>&1
289 if [ $? -eq 0 ]; then
290 pass "No memory leaks detected (pooled)"
291 else
292 fail "Memory leaks detected in pooled version"
293 warn "Check valgrind.out for details"
294 fi
295
296 valgrind --leak-check=full --error-exitcode=1 "$FORTSH_TRADITIONAL" -c "echo test" > valgrind_trad.out 2>&1
297 if [ $? -eq 0 ]; then
298 pass "No memory leaks detected (traditional)"
299 else
300 fail "Memory leaks detected in traditional version"
301 fi
302 else
303 warn "valgrind not available" "Skipping memory leak detection"
304 fi
305
306 # =====================================
307 # 7. DASHBOARD VALIDATION (Pooled only)
308 # =====================================
309 section "7. DASHBOARD TRACKING VALIDATION"
310
311 subsection "Dashboard output verification"
312 # Create a test that should trigger dashboard output
313 cat > dashboard_test.sh << 'EOF'
314 # Trigger various module allocations
315 X="test string"
316 Y="${X}_modified"
317 cd /tmp
318 echo "Dashboard test"
319 EOF
320
321 # Run with dashboard environment variable (if implemented)
322 MEMPOOL_DEBUG=1 "$FORTSH_POOLED" < dashboard_test.sh > dashboard.out 2>&1
323
324 if grep -q "Dashboard test" dashboard.out; then
325 pass "Dashboard: Command execution tracked"
326 # Check if we got any dashboard output (implementation-dependent)
327 if grep -q -i "allocation\|bucket\|cache" dashboard.out 2>/dev/null; then
328 pass "Dashboard: Tracking information present"
329 else
330 warn "Dashboard: No tracking output detected" "May need MEMPOOL_DEBUG flag"
331 fi
332 else
333 fail "Dashboard: Basic execution failed"
334 fi
335
336 # =====================================
337 # 8. BUCKET ALLOCATION TESTS
338 # =====================================
339 section "8. BUCKET ALLOCATION STRATEGY"
340
341 subsection "Testing different size allocations"
342 # Test various string sizes that should hit different buckets
343 cat > bucket_test.sh << 'EOF'
344 # 64-byte range
345 TINY="Short"
346 # 256-byte range
347 SMALL=$(printf "X%.0s" {1..100})
348 # 1KB range
349 MEDIUM=$(printf "X%.0s" {1..500})
350 # 4KB range
351 LARGE=$(printf "X%.0s" {1..2000})
352
353 echo "${#TINY} ${#SMALL} ${#MEDIUM} ${#LARGE}"
354 EOF
355
356 POOLED_OUT=$("$FORTSH_POOLED" < bucket_test.sh 2>&1)
357 TRAD_OUT=$("$FORTSH_TRADITIONAL" < bucket_test.sh 2>&1)
358
359 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
360 pass "Buckets: Different size allocations handled correctly"
361 else
362 fail "Buckets: Size handling differs" "Pooled: '$POOLED_OUT', Traditional: '$TRAD_OUT'"
363 fi
364
365 # =====================================
366 # 9. CONCURRENCY TESTS
367 # =====================================
368 section "9. CONCURRENT OPERATIONS"
369
370 subsection "Background jobs with pooling"
371 TEST_CMD='(echo "job1") & (echo "job2") & wait; echo "done"'
372 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1 | sort)
373 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1 | sort)
374
375 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
376 pass "Concurrency: Background jobs handled correctly"
377 else
378 fail "Concurrency: Different background job behavior"
379 fi
380
381 # =====================================
382 # 10. ZERO-COPY VALIDATION
383 # =====================================
384 section "10. ZERO-COPY BEHAVIOR VALIDATION"
385
386 subsection "String reference semantics"
387 # Test that string modifications work correctly
388 TEST_CMD='X="original"; Y="$X"; X="modified"; echo "$Y"'
389 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
390 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
391
392 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
393 pass "Zero-copy: Reference semantics preserved"
394 else
395 fail "Zero-copy: Different reference behavior"
396 fi
397
398 # =====================================
399 # 11. PERFORMANCE COMPARISON
400 # =====================================
401 section "11. PERFORMANCE COMPARISON"
402
403 subsection "Timing allocation-heavy operations"
404 # Create allocation-heavy script
405 cat > perf_test.sh << 'EOF'
406 start=$(date +%s%N)
407 for i in {1..1000}; do
408 VAR="String_$i"
409 MOD="${VAR}_modified"
410 unset VAR MOD
411 done
412 end=$(date +%s%N)
413 echo $((end - start))
414 EOF
415
416 POOLED_TIME=$("$FORTSH_POOLED" < perf_test.sh 2>&1)
417 TRAD_TIME=$("$FORTSH_TRADITIONAL" < perf_test.sh 2>&1)
418
419 if [ -n "$POOLED_TIME" ] && [ -n "$TRAD_TIME" ]; then
420 # Check if pooled is not significantly slower (within 2x)
421 if [ "$POOLED_TIME" -lt $((TRAD_TIME * 2)) ]; then
422 pass "Performance: Pooled version competitive"
423 printf " Pooled: %s ns, Traditional: %s ns\n" "$POOLED_TIME" "$TRAD_TIME"
424 else
425 warn "Performance: Pooled version slower" "Pooled: $POOLED_TIME ns, Traditional: $TRAD_TIME ns"
426 fi
427 else
428 warn "Performance: Could not measure timing"
429 fi
430
431 # =====================================
432 # 12. REGRESSION TESTS
433 # =====================================
434 section "12. REGRESSION TEST SUITE"
435
436 subsection "Running POSIX compliance tests"
437 cd "$FORTSH_DIR" || exit 1
438
439 # Basic POSIX test
440 if FORTSH_BIN="$FORTSH_POOLED" ./tests/posix_compliance_test.sh > /dev/null 2>&1; then
441 POOLED_BASIC_RESULT=$?
442 else
443 POOLED_BASIC_RESULT=$?
444 fi
445
446 if FORTSH_BIN="$FORTSH_TRADITIONAL" ./tests/posix_compliance_test.sh > /dev/null 2>&1; then
447 TRAD_BASIC_RESULT=$?
448 else
449 TRAD_BASIC_RESULT=$?
450 fi
451
452 if [ "$POOLED_BASIC_RESULT" -eq "$TRAD_BASIC_RESULT" ]; then
453 pass "Regression: POSIX basic tests consistent"
454 else
455 fail "Regression: Different POSIX basic results"
456 fi
457
458 # Builtins test
459 if FORTSH_BIN="$FORTSH_POOLED" ./tests/posix_compliance_builtins.sh > /dev/null 2>&1; then
460 POOLED_BUILTIN_RESULT=$?
461 else
462 POOLED_BUILTIN_RESULT=$?
463 fi
464
465 if FORTSH_BIN="$FORTSH_TRADITIONAL" ./tests/posix_compliance_builtins.sh > /dev/null 2>&1; then
466 TRAD_BUILTIN_RESULT=$?
467 else
468 TRAD_BUILTIN_RESULT=$?
469 fi
470
471 if [ "$POOLED_BUILTIN_RESULT" -eq "$TRAD_BUILTIN_RESULT" ]; then
472 pass "Regression: Builtins tests consistent"
473 else
474 fail "Regression: Different builtins results"
475 fi
476
477 cd "$TEST_WORK_DIR" || exit 1
478
479 # =====================================
480 # 13. EDGE CASES AND CORNER CONDITIONS
481 # =====================================
482 section "13. EDGE CASES AND CORNER CONDITIONS"
483
484 subsection "Empty string handling"
485 TEST_CMD='X=""; Y="${X}"; echo "[$Y]"'
486 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
487 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
488
489 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
490 pass "Edge: Empty string handling"
491 else
492 fail "Edge: Empty strings differ"
493 fi
494
495 subsection "Maximum length strings"
496 # Test with maximum reasonable string length (64KB)
497 TEST_CMD='BIG=$(printf "X%.0s" {1..65536}); echo "ok"'
498 "$FORTSH_POOLED" -c "$TEST_CMD" > pooled_big.out 2>&1
499 POOLED_RESULT=$?
500 "$FORTSH_TRADITIONAL" -c "$TEST_CMD" > trad_big.out 2>&1
501 TRAD_RESULT=$?
502
503 if [ "$POOLED_RESULT" -eq "$TRAD_RESULT" ]; then
504 pass "Edge: Maximum string length handling"
505 else
506 fail "Edge: Different max string behavior"
507 fi
508
509 subsection "Special characters in strings"
510 TEST_CMD='X="$(printf "\x01\x02\x03")"; echo "${#X}"'
511 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
512 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
513
514 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
515 pass "Edge: Special characters handled"
516 else
517 fail "Edge: Special character handling differs"
518 fi
519
520 # =====================================
521 # 14. MODULE INTEGRATION TESTS
522 # =====================================
523 section "14. MODULE INTEGRATION VALIDATION"
524
525 subsection "Parser → Expansion → Executor chain"
526 TEST_CMD='VAR="test"; echo "${VAR^^}" | grep TEST && echo "chain ok"'
527 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
528 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
529
530 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
531 pass "Integration: Module chain working"
532 else
533 fail "Integration: Module chain differs"
534 fi
535
536 subsection "Variables → Builtins interaction"
537 TEST_CMD='export TEST_VAR="pooled"; cd /tmp && printenv TEST_VAR'
538 POOLED_OUT=$("$FORTSH_POOLED" -c "$TEST_CMD" 2>&1)
539 TRAD_OUT=$("$FORTSH_TRADITIONAL" -c "$TEST_CMD" 2>&1)
540
541 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
542 pass "Integration: Variables-Builtins interaction"
543 else
544 fail "Integration: Variables-Builtins differs"
545 fi
546
547 # =====================================
548 # 15. FINAL VALIDATION
549 # =====================================
550 section "15. FINAL COMPREHENSIVE VALIDATION"
551
552 subsection "Complex real-world script"
553 cat > complex_test.sh << 'EOF'
554 #!/bin/sh
555 # Complex script testing all modules together
556
557 # Variables and arrays
558 NAMES=(Alice Bob Charlie)
559 COUNT=0
560
561 # Functions
562 greet() {
563 local name="$1"
564 echo "Hello, ${name}!"
565 COUNT=$((COUNT + 1))
566 }
567
568 # Control flow
569 for name in "${NAMES[@]}"; do
570 if [ "${#name}" -gt 3 ]; then
571 greet "$name"
572 fi
573 done
574
575 # Parameter expansion
576 FILE="/path/to/some/file.tar.gz"
577 echo "Extension: ${FILE##*.}"
578 echo "Basename: ${FILE##*/}"
579
580 # Builtins
581 cd /tmp
582 TEST_EXPORT="final_test"
583 export TEST_EXPORT
584
585 # Final output
586 echo "Greeted $COUNT people"
587 echo "PWD: $(pwd)"
588 echo "Export: $TEST_EXPORT"
589 EOF
590
591 POOLED_OUT=$("$FORTSH_POOLED" < complex_test.sh 2>&1)
592 TRAD_OUT=$("$FORTSH_TRADITIONAL" < complex_test.sh 2>&1)
593
594 if [ "$POOLED_OUT" = "$TRAD_OUT" ]; then
595 pass "Final: Complex script execution identical"
596 else
597 fail "Final: Complex script differs"
598 echo "=== Pooled Output ===" > complex_diff.txt
599 echo "$POOLED_OUT" >> complex_diff.txt
600 echo "=== Traditional Output ===" >> complex_diff.txt
601 echo "$TRAD_OUT" >> complex_diff.txt
602 warn "See complex_diff.txt for details"
603 fi
604
605 # =====================================
606 # TEST SUMMARY
607 # =====================================
608 section "TEST SUMMARY"
609
610 TOTAL=$((PASSED + FAILED + WARNINGS))
611
612 printf "\n${BLUE}==========================================\n"
613 printf "MEMORY POOL TEST BENCH RESULTS\n"
614 printf "==========================================${NC}\n"
615 printf "${GREEN}Passed:${NC} %3d\n" "$PASSED"
616 printf "${RED}Failed:${NC} %3d\n" "$FAILED"
617 printf "${YELLOW}Warnings:${NC} %3d\n" "$WARNINGS"
618 printf "Total: %3d\n" "$TOTAL"
619 printf "==========================================\n"
620
621 if [ "$TOTAL" -gt 0 ]; then
622 PASS_RATE=$((PASSED * 100 / TOTAL))
623 printf "Pass rate: %d%%\n" "$PASS_RATE"
624 fi
625
626 # Rebuild with pooling for production
627 printf "\n${CYAN}Rebuilding with memory pooling for production...${NC}\n"
628 cd "$FORTSH_DIR" || exit 1
629 make clean > /dev/null 2>&1
630 MEMPOOL=1 make > /dev/null 2>&1
631
632 if [ "$FAILED" -eq 0 ]; then
633 printf "\n${GREEN}✓ ALL MEMORY POOL TESTS PASSED!${NC}\n"
634 printf "Memory pooling is behaving exactly as designed.\n"
635 printf "Zero-copy pooling validated across all modules.\n"
636 exit 0
637 else
638 printf "\n${RED}✗ SOME TESTS FAILED${NC}\n"
639 printf "Memory pooling has issues that need investigation.\n"
640 exit 1
641 fi