1e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#include "test/jemalloc_test.h"
2e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
3e42940346e47de63bfc47470c86c3c132ec2db8cChristopher FerrisTEST_BEGIN(test_ticker_tick)
4e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris{
5e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#define	NREPS 2
6e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#define	NTICKS 3
7e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_t ticker;
8e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	int32_t i, j;
9e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
10e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_init(&ticker, NTICKS);
11e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	for (i = 0; i < NREPS; i++) {
12e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		for (j = 0; j < NTICKS; j++) {
13e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris			assert_u_eq(ticker_read(&ticker), NTICKS - j,
14e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris			    "Unexpected ticker value (i=%d, j=%d)", i, j);
15e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris			assert_false(ticker_tick(&ticker),
16e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris			    "Unexpected ticker fire (i=%d, j=%d)", i, j);
17e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		}
18e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		assert_u32_eq(ticker_read(&ticker), 0,
19e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		    "Expected ticker depletion");
20e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		assert_true(ticker_tick(&ticker),
21e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		    "Expected ticker fire (i=%d)", i);
22e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		assert_u32_eq(ticker_read(&ticker), NTICKS,
23e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris		    "Expected ticker reset");
24e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	}
25e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#undef NTICKS
26e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris}
27e42940346e47de63bfc47470c86c3c132ec2db8cChristopher FerrisTEST_END
28e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
29e42940346e47de63bfc47470c86c3c132ec2db8cChristopher FerrisTEST_BEGIN(test_ticker_ticks)
30e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris{
31e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#define	NTICKS 3
32e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_t ticker;
33e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
34e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_init(&ticker, NTICKS);
35e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
36e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
37e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_false(ticker_ticks(&ticker, NTICKS), "Unexpected ticker fire");
38e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&ticker), 0, "Unexpected ticker value");
39e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_true(ticker_ticks(&ticker, NTICKS), "Expected ticker fire");
40e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
41e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
42e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_true(ticker_ticks(&ticker, NTICKS + 1), "Expected ticker fire");
43e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
44e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#undef NTICKS
45e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris}
46e42940346e47de63bfc47470c86c3c132ec2db8cChristopher FerrisTEST_END
47e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
48e42940346e47de63bfc47470c86c3c132ec2db8cChristopher FerrisTEST_BEGIN(test_ticker_copy)
49e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris{
50e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#define	NTICKS 3
51e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_t ta, tb;
52e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
53e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_init(&ta, NTICKS);
54e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_copy(&tb, &ta);
55e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
56e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_true(ticker_ticks(&tb, NTICKS + 1), "Expected ticker fire");
57e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
58e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
59e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_tick(&ta);
60e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	ticker_copy(&tb, &ta);
61e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&tb), NTICKS - 1, "Unexpected ticker value");
62e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_true(ticker_ticks(&tb, NTICKS), "Expected ticker fire");
63e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
64e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris#undef NTICKS
65e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris}
66e42940346e47de63bfc47470c86c3c132ec2db8cChristopher FerrisTEST_END
67e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
68e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferrisint
69e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferrismain(void)
70e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris{
71e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris
72e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	return (test(
73e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	    test_ticker_tick,
74e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	    test_ticker_ticks,
75e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris	    test_ticker_copy));
76e42940346e47de63bfc47470c86c3c132ec2db8cChristopher Ferris}
77