nxt_lvlhsh_test.c (384:8f86d3ff3e29) nxt_lvlhsh_test.c (594:c89b29f038c4)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include "nxt_tests.h"

--- 116 unchanged lines hidden (view full) ---

125
126 return ret;
127}
128
129
130nxt_int_t
131nxt_lvlhsh_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool)
132{
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include "nxt_tests.h"

--- 116 unchanged lines hidden (view full) ---

125
126 return ret;
127}
128
129
130nxt_int_t
131nxt_lvlhsh_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool)
132{
133 void *value;
133 uintptr_t key;
134 nxt_mp_t *mp;
135 nxt_nsec_t start, end;
136 nxt_uint_t i;
137 nxt_lvlhsh_t lh;
138 nxt_lvlhsh_each_t lhe;
139 const nxt_lvlhsh_proto_t *proto;
140

--- 55 unchanged lines hidden (view full) ---

196 }
197
198 if (i != n) {
199 nxt_log_error(NXT_LOG_NOTICE, thr->log,
200 "lvlhsh each test failed at %ui of %ui", i, n);
201 return NXT_ERROR;
202 }
203
134 uintptr_t key;
135 nxt_mp_t *mp;
136 nxt_nsec_t start, end;
137 nxt_uint_t i;
138 nxt_lvlhsh_t lh;
139 nxt_lvlhsh_each_t lhe;
140 const nxt_lvlhsh_proto_t *proto;
141

--- 55 unchanged lines hidden (view full) ---

197 }
198
199 if (i != n) {
200 nxt_log_error(NXT_LOG_NOTICE, thr->log,
201 "lvlhsh each test failed at %ui of %ui", i, n);
202 return NXT_ERROR;
203 }
204
204 key = 0;
205 for (i = 0; i < n; i++) {
205 for (i = 0; i < n; i++) {
206 key = nxt_murmur_hash2(&key, sizeof(uint32_t));
206 value = nxt_lvlhsh_peek(&lh, proto);
207
207
208 if (value == NULL) {
209 break;
210 }
211
212 key = (uintptr_t) value;
213
208 if (nxt_lvlhsh_test_delete(&lh, proto, mp, key) != NXT_OK) {
209 return NXT_ERROR;
210 }
211 }
212
214 if (nxt_lvlhsh_test_delete(&lh, proto, mp, key) != NXT_OK) {
215 return NXT_ERROR;
216 }
217 }
218
219 if (i != n) {
220 nxt_log_error(NXT_LOG_NOTICE, thr->log,
221 "lvlhsh peek test failed at %ui of %ui", i, n);
222 return NXT_ERROR;
223 }
224
213 if (mp != NULL) {
214 if (!nxt_mp_is_empty(mp)) {
215 nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem pool is not empty");
216 return NXT_ERROR;
217 }
218
219 nxt_mp_destroy(mp);
220 }
221
222 nxt_thread_time_update(thr);
223 end = nxt_thread_monotonic_time(thr);
224
225 nxt_log_error(NXT_LOG_NOTICE, thr->log, "lvlhsh test passed: %0.3fs",
226 (end - start) / 1000000000.0);
227
228 return NXT_OK;
229}
225 if (mp != NULL) {
226 if (!nxt_mp_is_empty(mp)) {
227 nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem pool is not empty");
228 return NXT_ERROR;
229 }
230
231 nxt_mp_destroy(mp);
232 }
233
234 nxt_thread_time_update(thr);
235 end = nxt_thread_monotonic_time(thr);
236
237 nxt_log_error(NXT_LOG_NOTICE, thr->log, "lvlhsh test passed: %0.3fs",
238 (end - start) / 1000000000.0);
239
240 return NXT_OK;
241}