Created
August 3, 2017 21:54
-
-
Save jeamland/80dbd1bffae1612ed6972001ec4c6b71 to your computer and use it in GitHub Desktop.
Example of jemalloc test failure code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <errno.h> | |
#include <stdio.h> | |
#include "jemalloc/jemalloc.h" | |
int | |
main(int argc, char **argv) | |
{ | |
int *thing, frob, res; | |
size_t frobsize; | |
/* Test 1: Make sure things are actually working like we expect. */ | |
thing = je_malloc(12 * sizeof(int)); | |
printf("Test 1: thing=%p errno=%d\n", thing, errno); | |
je_free(thing); | |
/* Test 2: Make sure we can retrieve the initial value, should be 0. */ | |
frob = 0; | |
frobsize = sizeof(frob); | |
res = je_mallctl("testing.malloc_fail", &frob, &frobsize, NULL, 0); | |
printf("Test 2: res=%d frob=%d\n", res, frob); | |
/* Test 3: Make sure we can set a new value. */ | |
frob = ENOMEM; | |
res = je_mallctl("testing.malloc_fail", NULL, 0, &frob, frobsize); | |
printf("Test 3: res=%d\n", res); | |
/* Test 4: Make sure setting the value worked. */ | |
frob = 0; | |
frobsize = sizeof(frob); | |
res = je_mallctl("testing.malloc_fail", &frob, &frobsize, NULL, 0); | |
printf("Test 4: res=%d frob=%d\n", res, frob); | |
/* Test 5: Make sure that malloc now fails. */ | |
thing = je_malloc(12 * sizeof(int)); | |
printf("Test 5: thing=%p errno=%d\n", thing, errno); | |
/* Test 6: Make sure that the value reset. */ | |
frob = 0; | |
frobsize = sizeof(frob); | |
res = je_mallctl("testing.malloc_fail", &frob, &frobsize, NULL, 0); | |
printf("Test 6: res=%d frob=%d\n", res, frob); | |
/* Test 7: Make sure everything's back to normal. */ | |
errno = 0; | |
thing = je_malloc(12 * sizeof(int)); | |
printf("Test 7: thing=%p errno=%d\n", thing, errno); | |
je_free(thing); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment