summaryrefslogtreecommitdiffhomepage
path: root/test/nxt_lib_unit_test.c
blob: fce4c963cf16f22303db7570d741fe9a761471c6 (plain) (blame)
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

/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#include <nxt_main.h>


extern char  **environ;


/* The function is defined here to prevent inline optimizations. */
static nxt_bool_t
nxt_msec_less(nxt_msec_t first, nxt_msec_t second)
{
    return (nxt_msec_diff(first, second) < 0);
}


int nxt_cdecl
main(int argc, char **argv)
{
    nxt_thread_t  *thr;

    if (nxt_lib_start("lib_unit_test", argv, &environ) != NXT_OK) {
        return 1;
    }

    nxt_main_log.level = NXT_LOG_INFO;

    thr = nxt_thread();

#if (NXT_UNIT_TEST_RTDTSC)

    if (nxt_process_argv[1] != NULL
        && nxt_memcmp(nxt_process_argv[1], "rbm", 3) == 0)
    {
        if (nxt_rbtree1_mb_start(thr) != NXT_OK) {
            return 1;
        }

        if (nxt_rbtree_mb_start(thr) != NXT_OK) {
            return 1;
        }

        if (nxt_lvlhsh_unit_test(thr, 500 * 1000, 0) != NXT_OK) {
            return 1;
        }

        nxt_rbtree1_mb_insert(thr);
        nxt_rbtree_mb_insert(thr);

        if (nxt_lvlhsh_unit_test(thr, 500 * 1000, 0) != NXT_OK) {
            return 1;
        }

        nxt_rbtree1_mb_delete(thr);
        nxt_rbtree_mb_delete(thr);

        return 0;
    }

#endif

#if !(NXT_HAVE_ARC4RANDOM)
    if (nxt_random_unit_test(thr) != NXT_OK) {
        return 1;
    }
#endif

    if (nxt_term_parse_unit_test(thr) != NXT_OK) {
        return 1;
    }

    if (nxt_msec_diff_unit_test(thr, nxt_msec_less) != NXT_OK) {
        return 1;
    }

    if (nxt_rbtree_unit_test(thr, 100 * 1000) != NXT_OK) {
        return 1;
    }

    if (nxt_rbtree_unit_test(thr, 1000 * 1000) != NXT_OK) {
        return 1;
    }

    if (nxt_rbtree1_unit_test(thr, 100 * 1000) != NXT_OK) {
        return 1;
    }

    if (nxt_rbtree1_unit_test(thr, 1000 * 1000) != NXT_OK) {
        return 1;
    }

    if (nxt_mem_cache_pool_unit_test(thr, 100, 40000, 128 - 1) != NXT_OK) {
        return 1;
    }

    if (nxt_mem_cache_pool_unit_test(thr, 100, 1000, 4096 - 1) != NXT_OK) {
        return 1;
    }

    if (nxt_mem_cache_pool_unit_test(thr, 1000, 100, 64 * 1024 - 1) != NXT_OK) {
        return 1;
    }

    if (nxt_mem_zone_unit_test(thr, 100, 20000, 128 - 1) != NXT_OK) {
        return 1;
    }

    if (nxt_mem_zone_unit_test(thr, 100, 10000, 4096 - 1) != NXT_OK) {
        return 1;
    }

    if (nxt_mem_zone_unit_test(thr, 1000, 40, 64 * 1024 - 1) != NXT_OK) {
        return 1;
    }

    if (nxt_lvlhsh_unit_test(thr, 2, 1) != NXT_OK) {
        return 1;
    }

    if (nxt_lvlhsh_unit_test(thr, 100 * 1000, 1) != NXT_OK) {
        return 1;
    }

    if (nxt_lvlhsh_unit_test(thr, 100 * 1000, 0) != NXT_OK) {
        return 1;
    }

    if (nxt_lvlhsh_unit_test(thr, 1000 * 1000, 1) != NXT_OK) {
        return 1;
    }

    if (nxt_gmtime_unit_test(thr) != NXT_OK) {
        return 1;
    }

    if (nxt_sprintf_unit_test(thr) != NXT_OK) {
        return 1;
    }

    if (nxt_malloc_unit_test(thr) != NXT_OK) {
        return 1;
    }

    if (nxt_utf8_unit_test(thr) != NXT_OK) {
        return 1;
    }

    if (nxt_http_parse_unit_test(thr) != NXT_OK) {
        return 1;
    }

    return 0;
}