1 #include "test/jemalloc_test.h" 2 3 static unsigned test_count = 0; 4 static test_status_t test_counts[test_status_count] = {0, 0, 0}; 5 static test_status_t test_status = test_status_pass; 6 static const char * test_name = ""; 7 8 JEMALLOC_ATTR(format(printf, 1, 2)) 9 void 10 test_skip(const char *format, ...) 11 { 12 va_list ap; 13 14 va_start(ap, format); 15 malloc_vcprintf(NULL, NULL, format, ap); 16 va_end(ap); 17 malloc_printf("\n"); 18 test_status = test_status_skip; 19 } 20 21 JEMALLOC_ATTR(format(printf, 1, 2)) 22 void 23 test_fail(const char *format, ...) 24 { 25 va_list ap; 26 27 va_start(ap, format); 28 malloc_vcprintf(NULL, NULL, format, ap); 29 va_end(ap); 30 malloc_printf("\n"); 31 test_status = test_status_fail; 32 } 33 34 static const char * 35 test_status_string(test_status_t test_status) 36 { 37 38 switch (test_status) { 39 case test_status_pass: return "pass"; 40 case test_status_skip: return "skip"; 41 case test_status_fail: return "fail"; 42 default: not_reached(); 43 } 44 } 45 46 void 47 p_test_init(const char *name) 48 { 49 50 test_count++; 51 test_status = test_status_pass; 52 test_name = name; 53 } 54 55 void 56 p_test_fini(void) 57 { 58 59 test_counts[test_status]++; 60 malloc_printf("%s: %s\n", test_name, test_status_string(test_status)); 61 } 62 63 test_status_t 64 p_test(test_t* t, ...) 65 { 66 test_status_t ret = test_status_pass; 67 va_list ap; 68 69 va_start(ap, t); 70 for (; t != NULL; t = va_arg(ap, test_t*)) { 71 t(); 72 if (test_status > ret) 73 ret = test_status; 74 } 75 va_end(ap); 76 77 malloc_printf("--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n", 78 test_status_string(test_status_pass), 79 test_counts[test_status_pass], test_count, 80 test_status_string(test_status_skip), 81 test_counts[test_status_skip], test_count, 82 test_status_string(test_status_fail), 83 test_counts[test_status_fail], test_count); 84 85 return (ret); 86 } 87 88 void 89 p_test_fail(const char *prefix, const char *message) 90 { 91 92 malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message); 93 test_status = test_status_fail; 94 } 95