2 /* Test for correct functioning of the --malloc-fill and --free-fill
3 flags. Needs --malloc-fill=0x55 and --free-fill=0x77. */
8 #include "../memcheck.h"
14 #define TEST(x, exp_x, desc) \
15 (void)VALGRIND_MAKE_MEM_DEFINED(&x, sizeof(int)); \
17 fprintf(stderr, "PASSED: " desc "\n"); \
19 fprintf(stderr, "FAILED: " desc "\n"); \
22 //-------------------------------------------------------------
23 fprintf(stderr
, "test simple malloc/free:\n");
25 a
= malloc(10 * sizeof(int)); assert(a
);
26 TEST(a
[4], 0x55555555, "malloc-filled");
29 TEST(a
[5], 0x77777777, " free-filled");
31 //-------------------------------------------------------------
32 fprintf(stderr
, "\ntest realloc-larger:\n");
34 r
= malloc(30 * sizeof(int)); assert(r
);
35 TEST(r
[25], 0x55555555, "malloc-filled");
39 r
= realloc(r
, 40 * sizeof(int)); assert(r
);
41 TEST(oldr
[26], 0x77777777, " free-filled");
42 TEST( r
[35], 0x55555555, "malloc-filled");
46 //-------------------------------------------------------------
47 fprintf(stderr
, "\ntest realloc-smaller:\n");
49 r
= malloc(30 * sizeof(int)); assert(r
);
50 TEST(r
[25], 0x55555555, "malloc-filled");
54 r
= realloc(r
, 20 * sizeof(int)); assert(r
);
56 TEST(oldr
[26], 0x77777777, " free-filled");
60 //-------------------------------------------------------------
61 fprintf(stderr
, "\ntest calloc:\n");
62 a
= calloc(100, sizeof(int)); assert(r
);
64 TEST(a
[42], 0x00000000, "zero");