philosophers_prep/testers/run_all_tests.sh

100 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
# Master test runner - runs all tests
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
TESTER_DIR="testers"
echo "========================================"
echo -e "${BLUE}Philosophers Preparation - Test Suite${NC}"
echo "========================================"
echo ""
TOTAL_PASSED=0
TOTAL_FAILED=0
# Function to run a test
run_test() {
local test_script=$1
local test_name=$2
if [ -f "$TESTER_DIR/$test_script" ]; then
echo ""
echo -e "${BLUE}▶ Running: $test_name${NC}"
echo "----------------------------------------"
bash "$TESTER_DIR/$test_script"
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}$test_name - ALL TESTS PASSED${NC}"
((TOTAL_PASSED++))
else
echo -e "${RED}$test_name - SOME TESTS FAILED${NC}"
((TOTAL_FAILED++))
fi
echo ""
else
echo -e "${YELLOW}⊘ Skipping $test_name (tester not found)${NC}"
echo ""
fi
}
# Check if specific test is requested
if [ $# -eq 1 ]; then
case $1 in
1) run_test "test_1_thread_basics.sh" "Exercise 1: Thread Basics" ;;
2) run_test "test_2_mutex_basics.sh" "Exercise 2: Mutex Basics" ;;
3) run_test "test_3_precise_timing.sh" "Exercise 3: Precise Timing" ;;
4) run_test "test_4_state_monitor.sh" "Exercise 4: State Monitor" ;;
5) run_test "test_5_producer_consumer.sh" "Exercise 5: Producer-Consumer" ;;
6) run_test "test_6_deadlock_demo.sh" "Exercise 6: Deadlock Demo" ;;
7) run_test "test_7_limited_resources.sh" "Exercise 7: Limited Resources" ;;
8) run_test "test_8_simple_philosophers.sh" "Exercise 8: Simple Philosophers" ;;
9) run_test "test_9_death_monitor.sh" "Exercise 9: Death Monitor" ;;
10) run_test "test_10_philosophers_args.sh" "Exercise 10: Philosophers Args" ;;
11) run_test "test_11_race_detector.sh" "Exercise 11: Race Detector" ;;
12) run_test "test_12_philosophers_bonus.sh" "Exercise 12: Philosophers Bonus" ;;
*)
echo "Usage: $0 [exercise_number]"
echo "Example: $0 1 (to test only exercise 1)"
echo "Or run without arguments to test all exercises"
exit 1
;;
esac
else
# Run all tests
run_test "test_1_thread_basics.sh" "Exercise 1: Thread Basics"
run_test "test_2_mutex_basics.sh" "Exercise 2: Mutex Basics"
run_test "test_3_precise_timing.sh" "Exercise 3: Precise Timing"
run_test "test_4_state_monitor.sh" "Exercise 4: State Monitor"
run_test "test_5_producer_consumer.sh" "Exercise 5: Producer-Consumer"
run_test "test_6_deadlock_demo.sh" "Exercise 6: Deadlock Demo"
run_test "test_7_limited_resources.sh" "Exercise 7: Limited Resources"
run_test "test_8_simple_philosophers.sh" "Exercise 8: Simple Philosophers"
run_test "test_9_death_monitor.sh" "Exercise 9: Death Monitor"
run_test "test_10_philosophers_args.sh" "Exercise 10: Philosophers Args"
run_test "test_11_race_detector.sh" "Exercise 11: Race Detector"
run_test "test_12_philosophers_bonus.sh" "Exercise 12: Philosophers Bonus"
fi
# Final summary
echo "========================================"
echo -e "${BLUE}FINAL RESULTS${NC}"
echo "========================================"
echo -e "Exercises passed: ${GREEN}$TOTAL_PASSED${NC}"
echo -e "Exercises failed: ${RED}$TOTAL_FAILED${NC}"
echo "========================================"
if [ $TOTAL_FAILED -eq 0 ] && [ $TOTAL_PASSED -gt 0 ]; then
echo -e "${GREEN}🎉 All tests passed! Great job!${NC}"
exit 0
else
echo -e "${YELLOW}Keep working on the failed exercises.${NC}"
exit 1
fi