xref: /netbsd-src/external/bsd/jemalloc/dist/test/unit/thread_event.c (revision 7bdf38e5b7a28439665f2fdeff81e36913eef7dd)
1*7bdf38e5Schristos #include "test/jemalloc_test.h"
2*7bdf38e5Schristos 
3*7bdf38e5Schristos TEST_BEGIN(test_next_event_fast) {
4*7bdf38e5Schristos 	tsd_t *tsd = tsd_fetch();
5*7bdf38e5Schristos 	te_ctx_t ctx;
6*7bdf38e5Schristos 	te_ctx_get(tsd, &ctx, true);
7*7bdf38e5Schristos 
8*7bdf38e5Schristos 	te_ctx_last_event_set(&ctx, 0);
9*7bdf38e5Schristos 	te_ctx_current_bytes_set(&ctx, TE_NEXT_EVENT_FAST_MAX - 8U);
10*7bdf38e5Schristos 	te_ctx_next_event_set(tsd, &ctx, TE_NEXT_EVENT_FAST_MAX);
11*7bdf38e5Schristos #define E(event, condition, is_alloc)					\
12*7bdf38e5Schristos 	if (is_alloc && condition) {					\
13*7bdf38e5Schristos 		event##_event_wait_set(tsd, TE_NEXT_EVENT_FAST_MAX);	\
14*7bdf38e5Schristos 	}
15*7bdf38e5Schristos 	ITERATE_OVER_ALL_EVENTS
16*7bdf38e5Schristos #undef E
17*7bdf38e5Schristos 
18*7bdf38e5Schristos 	/* Test next_event_fast rolling back to 0. */
19*7bdf38e5Schristos 	void *p = malloc(16U);
20*7bdf38e5Schristos 	assert_ptr_not_null(p, "malloc() failed");
21*7bdf38e5Schristos 	free(p);
22*7bdf38e5Schristos 
23*7bdf38e5Schristos 	/* Test next_event_fast resuming to be equal to next_event. */
24*7bdf38e5Schristos 	void *q = malloc(SC_LOOKUP_MAXCLASS);
25*7bdf38e5Schristos 	assert_ptr_not_null(q, "malloc() failed");
26*7bdf38e5Schristos 	free(q);
27*7bdf38e5Schristos }
28*7bdf38e5Schristos TEST_END
29*7bdf38e5Schristos 
30*7bdf38e5Schristos int
31*7bdf38e5Schristos main(void) {
32*7bdf38e5Schristos 	return test(
33*7bdf38e5Schristos 	    test_next_event_fast);
34*7bdf38e5Schristos }
35