Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Concurrency & Rigor CI Pipeline

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
workflow_dispatch:

jobs:
build-and-concurrency-check:
name: Build & Concurrency Audit (${{ matrix.compiler }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang valgrind

- name: Verify compilation and Makefile targets
run: |
make clean
make all CC=${{ matrix.compiler }}
make fclean
make re CC=${{ matrix.compiler }}

- name: Concurrency Test — ThreadSanitizer (TSan Data-Race Audit)
run: |
make tsan CC=${{ matrix.compiler }}
echo "=== TSan Test 1: Single Philosopher (Must die at ~400ms) ==="
./philo/philo 1 400 200 200

echo "=== TSan Test 2: 4 Philosophers eating 5 times (Zero Data Races) ==="
./philo/philo 4 410 200 200 5

- name: Concurrency Test — Helgrind (Deadlock & Lock Order Audit)
run: |
make re CC=${{ matrix.compiler }}
echo "=== Helgrind Test: Lock contention and deadlock audit ==="
valgrind --tool=helgrind --error-exitcode=42 ./philo/philo 4 410 200 200 2
valgrind --tool=helgrind --error-exitcode=42 ./philo/philo 1 400 200 200

- name: Memory Test — Valgrind Memcheck (Zero Leaks Audit)
run: |
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=42 ./philo/philo 4 410 200 200 3
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=42 ./philo/philo 1 400 200 200

- name: Functional & Timing Verification
run: |
echo "=== Functional Test: Meal counting ==="
MEALS=$(./philo/philo 4 410 200 200 7 | grep -c "is eating")
echo "Total meals recorded: $MEALS"
if [ "$MEALS" -lt 28 ]; then
echo "Expected at least 28 meals, got $MEALS"
exit 1
fi
echo "All verification checks passed with 100% success!"
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Object and dependency files
*.o
*.d
obj/
philo/obj/

# Executables
philo/philo
/philo
philo_tsan
philo/philo_tsan

# Logs and test outputs
*.log
log_*
errors_log
.vscode/
philo/.vscode/

# OS and temporary files
.DS_Store
*~
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Ruben Higuita

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
68 changes: 17 additions & 51 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,31 @@
# By: rhiguita <rhiguita@student.42madrid.com +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/05/11 16:04:17 by rhiguita #+# #+# #
# Updated: 2025/11/02 15:32:40 by rhiguita ### ########.fr #
# Updated: 2026/09/22 17:30:30 by rhiguita ### ########.fr #
# #
# **************************************************************************** #

# Standard
NAME = philo
SUBDIR := philo

INC = -Iinc/
SRC_DIR = srcs/
OBJ_DIR = obj/
all:
@$(MAKE) -C $(SUBDIR) all

# Compiler and CFlags
CC = gcc
CFLAGS = -Wall -Werror -Wextra -g -pthread -I$(INC)
RM = rm -f

# Source Files
COMMANDS_DIR = srcs/main.c \
srcs/time.c \
srcs/utils.c \
srcs/init.c \
srcs/parser.c \
srcs/simulation.c \
srcs/monitor.c \
srcs/actions.c


# Concatenate all source files
SRCS = $(COMMANDS_DIR)

# Apply the pattern substitution to each source file in SRC and produce a corresponding list of object files in the OBJ_DIR
OBJ = $(patsubst $(SRC_DIR)%.c,$(OBJ_DIR)%.o,$(SRCS))

# Build rules
start:
@make -s all

all: $(NAME)
clean:
@$(MAKE) -C $(SUBDIR) clean

$(NAME): $(OBJ)
@$(CC) $(CFLAGS) $(INC) $(OBJ) -o $(NAME) 2>&1 | lolcat
fclean:
@$(MAKE) -C $(SUBDIR) fclean

# Compile object files from source files
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
@mkdir -p $(@D)
@echo "compiling $<" | lolcat
@$(CC) $(CFLAGS) $(INC) -c $< -o $@ 2>&1 | lolcat
re:
@$(MAKE) -C $(SUBDIR) re

clean:
@$(RM) -r $(OBJ_DIR)
@echo "Delete files objets" | lolcat
tsan:
@$(MAKE) -C $(SUBDIR) tsan

fclean: clean
@$(RM) $(NAME)
@$(RM)
@echo "Delete all files" | lolcat
debug:
@$(MAKE) -C $(SUBDIR) debug

re: fclean all
@echo "Finsh Recompiling" | lolcat
test: all
@./tester/tester.sh .

# Phony targets represent actions not files
.PHONY: start all clean fclean re
.PHONY: all clean fclean re tsan debug test
Loading
Loading