summaryrefslogtreecommitdiffhomepage
path: root/src/test/nxt_mp_test.c
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2017-11-21 18:55:28 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2017-11-21 18:55:28 +0300
commit78a77c3e38593a5dd1ba0970d036ed5f5100f88d (patch)
tree3011f02b551c623a926e85ed1532986b947da300 /src/test/nxt_mp_test.c
parent89a1c66dd0c396cda30a960e790817d28dc9a2de (diff)
downloadunit-78a77c3e38593a5dd1ba0970d036ed5f5100f88d.tar.gz
unit-78a77c3e38593a5dd1ba0970d036ed5f5100f88d.tar.bz2
Tests: move existing tests to "src" folder.
Diffstat (limited to 'src/test/nxt_mp_test.c')
-rw-r--r--src/test/nxt_mp_test.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/test/nxt_mp_test.c b/src/test/nxt_mp_test.c
new file mode 100644
index 00000000..39aa939d
--- /dev/null
+++ b/src/test/nxt_mp_test.c
@@ -0,0 +1,90 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_main.h>
+#include "nxt_tests.h"
+
+
+nxt_int_t
+nxt_mp_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks,
+ size_t max_size)
+{
+ void **blocks;
+ size_t total;
+ uint32_t value, size;
+ nxt_mp_t *mp;
+ nxt_bool_t valid;
+ nxt_uint_t i, n;
+
+ const size_t min_chunk_size = 16;
+ const size_t page_size = 128;
+ const size_t page_alignment = 128;
+ const size_t cluster_size = page_size * 8;
+
+ nxt_thread_time_update(thr);
+ nxt_log_error(NXT_LOG_NOTICE, thr->log,
+ "mem pool test started, max:%uz", max_size);
+
+ blocks = nxt_malloc(nblocks * sizeof(void *));
+ if (blocks == NULL) {
+ return NXT_ERROR;
+ }
+
+ valid = nxt_mp_test_sizes(cluster_size, page_alignment, page_size,
+ min_chunk_size);
+ if (!valid) {
+ return NXT_ERROR;
+ }
+
+ mp = nxt_mp_create(cluster_size, page_alignment, page_size, min_chunk_size);
+ if (mp == NULL) {
+ return NXT_ERROR;
+ }
+
+ value = 0;
+
+ for (i = 0; i < runs; i++) {
+
+ total = 0;
+
+ for (n = 0; n < nblocks; n++) {
+ value = nxt_murmur_hash2(&value, sizeof(uint32_t));
+
+ size = value & max_size;
+
+ if (size == 0) {
+ size++;
+ }
+
+ total += size;
+ blocks[n] = nxt_mp_alloc(mp, size);
+
+ if (blocks[n] == NULL) {
+ nxt_log_error(NXT_LOG_NOTICE, thr->log,
+ "mem pool test failed: %uz", total);
+ return NXT_ERROR;
+ }
+ }
+
+ for (n = 0; n < nblocks; n++) {
+ nxt_mp_free(mp, blocks[n]);
+ }
+ }
+
+ if (!nxt_mp_is_empty(mp)) {
+ nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem pool is not empty");
+ return NXT_ERROR;
+ }
+
+ nxt_mp_destroy(mp);
+
+ nxt_free(blocks);
+
+ nxt_thread_time_update(thr);
+ nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem pool test passed");
+
+ return NXT_OK;
+}