feat/stdout (#3)

* feat: disable standard output for tests

* fuck les fds

* patch some complation issues

* style: norm

* feat: timeout

* fix: patc more stuff

* fix: patch merge

* feat: more tests
This commit is contained in:
Erwann Lagouche
2026-01-25 16:43:39 +01:00
committed by GitHub
parent 442619f4cb
commit cf491b279d
30 changed files with 332 additions and 132 deletions

1
.gitignore vendored
View File

@@ -57,4 +57,5 @@ dkms.conf
/libunit
/real_tests/real_tests
/tests/tests
*.log

View File

@@ -1,13 +1,13 @@
NAME = libunit.a
AR = ar rcs
CC = cc
CCFLAGS = -Wall -Wextra -Werror -MMD -MP
CCFLAGS = -Wall -Wextra -Werror -MMD -MP -g3
CCFLAGS += -I$(LIBFT_DIR) -I. -Iframework
LDFLAGS = -Llibft -lunit -lft -L.
LIBFT_DIR = libft
LIBFT_A = $(LIBFT_DIR)/libft.a
SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c
SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c framework/libunit_logger.c
OBJ = $(SRC:.c=.o)
TESTD = tests
@@ -38,8 +38,8 @@ fclean: clean
@$(MAKE) -C $(TESTD) fclean
@$(MAKE) -C $(RTESTD) fclean
re: fclean
@$(MAKE) all
re: fclean all
@$(MAKE)
$(TESTB): FORCE
@$(MAKE) -C $(TESTD)

View File

@@ -6,94 +6,82 @@
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */
/* Updated: 2026/01/24 16:50:51 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:15:05 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "libunit.h"
#include <fcntl.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
static void print_wtermsig(int signal)
int parent_helper(int ffd, struct s_helper *h, const char *fn_name,
t_unit_test *test_list)
{
if (signal == 11)
ft_putstr_fd("[\x1B[33mSIGSEGV\x1B[0m]\n", 1);
else if (signal == 7)
ft_putstr_fd("[\x1B[33mSIGBUS\x1B[0m]\n", 1);
else if (signal == 6)
ft_putstr_fd("[\x1B[33mSIGABRT\x1B[0m]\n", 1);
else if (signal == 8)
ft_putstr_fd("[\x1B[33mSIGFPE\x1B[0m]\n", 1);
else if (signal == 13)
ft_putstr_fd("[\x1B[33mSIGPIPE\x1B[0m]\n", 1);
else if (signal == 4)
ft_putstr_fd("[\x1B[33mSIGILL\x1B[0m]\n", 1);
}
int status;
static size_t interpret_status(int status, const char *fn_name,
char *test_name)
{
ft_putstr_fd((char *)fn_name, 1);
ft_putstr_fd(" : ", 1);
ft_putstr_fd(test_name, 1);
ft_putstr_fd(" : ", 1);
if (WIFEXITED(status))
{
if (WEXITSTATUS(status))
ft_putstr_fd("[\x1B[31m\x1B[1mKO\x1B[0m]\n", 1);
else
{
ft_putstr_fd("[\x1B[32mOK\x1B[0m]\n", 1);
return (1);
}
}
else if (WIFSIGNALED(status))
print_wtermsig(WTERMSIG(status));
h->wpid = waitpid(h->wpid, &status, WCONTINUED);
if (h->wpid < 0)
return (-1);
h->ok_tests += interpret_status(ffd, status, fn_name, get_test_at(test_list,
h->i)->title);
return (0);
}
static void print_passed_test(size_t ok_tests, t_unit_test *test_list)
int child_helper(t_unit_test *test_list, t_h h)
{
size_t total;
int fd;
int res;
t_unit_test *test;
total = count_tests(test_list);
if (ok_tests == total)
ft_putstr_fd("\x1B[32m", 1);
else
ft_putstr_fd("\x1B[31m", 1);
ft_putnbr_fd(ok_tests, 1);
ft_putchar_fd('/', 1);
ft_putnbr_fd((int)total, 1);
ft_putstr_fd("\x1B[0m tests succeeded\n\n", 1);
fd = open("/dev/null", O_WRONLY);
if (!fd)
return (-1);
if (dup2(fd, STDOUT_FILENO) < 0)
return (-1);
test = get_test_at(test_list, h.i);
if (test->timeout)
alarm(test->timeout);
res = test->func();
close(fd);
exit(res);
}
int handle_out(const char *fn_name)
{
char *tmp;
int fd;
tmp = ft_strjoin(fn_name, ".log");
if (!tmp)
return (-1);
fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644);
free(tmp);
return (fd);
}
int launch_tests(t_unit_test *test_list, const char *fn_name)
{
size_t ok_tests;
pid_t wpid;
int status;
int i;
int ffd;
t_h h;
ok_tests = 0;
i = -1;
while (++i < (int)count_tests(test_list))
{
wpid = fork();
if (wpid < 0)
h.ok_tests = 0;
h.i = -1;
ffd = handle_out(fn_name);
if (ffd < 0)
return (1);
else if (wpid == 0)
exit(!get_test_at(test_list, i)->func());
else
while (++h.i < (int)count_tests(test_list))
{
wpid = wait(&status);
if (wpid < 0)
h.wpid = fork();
if (h.wpid < 0)
return (1);
else if (h.wpid == 0 && child_helper(test_list, h) < 0)
return (1);
else if (parent_helper(ffd, &h, fn_name, test_list))
return (1);
ok_tests += interpret_status(status, fn_name, get_test_at(test_list,
i)->title);
}
}
print_passed_test(ok_tests, test_list);
print_passed_test(ffd, h.ok_tests, test_list);
close(ffd);
return (0);
}

View File

@@ -6,14 +6,14 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:56:03 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:09:41 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBUNIT_H
# define LIBUNIT_H
# include "libft.h"
# include "../libft/libft.h"
# include <sys/types.h>
# include <unistd.h>
@@ -25,6 +25,7 @@ typedef struct s_unit_test
char *title;
int (*func)(void);
struct s_unit_test *next;
unsigned int timeout;
} t_unit_test;
/**
@@ -53,7 +54,7 @@ size_t count_tests(t_unit_test *head);
* @return -1 on error, 0 on success
*/
size_t load_test(t_unit_test **head_ptr, const char *title,
int (*test_func)(void));
int (*test_func)(void), unsigned int timeout);
/**
* @brief clears the tests memory
@@ -66,4 +67,17 @@ void clear_tests(t_unit_test **head_ptr);
int launch_tests(t_unit_test *test_list,
const char *fn_name);
typedef struct s_helper
{
pid_t wpid;
size_t ok_tests;
int i;
} t_h;
size_t interpret_status(int ffd, int status,
const char *fn_name, char *test_name);
void print_passed_test(int ffd, size_t ok_tests,
t_unit_test *test_list);
#endif // !LIBUNIT_H

View File

@@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libunit_logger.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 14:26:54 by elagouch #+# #+# */
/* Updated: 2026/01/25 14:56:06 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
static void print_wtermsig(int ffd, int signal)
{
static char *sigs[15];
char *msg;
sigs[4] = "SIGKILL";
sigs[6] = "SIGABRT";
sigs[7] = "SIGBUS";
sigs[8] = "SIGFPE";
sigs[11] = "SIGSEGV";
sigs[13] = "SIGPIPE";
sigs[14] = "TIMEOUT";
ft_putstr_fd("[\x1B[33m", 1);
ft_putstr_fd("[", ffd);
if ((signal >= 6 && signal <=8) || signal == 4 || signal == 11 || (signal >= 13 && signal <= 14))
msg = sigs[signal];
else
msg = "UNKNOWN";
ft_putstr_fd(msg, 1);
ft_putstr_fd(msg, ffd);
ft_putstr_fd("\x1B[0m]\n", 1);
ft_putstr_fd("]\n", ffd);
}
size_t interpret_status(int ffd, int status, const char *fn_name,
char *test_name)
{
ft_putstr_fd((char *)fn_name, 1);
ft_putstr_fd((char *)fn_name, ffd);
ft_putstr_fd(" : ", 1);
ft_putstr_fd(" : ", ffd);
ft_putstr_fd(test_name, 1);
ft_putstr_fd(test_name, ffd);
ft_putstr_fd(" : ", 1);
ft_putstr_fd(" : ", ffd);
if (WIFEXITED(status))
{
if (WEXITSTATUS(status))
{
ft_putstr_fd("[\x1B[31m\x1B[1mKO\x1B[0m]\n", 1);
ft_putstr_fd("[KO]\n", ffd);
}
else
{
ft_putstr_fd("[\x1B[32mOK\x1B[0m]\n", 1);
ft_putstr_fd("[OK]\n", ffd);
return (1);
}
}
else if (WIFSIGNALED(status))
print_wtermsig(ffd, WTERMSIG(status));
return (0);
}
void print_passed_test(int ffd, size_t ok_tests, t_unit_test *test_list)
{
size_t total;
total = count_tests(test_list);
if (ok_tests == total)
ft_putstr_fd("\x1B[32m", 1);
else
ft_putstr_fd("\x1B[31m", 1);
ft_putnbr_fd(ok_tests, 1);
ft_putnbr_fd(ok_tests, ffd);
ft_putchar_fd('/', 1);
ft_putchar_fd('/', ffd);
ft_putnbr_fd((int)total, 1);
ft_putnbr_fd((int)total, ffd);
ft_putstr_fd("\x1B[0m tests succeeded\n\n", 1);
ft_putstr_fd(" tests succeeded\n\n", ffd);
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:35:57 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:15:35 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:11:24 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,7 +39,7 @@ t_unit_test *get_last(t_unit_test *head)
/**
* @brief util function to allocate a new test
*/
t_unit_test *alloc_test(const char *title, int (*test_func)(void))
static t_unit_test *alloc_test(const char *title, int (*test_func)(void), unsigned int timeout)
{
t_unit_test *p;
@@ -47,11 +47,12 @@ t_unit_test *alloc_test(const char *title, int (*test_func)(void))
p->title = ft_strdup(title);
p->func = test_func;
p->next = NULL;
p->timeout = timeout;
return (p);
}
size_t load_test(t_unit_test **head_ptr, const char *title,
int (*test_func)(void))
int (*test_func)(void), unsigned int timeout)
{
t_unit_test *p;
t_unit_test *last;
@@ -60,14 +61,14 @@ size_t load_test(t_unit_test **head_ptr, const char *title,
return (-1);
if (!*head_ptr)
{
p = alloc_test(title, test_func);
p = alloc_test(title, test_func, timeout);
if (!p)
return (-1);
*head_ptr = p;
return (0);
}
last = get_last(*head_ptr);
last->next = alloc_test(title, test_func);
last->next = alloc_test(title, test_func, timeout);
if (!last->next)
return (-1);
return (0);

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 16:22:35 by dgaillet #+# #+# */
/* Updated: 2026/01/24 16:22:36 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:32:35 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,10 +18,10 @@ int atoi_launcher(void)
size_t res;
testlist = NULL;
load_test(&testlist, "Basic test", &atoi_basic_test);
load_test(&testlist, "INT MAX test", &atoi_int_max_test);
load_test(&testlist, "INT MIN test", &atoi_int_min_test);
load_test(&testlist, "NULL test", &atoi_null_test);
load_test(&testlist, "Basic test", &atoi_basic_test, 0);
load_test(&testlist, "INT MAX test", &atoi_int_max_test, 0);
load_test(&testlist, "INT MIN test", &atoi_int_min_test, 0);
load_test(&testlist, "NULL test", &atoi_null_test, 0);
res = launch_tests(testlist, "atoi");
clear_tests(&testlist);
return (res);

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_ok.c :+: :+: :+: */
/* 01_basic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 17:22:48 by dgaillet #+# #+# */
/* Updated: 2026/01/24 17:22:51 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:33:19 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,5 +15,5 @@
int atoi_basic_test(void)
{
return (ft_atoi("42") == 42);
return (!(ft_atoi("42") == 42));
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_ko.c :+: :+: :+: */
/* 02_int_max.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 17:23:00 by dgaillet #+# #+# */
/* Updated: 2026/01/24 17:23:01 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:33:35 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int atoi_int_max_test(void)
{
return (ft_atoi("2147483647") == 2147483647);
return (!(ft_atoi("2147483647") == 2147483647));
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_sigsegv.c :+: :+: :+: */
/* 03_int_min.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 17:23:10 by dgaillet #+# #+# */
/* Updated: 2026/01/24 17:23:11 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:33:46 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int atoi_int_min_test(void)
{
return (ft_atoi("-2147483648") == -2147483648);
return (!(ft_atoi("-2147483648") == -2147483648));
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:34:12 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:13:57 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,9 +18,9 @@ int strlen_launcher(void)
size_t res;
testlist = NULL;
load_test(&testlist, "null", &test_null);
load_test(&testlist, "basic", &test_basic);
load_test(&testlist, "large", &test_large);
load_test(&testlist, "null", &test_null, 0);
load_test(&testlist, "basic", &test_basic, 0);
load_test(&testlist, "large", &test_large, 0);
res = launch_tests(testlist, "strlen");
clear_tests(&testlist);
return (res);

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:17:14 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:16:59 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int test_basic(void)
{
return (ft_strlen("hello, world") == 12);
return (!(ft_strlen("hello, world") == 12));
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:17:04 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:16:28 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int test_null(void)
{
return (ft_strlen(NULL) == 0);
return (!(ft_strlen(NULL) == 0));
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:36:42 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:16:42 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,5 +23,5 @@ int test_large(void)
s[i] = ' ';
i++;
}
return (ft_strlen(s) == sizeof(s) + 1);
return (!(ft_strlen(s) == sizeof(s) + 1));
}

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 12:05:05 by dgaillet #+# #+# */
/* Updated: 2026/01/25 12:05:17 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:35:04 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,9 +18,9 @@ int strncmp_launcher(void)
size_t res;
testlist = NULL;
load_test(&testlist, "Basic test", &strncmp_basic_test);
load_test(&testlist, "Len test", &strncmp_len_test);
load_test(&testlist, "High len test", &strncmp_high_len_test);
load_test(&testlist, "Basic test", &strncmp_basic_test, 0);
load_test(&testlist, "Len test", &strncmp_len_test, 0);
load_test(&testlist, "High len test", &strncmp_high_len_test, 0);
res = launch_tests(testlist, "ft_strncmp");
clear_tests(&testlist);
return (res);

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 12:05:24 by dgaillet #+# #+# */
/* Updated: 2026/01/25 12:05:25 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 15:15:39 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int strncmp_basic_test(void)
{
return (!ft_strncmp("test", "test", 4));
return (ft_strncmp("test", "test", 4));
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_ko.c :+: :+: :+: */
/* 02_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 12:05:30 by dgaillet #+# #+# */
/* Updated: 2026/01/25 12:05:32 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:34:24 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int strncmp_len_test(void)
{
return (!ft_strncmp("test123", "test", 4));
return (ft_strncmp("test123", "test", 4));
}

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 16:01:01 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:01:03 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/25 16:35:34 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,5 @@
int strncmp_high_len_test(void)
{
return (!ft_strncmp("test", "test", 42));
return (ft_strncmp("test", "test", 42));
}

View File

@@ -1,9 +1,9 @@
NAME = tests
CC = cc
CCFLAGS = -Wall -Wextra -Werror -MMD -MP
CCFLAGS = -Wall -Wextra -Werror -MMD -MP -g3
SRC = main.c
SRC += libunit/00_launcher.c libunit/01_ok.c libunit/02_ko.c libunit/03_sigsegv.c libunit/04_sigbus.c
SRC += libunit/00_launcher.c libunit/01_ok.c libunit/02_ko.c libunit/03_sigsegv.c libunit/04_sigbus.c libunit/05_sigkill.c libunit/06_sigabrt.c libunit/07_sigfpe.c libunit/08_sigpipe.c libunit/09_timeout.c
OBJ = $(SRC:.c=.o)
LIBS = -L.. -lunit -L../libft -lft

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:47:43 by elagouch ### ########.fr */
/* Updated: 2026/01/25 16:41:49 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,10 +18,15 @@ int libunit_launcher(void)
size_t res;
testlist = NULL;
load_test(&testlist, "successful", &test_ok);
load_test(&testlist, "unsuccessful", &test_ko);
load_test(&testlist, "sigsegv", &test_sigsegv);
load_test(&testlist, "sigbus", &test_sigbus);
load_test(&testlist, "successful", &test_ok, 0);
load_test(&testlist, "unsuccessful", &test_ko, 0);
load_test(&testlist, "sigsegv", &test_sigsegv, 0);
load_test(&testlist, "sigbus", &test_sigbus, 0);
load_test(&testlist, "sigkill", &test_sigkill, 0);
load_test(&testlist, "sigabrt", &test_sigabrt, 0);
load_test(&testlist, "sigfpe", &test_sigfpe, 0);
load_test(&testlist, "sigpipe", &test_sigpipe, 0);
load_test(&testlist, "timeout", &test_timeout, 1);
res = launch_tests(testlist, "libunit");
clear_tests(&testlist);
return (res);

View File

@@ -6,11 +6,11 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:16:32 by elagouch ### ########.fr */
/* Updated: 2026/01/25 16:36:02 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
int test_ok(void)
{
return (1);
return (0);
}

View File

@@ -6,11 +6,11 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:16:37 by elagouch ### ########.fr */
/* Updated: 2026/01/25 16:36:07 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
int test_ko(void)
{
return (0);
return (1);
}

View File

@@ -6,14 +6,14 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:19:43 by elagouch ### ########.fr */
/* Updated: 2026/01/25 16:36:33 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
#include "../tests.h"
int test_sigsegv(void)
{
raise(SIGSEGV);
return (ft_atoi(NULL) == 0);
return (1);
}

View File

@@ -6,14 +6,20 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:19:50 by elagouch ### ########.fr */
/* Updated: 2026/01/25 15:22:52 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
#include <stdlib.h>
int test_sigbus(void)
{
raise(SIGBUS);
char *cptr;
int *iptr;
__asm__("pushf\norl $0x40000,(%rsp)\npopf");
cptr = malloc(sizeof(int) + 1);
iptr = (int *)++cptr;
*iptr = 42;
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 05_sigkill.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:38:20 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigkill(void)
{
raise(SIGKILL);
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 06_sigabrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:38:37 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigabrt(void)
{
raise(SIGABRT);
return (1);
}

19
tests/libunit/07_sigfpe.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 07_sigfpe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:39:11 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigfpe(void)
{
raise(SIGFPE);
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 08_sigpipe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:39:33 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigpipe(void)
{
raise(SIGPIPE);
return (1);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 09_timeout.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:40:07 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
int test_timeout(void)
{
while(1)
{}
return (1);
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:41:02 by elagouch ### ########.fr */
/* Updated: 2026/01/25 16:40:37 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,5 +23,10 @@ int test_ok(void);
int test_ko(void);
int test_sigsegv(void);
int test_sigbus(void);
int test_sigkill(void);
int test_sigabrt(void);
int test_sigfpe(void);
int test_sigpipe(void);
int test_timeout(void);
#endif // !TESTS_H