Increase tester functionality

- Tester now checks if executable exists in `rendu` filder, if not, compiles the source file and run the test on it
This commit is contained in:
Rui Ribeiro 2025-10-07 20:57:32 +01:00
parent f30d1e67b5
commit 8779aa24a6
12 changed files with 623 additions and 122 deletions

View File

@ -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... "

View File

@ -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... "

View File

@ -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..."

View File

@ -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)... "

View File

@ -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)... "

View File

@ -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... "

View File

@ -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... "

View File

@ -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... "

View File

@ -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)... "

View File

@ -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... "

View File

@ -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)... "

View File

@ -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... "