xref: /unit/src/test/nxt_tests.c (revision 1306:3604d05e48be)
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 extern char  **environ;
12 
13 nxt_module_init_t  nxt_init_modules[1];
14 nxt_uint_t         nxt_init_modules_n;
15 
16 
17 /* The function is defined here to prevent inline optimizations. */
18 static nxt_bool_t
19 nxt_msec_less(nxt_msec_t first, nxt_msec_t second)
20 {
21     return (nxt_msec_diff(first, second) < 0);
22 }
23 
24 
25 int nxt_cdecl
26 main(int argc, char **argv)
27 {
28     nxt_task_t    task;
29     nxt_thread_t  *thr;
30 
31     if (nxt_lib_start("tests", argv, &environ) != NXT_OK) {
32         return 1;
33     }
34 
35     nxt_main_log.level = NXT_LOG_INFO;
36     task.log  = &nxt_main_log;
37 
38     thr = nxt_thread();
39     thr->task = &task;
40 
41 #if (NXT_TEST_RTDTSC)
42 
43     if (nxt_process_argv[1] != NULL
44         && nxt_memcmp(nxt_process_argv[1], "rbm", 3) == 0)
45     {
46         if (nxt_rbtree1_mb_start(thr) != NXT_OK) {
47             return 1;
48         }
49 
50         if (nxt_rbtree_mb_start(thr) != NXT_OK) {
51             return 1;
52         }
53 
54         if (nxt_lvlhsh_test(thr, 500 * 1000, 0) != NXT_OK) {
55             return 1;
56         }
57 
58         nxt_rbtree1_mb_insert(thr);
59         nxt_rbtree_mb_insert(thr);
60 
61         if (nxt_lvlhsh_test(thr, 500 * 1000, 0) != NXT_OK) {
62             return 1;
63         }
64 
65         nxt_rbtree1_mb_delete(thr);
66         nxt_rbtree_mb_delete(thr);
67 
68         return 0;
69     }
70 
71 #endif
72 
73     if (nxt_random_test(thr) != NXT_OK) {
74         return 1;
75     }
76 
77     if (nxt_term_parse_test(thr) != NXT_OK) {
78         return 1;
79     }
80 
81     if (nxt_msec_diff_test(thr, nxt_msec_less) != NXT_OK) {
82         return 1;
83     }
84 
85     if (nxt_rbtree_test(thr, 100 * 1000) != NXT_OK) {
86         return 1;
87     }
88 
89     if (nxt_rbtree_test(thr, 1000 * 1000) != NXT_OK) {
90         return 1;
91     }
92 
93     if (nxt_rbtree1_test(thr, 100 * 1000) != NXT_OK) {
94         return 1;
95     }
96 
97     if (nxt_rbtree1_test(thr, 1000 * 1000) != NXT_OK) {
98         return 1;
99     }
100 
101     if (nxt_mp_test(thr, 100, 40000, 128 - 1) != NXT_OK) {
102         return 1;
103     }
104 
105     if (nxt_mp_test(thr, 100, 1000, 4096 - 1) != NXT_OK) {
106         return 1;
107     }
108 
109     if (nxt_mp_test(thr, 1000, 100, 64 * 1024 - 1) != NXT_OK) {
110         return 1;
111     }
112 
113     if (nxt_mem_zone_test(thr, 100, 20000, 128 - 1) != NXT_OK) {
114         return 1;
115     }
116 
117     if (nxt_mem_zone_test(thr, 100, 10000, 4096 - 1) != NXT_OK) {
118         return 1;
119     }
120 
121     if (nxt_mem_zone_test(thr, 1000, 40, 64 * 1024 - 1) != NXT_OK) {
122         return 1;
123     }
124 
125     if (nxt_lvlhsh_test(thr, 2, 1) != NXT_OK) {
126         return 1;
127     }
128 
129     if (nxt_lvlhsh_test(thr, 100 * 1000, 1) != NXT_OK) {
130         return 1;
131     }
132 
133     if (nxt_lvlhsh_test(thr, 100 * 1000, 0) != NXT_OK) {
134         return 1;
135     }
136 
137     if (nxt_lvlhsh_test(thr, 1000 * 1000, 1) != NXT_OK) {
138         return 1;
139     }
140 
141     if (nxt_gmtime_test(thr) != NXT_OK) {
142         return 1;
143     }
144 
145     if (nxt_sprintf_test(thr) != NXT_OK) {
146         return 1;
147     }
148 
149     if (nxt_malloc_test(thr) != NXT_OK) {
150         return 1;
151     }
152 
153     if (nxt_utf8_test(thr) != NXT_OK) {
154         return 1;
155     }
156 
157     if (nxt_http_parse_test(thr) != NXT_OK) {
158         return 1;
159     }
160 
161     if (nxt_strverscmp_test(thr) != NXT_OK) {
162         return 1;
163     }
164 
165 #if (NXT_HAVE_CLONE_NEWUSER)
166     if (nxt_clone_creds_test(thr) != NXT_OK) {
167         return 1;
168     }
169 #endif
170 
171     return 0;
172 }
173