alelievr / libft-unit-test

455 stars 88 forks source link

Calloc timeout #65

Closed ggjulio closed 4 years ago

ggjulio commented 4 years ago

Calloc timeout at test_ft_calloc_too_big :

ft_calloc:     [OK] [OK] [OK] [OK] [OK] [TIMEOUT] Test code:
    void *d1 = ft_calloc((9223372036854775807L *2UL+1UL), sizeof(char));

    void *d2 = ft_calloc(2, 1073741829);
    void *d3 = ft_calloc(1, (9223372036854775807L *2UL+1UL));
    if (d1 || d3 || !d2)
        exit(TEST_FAILED);
    exit(TEST_SUCCESS);
void            test_ft_calloc_too_big(void *ptr) {
    typeof(calloc)  *ft_calloc = ptr;
    SET_EXPLANATION("your calloc does not work with too large numbers");

    SANDBOX_RAISE(
            void *d1 = ft_calloc(ULONG_MAX, sizeof(char));
            void *d2 = ft_calloc(2, 1073741829); // overflow the int max
            void *d3 = ft_calloc(1, ULONG_MAX);
            if (d1 || d3 || !d2)
                exit(TEST_FAILED);
            exit(TEST_SUCCESS);
            );
}

When I forked your repo Monday, and fixed calloc renaming memalloc into calloc. There was also a timeout, but not in the same function -> test_ft_calloc_zero:


ft_calloc:     [OK] [TIMEOUT] [OK] [OK] [OK] Test code:
    size_t size = 514;
    char *cmp = malloc(size);
    int diff;

    char *ret = ft_calloc(size);
    __builtin___memset_chk (cmp, 0, size, __builtin_object_size (cmp, 0));
    if ((diff = memcmp(cmp, ret, size)))
    {
        exit(TEST_FAILED);
    }
    free(ret);
    exit(TEST_SUCCESS);
void            test_ft_calloc_zero(void *ptr) {
    void *  (*ft_calloc)(size_t) = ptr;
    SET_EXPLANATION("your calloc does not set allocated mem to 0");

    SANDBOX_RAISE(
            size_t  size = 514;
            char    *cmp = malloc(size);
            int     diff;

            MALLOC_MEMSET;
            char    *ret = ft_calloc(size);
            MALLOC_RESET;

            bzero(cmp, size);
            if ((diff = memcmp(cmp, ret, size))) {
        SET_DIFF_INT(0, diff);
                exit(TEST_FAILED);
            }
            free(ret);
            exit(TEST_SUCCESS);
            );
}

I don't undertand why.

AlaaZorkane commented 4 years ago

Same issue

alelievr commented 4 years ago

It's probably due to the time it takes to bzero 2Gb of memory, if you have a slow implementation of the bzero (which will be if you've done it the naive way) then it'll timeout. It's worked with my implementation of bzero because i optimized it.

I guess i'll disable this test for now as i don't want a failure because of a slow function :(

alelievr commented 4 years ago

57f58ee56e4e435cf7430f0fd6c089c4f59e371d