summaryrefslogtreecommitdiffstats
path: root/deps/jemalloc/test/include/test/test.h
blob: d4b65912dcbd58d99c916205fbe4d8c1adacd0f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#define ASSERT_BUFSIZE	256

#define verify_cmp(may_abort, t, a, b, cmp, neg_cmp, pri, ...) do {	\
	const t a_ = (a);						\
	const t b_ = (b);						\
	if (!(a_ cmp b_)) {						\
		char prefix[ASSERT_BUFSIZE];				\
		char message[ASSERT_BUFSIZE];				\
		malloc_snprintf(prefix, sizeof(prefix),			\
		    "%s:%s:%d: Failed assertion: "			\
		    "(%s) " #cmp " (%s) --> "				\
		    "%" pri " " #neg_cmp " %" pri ": ",			\
		    __func__, __FILE__, __LINE__,			\
		    #a, #b, a_, b_);					\
		malloc_snprintf(message, sizeof(message), __VA_ARGS__);	\
		if (may_abort) {					\
			abort();					\
		} else {						\
			p_test_fail(prefix, message);			\
		}							\
	}								\
} while (0)

#define expect_cmp(t, a, b, cmp, neg_cmp, pri, ...) verify_cmp(false,	\
    t, a, b, cmp, neg_cmp, pri, __VA_ARGS__)

#define expect_ptr_eq(a, b, ...)	expect_cmp(void *, a, b, ==,	\
    !=, "p", __VA_ARGS__)
#define expect_ptr_ne(a, b, ...)	expect_cmp(void *, a, b, !=,	\
    ==, "p", __VA_ARGS__)
#define expect_ptr_null(a, ...)		expect_cmp(void *, a, NULL, ==,	\
    !=, "p", __VA_ARGS__)
#define expect_ptr_not_null(a, ...)	expect_cmp(void *, a, NULL, !=,	\
    ==, "p", __VA_ARGS__)

#define expect_c_eq(a, b, ...)	expect_cmp(char, a, b, ==, !=, "c", __VA_ARGS__)
#define expect_c_ne(a, b, ...)	expect_cmp(char, a, b, !=, ==, "c", __VA_ARGS__)
#define expect_c_lt(a, b, ...)	expect_cmp(char, a, b, <, >=, "c", __VA_ARGS__)
#define expect_c_le(a, b, ...)	expect_cmp(char, a, b, <=, >, "c", __VA_ARGS__)
#define expect_c_ge(a, b, ...)	expect_cmp(char, a, b, >=, <, "c", __VA_ARGS__)
#define expect_c_gt(a, b, ...)	expect_cmp(char, a, b, >, <=, "c", __VA_ARGS__)

#define expect_x_eq(a, b, ...)	expect_cmp(int, a, b, ==, !=, "#x", __VA_ARGS__)
#define expect_x_ne(a, b, ...)	expect_cmp(int, a, b, !=, ==, "#x", __VA_ARGS__)
#define expect_x_lt(a, b, ...)	expect_cmp(int, a, b, <, >=, "#x", __VA_ARGS__)
#define expect_x_le(a, b, ...)	expect_cmp(int, a, b, <=, >, "#x", __VA_ARGS__)
#define expect_x_ge(a, b, ...)	expect_cmp(int, a, b, >=, <, "#x", __VA_ARGS__)
#define expect_x_gt(a, b, ...)	expect_cmp(int, a, b, >, <=, "#x", __VA_ARGS__)

#define expect_d_eq(a, b, ...)	expect_cmp(int, a, b, ==, !=, "d", __VA_ARGS__)
#define expect_d_ne(a, b, ...)	expect_cmp(int, a, b, !=, ==, "d", __VA_ARGS__)
#define expect_d_lt(a, b, ...)	expect_cmp(int, a, b, <, >=, "d", __VA_ARGS__)
#define expect_d_le(a, b, ...)	expect_cmp(int, a, b, <=, >, "d", __VA_ARGS__)
#define expect_d_ge(a, b, ...)	expect_cmp(int, a, b, >=, <, "d", __VA_ARGS__)
#define expect_d_gt(a, b, ...)	expect_cmp(int, a, b, >, <=, "d", __VA_ARGS__)

#define expect_u_eq(a, b, ...)	expect_cmp(int, a, b, ==, !=, "u", __VA_ARGS__)
#define expect_u_ne(a, b, ...)	expect_cmp(int, a, b, !=, ==, "u", __VA_ARGS__)
#define expect_u_lt(a, b, ...)	expect_cmp(int, a, b, <, >=, "u", __VA_ARGS__)
#define expect_u_le(a, b, ...)	expect_cmp(int, a, b, <=, >, "u", __VA_ARGS__)
#define expect_u_ge(a, b, ...)	expect_cmp(int, a, b, >=, <, "u", __VA_ARGS__)
#define expect_u_gt(a, b, ...)	expect_cmp(int, a, b, >, <=, "u", __VA_ARGS__)

#define expect_ld_eq(a, b, ...)	expect_cmp(long, a, b, ==,	\
    !=, "ld", __VA_ARGS__)
#define expect_ld_ne(a, b, ...)	expect_cmp(long, a, b, !=,	\
    ==, "ld", __VA_ARGS__)
#define expect_ld_lt(a, b, ...)	expect_cmp(long, a, b, <,	\
    >=, "ld", __VA_ARGS__)
#define expect_ld_le(a, b, ...)	expect_cmp(long, a, b, <=,	\
    >, "ld", __VA_ARGS__)
#define expect_ld_ge(a, b, ...)	expect_cmp(long, a, b, >=,	\
    <, "ld", __VA_ARGS__)
#define expect_ld_gt(a, b, ...)	expect_cmp(long, a, b, >,	\
    <=, "ld", __VA_ARGS__)

#define expect_lu_eq(a, b, ...)	expect_cmp(unsigned long,	\
    a, b, ==, !=, "lu", __VA_ARGS__)
#define expect_lu_ne(a, b, ...)	expect_cmp(unsigned long,	\
    a, b, !=, ==, "lu", __VA_ARGS__)
#define expect_lu_lt(a, b, ...)	expect_cmp(unsigned long,	\
    a, b, <, >=, "lu", __VA_ARGS__)
#define expect_lu_le(a, b, ...)	expect_cmp(unsigned long,	\
    a, b, <=, >, "lu", __VA_ARGS__)
#define expect_lu_ge(a, b, ...)	expect_cmp(unsigned long,	\
    a, b, >=, <, "lu", __VA_ARGS__)
#define expect_lu_gt(a, b, ...)	expect_cmp(unsigned long,	\
    a, b, >, <=, "lu", __VA_ARGS__)

#define expect_qd_eq(a, b, ...)	expect_cmp(long long, a, b, ==,	\
    !=, "qd", __VA_ARGS__)
#define expect_qd_ne(a, b, ...)	expect_cmp(long long, a, b, !=,	\
    ==, "qd", __VA_ARGS__)
#define expect_qd_lt(a, b, ...)	expect_cmp(long long, a, b, <,	\
    >=, "qd", __VA_ARGS__)
#define expect_qd_le(a, b, ...)	expect_cmp(long long, a, b, <=,	\
    >, "qd", __VA_ARGS__)
#define expect_qd_ge(a, b, ...)	expect_cmp(long long, a, b, >=,	\
    <, "qd", __VA_ARGS__)
#define expect_qd_gt(a, b, ...)	expect_cmp(long long, a, b, >,	\
    <=, "qd", __VA_ARGS__)

#define expect_qu_eq(a, b, ...)	expect_cmp(unsigned long long,	\
    a, b, ==, !=, "qu", __VA_ARGS__)
#define expect_qu_ne(a, b, ...)	expect_cmp(unsigned long long,	\
    a, b, !=, ==, "qu", __VA_ARGS__)
#define expect_qu_lt(a, b, ...)	expect_cmp(unsigned long long,	\
    a, b, <, >=, "qu", __VA_ARGS__)
#define expect_qu_le(a, b, ...)	expect_cmp(unsigned long long,	\
    a, b, <=, >, "qu", __VA_ARGS__)
#define expect_qu_ge(a, b, ...)	expect_cmp(unsigned long long,	\
    a, b, >=, <, "qu", __VA_ARGS__)
#define expect_qu_gt(a, b, ...)	expect_cmp(unsigned long long,	\
    a, b, >, <=, "qu", __VA_ARGS__)

#define expect_jd_eq(a, b, ...)	expect_cmp(intmax_t, a, b, ==,	\
    !=, "jd", __VA_ARGS__)
#define expect_jd_ne(a, b, ...)	expect_cmp(intmax_t, a, b, !=,	\
    ==, "jd", __VA_ARGS__)
#define expect_jd_lt(a, b, ...)	expect_cmp(intmax_t, a, b, <,	\
    >=, "jd", __VA_ARGS__)
#define expect_jd_le(a, b, ...)	expect_cmp(intmax_t, a, b, <=,	\
    >, "jd", __VA_ARGS__)
#define expect_jd_ge(a, b, ...)	expect_cmp(intmax_t, a, b, >=,	\
    <, "jd", __VA_ARGS__)
#define expect_jd_gt(a, b, ...)	expect_cmp(intmax_t, a, b, >,	\
    <=, "jd", __VA_ARGS__)

#define expect_ju_eq(a, b, ...)	expect_cmp(uintmax_t, a, b, ==,	\
    !=, "ju", __VA_ARGS__)
#define expect_ju_ne(a, b, ...)	expect_cmp(uintmax_t, a, b, !=,	\
    ==, "ju", __VA_ARGS__)
#define expect_ju_lt(a, b, ...)	expect_cmp(uintmax_t, a, b, <,	\
    >=, "ju", __VA_ARGS__)
#define expect_ju_le(a, b, ...)	expect_cmp(uintmax_t, a, b, <=,	\
    >, "ju", __VA_ARGS__)
#define expect_ju_ge(a, b, ...)	expect_cmp(uintmax_t, a, b, >=,	\
    <, "ju", __VA_ARGS__)
#define expect_ju_gt(a, b, ...)	expect_cmp(uintmax_t, a, b, >,	\
    <=, "ju", __VA_ARGS__)

#define expect_zd_eq(a, b, ...)	expect_cmp(ssize_t, a, b, ==,	\
    !=, "zd", __VA_ARGS__)
#define expect_zd_ne(a, b, ...)	expect_cmp(ssize_t, a, b, !=,	\
    ==, "zd", __VA_ARGS__)
#define expect_zd_lt(a, b, ...)	expect_cmp(ssize_t, a, b, <,	\
    >=, "zd", __VA_ARGS__)
#define expect_zd_le(a, b, ...)	expect_cmp(ssize_t, a, b, <=,	\
    >, "zd", __VA_ARGS__)
#define expect_zd_ge(a, b, ...)	expect_cmp(ssize_t, a, b, >=,	\
    <, "zd", __VA_ARGS__)
#define expect_zd_gt(a, b, ...)	expect_cmp(ssize_t, a, b, >,	\
    <=, "zd", __VA_ARGS__)

#define expect_zu_eq(a, b, ...)	expect_cmp(size_t, a, b, ==,	\
    !=, "zu", __VA_ARGS__)
#define expect_zu_ne(a, b, ...)	expect_cmp(size_t, a, b, !=,	\
    ==, "zu", __VA_ARGS__)
#define expect_zu_lt(a, b, ...)	expect_cmp(size_t, a, b, <,	\
    >=, "zu", __VA_ARGS__)
#define expect_zu_le(a, b, ...)	expect_cmp(size_t, a, b, <=,	\
    >, "zu", __VA_ARGS__)
#define expect_zu_ge(a, b, ...)	expect_cmp(size_t, a, b, >=,	\
    <, "zu", __VA_ARGS__)
#define expect_zu_gt(a, b, ...)	expect_cmp(size_t, a, b, >,	\
    <=, "zu", __VA_ARGS__)

#define expect_d32_eq(a, b, ...)	expect_cmp(int32_t, a, b, ==,	\
    !=, FMTd32, __VA_ARGS__)
#define expect_d32_ne(a, b, ...)	expect_cmp(int32_t, a, b, !=,	\
    ==, FMTd32, __VA_ARGS__)
#define expect_d32_lt(a, b, ...)	expect_cmp(int32_t, a, b, <,	\
    >=, FMTd32, __VA_ARGS__)
#define expect_d32_le(a, b, ...)	expect_cmp(int32_t, a, b, <=,	\
    >, FMTd32, __VA_ARGS__)
#define expect_d32_ge(a, b, ...)	expect_cmp(int32_t, a, b, >=,	\
    <, FMTd32, __VA_ARGS__)
#define expect_d32_gt(a, b, ...)	expect_cmp(int32_t, a, b, >,	\
    <=, FMTd32, __VA_ARGS__)

#define expect_u32_eq(a, b, ...)	expect_cmp(uint32_t, a, b, ==,	\
    !=, FMTu32, __VA_ARGS__)
#define expect_u32_ne(a, b, ...)	expect_cmp(uint32_t, a, b, !=,	\
    ==, FMTu32, __VA_ARGS__)
#define expect_u32_lt(a, b, ...)	expect_cmp(uint32_t, a, b, <,	\
    >=, FMTu32, __VA_ARGS__)
#define expect_u32_le(a, b, ...)	expect_cmp(uint32_t, a, b, <=,	\
    >, FMTu32, __VA_ARGS__)
#define expect_u32_ge(a, b, ...)	expect_cmp(uint32_t, a, b, >=,	\
    <, FMTu32, __VA_ARGS__)
#define expect_u32_gt(a, b, ...)	expect_cmp(uint32_t, a, b, >,	\
    <=, FMTu32, __VA_ARGS__)

#define expect_d64_eq(a, b, ...)	expect_cmp(int64_t, a, b, ==,	\
    !=, FMTd64, __VA_ARGS__)
#define expect_d64_ne(a, b, ...)	expect_cmp(int64_t, a, b, !=,	\
    ==, FMTd64, __VA_ARGS__)
#define expect_d64_lt(a, b, ...)	expect_cmp(int64_t, a, b, <,	\
    >=, FMTd64, __VA_ARGS__)
#define expect_d64_le(a, b, ...)	expect_cmp(int64_t, a, b, <=,	\
    >, FMTd64, __VA_ARGS__)
#define expect_d64_ge(a, b, ...)	expect_cmp(int64_t, a, b, >=,	\
    <, FMTd64, __VA_ARGS__)
#define expect_d64_gt(a, b, ...)	expect_cmp(int64_t, a, b, >,	\
    <=, FMTd64, __VA_ARGS__)

#define expect_u64_eq(a, b, ...)	expect_cmp(uint64_t, a, b, ==,	\
    !=, FMTu64, __VA_ARGS__)
#define expect_u64_ne(a, b, ...)	expect_cmp(uint64_t, a, b, !=,	\
    ==, FMTu64, __VA_ARGS__)
#define expect_u64_lt(a, b, ...)	expect_cmp(uint64_t, a, b, <,	\
    >=, FMTu64, __VA_ARGS__)
#define expect_u64_le(a, b, ...)	expect_cmp(uint64_t, a, b, <=,	\
    >, FMTu64, __VA_ARGS__)
#define expect_u64_ge(a, b, ...)	expect_cmp(uint64_t, a, b, >=,	\
    <, FMTu64, __VA_ARGS__)
#define expect_u64_gt(a, b, ...)	expect_cmp(uint64_t, a, b, >,	\
    <=, FMTu64, __VA_ARGS__)

#define verify_b_eq(may_abort, a, b, ...) do {				\
	bool a_ = (a);							\
	bool b_ = (b);							\
	if (!(a_ == b_)) {						\
		char prefix[ASSERT_BUFSIZE];				\
		char message[ASSERT_BUFSIZE];				\
		malloc_snprintf(prefix, sizeof(prefix),			\
		    "%s:%s:%d: Failed assertion: "			\
		    "(%s) == (%s) --> %s != %s: ",			\
		    __func__, __FILE__, __LINE__,			\
		    #a, #b, a_ ? "true" : "false",			\
		    b_ ? "true" : "false");				\
		malloc_snprintf(message, sizeof(message), __VA_ARGS__);	\
		if (may_abort) {					\
			abort();					\
		} else {						\
			p_test_fail(prefix, message);			\
		}							\
	}								\
} while (0)

#define verify_b_ne(may_abort, a, b, ...) do {				\
	bool a_ = (a);							\
	bool b_ = (b);							\
	if (!(a_ != b_)) {						\
		char prefix[ASSERT_BUFSIZE];				\
		char message[ASSERT_BUFSIZE];				\
		malloc_snprintf(prefix, sizeof(prefix),			\
		    "%s:%s:%d: Failed assertion: "			\
		    "(%s) != (%s) --> %s == %s: ",			\
		    __func__, __FILE__, __LINE__,			\
		    #a, #b, a_ ? "true" : "false",			\
		    b_ ? "true" : "false");				\
		malloc_snprintf(message, sizeof(message), __VA_ARGS__);	\
		if (may_abort) {					\
			abort();					\
		} else {						\
			p_test_fail(prefix, message);			\
		}							\
	}								\
} while (0)

#define expect_b_eq(a, b, ...)	verify_b_eq(false, a, b, __VA_ARGS__)
#define expect_b_ne(a, b, ...)	verify_b_ne(false, a, b, __VA_ARGS__)

#define expect_true(a, ...)	expect_b_eq(a, true, __VA_ARGS__)
#define expect_false(a, ...)	expect_b_eq(a, false, __VA_ARGS__)

#define verify_str_eq(may_abort, a, b, ...) do {			\
	if (strcmp((a), (b))) {						\
		char prefix[ASSERT_BUFSIZE];				\
		char message[ASSERT_BUFSIZE];				\
		malloc_snprintf(prefix, sizeof(prefix),			\
		    "%s:%s:%d: Failed assertion: "			\
		    "(%s) same as (%s) --> "				\
		    "\"%s\" differs from \"%s\": ",			\
		    __func__, __FILE__, __LINE__, #a, #b, a, b);	\
		malloc_snprintf(message, sizeof(message), __VA_ARGS__);	\
		if (may_abort) {					\
			abort();					\
		} else {						\
			p_test_fail(prefix, message);			\
		}							\
	}								\
} while (0)

#define verify_str_ne(may_abort, a, b, ...) do {			\
	if (!strcmp((a), (b))) {					\
		char prefix[ASSERT_BUFSIZE];				\
		char message[ASSERT_BUFSIZE];				\
		malloc_snprintf(prefix, sizeof(prefix),			\
		    "%s:%s:%d: Failed assertion: "			\
		    "(%s) differs from (%s) --> "			\
		    "\"%s\" same as \"%s\": ",				\
		    __func__, __FILE__, __LINE__, #a, #b, a, b);	\
		malloc_snprintf(message, sizeof(message), __VA_ARGS__);	\
		if (may_abort) {					\
			abort();					\
		} else {						\
			p_test_fail(prefix, message);			\
		}							\
	}								\
} while (0)

#define expect_str_eq(a, b, ...) verify_str_eq(false, a, b, __VA_ARGS__)
#define expect_str_ne(a, b, ...) verify_str_ne(false, a, b, __VA_ARGS__)

#define verify_not_reached(may_abort, ...) do {				\
	char prefix[ASSERT_BUFSIZE];					\
	char message[ASSERT_BUFSIZE];					\
	malloc_snprintf(prefix, sizeof(prefix),				\
	    "%s:%s:%d: Unreachable code reached: ",			\
	    __func__, __FILE__, __LINE__);				\
	malloc_snprintf(message, sizeof(message), __VA_ARGS__);		\
	if (may_abort) {						\
		abort();						\
	} else {							\
		p_test_fail(prefix, message);				\
	}								\
} while (0)

#define expect_not_reached(...) verify_not_reached(false, __VA_ARGS__)

#define assert_cmp(t, a, b, cmp, neg_cmp, pri, ...) verify_cmp(true,	\
    t, a, b, cmp, neg_cmp, pri, __VA_ARGS__)

#define assert_ptr_eq(a, b, ...)	assert_cmp(void *, a, b, ==,	\
    !=, "p", __VA_ARGS__)
#define assert_ptr_ne(a, b, ...)	assert_cmp(void *, a, b, !=,	\
    ==, "p", __VA_ARGS__)
#define assert_ptr_null(a, ...)		assert_cmp(void *, a, NULL, ==,	\
    !=, "p", __VA_ARGS__)
#define assert_ptr_not_null(a, ...)	assert_cmp(void *, a, NULL, !=,	\
    ==, "p", __VA_ARGS__)

#define assert_c_eq(a, b, ...)	assert_cmp(char, a, b, ==, !=, "c", __VA_ARGS__)
#define assert_c_ne(a, b, ...)	assert_cmp(char, a, b, !=, ==, "c", __VA_ARGS__)
#define assert_c_lt(a, b, ...)	assert_cmp(char, a, b, <, >=, "c", __VA_ARGS__)
#define assert_c_le(a, b, ...)	assert_cmp(char, a, b, <=, >, "c", __VA_ARGS__)
#define assert_c_ge(a, b, ...)	assert_cmp(char, a, b, >=, <, "c", __VA_ARGS__)
#define assert_c_gt(a, b, ...)	assert_cmp(char, a, b, >, <=, "c", __VA_ARGS__)

#define assert_x_eq(a, b, ...)	assert_cmp(int, a, b, ==, !=, "#x", __VA_ARGS__)
#define assert_x_ne(a, b, ...)	assert_cmp(int, a, b, !=, ==, "#x", __VA_ARGS__)
#define assert_x_lt(a, b, ...)	assert_cmp(int, a, b, <, >=, "#x", __VA_ARGS__)
#define assert_x_le(a, b, ...)	assert_cmp(int, a, b, <=, >, "#x", __VA_ARGS__)
#define assert_x_ge(a, b, ...)	assert_cmp(int, a, b, >=, <, "#x", __VA_ARGS__)
#define assert_x_gt(a, b, ...)	assert_cmp(int, a, b, >, <=, "#x", __VA_ARGS__)

#define assert_d_eq(a, b, ...)	assert_cmp(int, a, b, ==, !=, "d", __VA_ARGS__)
#define assert_d_ne(a, b, ...)	assert_cmp(int, a, b, !=, ==, "d", __VA_ARGS__)
#define assert_d_lt(a, b, ...)	assert_cmp(int, a, b, <, >=, "d", __VA_ARGS__)
#define assert_d_le(a, b, ...)	assert_cmp(int, a, b, <=, >, "d", __VA_ARGS__)
#define assert_d_ge(a, b, ...)	assert_cmp(int, a, b, >=, <, "d", __VA_ARGS__)
#define assert_d_gt(a, b, ...)	assert_cmp(int, a, b, >, <=, "d", __VA_ARGS__)

#define assert_u_eq(a, b, ...)	assert_cmp(int, a, b, ==, !=, "u", __VA_ARGS__)
#define assert_u_ne(a, b, ...)	assert_cmp(int, a, b, !=, ==, "u", __VA_ARGS__)
#define assert_u_lt(a, b, ...)	assert_cmp(int, a, b, <, >=, "u", __VA_ARGS__)
#define assert_u_le(a, b, ...)	assert_cmp(int, a, b, <=, >, "u", __VA_ARGS__)
#define assert_u_ge(a, b, ...)	assert_cmp(int, a, b, >=, <, "u", __VA_ARGS__)
#define assert_u_gt(a, b, ...)	assert_cmp(int, a, b, >, <=, "u", __VA_ARGS__)

#define assert_ld_eq(a, b, ...)	assert_cmp(long, a, b, ==,	\
    !=, "ld", __VA_ARGS__)
#define assert_ld_ne(a, b, ...)	assert_cmp(long, a, b, !=,	\
    ==, "ld", __VA_ARGS__)
#define assert_ld_lt(a, b, ...)	assert_cmp(long, a, b, <,	\
    >=, "ld", __VA_ARGS__)
#define assert_ld_le(a, b, ...)	assert_cmp(long, a, b, <=,	\
    >, "ld", __VA_ARGS__)
#define assert_ld_ge(a, b, ...)	assert_cmp(long, a, b, >=,	\
    <, "ld", __VA_ARGS__)
#define assert_ld_gt(a, b, ...)	assert_cmp(long, a, b, >,	\
    <=, "ld", __VA_ARGS__)

#define assert_lu_eq(a, b, ...)	assert_cmp(unsigned long,	\
    a, b, ==, !=, "lu", __VA_ARGS__)
#define assert_lu_ne(a, b, ...)	assert_cmp(unsigned long,	\
    a, b, !=, ==, "lu", __VA_ARGS__)
#define assert_lu_lt(a, b, ...)	assert_cmp(unsigned long,	\
    a, b, <, >=, "lu", __VA_ARGS__)
#define assert_lu_le(a, b, ...)	assert_cmp(unsigned long,	\
    a, b, <=, >, "lu", __VA_ARGS__)
#define assert_lu_ge(a, b, ...)	assert_cmp(unsigned long,	\
    a, b, >=, <, "lu", __VA_ARGS__)
#define assert_lu_gt(a, b, ...)	assert_cmp(unsigned long,	\
    a, b, >, <=, "lu", __VA_ARGS__)

#define assert_qd_eq(a, b, ...)	assert_cmp(long long, a, b, ==,	\
    !=, "qd", __VA_ARGS__)
#define assert_qd_ne(a, b, ...)	assert_cmp(long long, a, b, !=,	\
    ==, "qd", __VA_ARGS__)
#define assert_qd_lt(a, b, ...)	assert_cmp(long long, a, b, <,	\
    >=, "qd", __VA_ARGS__)
#define assert_qd_le(a, b, ...)	assert_cmp(long long, a, b, <=,	\
    >, "qd", __VA_ARGS__)
#define assert_qd_ge(a, b, ...)	assert_cmp(long long, a, b, >=,	\
    <, "qd", __VA_ARGS__)
#define assert_qd_gt(a, b, ...)	assert_cmp(long long, a, b, >,	\
    <=, "qd", __VA_ARGS__)

#define assert_qu_eq(a, b, ...)	assert_cmp(unsigned long long,	\
    a, b, ==, !=, "qu", __VA_ARGS__)
#define assert_qu_ne(a, b, ...)	assert_cmp(unsigned long long,	\
    a, b, !=, ==, "qu", __VA_ARGS__)
#define assert_qu_lt(a, b, ...)	assert_cmp(unsigned long long,	\
    a, b, <, >=, "qu", __VA_ARGS__)
#define assert_qu_le(a, b, ...)	assert_cmp(unsigned long long,	\
    a, b, <=, >, "qu", __VA_ARGS__)
#define assert_qu_ge(a, b, ...)	assert_cmp(unsigned long long,	\
    a, b, >=, <, "qu", __VA_ARGS__)
#define assert_qu_gt(a, b, ...)	assert_cmp(unsigned long long,	\
    a, b, >, <=, "qu", __VA_ARGS__)

#define assert_jd_eq(a, b, ...)	assert_cmp(intmax_t, a, b, ==,	\
    !=, "jd", __VA_ARGS__)
#define assert_jd_ne(a, b, ...)	assert_cmp(intmax_t, a, b, !=,	\
    ==, "jd", __VA_ARGS__)
#define assert_jd_lt(a, b, ...)	assert_cmp(intmax_t, a, b, <,	\
    >=, "jd", __VA_ARGS__)
#define assert_jd_le(a, b, ...)	assert_cmp(intmax_t, a, b, <=,	\
    >, "jd", __VA_ARGS__)
#define assert_jd_ge(a, b, ...)	assert_cmp(intmax_t, a, b, >=,	\
    <, "jd", __VA_ARGS__)
#define assert_jd_gt(a, b, ...)	assert_cmp(intmax_t, a, b, >,	\
    <=, "jd", __VA_ARGS__)

#define assert_ju_eq(a, b, ...)	assert_cmp(uintmax_t, a, b, ==,	\
    !=, "ju", __VA_ARGS__)
#define assert_ju_ne(a, b, ...)	assert_cmp(uintmax_t, a, b, !=,	\
    ==, "ju", __VA_ARGS__)
#define assert_ju_lt(a, b, ...)	assert_cmp(uintmax_t, a, b, <,	\
    >=, "ju", __VA_ARGS__)
#define assert_ju_le(a, b, ...)	assert_cmp(uintmax_t, a, b, <=,	\
    >, "ju", __VA_ARGS__)
#define assert_ju_ge(a, b, ...)	assert_cmp(uintmax_t, a, b, >=,	\
    <, "ju", __VA_ARGS__)
#define assert_ju_gt(a, b, ...)	assert_cmp(uintmax_t, a, b, >,	\
    <=, "ju", __VA_ARGS__)

#define assert_zd_eq(a, b, ...)	assert_cmp(ssize_t, a, b, ==,	\
    !=, "zd", __VA_ARGS__)
#define assert_zd_ne(a, b, ...)	assert_cmp(ssize_t, a, b, !=,	\
    ==, "zd", __VA_ARGS__)
#define assert_zd_lt(a, b, ...)	assert_cmp(ssize_t, a, b, <,	\
    >=, "zd", __VA_ARGS__)
#define assert_zd_le(a, b, ...)	assert_cmp(ssize_t, a, b, <=,	\
    >, "zd", __VA_ARGS__)
#define assert_zd_ge(a, b, ...)	assert_cmp(ssize_t, a, b, >=,	\
    <, "zd", __VA_ARGS__)
#define assert_zd_gt(a, b, ...)	assert_cmp(ssize_t, a, b, >,	\
    <=, "zd", __VA_ARGS__)

#define assert_zu_eq(a, b, ...)	assert_cmp(size_t, a, b, ==,	\
    !=, "zu", __VA_ARGS__)
#define assert_zu_ne(a, b, ...)	assert_cmp(size_t, a, b, !=,	\
    ==, "zu", __VA_ARGS__)
#define assert_zu_lt(a, b, ...)	assert_cmp(size_t, a, b, <,	\
    >=, "zu", __VA_ARGS__)
#define assert_zu_le(a, b, ...)	assert_cmp(size_t, a, b, <=,	\
    >, "zu", __VA_ARGS__)
#define assert_zu_ge(a, b, ...)	assert_cmp(size_t, a, b, >=,	\
    <, "zu", __VA_ARGS__)
#define assert_zu_gt(a, b, ...)	assert_cmp(size_t, a, b, >,	\
    <=, "zu", __VA_ARGS__)

#define assert_d32_eq(a, b, ...)	assert_cmp(int32_t, a, b, ==,	\
    !=, FMTd32, __VA_ARGS__)
#define assert_d32_ne(a, b, ...)	assert_cmp(int32_t, a, b, !=,	\
    ==, FMTd32, __VA_ARGS__)
#define assert_d32_lt(a, b, ...)	assert_cmp(int32_t, a, b, <,	\
    >=, FMTd32, __VA_ARGS__)
#define assert_d32_le(a, b, ...)	assert_cmp(int32_t, a, b, <=,	\
    >, FMTd32, __VA_ARGS__)
#define assert_d32_ge(a, b, ...)	assert_cmp(int32_t, a, b, >=,	\
    <, FMTd32, __VA_ARGS__)
#define assert_d32_gt(a, b, ...)	assert_cmp(int32_t, a, b, >,	\
    <=, FMTd32, __VA_ARGS__)

#define assert_u32_eq(a, b, ...)	assert_cmp(uint32_t, a, b, ==,	\
    !=, FMTu32, __VA_ARGS__)
#define assert_u32_ne(a, b, ...)	assert_cmp(uint32_t, a, b, !=,	\
    ==, FMTu32, __VA_ARGS__)
#define assert_u32_lt(a, b, ...)	assert_cmp(uint32_t, a, b, <,	\
    >=, FMTu32, __VA_ARGS__)
#define assert_u32_le(a, b, ...)	assert_cmp(uint32_t, a, b, <=,	\
    >, FMTu32, __VA_ARGS__)
#define assert_u32_ge(a, b, ...)	assert_cmp(uint32_t, a, b, >=,	\
    <, FMTu32, __VA_ARGS__)
#define assert_u32_gt(a, b, ...)	assert_cmp(uint32_t, a, b, >,	\
    <=, FMTu32, __VA_ARGS__)

#define assert_d64_eq(a, b, ...)	assert_cmp(int64_t, a, b, ==,	\
    !=, FMTd64, __VA_ARGS__)
#define assert_d64_ne(a, b, ...)	assert_cmp(int64_t, a, b, !=,	\
    ==, FMTd64, __VA_ARGS__)
#define assert_d64_lt(a, b, ...)	assert_cmp(int64_t, a, b, <,	\
    >=, FMTd64, __VA_ARGS__)
#define assert_d64_le(a, b, ...)	assert_cmp(int64_t, a, b, <=,	\
    >, FMTd64, __VA_ARGS__)
#define assert_d64_ge(a, b, ...)	assert_cmp(int64_t, a, b, >=,	\
    <, FMTd64, __VA_ARGS__)
#define assert_d64_gt(a, b, ...)	assert_cmp(int64_t, a, b, >,	\
    <=, FMTd64, __VA_ARGS__)

#define assert_u64_eq(a, b, ...)	assert_cmp(uint64_t, a, b, ==,	\
    !=, FMTu64, __VA_ARGS__)
#define assert_u64_ne(a, b, ...)	assert_cmp(uint64_t, a, b, !=,	\
    ==, FMTu64, __VA_ARGS__)
#define assert_u64_lt(a, b, ...)	assert_cmp(uint64_t, a, b, <,	\
    >=, FMTu64, __VA_ARGS__)
#define assert_u64_le(a, b, ...)	assert_cmp(uint64_t, a, b, <=,	\
    >, FMTu64, __VA_ARGS__)
#define assert_u64_ge(a, b, ...)	assert_cmp(uint64_t, a, b, >=,	\
    <, FMTu64, __VA_ARGS__)
#define assert_u64_gt(a, b, ...)	assert_cmp(uint64_t, a, b, >,	\
    <=, FMTu64, __VA_ARGS__)

#define assert_b_eq(a, b, ...)	verify_b_eq(true, a, b, __VA_ARGS__)
#define assert_b_ne(a, b, ...)	verify_b_ne(true, a, b, __VA_ARGS__)

#define assert_true(a, ...)	assert_b_eq(a, true, __VA_ARGS__)
#define assert_false(a, ...)	assert_b_eq(a, false, __VA_ARGS__)

#define assert_str_eq(a, b, ...) verify_str_eq(true, a, b, __VA_ARGS__)
#define assert_str_ne(a, b, ...) verify_str_ne(true, a, b, __VA_ARGS__)

#define assert_not_reached(...) verify_not_reached(true, __VA_ARGS__)

/*
 * If this enum changes, corresponding changes in test/test.sh.in are also
 * necessary.
 */
typedef enum {
	test_status_pass = 0,
	test_status_skip = 1,
	test_status_fail = 2,

	test_status_count = 3
} test_status_t;

typedef void (test_t)(void);

#define TEST_BEGIN(f)							\
static void								\
f(void) {								\
	p_test_init(#f);

#define TEST_END							\
	goto label_test_end;						\
label_test_end:								\
	p_test_fini();							\
}

#define test(...)							\
	p_test(__VA_ARGS__, NULL)

#define test_no_reentrancy(...)							\
	p_test_no_reentrancy(__VA_ARGS__, NULL)

#define test_no_malloc_init(...)					\
	p_test_no_malloc_init(__VA_ARGS__, NULL)

#define test_skip_if(e) do {						\
	if (e) {							\
		test_skip("%s:%s:%d: Test skipped: (%s)",		\
		    __func__, __FILE__, __LINE__, #e);			\
		goto label_test_end;					\
	}								\
} while (0)

bool test_is_reentrant();

void	test_skip(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
void	test_fail(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);

/* For private use by macros. */
test_status_t	p_test(test_t *t, ...);
test_status_t	p_test_no_reentrancy(test_t *t, ...);
test_status_t	p_test_no_malloc_init(test_t *t, ...);
void	p_test_init(const char *name);
void	p_test_fini(void);
void	p_test_fail(const char *prefix, const char *message);