xref: /unit/src/test/nxt_msec_diff_test.c (revision 611:323e11065f83)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #include <nxt_main.h>
8 #include "nxt_tests.h"
9 
10 
11 static const nxt_msec_t  pairs[] = {
12 
13     0x00000000, 0x00000001,
14     0x00000000, 0x7FFFFFFF,
15 
16     0x7FFFFFFF, 0x80000000,
17     0x7FFFFFFF, 0x80000001,
18 
19     0x80000000, 0x80000001,
20     0x80000000, 0xFFFFFFFF,
21 
22     0xFFFFFFFF, 0x00000000,
23     0xFFFFFFFF, 0x00000001,
24 };
25 
26 
27 nxt_int_t
nxt_msec_diff_test(nxt_thread_t * thr,nxt_msec_less_t less)28 nxt_msec_diff_test(nxt_thread_t *thr, nxt_msec_less_t less)
29 {
30     nxt_uint_t  i;
31 
32     nxt_thread_time_update(thr);
33 
34     for (i = 0; i < nxt_nitems(pairs); i += 2) {
35 
36         if (!less(pairs[i], pairs[i + 1])) {
37             nxt_log_alert(thr->log,
38                           "msec diff test failed: 0x%08XM 0x%08XM",
39                           pairs[i], pairs[i + 1]);
40             return NXT_ERROR;
41         }
42     }
43 
44     nxt_log_error(NXT_LOG_NOTICE, thr->log, "msec diff test passed");
45     return NXT_OK;
46 }
47