Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile #3

Merged
merged 14 commits into from
Feb 26, 2024
Merged
17 changes: 17 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: C/C++ CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: make
run: make re && make && make fclean
19 changes: 19 additions & 0 deletions .github/workflows/evaluator.bkp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Evaluator

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: 42valgrind Leak checker
uses: solareenlo/42valgrind-action@v1.0.3
with:
flags: "cd qa && ./evaluator.py"
17 changes: 17 additions & 0 deletions .github/workflows/evaluator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Evaluator

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: evaluator
run: sudo apt update && sudo apt install valgrind && cd qa && ./evaluator.py
61 changes: 2 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ DFLAGS = -g3
# Paths for libraries
LIB_PATH = ./lib
LIB_NAME = libft.a
# LIB_PRINTF_NAME = libftprintf.a
# LIB_PRINTF_PATH = ./lib/ft_printf

# Colors Definition
GREEN = "\033[32;1m"
Expand All @@ -33,9 +31,8 @@ HEADER_PATH = ./includes/
HEADER = $(HEADER_PATH)push_swap.h
OBJ_PATH = ./obj/
DEBUG_OBJ_PATH = ./obj_debug/
TESTS_PATH = ./tests/
SOURCES_PATH = ./sources/
SOURCES = $(shell find sources/ -name "*.c" | cut -d/ -f2)
SOURCES = 00_main.c 01_user_input_validation.c 02_indexing.c 03_do_moves.c 03_moves.c 04_pre_sort.c 05_target_position.c 06_comp_cost.c 07_cheapest_move.c 08_sort.c 09_push_swap.c 10_dial.c 93_utils.c 94_utils.c 95_utils.c 96_utils.c 97_utils.c 98_utils.c 99_2_utils.c 99_utils.c
MANDATORY_SOURCES = $(addprefix $(SOURCES_PATH), $(SOURCES))

ifdef WITH_DEBUG
Expand All @@ -44,41 +41,12 @@ ifdef WITH_DEBUG
OBJ_PATH = ./obj_debug/
endif

ifdef DEBUG
ifeq ($(DEBUG),1)
CFLAGS += $(DFLAGS) -D DEBUG=1
else ifeq ($(DEBUG),2)
CFLAGS += $(DFLAGS) -D DEBUG=2
else ifeq ($(DEBUG),3)
CFLAGS += $(DFLAGS) -D DEBUG=3
else ifeq ($(DEBUG),4)
CFLAGS += $(DFLAGS) -D DEBUG=4
else ifeq ($(DEBUG),5)
CFLAGS += $(DFLAGS) -D DEBUG=5
else ifeq ($(DEBUG),6)
CFLAGS += $(DFLAGS) -D DEBUG=6
else ifeq ($(DEBUG),7)
CFLAGS += $(DFLAGS) -D DEBUG=7
else ifeq ($(DEBUG),8)
CFLAGS += $(DFLAGS) -D DEBUG=8
else ifeq ($(DEBUG),9)
CFLAGS += $(DFLAGS) -D DEBUG=9
else ifeq ($(DEBUG),10)
CFLAGS += $(DFLAGS) -D DEBUG=10
else ifeq ($(DEBUG),11)
CFLAGS += $(DFLAGS) -D DEBUG=11
endif
endif

OBJECTS = $(addprefix $(OBJ_PATH), $(SOURCES:%.c=%.o))

all: libft $(OBJ_PATH) $(NAME)

libft:
@make --directory=$(LIB_PATH) --no-print-directory

# libftprintf:
# @make --directory=$(LIB_PRINTF_PATH) --no-print-directory

debug:
@make WITH_DEBUG=TRUE --no-print-directory
Expand All @@ -98,43 +66,18 @@ $(OBJ_PATH)%.o: $(SOURCES_PATH)%.c $(HEADER)
$(CC) $(CFLAGS) -c $< -o $@ -I $(HEADER_PATH)
@echo " "

valgrind: debug
@echo $(GREEN)[Running memory checks]$(COLOR_LIMITER)
@wget -nc https://raw.githubusercontent.com/jos-felipe/pipex/master/memory_checker.sh > /dev/null 2>&1
@chmod +x memory_checker.sh
@./memory_checker.sh

nor:
@echo $(GREEN)[Running Norminette]$(COLOR_LIMITER)
@norminette -R CheckForbiddenSourceHeader $(SOURCES_PATH) $(HEADER_PATH)
@echo $(GREEN)[Running Norminette on Libft]$(COLOR_LIMITER)
@norminette -R CheckForbiddenSourceHeader $(LIB_PATH)
@echo $(GREEN)[Running Norminette on Libftprintf]$(COLOR_LIMITER)
@norminette -R CheckForbiddenSourceHeader $(LIB_PRINTF_PATH)

tester: all
@echo $(GREEN)[Running tests]$(COLOR_LIMITER)
@wget -nc https://raw.githubusercontent.com/jos-felipe/pipex/master/funcional_checker.sh > /dev/null 2>&1
@chmod +x funcional_checker.sh
@./funcional_checker.sh

qa: nor tester valgrind

clean:
@echo $(RED)[Removing Objects]$(COLOR_LIMITER)
-rm -rf $(OBJ_PATH)
-rm -rf $(DEBUG_OBJ_PATH)
@echo $(RED)[Removing test files]$(COLOR_LIMITER)
-rm -rf $(TESTS_PATH)

fclean: clean
@echo $(RED)[Removing $(NAME) executable]$(COLOR_LIMITER)
@rm -rf $(NAME)
@rm -rf $(DEBUG_NAME)
@make fclean -C $(LIB_PATH) --no-print-directory
# @make fclean -C $(LIB_PRINTF_PATH) --no-print-directory

re: fclean
@make --no-print-directory

.PHONY: all clean fclean re libft libftprintf debug valgrind tester nor
.PHONY: all clean fclean re libft debug
6 changes: 3 additions & 3 deletions includes/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* push_swap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: josfelip <josfelip@student.42sp.org.br> +#+ +:+ +#+ */
/* By: gfantoni <gfantoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/30 10:52:24 by josfelip #+# #+# */
/* Updated: 2024/02/23 12:17:15 by josfelip ### ########.fr */
/* Updated: 2024/02/26 09:18:48 by gfantoni ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -60,7 +60,7 @@ void push_pre_user_input_validation(int *argc, char ***argv);
void push_fill_stack(t_list_push **a, int argc, char *argv[]);
int push_bst_is_member(t_bst *node, int find_key);
void push_lst_indexing(t_list_push *a, t_bst *bst);
void push_bst_indexing(t_bst **bst, t_list_push **a);
void push_bst_indexing(t_bst **bst);
void push_bst_in_order_static(t_bst *node, int index);

// 03_moves.c
Expand Down
6 changes: 2 additions & 4 deletions lib/sources/functions/sources/ft_math_sqrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_math_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gfantoni <gfantoni@student.42.fr> +#+ +:+ +#+ */
/* By: josfelip <josfelip@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/23 18:07:22 by gfantoni #+# #+# */
/* Updated: 2024/01/29 09:58:19 by gfantoni ### ########.fr */
/* Updated: 2024/02/23 19:01:14 by josfelip ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,9 +15,7 @@
long ft_math_sqrt(long nb, long kick)
{
long result;
long iteration;

iteration = 0;
if (nb > 0)
{
while (1)
Expand Down
30 changes: 21 additions & 9 deletions qa/evaluator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import subprocess
import sys

from evaluator_modules import _01_error_management
from evaluator_modules import _02_identity_test
Expand All @@ -10,6 +11,10 @@
from evaluator_modules import _06_advanced_version
from evaluator_modules import _07_nothing_on_string
from evaluator_modules import _08_only_space_on_string
from evaluator_modules import _00_preparing_environment

# Exit Status
exit_status = 0

# Constant args
program = ["../push_swap"]
Expand All @@ -28,44 +33,51 @@
make = ["make", "-C", "../"]
subprocess.run(make, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

# Preparing environment
print("\nPreparing environment")
_00_preparing_environment.preparing_environment()
print("\n")

# Error management test
print("Error management")
_01_error_management.error_management(program, valgrind, valgrind_check, colours)
exit_status = _01_error_management.error_management(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Identity test
print("Identity test")
_02_identity_test.identity_test(program, valgrind, valgrind_check, colours)
exit_status = _02_identity_test.identity_test(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Simple version
print("Simple version")
_03_simple_version.simple_version(program, valgrind, valgrind_check, colours)
exit_status = _03_simple_version.simple_version(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Another simple version
print("Another simple version")
_04_another_simple_version.another_simple_version(program, valgrind, valgrind_check, colours)
exit_status = _04_another_simple_version.another_simple_version(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Middle version
print("Middle version")
_05_middle_version.middle_version(program, valgrind, valgrind_check, colours)
exit_status = _05_middle_version.middle_version(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Advanced version
print("Advanced version")
_06_advanced_version.advanced_version(program, valgrind, valgrind_check, colours)
exit_status = _06_advanced_version.advanced_version(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Nothing on string
print("Nothing on string")
_07_nothing_on_string.nothing_on_string(program, valgrind, valgrind_check, colours)
exit_status = _07_nothing_on_string.nothing_on_string(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

# Only space on string
print("Only space on string")
_08_only_space_on_string.only_space_on_string(program, valgrind, valgrind_check, colours)
exit_status = _08_only_space_on_string.only_space_on_string(program, valgrind, valgrind_check, colours, exit_status)
print("\n")

subprocess.run(clean, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
subprocess.run(clean, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

exit(exit_status)
8 changes: 8 additions & 0 deletions qa/evaluator_modules/_00_preparing_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import subprocess

def preparing_environment():
arg_wget = "wget -P ../ -nc https://cdn.intra.42.fr/document/document/23675/checker_linux"
arg_chmod = "chmod +x ../checker_linux"

subprocess.run(arg_wget, text=True, shell=True)
subprocess.run(arg_chmod, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
8 changes: 6 additions & 2 deletions qa/evaluator_modules/_01_error_management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess

def error_management(program, valgrind, valgrind_check, colours):
def error_management(program, valgrind, valgrind_check, colours, exit_status):

# Creating args
battery = ["str on list", "dup on list", "max on list", "nothing on list"]
Expand Down Expand Up @@ -33,8 +33,12 @@ def error_management(program, valgrind, valgrind_check, colours):
print(f"{colours[0]}{i + 1}. OK{colours[2]}")
else:
print(f"{colours[1]}{i + 1}. KO{colours[2]}")
exit_status = 1
if valgrind_check in err_val:
print(f"{colours[0]} MOK\n{colours[2]}")
else:
print(f"{colours[1]} MKO\n{colours[2]}")
i = i + 1
exit_status = 1
i = i + 1

return (exit_status)
8 changes: 6 additions & 2 deletions qa/evaluator_modules/_02_identity_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess

def identity_test(program, valgrind, valgrind_check, colours):
def identity_test(program, valgrind, valgrind_check, colours, exit_status):

# Creating args
battery = ["One arg ordered", "Two args ordered", "Four args ordered", "Nine args ordered"]
Expand Down Expand Up @@ -35,8 +35,12 @@ def identity_test(program, valgrind, valgrind_check, colours):
print(f"{colours[0]}{i + 1}. OK{colours[2]}")
else:
print(f"{colours[1]}{i + 1}. KO{colours[2]}")
exit_status = 1
if valgrind_check in err_val:
print(f"{colours[0]} MOK\n{colours[2]}")
else:
print(f"{colours[1]} MKO\n{colours[2]}")
i = i + 1
exit_status = 1
i = i + 1

return (exit_status)
8 changes: 6 additions & 2 deletions qa/evaluator_modules/_03_simple_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess

def simple_version(program, valgrind, valgrind_check, colours):
def simple_version(program, valgrind, valgrind_check, colours, exit_status):

# Definig args
all_tiny_sort_args_checker = ["'1 3 2'", "'2 1 3'", "'2 3 1'", "'3 1 2'", "'3 2 1'"]
Expand Down Expand Up @@ -38,8 +38,12 @@ def simple_version(program, valgrind, valgrind_check, colours):
print(f"{colours[0]}{i}. OK {colours[2]}")
else:
print(f"{colours[1]}{i}. KO {colours[2]}")
exit_status = 1
if valgrind_check in out_val:
print(f"{colours[0]} MOK{colours[2]}")
else:
print(f"{colours[1]} MKO{colours[2]}")
i = i + 1
exit_status = 1
i = i + 1

return (exit_status)
8 changes: 6 additions & 2 deletions qa/evaluator_modules/_04_another_simple_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess

def another_simple_version(program, valgrind, valgrind_check, colours):
def another_simple_version(program, valgrind, valgrind_check, colours, exit_status):

# Definig args
all_tiny_sort_args_checker = ["'1 5 2 4 3'", "'5 4 3 2 1'"]
Expand Down Expand Up @@ -38,8 +38,12 @@ def another_simple_version(program, valgrind, valgrind_check, colours):
print(f"{colours[0]}{i}. OK {colours[2]}")
else:
print(f"{colours[1]}{i}. KO {colours[2]}")
exit_status = 1
if valgrind_check in out_val:
print(f"{colours[0]} MOK{colours[2]}")
else:
print(f"{colours[1]} MKO{colours[2]}")
i = i + 1
exit_status = 1
i = i + 1

return (exit_status)
Loading
Loading