From 8779aa24a624414b28152ae3be77473359356183 Mon Sep 17 00:00:00 2001 From: Rui Ribeiro <42305006+ruiribeiro04@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:57:32 +0100 Subject: [PATCH] Increase tester functionality - Tester now checks if executable exists in `rendu` filder, if not, compiles the source file and run the test on it --- testers/test_10_philosophers_args.sh | 62 ++++++++++++++++++---- testers/test_11_race_detector.sh | 62 ++++++++++++++++++---- testers/test_12_philosophers_bonus.sh | 75 +++++++++++++++++++++++---- testers/test_1_thread_basics.sh | 50 +++++++++++++----- testers/test_2_mutex_basics.sh | 62 ++++++++++++++++++---- testers/test_3_precise_timing.sh | 62 ++++++++++++++++++---- testers/test_4_state_monitor.sh | 62 ++++++++++++++++++---- testers/test_5_producer_consumer.sh | 62 ++++++++++++++++++---- testers/test_6_deadlock_demo.sh | 62 ++++++++++++++++++---- testers/test_7_limited_resources.sh | 62 ++++++++++++++++++---- testers/test_8_simple_philosophers.sh | 62 ++++++++++++++++++---- testers/test_9_death_monitor.sh | 62 ++++++++++++++++++---- 12 files changed, 623 insertions(+), 122 deletions(-) diff --git a/testers/test_10_philosophers_args.sh b/testers/test_10_philosophers_args.sh index f5bfea4..c415c16 100755 --- a/testers/test_10_philosophers_args.sh +++ b/testers/test_10_philosophers_args.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE (Complete Philosophers)" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread philosophers_args.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Basic execution (no one should die) echo -n "Test 1: Basic case - 5 800 200 200... " diff --git a/testers/test_11_race_detector.sh b/testers/test_11_race_detector.sh index c825ca5..1d7c11e 100755 --- a/testers/test_11_race_detector.sh +++ b/testers/test_11_race_detector.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread race_detector.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Basic execution echo -n "Test 1: Basic execution - 4 410 200 200... " diff --git a/testers/test_12_philosophers_bonus.sh b/testers/test_12_philosophers_bonus.sh index 2e1777f..279964c 100755 --- a/testers/test_12_philosophers_bonus.sh +++ b/testers/test_12_philosophers_bonus.sh @@ -20,19 +20,74 @@ echo "========================================" echo "Testing: $EXERCISE (Bonus)" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread philosophers_bonus.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + # Bonus part requires -lrt for semaphores on some systems + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'. Trying with -lrt...${NC}" + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU" -lrt; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful with -lrt.${NC}" + else + echo -e "${RED}✗ Compilation failed again. Please check your code.${NC}" + exit 1 + fi + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'. Trying with -lrt...${NC}" + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT" -lrt; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful with -lrt.${NC}" + else + echo -e "${RED}✗ Compilation failed again. Please check your code.${NC}" + exit 1 + fi + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Clean up any leftover semaphores from previous runs echo "Cleaning up old semaphores..." diff --git a/testers/test_1_thread_basics.sh b/testers/test_1_thread_basics.sh index a2773ac..71f5c79 100755 --- a/testers/test_1_thread_basics.sh +++ b/testers/test_1_thread_basics.sh @@ -20,19 +20,45 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" -else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread thread_basics.c -o $EXERCISE" - exit 1 -fi +# --- Compilation and Executable Finding Logic --- +EXE_PATH="$PROJECT_ROOT/$EXERCISE" +RENDU_EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +SOURCE_FILE="$PROJECT_ROOT/${EXERCISE}.c" +RENDU_SOURCE_FILE="$PROJECT_ROOT/rendu/${EXERCISE}.c" -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +# Prefer executable in 'rendu' directory +if [ -f "$RENDU_EXE_PATH" ]; then + EXE_PATH="$RENDU_EXE_PATH" +# Fallback to root directory executable +elif [ -f "$EXE_PATH" ]; then + : # EXE_PATH is already set correctly +# If no executable, try to compile from source +else + COMPILE_CANDIDATE="" + if [ -f "$RENDU_SOURCE_FILE" ]; then + COMPILE_CANDIDATE="$RENDU_SOURCE_FILE" + elif [ -f "$SOURCE_FILE" ]; then + COMPILE_CANDIDATE="$SOURCE_FILE" + fi + + if [ -n "$COMPILE_CANDIDATE" ]; then + echo -e "${YELLOW}Executable not found, attempting to compile from $COMPILE_CANDIDATE...${NC}" + # Compile into the root directory + gcc -Wall -Wextra -Werror -pthread "$COMPILE_CANDIDATE" -o "$PROJECT_ROOT/$EXERCISE" + if [ $? -eq 0 ]; then + echo -e "${GREEN}✓ Compilation successful.${NC}" + EXE_PATH="$PROJECT_ROOT/$EXERCISE" # Use the newly compiled executable + else + echo -e "${RED}✗ Compilation failed.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Executable and source file for '$EXERCISE' not found.${NC}" + exit 1 + fi +fi +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" +# --- End of Logic --- # Test 1: Basic execution with 1 message echo -n "Test 1: Basic execution (1 message)... " diff --git a/testers/test_2_mutex_basics.sh b/testers/test_2_mutex_basics.sh index 055d09e..8466aa8 100755 --- a/testers/test_2_mutex_basics.sh +++ b/testers/test_2_mutex_basics.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread mutex_basics.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Counter should be exactly 4000 echo -n "Test 1: Counter correctness (should be 4000)... " diff --git a/testers/test_3_precise_timing.sh b/testers/test_3_precise_timing.sh index 38af044..069babe 100755 --- a/testers/test_3_precise_timing.sh +++ b/testers/test_3_precise_timing.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread precise_timing.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Basic execution echo -n "Test 1: Program runs successfully... " diff --git a/testers/test_4_state_monitor.sh b/testers/test_4_state_monitor.sh index 9e45ab0..e575e74 100755 --- a/testers/test_4_state_monitor.sh +++ b/testers/test_4_state_monitor.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread state_monitor.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Program runs for reasonable time echo -n "Test 1: Program execution... " diff --git a/testers/test_5_producer_consumer.sh b/testers/test_5_producer_consumer.sh index f92b4d2..e53b903 100755 --- a/testers/test_5_producer_consumer.sh +++ b/testers/test_5_producer_consumer.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread producer_consumer.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Program runs to completion echo -n "Test 1: Program execution... " diff --git a/testers/test_6_deadlock_demo.sh b/testers/test_6_deadlock_demo.sh index 5e84f3c..44cb3f1 100755 --- a/testers/test_6_deadlock_demo.sh +++ b/testers/test_6_deadlock_demo.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread deadlock_demo.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Deadlock mode (should hang or timeout) echo -n "Test 1: Deadlock demonstration (mode 0)... " diff --git a/testers/test_7_limited_resources.sh b/testers/test_7_limited_resources.sh index 526d943..54a10c5 100755 --- a/testers/test_7_limited_resources.sh +++ b/testers/test_7_limited_resources.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread limited_resources.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Program runs to completion echo -n "Test 1: Program execution... " diff --git a/testers/test_8_simple_philosophers.sh b/testers/test_8_simple_philosophers.sh index 4af1f60..3aae748 100755 --- a/testers/test_8_simple_philosophers.sh +++ b/testers/test_8_simple_philosophers.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread simple_philosophers.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Program runs for approximately 10 seconds echo -n "Test 1: Program duration (~10 seconds)... " diff --git a/testers/test_9_death_monitor.sh b/testers/test_9_death_monitor.sh index be7e99b..d5a6dff 100755 --- a/testers/test_9_death_monitor.sh +++ b/testers/test_9_death_monitor.sh @@ -20,19 +20,61 @@ echo "========================================" echo "Testing: $EXERCISE" echo "========================================" -# Find the executable in the project root or the 'rendu' subdirectory. -if [ -f "$PROJECT_ROOT/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/$EXERCISE" -elif [ -f "$PROJECT_ROOT/rendu/$EXERCISE" ]; then - EXE_PATH="$PROJECT_ROOT/rendu/$EXERCISE" +# --- Find or compile the executable --- +# Priority: +# 1. rendu/executable +# 2. root/executable +# 3. rendu/source -> compile +# 4. root/source -> compile + +# Define potential paths for executable and source +EXE_IN_RENDU="$PROJECT_ROOT/rendu/$EXERCISE" +EXE_IN_ROOT="$PROJECT_ROOT/$EXERCISE" +SRC_IN_RENDU="$PROJECT_ROOT/rendu/${EXERCISE}.c" +SRC_IN_ROOT="$PROJECT_ROOT/${EXERCISE}.c" + +# Check for existing executable +if [ -f "$EXE_IN_RENDU" ]; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${YELLOW}Found executable in 'rendu' directory.${NC}" +elif [ -f "$EXE_IN_ROOT" ]; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${YELLOW}Found executable in root directory.${NC}" else - echo -e "${RED}✗ Executable '$EXERCISE' not found in '$PROJECT_ROOT' or '$PROJECT_ROOT/rendu'${NC}" - echo "Please compile your program first. Example:" - echo "gcc -Wall -Wextra -Werror -pthread death_monitor.c -o $EXERCISE" - exit 1 + echo -e "${YELLOW}Executable not found. Attempting to compile from source...${NC}" + COMPILE_CMD="gcc -Wall -Wextra -Werror -pthread" + + # Check for source file and compile + if [ -f "$SRC_IN_RENDU" ]; then + echo "Found source file in 'rendu'. Compiling..." + if $COMPILE_CMD "$SRC_IN_RENDU" -o "$EXE_IN_RENDU"; then + EXE_PATH="$EXE_IN_RENDU" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_RENDU'.${NC}" + exit 1 + fi + elif [ -f "$SRC_IN_ROOT" ]; then + echo "Found source file in root. Compiling..." + if $COMPILE_CMD "$SRC_IN_ROOT" -o "$EXE_IN_ROOT"; then + EXE_PATH="$EXE_IN_ROOT" + echo -e "${GREEN}Compilation successful.${NC}" + else + echo -e "${RED}✗ Compilation failed for '$SRC_IN_ROOT'.${NC}" + exit 1 + fi + else + echo -e "${RED}✗ Neither executable nor source file found for '$EXERCISE'.${NC}" + echo "Looked for:" + echo " - $EXE_IN_RENDU" + echo " - $EXE_IN_ROOT" + echo " - $SRC_IN_RENDU" + echo " - $SRC_IN_ROOT" + exit 1 + fi fi -echo -e "${YELLOW}Found executable at: $EXE_PATH${NC}" +echo -e "${YELLOW}Using executable at: $EXE_PATH${NC}" # Test 1: Program runs echo -n "Test 1: Program execution... "