diff --git a/Makefile b/Makefile index 8f86916..8346250 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: alelievr +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created 2015/04/04 19:22:36 by alelievr #+# #+# # -# Updated: 2019/11/03 22:05:40 by tjans ######## odam.nl # +# Updated: 2021/10/25 06:49:48 by gbaconni ### ########.fr # # # # **************************************************************************** # @@ -36,7 +36,6 @@ SRC = src/main.c \ hardcore-mode/test-strncmp.c \ hardcore-mode/test-memset.c \ hardcore-mode/test-memcpy.c \ - hardcore-mode/test-memccpy.c \ hardcore-mode/test-memmove.c \ hardcore-mode/test-memchr.c \ hardcore-mode/test-memcmp.c \ @@ -63,7 +62,6 @@ ASSETDIR = assets # Output NAME = libtests -SONAME = libft.so ANAME = libft.a LIBMALLOC = malloc.dylib TMPLIB = $(ASSETDIR)/tmp @@ -73,8 +71,6 @@ FRAMEWORK = # Compiler CFLAGS = -Werror -Wall -Wextra# -g3 -fsanitize=address -CSOFLAGS = -shared -fPIC -CSOFLAGS2 = CC = clang CC_SO = $(CC) @@ -148,34 +144,15 @@ endif ################# # First target -all: $(ASSETDIR)/$(ANAME) $(SONAME) $(ASSETDIR)/$(NAME) $(ASSETDIR)/$(LIBMALLOC) $(WRAPNAME) - -ifneq ($(OS),Linux) -$(SONAME): - @rm -rf $(TMPLIB) || echo -n - @mkdir -p $(TMPLIB) - @cd $(TMPLIB) && ar -xv ../libft.a 1>/dev/null - @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m➤ \033[38;5;$(LINK_COLOR)m",\ - $(CC_SO), $(CSOFLAGS), $(TMPLIB)/*.o, -o, $(SONAME)) -else -$(SONAME): - @make -C $(LIBFTDIR) so - @if [ -e $(LIBFTDIR)/libft.so ];\ - then\ - cp $(LIBFTDIR)/libft.so . ;\ - else\ - echo Please provide a libft.so in the directory $(shell pwd); \ - fi -endif +all: $(ASSETDIR)/$(ANAME) $(ASSETDIR)/$(NAME) $(ASSETDIR)/$(LIBMALLOC) $(WRAPNAME) $(WRAPNAME): $(ASSETDIR)/wrapper.c - @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", $(CC) $(CFLAGS) $(ASSETDIR)/wrapper.c -I $(INCDIR) -o $(WRAPNAME)) + @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", $(CC) $(CFLAGS) $(ASSETDIR)/wrapper.c -I $(INCDIR) -L$(LIBFTDIR) -lft -o $(WRAPNAME)) $(ASSETDIR)/$(LIBMALLOC): $(ASSETDIR)/malloc.c @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", $(CC) $(CFLAGS) $(DYLIBFLAG) $(ASSETDIR)/malloc.c -I $(INCDIR) -o $(ASSETDIR)/$(LIBMALLOC)) $(ASSETDIR)/$(ANAME): - @rm -f $(SONAME) @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", make -j 3 -C "$(LIBFTDIR)") @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", make bonus -j 3 -C "$(LIBFTDIR)" || true) @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", cp "$(LIBFTDIR)/libft.a" $(ASSETDIR)/) @@ -202,7 +179,7 @@ clean: @$(call exec_color,"\033[38;5;$(CLEAN_COLOR_T)m➤ \033[38;5;$(CLEAN_COLOR)m",\ rm -f, $(OBJ)) # <- Cleaning objs @$(call exec_color,"\033[38;5;$(CLEAN_COLOR_T)m➤ \033[38;5;$(CLEAN_COLOR)m",\ - rm -f, $(SONAME) $(ASSETDIR)/$(ANAME) $(ASSETDIR)$(NAME) $(ASSETDIR)/$(LIBMALLOC)) # <- Cleaning assets + rm -f, $(ASSETDIR)/$(ANAME) $(ASSETDIR)$(NAME) $(ASSETDIR)/$(LIBMALLOC)) # <- Cleaning assets @rmdir $(OBJDIR) 2> /dev/null || echo "" > /dev/null @$(eval ALREADY_RM=x) diff --git a/hardcore-mode/hardcore-main.c b/hardcore-mode/hardcore-main.c index cb77a51..a381afc 100644 --- a/hardcore-mode/hardcore-main.c +++ b/hardcore-mode/hardcore-main.c @@ -36,7 +36,6 @@ const char *mtable[] = { struct { int (*fun)(void *); char *name; void *ft; } test_table[18] = { {test_main_memset, "ft_memset", NULL}, {test_main_memcpy, "ft_memcpy", NULL}, - {test_main_memccpy, "ft_memccpy", NULL}, {test_main_memmove, "ft_memmove", NULL}, {test_main_memchr, "ft_memchr", NULL}, {test_main_memcmp, "ft_memcmp", NULL}, diff --git a/hardcore-mode/test-memccpy.c b/hardcore-mode/test-memccpy.c deleted file mode 100644 index 589ae11..0000000 --- a/hardcore-mode/test-memccpy.c +++ /dev/null @@ -1,259 +0,0 @@ -#include "utils.h" - -typedef void *(*proto_t) (void *, const void *, int c, size_t); - - static void -do_one_test (impl_t *impl, void *dst, const void *src, int c, size_t len, - size_t n) -{ - void *expect = len > n ? NULL : (char *) dst + len; - if (CALL (impl, dst, src, c, n) != expect) - { - error (0, 0, "Wrong result in function %s %p %p", impl->name, - CALL (impl, dst, src, c, n), expect); - ret = 1; - return; - } - - if (memcmp (dst, src, len > n ? n : len) != 0) - { - error (0, 0, "Wrong result in function %s", impl->name); - ret = 1; - return; - } -} - - static void -do_test (size_t align1, size_t align2, int c, size_t len, size_t n, - int max_char) -{ - size_t i; - char *s1, *s2; - - align1 &= 7; - if (align1 + len >= page_size) - return; - - align2 &= 7; - if (align2 + len >= page_size) - return; - - s1 = (char *) (buf1 + align1); - s2 = (char *) (buf2 + align2); - - for (i = 0; i < len - 1; ++i) - { - s1[i] = 32 + 23 * i % (max_char - 32); - if (s1[i] == (char) c) - --s1[i]; - } - s1[len - 1] = c; - for (i = len; i + align1 < page_size && i < len + 64; ++i) - s1[i] = 32 + 32 * i % (max_char - 32); - - FOR_EACH_IMPL (impl, 0) - do_one_test (impl, s2, s1, c, len, n); -} - - static void -do_random_tests (void) -{ - size_t i, j, n, align1, align2, len, size, mode; - unsigned char *p1 = buf1 + page_size - 512; - unsigned char *p2 = buf2 + page_size - 512; - unsigned char *res, c; - - for (n = 0; n < ITERATIONS; n++) - { - mode = random (); - c = random (); - if (mode & 1) - { - size = random () & 255; - align1 = 512 - size - (random () & 15); - if (mode & 2) - align2 = align1 - (random () & 24); - else - align2 = align1 - (random () & 31); - if (mode & 4) - { - j = align1; - align1 = align2; - align2 = j; - } - if (mode & 8) - len = size - (random () & 31); - else - len = 512; - if (len >= 512) - len = random () & 511; - } - else - { - align1 = random () & 31; - if (mode & 2) - align2 = random () & 31; - else - align2 = align1 + (random () & 24); - len = random () & 511; - j = align1; - if (align2 > j) - j = align2; - if (mode & 4) - { - size = random () & 511; - if (size + j > 512) - size = 512 - j - (random() & 31); - } - else - size = 512 - j; - if ((mode & 8) && len + j >= 512) - len = 512 - j - (random () & 7); - } - j = len + align1 + 64; - if (j > 512) - j = 512; - for (i = 0; i < j; i++) - { - if (i == len + align1) - p1[i] = c; - else - { - p1[i] = random () & 255; - if (i >= align1 && i < len + align1 && p1[i] == c) - p1[i] = (random () & 127) + 3 + c; - } - } - - FOR_EACH_IMPL (impl, 1) - { - unsigned char *expect; - memset (p2 - 64, '\1', 512 + 64); - res = CALL (impl, p2 + align2, p1 + align1, (char) c, size); - if (len >= size) - expect = NULL; - else - expect = p2 + align2 + len + 1; - - if (res != expect) - { - error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd, %d) %p != %p", - n, impl->name, align1, align2, len, size, c, res, expect); - ret = 1; - } - for (j = 0; j < align2 + 64; ++j) - { - if (p2[j - 64] != '\1') - { - error (0, 0, "Iteration %zd - garbage before, %s (%zd, %zd, %zd)", - n, impl->name, align1, align2, len); - ret = 1; - break; - } - } - j = align2 + len + 1; - if (size + align2 < j) - j = size + align2; - for (; j < 512; ++j) - { - if (p2[j] != '\1') - { - error (0, 0, "Iteration %zd - garbage after, %s (%zd, %zd, %zd)", - n, impl->name, align1, align2, len); - ret = 1; - break; - } - } - j = len + 1; - if (size < j) - j = size; - if (memcmp (p1 + align1, p2 + align2, j)) - { - error (0, 0, "Iteration %zd - different strings, %s (%zd, %zd, %zd)", - n, impl->name, align1, align2, len); - ret = 1; - } - } - } -} - -static void -test_memccpy (void *ft_memccpy) -{ - typeof(memccpy) *memccpy_fun = (typeof(memccpy) *)ft_memccpy; - /* First test like memcpy, then the search part The SVID, the only - place where memccpy_fun is mentioned, says overlap might fail, so we - don't try it. Besides, it's hard to see the rationale for a - non-left-to-right memccpy_fun. */ - it = "ft_memccpy"; - check(memccpy_fun(one, "abc", 'q', 4) == NULL, 1); /* Returned value. */ - equal(one, "abc", 2); /* Did the copy go right? */ - - (void) strcpy(one, "abcdefgh"); - (void) memccpy_fun(one+1, "xyz", 'q', 2); - equal(one, "axydefgh", 3); /* Basic test. */ - - (void) strcpy(one, "abc"); - (void) memccpy_fun(one, "xyz", 'q', 0); - equal(one, "abc", 4); /* Zero-length copy. */ - - (void) strcpy(one, "hi there"); - (void) strcpy(two, "foo"); - (void) memccpy_fun(two, one, 'q', 9); - equal(two, "hi there", 5); /* Just paranoia. */ - equal(one, "hi there", 6); /* Stomped on source? */ - - (void) strcpy(one, "abcdefgh"); - (void) strcpy(two, "horsefeathers"); - check(memccpy_fun(two, one, 'f', 9) == two+6, 7); /* Returned value. */ - equal(one, "abcdefgh", 8); /* Source intact? */ - equal(two, "abcdefeathers", 9); /* Copy correct? */ - - (void) strcpy(one, "abcd"); - (void) strcpy(two, "bumblebee"); - check(memccpy_fun(two, one, 'a', 4) == two+1, 10); /* First char. */ - equal(two, "aumblebee", 11); - check(memccpy_fun(two, one, 'd', 4) == two+4, 12); /* Last char. */ - equal(two, "abcdlebee", 13); - (void) strcpy(one, "xyz"); - check(memccpy_fun(two, one, 'x', 1) == two+1, 14); /* Singleton. */ - equal(two, "xbcdlebee", 15); -} - - - int -test_main_memccpy (void *ft_memccpy) -{ - size_t i; - - INIT(); - - IMPL (ft_memccpy, 1); - - test_memccpy(ft_memccpy); - - test_init (); - - for (i = 1; i < 8; ++i) - { - do_test (i, i, 12, 16, 16, 127); - do_test (i, i, 23, 16, 16, 255); - do_test (i, 2 * i, 28, 16, 16, 127); - do_test (2 * i, i, 31, 16, 16, 255); - do_test (8 - i, 2 * i, 1, 1 << i, 2 << i, 127); - do_test (2 * i, 8 - i, 17, 2 << i, 1 << i, 127); - do_test (8 - i, 2 * i, 0, 1 << i, 2 << i, 255); - do_test (2 * i, 8 - i, i, 2 << i, 1 << i, 255); - } - - for (i = 1; i < 8; ++i) - { - do_test (0, 0, i, 4 << i, 8 << i, 127); - do_test (0, 0, i, 16 << i, 8 << i, 127); - do_test (8 - i, 2 * i, i, 4 << i, 8 << i, 127); - do_test (8 - i, 2 * i, i, 16 << i, 8 << i, 127); - } - - do_random_tests (); - return ret; -} diff --git a/src/init.c b/src/init.c index 961a356..b3afb6d 100644 --- a/src/init.c +++ b/src/init.c @@ -39,7 +39,6 @@ t_libft_test fun_test_table[] = { {"ft_memset", test_ft_memset, 1, 1}, {"ft_bzero", test_ft_bzero, 1, 1}, {"ft_memcpy", test_ft_memcpy, 1, 1}, - {"ft_memccpy", test_ft_memccpy, 1, 1}, {"ft_memmove", test_ft_memmove, 1, 1}, {"ft_memchr", test_ft_memchr, 1, 1}, {"ft_memcmp", test_ft_memcmp, 1, 1}, @@ -117,7 +116,6 @@ t_libft_bench fun_bench_table[] = { {"ft_memset", bench_ft_memset, 1}, {"ft_bzero", bench_ft_bzero, 1}, {"ft_memcpy", bench_ft_memcpy, 1}, - {"ft_memccpy", bench_ft_memccpy, 1}, {"ft_memmove", bench_ft_memmove, 1}, {"ft_memchr", bench_ft_memchr, 1}, {"ft_memcmp", bench_ft_memcmp, 1},