From 78a77c3e38593a5dd1ba0970d036ed5f5100f88d Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Tue, 21 Nov 2017 18:55:28 +0300 Subject: Tests: move existing tests to "src" folder. --- src/test/nxt_mem_zone_test.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/nxt_mem_zone_test.c (limited to 'src/test/nxt_mem_zone_test.c') diff --git a/src/test/nxt_mem_zone_test.c b/src/test/nxt_mem_zone_test.c new file mode 100644 index 00000000..faf0feee --- /dev/null +++ b/src/test/nxt_mem_zone_test.c @@ -0,0 +1,74 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include +#include "nxt_tests.h" + + +nxt_int_t +nxt_mem_zone_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, + size_t max_size) +{ + void *start, **blocks; + size_t total, zone_size; + uint32_t size; + nxt_uint_t i, n; + nxt_mem_zone_t *zone; + const size_t page_size = 4096; + + nxt_thread_time_update(thr); + nxt_log_error(NXT_LOG_NOTICE, thr->log, + "mem zone test started, max:%uz", max_size); + + zone_size = (max_size + 1) * nblocks; + + start = nxt_memalign(page_size, zone_size); + if (start == NULL) { + return NXT_ERROR; + } + + zone = nxt_mem_zone_init(start, zone_size, page_size); + if (zone == NULL) { + return NXT_ERROR; + } + + blocks = nxt_malloc(nblocks * sizeof(void *)); + if (blocks == NULL) { + return NXT_ERROR; + } + + size = 0; + + for (i = 0; i < runs; i++) { + + total = 0; + + for (n = 0; n < nblocks; n++) { + size = nxt_murmur_hash2(&size, sizeof(uint32_t)); + + total += size & max_size; + blocks[n] = nxt_mem_zone_alloc(zone, size & max_size); + + if (blocks[n] == NULL) { + nxt_log_error(NXT_LOG_NOTICE, thr->log, + "mem zone test failed: %uz", total); + return NXT_ERROR; + } + } + + for (n = 0; n < nblocks; n++) { + nxt_mem_zone_free(zone, blocks[n]); + } + } + + nxt_free(blocks); + nxt_free(zone); + + nxt_thread_time_update(thr); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem zone test passed"); + + return NXT_OK; +} -- cgit