#include <getopt.h>
#include <limits.h>
#include <execinfo.h>
+#include <errno.h>
+#include <ecoli_init.h>
#include <ecoli_log.h>
#include <ecoli_test.h>
#include <ecoli_malloc.h>
struct debug_alloc_ftr *ftr;
size_t new_size = size + sizeof(*hdr) + sizeof(*ftr);
void *ret;
+ int r = random();
-
- if (alloc_fail_proba != 0 && (random() % 100) < alloc_fail_proba)
+ if (alloc_fail_proba != 0 && (r % 100) < alloc_fail_proba)
hdr = NULL;
else
hdr = malloc(new_size);
ftr->cookie = 0x87654321;
}
- EC_LOG(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p\n",
- file, line, size, ret);
+ EC_LOG(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p [rand=%d]\n",
+ file, line, size, ret, r);
+ if (r == 976499400)
+ printf("here\n");
if (ret)
alloc_success++;
if (level > (unsigned int)log_level)
return 0;
- return printf("%s", str);
+ if (printf("%s", str) < 0)
+ return -1;
+
+ return 0;
}
int main(int argc, char **argv)
srandom(seed);
- if (0) ec_log_fct_register(debug_log, NULL);
-
/* register a new malloc to track memleaks */
TAILQ_INIT(&debug_alloc_hdr_list);
if (ec_malloc_register(debug_malloc, debug_free, debug_realloc) < 0) {
EC_LOG(EC_LOG_ERR, "cannot register new malloc\n");
- return -1;
+ return 1;
+ }
+
+ if (ec_init() < 0) {
+ fprintf(stderr, "cannot init ecoli: %s\n", strerror(errno));
+ return 1;
}
+ ec_log_fct_register(debug_log, NULL);
ret = 0;
if (argc <= 1) {
ret |= ec_test_one(argv[i]);
}
- ec_malloc_unregister();
leaks = debug_alloc_dump_leaks();
if (alloc_fail_proba == 0 && ret != 0) {