aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-06 15:15:48 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-06 15:15:48 +0200
commitd2fac61b27d827dc81a6ed867ec92dfad14a3385 (patch)
tree90015f6aefb18da07f1a7868cb9b8c6292e5bd62
parent757749f4c514dd45d906a821eb41f8bba690c3e2 (diff)
downloadlibasm_test-d2fac61b27d827dc81a6ed867ec92dfad14a3385.tar.gz
libasm_test-d2fac61b27d827dc81a6ed867ec92dfad14a3385.tar.bz2
libasm_test-d2fac61b27d827dc81a6ed867ec92dfad14a3385.zip
Enabling ft_write/ft_read segfault test know that I know that it's not the test fault
-rw-r--r--README.md8
-rw-r--r--libasm_test.h34
-rw-r--r--main.c2
-rw-r--r--test/ft_read_test.c32
-rw-r--r--test/ft_write_test.c86
5 files changed, 81 insertions, 81 deletions
diff --git a/README.md b/README.md
index aeb7d62..b94eac4 100644
--- a/README.md
+++ b/README.md
@@ -6,13 +6,15 @@ Unit tests for the libasm project.
## Usage
+The default path to your libasm is `../libasm`. You can modify it in the Makefile.
+
- `> make run` show regular pretty output.
- `> make run_raw` show parsable output.
### Bonus
-Suffix all Makefile commands with `bonus` i.e `> make runbonus`.
+Suffix all Makefile commands with `bonus` (i.e `> make runbonus`).
-## Configuration
+## Help, ft\_write and ft\_read crash for no reason
-The default path to your libasm is `../libasm`. You can modify it in the Makefile.
+<https://stackoverflow.com/c/42network/questions/1494>
diff --git a/libasm_test.h b/libasm_test.h
index bc8714c..852a27a 100644
--- a/libasm_test.h
+++ b/libasm_test.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 03:07:19 by cacharle #+# #+# */
-/* Updated: 2020/05/04 21:27:44 by charles ### ########.fr */
+/* Updated: 2020/10/06 15:11:17 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,8 +24,6 @@
# include <stddef.h>
# include <errno.h>
-# define TO_STRING(x) #x
-
# ifdef __linux__
# define OPEN_MAX FOPEN_MAX
# endif
@@ -33,11 +31,11 @@
/*
* mandatory
*/
-int ft_strlen(char *str);
+int ft_strlen(char *str);
char* ft_strcpy(char *dst, const char *src);
-int ft_strcmp(const char *s1, const char *s2);
-int ft_write(int fildes, const void *buf, size_t buf_size);
-int ft_read(int fildes, void *buf, size_t buf_size);
+int ft_strcmp(const char *s1, const char *s2);
+int ft_write(int fildes, const void *buf, size_t buf_size);
+int ft_read(int fildes, void *buf, size_t buf_size);
char* ft_strdup(const char *str);
/*
@@ -52,10 +50,10 @@ typedef struct s_list
} t_list;
void ft_list_push_front(t_list **begin_list, void *data);
-int ft_list_size(t_list *begin_list);
+int ft_list_size(t_list *begin_list);
void ft_list_sort(t_list **begin_list, int (*cmp)());
void ft_list_remove_if(t_list **begin_list, void *data_ref,
- int (*cmp)(), void (*free_fct)(void *));
+ int (*cmp)(), void (*free_fct)(void *));
/*
* test_functions
@@ -80,28 +78,28 @@ void ft_list_remove_if_test(void);
void print_ok(void);
void print_signaled_ko(void);
-int* create_data_elem(int data);
+int* create_data_elem(int data);
t_list* create_elem(int data);
t_list* list_from_format(char *fmt);
t_list* list_dup(t_list *list);
-int list_cmp(t_list *l1, t_list *l2);
-void list_print(t_list *list);
-void list_destroy(t_list *list);
+int list_cmp(t_list *l1, t_list *l2);
+void list_print(t_list *list);
+void list_destroy(t_list *list);
/*
* function of reference
*/
-int ref_ft_atoi_base(char *str, char *base);
+int ref_ft_atoi_base(char *str, char *base);
void ref_ft_list_push_front(t_list **begin_list, void *data);
-int ref_ft_list_size(t_list *begin_list);
+int ref_ft_list_size(t_list *begin_list);
void ref_ft_list_sort(t_list **begin_list, int (*cmp)());
void ref_ft_list_remove_if(t_list **begin_list, void *data_ref,
- int (*cmp)(), void (*free_fct)(void *));
+ int (*cmp)(), void (*free_fct)(void *));
/*
* segfault tester
*/
-int pid;
+int pid;
bool signaled;
# define TEST_SEGFAULT(x) do { \
@@ -112,7 +110,7 @@ bool signaled;
exit(EXIT_SUCCESS); \
} else { \
wait(&pid); \
- signaled = !WIFEXITED(pid); \
+ signaled = WIFSIGNALED(pid); \
} \
} while(0)
diff --git a/main.c b/main.c
index abbb4cd..54326d7 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 03:06:45 by cacharle #+# #+# */
-/* Updated: 2020/04/13 15:01:24 by charles ### ########.fr */
+/* Updated: 2020/10/06 15:04:34 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/test/ft_read_test.c b/test/ft_read_test.c
index 34fd7bc..2379a3f 100644
--- a/test/ft_read_test.c
+++ b/test/ft_read_test.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 03:07:44 by cacharle #+# #+# */
-/* Updated: 2020/06/18 14:58:54 by charles ### ########.fr */
+/* Updated: 2020/10/06 15:05:51 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -58,21 +58,21 @@ static int read_origin_errno;
static
void ft_read_test_segfault(void)
{
- /* int tmp[2]; */
- /* char buf_read[2048]; */
- /* */
- /* if (pipe(tmp) < 0) */
- /* exit(EXIT_FAILURE); */
- /* write(tmp[1], "asdfkasdfkl;jasd;ljkfa;lssdlfasdfasdfasdfasdfasdfasdfasdfasdfasdf", 40); */
- /* TEST_ASM_FUNCTION(ft_read(-1, buf_read, 2)); */
- /* TEST_ASM_FUNCTION(ft_read(tmp[0], NULL, 2)); */
- /* TEST_ASM_FUNCTION(ft_read(tmp[0], buf_read, 0)); */
- /* TEST_ASM_FUNCTION(ft_read(tmp[0], buf_read, 5)); */
- /* TEST_ASM_FUNCTION(ft_read(tmp[0], buf_read, 32)); */
- /* close(tmp[0]); */
- /* close(tmp[1]); */
- /* TEST_ASM_FUNCTION(ft_read(-1, buf_read, 2)); */
- /* TEST_ASM_FUNCTION(ft_read(OPEN_MAX + 1, buf_read, 2)); */
+ int tmp[2];
+ char buf_read[2048];
+
+ if (pipe(tmp) < 0)
+ exit(EXIT_FAILURE);
+ write(tmp[1], "asdfkasdfkl;jasd;ljkfa;lssdlfasdfasdfasdfasdfasdfasdfasdfasdfasdf", 40);
+ TEST_ASM_FUNCTION(ft_read(-1, buf_read, 2));
+ TEST_ASM_FUNCTION(ft_read(tmp[0], NULL, 2));
+ TEST_ASM_FUNCTION(ft_read(tmp[0], buf_read, 0));
+ TEST_ASM_FUNCTION(ft_read(tmp[0], buf_read, 5));
+ TEST_ASM_FUNCTION(ft_read(tmp[0], buf_read, 32));
+ close(tmp[0]);
+ close(tmp[1]);
+ TEST_ASM_FUNCTION(ft_read(-1, buf_read, 2));
+ TEST_ASM_FUNCTION(ft_read(OPEN_MAX + 1, buf_read, 2));
}
static
diff --git a/test/ft_write_test.c b/test/ft_write_test.c
index 32e0712..6ae96a6 100644
--- a/test/ft_write_test.c
+++ b/test/ft_write_test.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 03:07:48 by cacharle #+# #+# */
-/* Updated: 2020/06/18 14:58:45 by charles ### ########.fr */
+/* Updated: 2020/10/06 14:40:00 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,59 +22,59 @@ static int write_errno;
static int write_origin_errno;
static ssize_t ret;
-#define FT_WRITE_EXPECT(str) do { \
- if (pipe(ft_write_pipe) < 0) \
- exit(EXIT_FAILURE); \
- fcntl(ft_write_pipe[0], F_SETFL, O_NONBLOCK); \
- ERRNO_WRAP(write_origin_ret = write(ft_write_pipe[1], str, strlen(str)), write_origin_errno); \
- read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \
- ERRNO_WRAP(write_ret = ft_write(ft_write_pipe[1], str, strlen(str)), write_errno); \
- ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \
- buf[ret] = '\0'; \
- if (write_errno != write_origin_errno) \
- printf("KO: [COMPARE]: %s: expected: errno %d got: errno %d with: "#str"\n", \
- test_name, write_origin_errno, write_errno); \
- else if (strcmp(buf, str) != 0 || write_ret != write_origin_ret) \
+#define FT_WRITE_EXPECT(str) do { \
+ if (pipe(ft_write_pipe) < 0) \
+ exit(EXIT_FAILURE); \
+ fcntl(ft_write_pipe[0], F_SETFL, O_NONBLOCK); \
+ ERRNO_WRAP(write_origin_ret = write(ft_write_pipe[1], str, strlen(str)), write_origin_errno); \
+ read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \
+ ERRNO_WRAP(write_ret = ft_write(ft_write_pipe[1], str, strlen(str)), write_errno); \
+ ret = read(ft_write_pipe[0], buf, FT_WRITE_BUF_SIZE); \
+ buf[ret] = '\0'; \
+ if (write_errno != write_origin_errno) \
+ printf("KO: [COMPARE]: %s: expected: errno %d got: errno %d with: "#str"\n", \
+ test_name, write_origin_errno, write_errno); \
+ else if (strcmp(buf, str) != 0 || write_ret != write_origin_ret) \
printf("KO: [COMPARE]: %s: expected: %lu \"%s\" got: %lu \"%s\" with: %d, \"%s\", %zu \n", \
test_name, strlen(str), str, write_ret, buf, ft_write_pipe[0], buf, strlen(str)); \
- else \
- print_ok(); \
- close(ft_write_pipe[1]); \
- close(ft_write_pipe[0]); \
+ else \
+ print_ok(); \
+ close(ft_write_pipe[1]); \
+ close(ft_write_pipe[0]); \
} while (0);
-#define FT_WRITE_EXPECT_ERROR(fd, str, size) do { \
- ERRNO_WRAP(write_ret = ft_write(fd, str, size), write_errno); \
- ERRNO_WRAP(write_origin_ret = write(fd, str, size), write_origin_errno); \
- if ((long)write_ret != -1) \
- printf("KO: [COMPARE]: %s: expected: %ld got: %ld with: %d "#str", %d\n", \
- test_name, -1l, (long)write_ret, fd, size); \
- else if (write_errno != write_origin_errno) \
+#define FT_WRITE_EXPECT_ERROR(fd, str, size) do { \
+ ERRNO_WRAP(write_ret = ft_write(fd, str, size), write_errno); \
+ ERRNO_WRAP(write_origin_ret = write(fd, str, size), write_origin_errno); \
+ if ((long)write_ret != -1) \
+ printf("KO: [COMPARE]: %s: expected: %ld got: %ld with: %d "#str", %d\n", \
+ test_name, -1l, (long)write_ret, fd, size); \
+ else if (write_errno != write_origin_errno) \
printf("KO: [COMPARE]: %s: expected: errno %d got: errno %d with: %d "#str", %d\n", \
test_name, write_origin_errno, write_errno, fd, size); \
- else \
- print_ok(); \
+ else \
+ print_ok(); \
} while (0);
static
void ft_write_test_segfault(void)
{
- /* int tmp[2]; */
- /* if (pipe(tmp) < 0) */
- /* exit(EXIT_FAILURE); */
- /* TEST_ASM_FUNCTION(ft_write(-1, "test", 5)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], NULL, 5)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 0)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 5)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], "t", 1)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], "", 0)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 4)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 2)); */
- /* TEST_ASM_FUNCTION(ft_write(tmp[1], NULL, 2)); */
- /* close(tmp[0]); */
- /* close(tmp[1]); */
- /* TEST_ASM_FUNCTION(ft_write(-1, "tt", 2)); */
- /* TEST_ASM_FUNCTION(ft_write(OPEN_MAX + 1, "tt", 2)); */
+ int tmp[2];
+ if (pipe(tmp) < 0)
+ exit(EXIT_FAILURE);
+ TEST_ASM_FUNCTION(ft_write(-1, "test", 5));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], NULL, 5));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 0));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 5));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], "t", 1));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], "", 0));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 4));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], "test", 2));
+ TEST_ASM_FUNCTION(ft_write(tmp[1], NULL, 2));
+ close(tmp[0]);
+ close(tmp[1]);
+ TEST_ASM_FUNCTION(ft_write(-1, "tt", 2));
+ TEST_ASM_FUNCTION(ft_write(OPEN_MAX + 1, "tt", 2));
}
static