diff options
Diffstat (limited to '')
-rw-r--r-- | auto/make | 27 | ||||
-rw-r--r-- | auto/options | 4 | ||||
-rw-r--r-- | auto/sources | 42 | ||||
-rwxr-xr-x | configure | 1 | ||||
-rw-r--r-- | src/nxt_main.h | 7 | ||||
-rw-r--r-- | src/nxt_random.c | 9 | ||||
-rw-r--r-- | src/nxt_random.h | 4 | ||||
-rw-r--r-- | test/nxt_gmtime_test.c (renamed from test/nxt_gmtime_unit_test.c) | 9 | ||||
-rw-r--r-- | test/nxt_http_parse_test.c (renamed from test/nxt_http_parse_unit_test.c) | 180 | ||||
-rw-r--r-- | test/nxt_lib_unit_test.h | 71 | ||||
-rw-r--r-- | test/nxt_lvlhsh_test.c (renamed from test/nxt_lvlhsh_unit_test.c) | 45 | ||||
-rw-r--r-- | test/nxt_malloc_test.c (renamed from test/nxt_malloc_unit_test.c) | 11 | ||||
-rw-r--r-- | test/nxt_mem_zone_test.c (renamed from test/nxt_mem_zone_unit_test.c) | 9 | ||||
-rw-r--r-- | test/nxt_mp_test.c (renamed from test/nxt_mp_unit_test.c) | 9 | ||||
-rw-r--r-- | test/nxt_msec_diff_test.c (renamed from test/nxt_msec_diff_unit_test.c) | 7 | ||||
-rw-r--r-- | test/nxt_rbtree1_test.c (renamed from test/nxt_rbtree1_unit_test.c) | 46 | ||||
-rw-r--r-- | test/nxt_rbtree_test.c (renamed from test/nxt_rbtree_unit_test.c) | 40 | ||||
-rw-r--r-- | test/nxt_sprintf_test.c (renamed from test/nxt_sprintf_unit_test.c) | 5 | ||||
-rw-r--r-- | test/nxt_term_parse_test.c (renamed from test/nxt_term_parse_unit_test.c) | 7 | ||||
-rw-r--r-- | test/nxt_tests.c (renamed from test/nxt_lib_unit_test.c) | 53 | ||||
-rw-r--r-- | test/nxt_tests.h | 68 | ||||
-rw-r--r-- | test/nxt_utf8_file_name_test.c | 2 | ||||
-rw-r--r-- | test/nxt_utf8_test.c (renamed from test/nxt_utf8_unit_test.c) | 7 |
23 files changed, 326 insertions, 337 deletions
@@ -45,7 +45,7 @@ $echo >> $NXT_MAKEFILE $echo "NXT_LIB_DEPS = \\" >> $NXT_MAKEFILE -for nxt_dep in $NXT_LIB_DEPS $NXT_LIB_UNIT_TEST_DEPS $NXT_AUTO_CONFIG_H +for nxt_dep in $NXT_LIB_DEPS $NXT_TEST_DEPS $NXT_AUTO_CONFIG_H do $echo " $nxt_dep \\" >> $NXT_MAKEFILE done @@ -87,7 +87,7 @@ END # Object files. -for nxt_src in $NXT_LIB_SRCS $NXT_LIB_UNIT_TEST_SRCS +for nxt_src in $NXT_LIB_SRCS $NXT_TEST_SRCS do nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/\.o/"` cat << END >> $NXT_MAKEFILE @@ -103,25 +103,25 @@ done $echo >> $NXT_MAKEFILE -# Unit test object files list. +# Test object files list. -$echo "NXT_LIB_UNIT_TEST_OBJS = \\" >> $NXT_MAKEFILE +$echo "NXT_TEST_OBJS = \\" >> $NXT_MAKEFILE -for nxt_src in $NXT_LIB_UNIT_TEST_SRCS +for nxt_src in $NXT_TEST_SRCS do nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/\.o/"` $echo " $NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE done -# Unit test and utf8 test executables. +# Test executables. cat << END >> $NXT_MAKEFILE -$NXT_BUILD_DIR/lib_unit_test: \$(NXT_LIB_UNIT_TEST_OBJS) \\ +$NXT_BUILD_DIR/tests: \$(NXT_TEST_OBJS) \\ $NXT_BUILD_DIR/$NXT_LIB_STATIC \$(NXT_LIB_DEPS) - \$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/lib_unit_test \\ - \$(CFLAGS) \$(NXT_LIB_UNIT_TEST_OBJS) \\ + \$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/tests \\ + \$(CFLAGS) \$(NXT_TEST_OBJS) \\ $NXT_BUILD_DIR/$NXT_LIB_STATIC \\ $NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS @@ -136,11 +136,6 @@ $NXT_BUILD_DIR/utf8_file_name_test: $NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\ END -if [ $NXT_LIB_UNIT_TEST = YES ]; then - NXT_UNIT_TEST_TARGETS="$NXT_UNIT_TEST_TARGETS lib_test" -fi - - NXT_MAKE_INCS="src $NXT_BUILD_DIR" NXT_MAKE_DEPS="\$(NXT_LIB_DEPS) $NXT_DEPS" NXT_MAKE_SRCS="$NXT_SRCS" @@ -222,8 +217,8 @@ cat << END > Makefile include $NXT_MAKEFILE -.PHONY: lib_test -lib_test: $NXT_BUILD_DIR/lib_unit_test $NXT_BUILD_DIR/utf8_file_name_test +.PHONY: tests +tests: $NXT_BUILD_DIR/tests $NXT_BUILD_DIR/utf8_file_name_test clean: rm -rf $NXT_BUILD_DIR *.dSYM Makefile diff --git a/auto/options b/auto/options index 67f53258..19cd3dee 100644 --- a/auto/options +++ b/auto/options @@ -38,7 +38,7 @@ NXT_TEST_BUILD_SOLARIS_SENDFILEV=NO NXT_TEST_BUILD_AIX_SEND_FILE=NO NXT_TEST_BUILD_HPUX_SENDFILE=NO -NXT_LIB_UNIT_TEST=NO +NXT_TESTS=NO for nxt_option do @@ -89,7 +89,7 @@ do --test-build-aix-send_file) NXT_TEST_BUILD_AIX_SEND_FILE=YES ;; --test-build-hpux-sendfile) NXT_TEST_BUILD_HPUX_SENDFILE=YES ;; - --tests) NXT_LIB_UNIT_TEST=YES ;; + --tests) NXT_TESTS=YES ;; *) $echo diff --git a/auto/sources b/auto/sources index eab4e29b..c1d8b37f 100644 --- a/auto/sources +++ b/auto/sources @@ -198,28 +198,28 @@ NXT_LIB_MACOSX_SENDFILE_SRCS="src/nxt_macosx_sendfile.c" NXT_LIB_AIX_SEND_FILE_SRCS="src/nxt_aix_send_file.c" NXT_LIB_HPUX_SENDFILE_SRCS="src/nxt_hpux_sendfile.c" -NXT_LIB_TEST_BUILD_DEPS="src/nxt_test_build.h" -NXT_LIB_TEST_BUILD_SRCS="src/nxt_test_build.c" +NXT_TEST_BUILD_DEPS="src/nxt_test_build.h" +NXT_TEST_BUILD_SRCS="src/nxt_test_build.c" -NXT_LIB_UNIT_TEST_DEPS="test/nxt_lib_unit_test.h \ +NXT_TEST_DEPS="test/nxt_tests.h \ test/nxt_rbtree1.h \ " -NXT_LIB_UNIT_TEST_SRCS=" \ - test/nxt_lib_unit_test.c \ +NXT_TEST_SRCS=" \ + test/nxt_tests.c \ test/nxt_rbtree1.c \ - test/nxt_rbtree_unit_test.c \ - test/nxt_term_parse_unit_test.c \ - test/nxt_msec_diff_unit_test.c \ - test/nxt_mp_unit_test.c \ - test/nxt_mem_zone_unit_test.c \ - test/nxt_lvlhsh_unit_test.c \ - test/nxt_gmtime_unit_test.c \ - test/nxt_sprintf_unit_test.c \ - test/nxt_malloc_unit_test.c \ - test/nxt_utf8_unit_test.c \ - test/nxt_rbtree1_unit_test.c \ - test/nxt_http_parse_unit_test.c \ + test/nxt_rbtree_test.c \ + test/nxt_term_parse_test.c \ + test/nxt_msec_diff_test.c \ + test/nxt_mp_test.c \ + test/nxt_mem_zone_test.c \ + test/nxt_lvlhsh_test.c \ + test/nxt_gmtime_test.c \ + test/nxt_sprintf_test.c \ + test/nxt_malloc_test.c \ + test/nxt_utf8_test.c \ + test/nxt_rbtree1_test.c \ + test/nxt_http_parse_test.c \ " NXT_LIB_UTF8_FILE_NAME_TEST_SRCS=" \ @@ -323,13 +323,13 @@ fi if [ "$NXT_TEST_BUILD" = "YES" ]; then - NXT_LIB_DEPS="$NXT_LIB_DEPS $NXT_LIB_TEST_BUILD_DEPS" - NXT_LIB_SRCS="$NXT_LIB_SRCS $NXT_LIB_TEST_BUILD_SRCS" + NXT_LIB_DEPS="$NXT_LIB_DEPS $NXT_TEST_BUILD_DEPS" + NXT_LIB_SRCS="$NXT_LIB_SRCS $NXT_TEST_BUILD_SRCS" fi -if [ $NXT_LIB_UNIT_TEST = YES ]; then - nxt_have=NXT_LIB_UNIT_TEST . auto/have +if [ $NXT_TESTS = YES ]; then + nxt_have=NXT_TESTS . auto/have fi NXT_DEPS=" \ @@ -18,7 +18,6 @@ set -u CFLAGS=${CFLAGS=} NXT_TEST_CFLAGS=${NXT_TEST_CFLAGS=} NXT_TEST_LIBS=${NXT_TEST_LIBS=} -NXT_UNIT_TEST_TARGETS=${NXT_UNIT_TEST_TARGETS=} # STUB NXT_BUILD_DIR=build diff --git a/src/nxt_main.h b/src/nxt_main.h index a0be58a1..c7776c8b 100644 --- a/src/nxt_main.h +++ b/src/nxt_main.h @@ -161,13 +161,6 @@ typedef struct nxt_upstream_source_s nxt_upstream_source_t; #include <nxt_port_hash.h> -#if (NXT_LIB_UNIT_TEST) -#include <../test/nxt_lib_unit_test.h> -#else -#define NXT_LIB_UNIT_TEST_STATIC static -#endif - - /* * The envp argument must be &environ if application may * change its process title with nxt_process_title(). diff --git a/src/nxt_random.c b/src/nxt_random.c index ea73ae18..38b14e56 100644 --- a/src/nxt_random.c +++ b/src/nxt_random.c @@ -162,10 +162,10 @@ nxt_random_byte(nxt_random_t *r) } -#if (NXT_LIB_UNIT_TEST) +#if (NXT_TESTS) nxt_int_t -nxt_random_unit_test(nxt_thread_t *thr) +nxt_random_test(nxt_thread_t *thr) { nxt_uint_t n; nxt_random_t r; @@ -188,14 +188,13 @@ nxt_random_unit_test(nxt_thread_t *thr) } if (nxt_random(&r) == 0x6FCAE186) { - nxt_log_error(NXT_LOG_NOTICE, thr->log, - "arc4random unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "arc4random test passed"); return NXT_OK; } } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "arc4random unit test failed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "arc4random test failed"); return NXT_ERROR; } diff --git a/src/nxt_random.h b/src/nxt_random.h index f9c07e54..962fdf8f 100644 --- a/src/nxt_random.h +++ b/src/nxt_random.h @@ -19,8 +19,8 @@ typedef struct { void nxt_random_init(nxt_random_t *r); uint32_t nxt_random(nxt_random_t *r); -#if (NXT_LIB_UNIT_TEST) -nxt_int_t nxt_random_unit_test(nxt_thread_t *thr); +#if (NXT_TESTS) +nxt_int_t nxt_random_test(nxt_thread_t *thr); #endif diff --git a/test/nxt_gmtime_unit_test.c b/test/nxt_gmtime_test.c index eea916f3..cec81ab4 100644 --- a/test/nxt_gmtime_unit_test.c +++ b/test/nxt_gmtime_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" #if (NXT_TIME_T_SIZE == 4) @@ -22,14 +23,14 @@ nxt_int_t -nxt_gmtime_unit_test(nxt_thread_t *thr) +nxt_gmtime_test(nxt_thread_t *thr) { struct tm tm0, *tm1; nxt_time_t s; nxt_nsec_t start, end; nxt_thread_time_update(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "gmtime unit test started"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "gmtime test started"); for (s = 0; s < NXT_GMTIME_MAX; s += 86400) { @@ -43,7 +44,7 @@ nxt_gmtime_unit_test(nxt_thread_t *thr) || tm0.tm_wday != tm1->tm_wday) { nxt_log_alert(thr->log, - "gmtime unit test failed: %T @ %02d.%02d.%d", + "gmtime test failed: %T @ %02d.%02d.%d", s, tm1->tm_mday, tm1->tm_mon + 1, tm1->tm_year + 1900); return NXT_ERROR; @@ -78,6 +79,6 @@ nxt_gmtime_unit_test(nxt_thread_t *thr) nxt_log_error(NXT_LOG_NOTICE, thr->log, "gmtime(): %0.1fns", (end - start) / 10000000.0); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "gmtime unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "gmtime test passed"); return NXT_OK; } diff --git a/test/nxt_http_parse_unit_test.c b/test/nxt_http_parse_test.c index fe9b6b97..d2af4245 100644 --- a/test/nxt_http_parse_unit_test.c +++ b/test/nxt_http_parse_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" typedef struct { @@ -22,49 +23,48 @@ typedef struct { unsigned space_in_target:1; /* target with "+" */ unsigned plus_in_target:1; -} nxt_http_parse_unit_test_request_line_t; +} nxt_http_parse_test_request_line_t; typedef union { - void *pointer; - nxt_int_t result; - nxt_http_parse_unit_test_request_line_t request_line; -} nxt_http_parse_unit_test_data_t; + void *pointer; + nxt_int_t result; + nxt_http_parse_test_request_line_t request_line; +} nxt_http_parse_test_data_t; typedef struct { nxt_str_t request; nxt_int_t result; nxt_int_t (*handler)(nxt_http_request_parse_t *rp, - nxt_http_parse_unit_test_data_t *data, + nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log); - nxt_http_parse_unit_test_data_t data; -} nxt_http_parse_unit_test_case_t; + nxt_http_parse_test_data_t data; +} nxt_http_parse_test_case_t; -static nxt_int_t nxt_http_parse_unit_test_run(nxt_http_request_parse_t *rp, +static nxt_int_t nxt_http_parse_test_run(nxt_http_request_parse_t *rp, nxt_str_t *request); -static nxt_int_t nxt_http_parse_unit_test_bench(nxt_thread_t *thr, +static nxt_int_t nxt_http_parse_test_bench(nxt_thread_t *thr, nxt_str_t *request, nxt_http_fields_hash_t *hash, const char *name, nxt_uint_t n); -static nxt_int_t nxt_http_parse_unit_test_request_line( - nxt_http_request_parse_t *rp, nxt_http_parse_unit_test_data_t *data, - nxt_str_t *request, nxt_log_t *log); -static nxt_int_t nxt_http_parse_unit_test_fields( - nxt_http_request_parse_t *rp, nxt_http_parse_unit_test_data_t *data, +static nxt_int_t nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp, + nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log); +static nxt_int_t nxt_http_parse_test_fields(nxt_http_request_parse_t *rp, + nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log); -static nxt_int_t nxt_http_unit_test_header_return(void *ctx, - nxt_http_field_t *field, nxt_log_t *log); +static nxt_int_t nxt_http_test_header_return(void *ctx, nxt_http_field_t *field, + nxt_log_t *log); -static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { +static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { nxt_string("GET / HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/"), @@ -77,7 +77,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("XXX-METHOD /d.ir/fi+le.ext?key=val HTTP/1.2\n\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("XXX-METHOD"), nxt_string("/d.ir/fi+le.ext?key=val"), @@ -90,7 +90,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET /di.r/? HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/di.r/?"), @@ -128,7 +128,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET /. HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/."), @@ -141,7 +141,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET /# HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/#"), @@ -154,7 +154,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET /?# HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/?#"), @@ -167,7 +167,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET // HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("//"), @@ -180,7 +180,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET /%20 HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/%20"), @@ -193,7 +193,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET / a HTTP/1.0\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/ a"), @@ -206,7 +206,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { { nxt_string("GET / HTTP/1.0 HTTP/1.1\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_request_line, + &nxt_http_parse_test_request_line, { .request_line = { nxt_string("GET"), nxt_string("/ HTTP/1.0"), @@ -275,7 +275,7 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { "X-Unknown-Header: value\r\n" "X-Good-Header: value\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_fields, + &nxt_http_parse_test_fields, { .result = NXT_OK } }, { @@ -284,64 +284,64 @@ static nxt_http_parse_unit_test_case_t nxt_http_unit_test_cases[] = { "X-Unknown-Header: value\r\n" "X-Bad-Header: value\r\n\r\n"), NXT_DONE, - &nxt_http_parse_unit_test_fields, + &nxt_http_parse_test_fields, { .result = NXT_ERROR } }, }; -static nxt_http_fields_hash_entry_t nxt_http_unit_test_fields[] = { +static nxt_http_fields_hash_entry_t nxt_http_test_fields[] = { { nxt_string("X-Bad-Header"), - &nxt_http_unit_test_header_return, + &nxt_http_test_header_return, (uintptr_t) NXT_ERROR }, { nxt_string("X-Good-Header"), - &nxt_http_unit_test_header_return, + &nxt_http_test_header_return, (uintptr_t) NXT_OK }, { nxt_null_string, NULL, 0 } }; -static nxt_http_fields_hash_entry_t nxt_http_unit_test_bench_fields[] = { +static nxt_http_fields_hash_entry_t nxt_http_test_bench_fields[] = { { nxt_string("Host"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("User-Agent"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Accept-Encoding"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Accept-Language"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Connection"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Content-Length"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Content-Type"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("If-Modified-Since"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("If-Match"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Date"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("Upgrade"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("X-Forwarded-For"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_string("X-Request-ID"), - &nxt_http_unit_test_header_return, NXT_OK }, + &nxt_http_test_header_return, NXT_OK }, { nxt_null_string, NULL, 0 } }; -static nxt_str_t nxt_http_unit_test_simple_request = nxt_string( +static nxt_str_t nxt_http_test_simple_request = nxt_string( "GET /page HTTP/1.1\r\n" "Host: example.com\r\n\r\n" ); -static nxt_str_t nxt_http_unit_test_big_request = nxt_string( +static nxt_str_t nxt_http_test_big_request = nxt_string( "POST /path/to/very/interesting/article/on.this.site?arg1=value&arg2=value" "2&very_big_arg=even_bigger_value HTTP/1.1\r\n" "Host: www.example.com\r\n" @@ -414,14 +414,14 @@ static nxt_str_t nxt_http_unit_test_big_request = nxt_string( nxt_int_t -nxt_http_parse_unit_test(nxt_thread_t *thr) +nxt_http_parse_test(nxt_thread_t *thr) { - nxt_mp_t *mp, *mp_temp; - nxt_int_t rc; - nxt_uint_t i; - nxt_http_fields_hash_t *hash; - nxt_http_request_parse_t rp; - nxt_http_parse_unit_test_case_t *test; + nxt_mp_t *mp, *mp_temp; + nxt_int_t rc; + nxt_uint_t i; + nxt_http_fields_hash_t *hash; + nxt_http_request_parse_t rp; + nxt_http_parse_test_case_t *test; nxt_thread_time_update(thr); @@ -430,13 +430,13 @@ nxt_http_parse_unit_test(nxt_thread_t *thr) return NXT_ERROR; } - hash = nxt_http_fields_hash_create(nxt_http_unit_test_fields, mp); + hash = nxt_http_fields_hash_create(nxt_http_test_fields, mp); if (hash == NULL) { return NXT_ERROR; } - for (i = 0; i < nxt_nitems(nxt_http_unit_test_cases); i++) { - test = &nxt_http_unit_test_cases[i]; + for (i = 0; i < nxt_nitems(nxt_http_test_cases); i++) { + test = &nxt_http_test_cases[i]; nxt_memzero(&rp, sizeof(nxt_http_request_parse_t)); @@ -451,10 +451,10 @@ nxt_http_parse_unit_test(nxt_thread_t *thr) rp.fields_hash = hash; - rc = nxt_http_parse_unit_test_run(&rp, &test->request); + rc = nxt_http_parse_test_run(&rp, &test->request); if (rc != test->result) { - nxt_log_alert(thr->log, "http parse unit test case failed:\n" + nxt_log_alert(thr->log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - result: %i (expected: %i)", &test->request, rc, test->result); @@ -471,22 +471,22 @@ nxt_http_parse_unit_test(nxt_thread_t *thr) nxt_mp_destroy(mp_temp); } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "http parse unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "http parse test passed"); - hash = nxt_http_fields_hash_create(nxt_http_unit_test_bench_fields, mp); + hash = nxt_http_fields_hash_create(nxt_http_test_bench_fields, mp); if (hash == NULL) { return NXT_ERROR; } - if (nxt_http_parse_unit_test_bench(thr, &nxt_http_unit_test_simple_request, - hash, "simple", 10000000) + if (nxt_http_parse_test_bench(thr, &nxt_http_test_simple_request, + hash, "simple", 10000000) != NXT_OK) { return NXT_ERROR; } - if (nxt_http_parse_unit_test_bench(thr, &nxt_http_unit_test_big_request, - hash, "big", 100000) + if (nxt_http_parse_test_bench(thr, &nxt_http_test_big_request, + hash, "big", 100000) != NXT_OK) { return NXT_ERROR; @@ -499,7 +499,7 @@ nxt_http_parse_unit_test(nxt_thread_t *thr) static nxt_int_t -nxt_http_parse_unit_test_run(nxt_http_request_parse_t *rp, nxt_str_t *request) +nxt_http_parse_test_run(nxt_http_request_parse_t *rp, nxt_str_t *request) { nxt_int_t rc; nxt_buf_mem_t buf; @@ -520,7 +520,7 @@ nxt_http_parse_unit_test_run(nxt_http_request_parse_t *rp, nxt_str_t *request) static nxt_int_t -nxt_http_parse_unit_test_bench(nxt_thread_t *thr, nxt_str_t *request, +nxt_http_parse_test_bench(nxt_thread_t *thr, nxt_str_t *request, nxt_http_fields_hash_t *hash, const char *name, nxt_uint_t n) { nxt_mp_t *mp; @@ -530,8 +530,7 @@ nxt_http_parse_unit_test_bench(nxt_thread_t *thr, nxt_str_t *request, nxt_http_request_parse_t rp; nxt_log_error(NXT_LOG_NOTICE, thr->log, - "http parse unit %s request bench started: " - "%uz bytes, %ui runs", + "http parse %s request bench started: %uz bytes, %ui runs", name, request->length, n); buf.start = request->start; @@ -558,7 +557,7 @@ nxt_http_parse_unit_test_bench(nxt_thread_t *thr, nxt_str_t *request, buf.free = buf.end; if (nxt_slow_path(nxt_http_parse_request(&rp, &buf) != NXT_DONE)) { - nxt_log_alert(thr->log, "http parse unit %s request bench failed " + nxt_log_alert(thr->log, "http parse %s request bench failed " "while parsing", name); return NXT_ERROR; } @@ -566,7 +565,7 @@ nxt_http_parse_unit_test_bench(nxt_thread_t *thr, nxt_str_t *request, if (nxt_slow_path(nxt_http_fields_process(rp.fields, NULL, thr->log) != NXT_OK)) { - nxt_log_alert(thr->log, "http parse unit %s request bench failed " + nxt_log_alert(thr->log, "http parse %s request bench failed " "while fields processing", name); return NXT_ERROR; } @@ -578,7 +577,7 @@ nxt_http_parse_unit_test_bench(nxt_thread_t *thr, nxt_str_t *request, end = nxt_thread_monotonic_time(thr); nxt_log_error(NXT_LOG_NOTICE, thr->log, - "http parse unit %s request bench: %0.3fs", + "http parse %s request bench: %0.3fs", name, (end - start) / 1000000000.0); return NXT_OK; @@ -586,17 +585,17 @@ nxt_http_parse_unit_test_bench(nxt_thread_t *thr, nxt_str_t *request, static nxt_int_t -nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, - nxt_http_parse_unit_test_data_t *data, nxt_str_t *request, nxt_log_t *log) +nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp, + nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log) { nxt_str_t str; - nxt_http_parse_unit_test_request_line_t *test = &data->request_line; + nxt_http_parse_test_request_line_t *test = &data->request_line; if (rp->method.start != test->method.start && !nxt_strstr_eq(&rp->method, &test->method)) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - method: \"%V\" (expected: \"%V\")", request, &rp->method, &test->method); @@ -609,7 +608,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, if (str.start != test->target.start && !nxt_strstr_eq(&str, &test->target)) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - target: \"%V\" (expected: \"%V\")", request, &str, &test->target); @@ -623,7 +622,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, if (str.start != test->exten.start && !nxt_strstr_eq(&str, &test->exten)) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - exten: \"%V\" (expected: \"%V\")", request, &str, &test->exten); @@ -637,7 +636,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, if (str.start != test->args.start && !nxt_strstr_eq(&str, &test->args)) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - args: \"%V\" (expected: \"%V\")", request, &str, &test->args); @@ -645,7 +644,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, } if (nxt_memcmp(rp->version.str, test->version, 8) != 0) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - version: \"%*s\" (expected: \"%*s\")", request, 8, rp->version.str, 8, test->version); @@ -653,7 +652,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, } if (rp->complex_target != test->complex_target) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - complex_target: %d (expected: %d)", request, rp->complex_target, test->complex_target); @@ -661,7 +660,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, } if (rp->quoted_target != test->quoted_target) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - quoted_target: %d (expected: %d)", request, rp->quoted_target, test->quoted_target); @@ -669,7 +668,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, } if (rp->space_in_target != test->space_in_target) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - space_in_target: %d (expected: %d)", request, rp->space_in_target, test->space_in_target); @@ -677,7 +676,7 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, } if (rp->plus_in_target != test->plus_in_target) { - nxt_log_alert(log, "http parse unit test case failed:\n" + nxt_log_alert(log, "http parse test case failed:\n" " - request:\n\"%V\"\n" " - plus_in_target: %d (expected: %d)", request, rp->plus_in_target, test->plus_in_target); @@ -689,15 +688,15 @@ nxt_http_parse_unit_test_request_line(nxt_http_request_parse_t *rp, static nxt_int_t -nxt_http_parse_unit_test_fields(nxt_http_request_parse_t *rp, - nxt_http_parse_unit_test_data_t *data, nxt_str_t *request, nxt_log_t *log) +nxt_http_parse_test_fields(nxt_http_request_parse_t *rp, + nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log) { nxt_int_t rc; rc = nxt_http_fields_process(rp->fields, NULL, log); if (rc != data->result) { - nxt_log_alert(log, "http parse unit test hash failed:\n" + nxt_log_alert(log, "http parse test hash failed:\n" " - request:\n\"%V\"\n" " - result: %i (expected: %i)", request, rc, data->result); @@ -709,8 +708,7 @@ nxt_http_parse_unit_test_fields(nxt_http_request_parse_t *rp, static nxt_int_t -nxt_http_unit_test_header_return(void *ctx, nxt_http_field_t *field, - nxt_log_t *log) +nxt_http_test_header_return(void *ctx, nxt_http_field_t *field, nxt_log_t *log) { return (nxt_int_t) field->data; } diff --git a/test/nxt_lib_unit_test.h b/test/nxt_lib_unit_test.h deleted file mode 100644 index d215a009..00000000 --- a/test/nxt_lib_unit_test.h +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - * Copyright (C) NGINX, Inc. - */ - -#ifndef _NXT_LIB_UNIT_TEST_H_INCLUDED_ -#define _NXT_LIB_UNIT_TEST_H_INCLUDED_ - - -#define NXT_LIB_UNIT_TEST_STATIC - - -typedef nxt_bool_t (*nxt_msec_less_t)(nxt_msec_t first, nxt_msec_t second); - - -#define NXT_RBT_NODES 1500 - - -#if (__i386__ || __i386 || __amd64__ || __amd64) -#if (NXT_GCC || NXT_CLANG) - -#define NXT_UNIT_TEST_RTDTSC 1 - -nxt_inline uint64_t -nxt_rdtsc(void) -{ - uint32_t eax, edx; - - __asm__ volatile ("rdtsc" : "=a" (eax), "=d" (edx)); - - return ((uint64_t) edx << 32) | eax; -} - -#endif -#endif - - -nxt_int_t nxt_term_parse_unit_test(nxt_thread_t *thr); -nxt_int_t nxt_msec_diff_unit_test(nxt_thread_t *thr, nxt_msec_less_t); - -nxt_int_t nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n); -nxt_int_t nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n); - -#if (NXT_UNIT_TEST_RTDTSC) - -nxt_int_t nxt_rbtree_mb_start(nxt_thread_t *thr); -void nxt_rbtree_mb_insert(nxt_thread_t *thr); -void nxt_rbtree_mb_delete(nxt_thread_t *thr); - -nxt_int_t nxt_rbtree1_mb_start(nxt_thread_t *thr); -void nxt_rbtree1_mb_insert(nxt_thread_t *thr); -void nxt_rbtree1_mb_delete(nxt_thread_t *thr); - -#endif - -nxt_int_t nxt_mp_unit_test(nxt_thread_t *thr, nxt_uint_t runs, - nxt_uint_t nblocks, size_t max_size); -nxt_int_t nxt_mem_zone_unit_test(nxt_thread_t *thr, nxt_uint_t runs, - nxt_uint_t nblocks, size_t max_size); -nxt_int_t nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, - nxt_bool_t use_pool); - -nxt_int_t nxt_gmtime_unit_test(nxt_thread_t *thr); -nxt_int_t nxt_sprintf_unit_test(nxt_thread_t *thr); -nxt_int_t nxt_malloc_unit_test(nxt_thread_t *thr); -nxt_int_t nxt_utf8_unit_test(nxt_thread_t *thr); -nxt_int_t nxt_http_parse_unit_test(nxt_thread_t *thr); - - -#endif /* _NXT_LIB_UNIT_TEST_H_INCLUDED_ */ diff --git a/test/nxt_lvlhsh_unit_test.c b/test/nxt_lvlhsh_test.c index 046ee2a5..62139fe6 100644 --- a/test/nxt_lvlhsh_unit_test.c +++ b/test/nxt_lvlhsh_test.c @@ -5,10 +5,11 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" static nxt_int_t -nxt_lvlhsh_unit_test_key_test(nxt_lvlhsh_query_t *lhq, void *data) +nxt_lvlhsh_test_key_test(nxt_lvlhsh_query_t *lhq, void *data) { if (*(uintptr_t *) lhq->key.start == (uintptr_t) data) { return NXT_OK; @@ -19,14 +20,14 @@ nxt_lvlhsh_unit_test_key_test(nxt_lvlhsh_query_t *lhq, void *data) static void * -nxt_lvlhsh_unit_test_pool_alloc(void *pool, size_t size) +nxt_lvlhsh_test_pool_alloc(void *pool, size_t size) { return nxt_mp_align(pool, size, size); } static void -nxt_lvlhsh_unit_test_pool_free(void *pool, void *p) +nxt_lvlhsh_test_pool_free(void *pool, void *p) { nxt_mp_free(pool, p); } @@ -35,21 +36,21 @@ nxt_lvlhsh_unit_test_pool_free(void *pool, void *p) static const nxt_lvlhsh_proto_t malloc_proto nxt_aligned(64) = { //NXT_LVLHSH_LARGE_MEMALIGN, NXT_LVLHSH_DEFAULT, - nxt_lvlhsh_unit_test_key_test, + nxt_lvlhsh_test_key_test, nxt_lvlhsh_alloc, nxt_lvlhsh_free, }; static const nxt_lvlhsh_proto_t pool_proto nxt_aligned(64) = { NXT_LVLHSH_LARGE_SLAB, - nxt_lvlhsh_unit_test_key_test, - nxt_lvlhsh_unit_test_pool_alloc, - nxt_lvlhsh_unit_test_pool_free, + nxt_lvlhsh_test_key_test, + nxt_lvlhsh_test_pool_alloc, + nxt_lvlhsh_test_pool_free, }; static nxt_int_t -nxt_lvlhsh_unit_test_add(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, +nxt_lvlhsh_test_add(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, void *pool, uintptr_t key) { nxt_lvlhsh_query_t lhq; @@ -68,7 +69,7 @@ nxt_lvlhsh_unit_test_add(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, return NXT_OK; case NXT_DECLINED: - nxt_thread_log_alert("lvlhsh unit test failed: " + nxt_thread_log_alert("lvlhsh test failed: " "key %p is already in hash", key); /* Fall through. */ default: @@ -78,7 +79,7 @@ nxt_lvlhsh_unit_test_add(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, static nxt_int_t -nxt_lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, +nxt_lvlhsh_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, uintptr_t key) { nxt_lvlhsh_query_t lhq; @@ -95,7 +96,7 @@ nxt_lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, } } - nxt_thread_log_alert("lvlhsh unit test failed: " + nxt_thread_log_alert("lvlhsh test failed: " "key %p not found in hash", key); return NXT_ERROR; @@ -103,7 +104,7 @@ nxt_lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, static nxt_int_t -nxt_lvlhsh_unit_test_delete(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, +nxt_lvlhsh_test_delete(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, void *pool, uintptr_t key) { nxt_int_t ret; @@ -118,7 +119,7 @@ nxt_lvlhsh_unit_test_delete(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, ret = nxt_lvlhsh_delete(lh, &lhq); if (ret != NXT_OK) { - nxt_thread_log_alert("lvlhsh unit test failed: " + nxt_thread_log_alert("lvlhsh test failed: " "key %p not found in hash", key); } @@ -127,7 +128,7 @@ nxt_lvlhsh_unit_test_delete(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, nxt_int_t -nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) +nxt_lvlhsh_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) { uintptr_t key; nxt_mp_t *mp; @@ -153,12 +154,12 @@ nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) } nxt_log_error(NXT_LOG_NOTICE, thr->log, - "lvlhsh unit test started: %uD pool", n); + "lvlhsh test started: %uD pool", n); proto = &pool_proto; } else { nxt_log_error(NXT_LOG_NOTICE, thr->log, - "lvlhsh unit test started: %uD malloc", n); + "lvlhsh test started: %uD malloc", n); proto = &malloc_proto; mp = NULL; } @@ -169,9 +170,9 @@ nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) for (i = 0; i < n; i++) { key = nxt_murmur_hash2(&key, sizeof(uint32_t)); - if (nxt_lvlhsh_unit_test_add(&lh, proto, mp, key) != NXT_OK) { + if (nxt_lvlhsh_test_add(&lh, proto, mp, key) != NXT_OK) { nxt_log_error(NXT_LOG_NOTICE, thr->log, - "lvlhsh add unit test failed at %ui", i); + "lvlhsh add test failed at %ui", i); return NXT_ERROR; } } @@ -180,7 +181,7 @@ nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) for (i = 0; i < n; i++) { key = nxt_murmur_hash2(&key, sizeof(uint32_t)); - if (nxt_lvlhsh_unit_test_get(&lh, proto, key) != NXT_OK) { + if (nxt_lvlhsh_test_get(&lh, proto, key) != NXT_OK) { return NXT_ERROR; } } @@ -196,7 +197,7 @@ nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) if (i != n) { nxt_log_error(NXT_LOG_NOTICE, thr->log, - "lvlhsh each unit test failed at %ui of %ui", i, n); + "lvlhsh each test failed at %ui of %ui", i, n); return NXT_ERROR; } @@ -204,7 +205,7 @@ nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) for (i = 0; i < n; i++) { key = nxt_murmur_hash2(&key, sizeof(uint32_t)); - if (nxt_lvlhsh_unit_test_delete(&lh, proto, mp, key) != NXT_OK) { + if (nxt_lvlhsh_test_delete(&lh, proto, mp, key) != NXT_OK) { return NXT_ERROR; } } @@ -221,7 +222,7 @@ nxt_lvlhsh_unit_test(nxt_thread_t *thr, nxt_uint_t n, nxt_bool_t use_pool) nxt_thread_time_update(thr); end = nxt_thread_monotonic_time(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "lvlhsh unit test passed: %0.3fs", + nxt_log_error(NXT_LOG_NOTICE, thr->log, "lvlhsh test passed: %0.3fs", (end - start) / 1000000000.0); return NXT_OK; diff --git a/test/nxt_malloc_unit_test.c b/test/nxt_malloc_test.c index f1f67593..daa609b1 100644 --- a/test/nxt_malloc_unit_test.c +++ b/test/nxt_malloc_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" #define TIMES 1000 @@ -18,7 +19,7 @@ typedef struct { static nxt_malloc_size_t * -nxt_malloc_test(nxt_thread_t *thr, nxt_malloc_size_t *last, size_t size, +nxt_malloc_run_test(nxt_thread_t *thr, nxt_malloc_size_t *last, size_t size, nxt_uint_t times) { size_t a, s, alignment; @@ -81,7 +82,7 @@ nxt_malloc_test(nxt_thread_t *thr, nxt_malloc_size_t *last, size_t size, nxt_int_t -nxt_malloc_unit_test(nxt_thread_t *thr) +nxt_malloc_test(nxt_thread_t *thr) { size_t size; nxt_malloc_size_t *last, *s; @@ -92,21 +93,21 @@ nxt_malloc_unit_test(nxt_thread_t *thr) last = &sizes[0]; for (size = 1; size < 64; size++) { - last = nxt_malloc_test(thr, last, size, TIMES); + last = nxt_malloc_run_test(thr, last, size, TIMES); if (last == NULL) { return NXT_ERROR; } } for (size = 64; size < 16384; size += 8) { - last = nxt_malloc_test(thr, last, size, TIMES / 4); + last = nxt_malloc_run_test(thr, last, size, TIMES / 4); if (last == NULL) { return NXT_ERROR; } } for (size = 16384; size < 512 * 1024 + 129; size += 128) { - last = nxt_malloc_test(thr, last, size, TIMES / 16); + last = nxt_malloc_run_test(thr, last, size, TIMES / 16); if (last == NULL) { return NXT_ERROR; } diff --git a/test/nxt_mem_zone_unit_test.c b/test/nxt_mem_zone_test.c index cce9b702..faf0feee 100644 --- a/test/nxt_mem_zone_unit_test.c +++ b/test/nxt_mem_zone_test.c @@ -5,10 +5,11 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" nxt_int_t -nxt_mem_zone_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, +nxt_mem_zone_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, size_t max_size) { void *start, **blocks; @@ -20,7 +21,7 @@ nxt_mem_zone_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, nxt_thread_time_update(thr); nxt_log_error(NXT_LOG_NOTICE, thr->log, - "mem zone unit test started, max:%uz", max_size); + "mem zone test started, max:%uz", max_size); zone_size = (max_size + 1) * nblocks; @@ -53,7 +54,7 @@ nxt_mem_zone_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, if (blocks[n] == NULL) { nxt_log_error(NXT_LOG_NOTICE, thr->log, - "mem zone unit test failed: %uz", total); + "mem zone test failed: %uz", total); return NXT_ERROR; } } @@ -67,7 +68,7 @@ nxt_mem_zone_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, nxt_free(zone); nxt_thread_time_update(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem zone unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem zone test passed"); return NXT_OK; } diff --git a/test/nxt_mp_unit_test.c b/test/nxt_mp_test.c index c51c9152..39aa939d 100644 --- a/test/nxt_mp_unit_test.c +++ b/test/nxt_mp_test.c @@ -5,10 +5,11 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" nxt_int_t -nxt_mp_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, +nxt_mp_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, size_t max_size) { void **blocks; @@ -25,7 +26,7 @@ nxt_mp_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, nxt_thread_time_update(thr); nxt_log_error(NXT_LOG_NOTICE, thr->log, - "mem pool unit test started, max:%uz", max_size); + "mem pool test started, max:%uz", max_size); blocks = nxt_malloc(nblocks * sizeof(void *)); if (blocks == NULL) { @@ -63,7 +64,7 @@ nxt_mp_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, if (blocks[n] == NULL) { nxt_log_error(NXT_LOG_NOTICE, thr->log, - "mem pool unit test failed: %uz", total); + "mem pool test failed: %uz", total); return NXT_ERROR; } } @@ -83,7 +84,7 @@ nxt_mp_unit_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, nxt_free(blocks); nxt_thread_time_update(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem pool unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "mem pool test passed"); return NXT_OK; } diff --git a/test/nxt_msec_diff_unit_test.c b/test/nxt_msec_diff_test.c index 504cbb5a..5af7c011 100644 --- a/test/nxt_msec_diff_unit_test.c +++ b/test/nxt_msec_diff_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" static const nxt_msec_t pairs[] = { @@ -24,7 +25,7 @@ static const nxt_msec_t pairs[] = { nxt_int_t -nxt_msec_diff_unit_test(nxt_thread_t *thr, nxt_msec_less_t less) +nxt_msec_diff_test(nxt_thread_t *thr, nxt_msec_less_t less) { nxt_uint_t i; @@ -34,12 +35,12 @@ nxt_msec_diff_unit_test(nxt_thread_t *thr, nxt_msec_less_t less) if (!less(pairs[i], pairs[i + 1])) { nxt_log_alert(thr->log, - "msec diff unit test failed: 0x%08XM 0x%08XM", + "msec diff test failed: 0x%08XM 0x%08XM", pairs[i], pairs[i + 1]); return NXT_ERROR; } } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "msec diff unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "msec diff test passed"); return NXT_OK; } diff --git a/test/nxt_rbtree1_unit_test.c b/test/nxt_rbtree1_test.c index c3e9f6de..d4783ea1 100644 --- a/test/nxt_rbtree1_unit_test.c +++ b/test/nxt_rbtree1_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" #include "nxt_rbtree1.h" @@ -43,18 +44,18 @@ nxt_rbtree1_node_successor(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) } -static void nxt_rbtree1_unit_test_insert_value(nxt_rbtree1_node_t *temp, +static void nxt_rbtree1_test_insert_value(nxt_rbtree1_node_t *temp, nxt_rbtree1_node_t *node, nxt_rbtree1_node_t *sentinel); -static nxt_int_t nxt_rbtree1_unit_test_compare(nxt_rbtree1_node_t *node1, +static nxt_int_t nxt_rbtree1_test_compare(nxt_rbtree1_node_t *node1, nxt_rbtree1_node_t *node2); -static int nxt_cdecl nxt_rbtree1_unit_test_sort_cmp(const void *one, +static int nxt_cdecl nxt_rbtree1_test_sort_cmp(const void *one, const void *two); -static nxt_rbtree1_node_t *nxt_rbtree1_unit_test_find(nxt_rbtree1_t *tree, +static nxt_rbtree1_node_t *nxt_rbtree1_test_find(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node); nxt_int_t -nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) +nxt_rbtree1_test(nxt_thread_t *thr, nxt_uint_t n) { uint32_t key, *keys; nxt_uint_t i; @@ -64,10 +65,9 @@ nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) nxt_thread_time_update(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, - "rbtree1 unit test started: %ui", n); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree1 test started: %ui", n); - nxt_rbtree1_init(&tree, &sentinel, nxt_rbtree1_unit_test_insert_value); + nxt_rbtree1_init(&tree, &sentinel, nxt_rbtree1_test_insert_value); nodes = nxt_malloc(n * sizeof(nxt_rbtree1_node_t)); if (nodes == NULL) { @@ -89,7 +89,7 @@ nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) nodes[i].key = key; } - nxt_qsort(keys, n, sizeof(uint32_t), nxt_rbtree1_unit_test_sort_cmp); + nxt_qsort(keys, n, sizeof(uint32_t), nxt_rbtree1_test_sort_cmp); nxt_thread_time_update(thr); start = nxt_thread_monotonic_time(thr); @@ -99,8 +99,8 @@ nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) } for (i = 0; i < n; i++) { - if (nxt_rbtree1_unit_test_find(&tree, &nodes[i]) != &nodes[i]) { - nxt_log_alert(thr->log, "rbtree1 unit test failed: %08XD not found", + if (nxt_rbtree1_test_find(&tree, &nodes[i]) != &nodes[i]) { + nxt_log_alert(thr->log, "rbtree1 test failed: %08XD not found", nodes[i].key); goto fail; } @@ -112,7 +112,7 @@ nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) while (nxt_rbtree1_is_there_successor(&tree, node)) { if (keys[i] != node->key) { - nxt_log_alert(thr->log, "rbtree1 unit test failed: %i: %08XD %08XD", + nxt_log_alert(thr->log, "rbtree1 test failed: %i: %08XD %08XD", i, keys[i], node->key); goto fail; } @@ -122,7 +122,7 @@ nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) } if (i != n) { - nxt_log_alert(thr->log, "rbtree1 unit test failed: %ui", i); + nxt_log_alert(thr->log, "rbtree1 test failed: %ui", i); goto fail; } @@ -135,14 +135,14 @@ nxt_rbtree1_unit_test(nxt_thread_t *thr, nxt_uint_t n) end = nxt_thread_monotonic_time(thr); if (!nxt_rbtree1_is_empty(&tree)) { - nxt_log_alert(thr->log, "rbtree1 unit test failed: tree is not empty"); + nxt_log_alert(thr->log, "rbtree1 test failed: tree is not empty"); goto fail; } nxt_free(keys); nxt_free(nodes); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree1 unit test passed %0.3fs", + nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree1 test passed %0.3fs", (end - start) / 1000000000.0); return NXT_OK; @@ -157,7 +157,7 @@ fail: static void -nxt_rbtree1_unit_test_insert_value(nxt_rbtree1_node_t *temp, +nxt_rbtree1_test_insert_value(nxt_rbtree1_node_t *temp, nxt_rbtree1_node_t *node, nxt_rbtree1_node_t *sentinel) { nxt_rbtree1_node_t **p; @@ -190,8 +190,7 @@ nxt_rbtree1_unit_test_insert_value(nxt_rbtree1_node_t *temp, */ nxt_inline nxt_int_t -nxt_rbtree1_unit_test_compare(nxt_rbtree1_node_t *node1, - nxt_rbtree1_node_t *node2) +nxt_rbtree1_test_compare(nxt_rbtree1_node_t *node1, nxt_rbtree1_node_t *node2) { if (node1->key < node2->key) { return -1; @@ -206,7 +205,7 @@ nxt_rbtree1_unit_test_compare(nxt_rbtree1_node_t *node1, static int nxt_cdecl -nxt_rbtree1_unit_test_sort_cmp(const void *one, const void *two) +nxt_rbtree1_test_sort_cmp(const void *one, const void *two) { const uint32_t *first, *second; @@ -226,7 +225,7 @@ nxt_rbtree1_unit_test_sort_cmp(const void *one, const void *two) static nxt_rbtree1_node_t * -nxt_rbtree1_unit_test_find(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) +nxt_rbtree1_test_find(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) { nxt_int_t n; nxt_rbtree1_node_t *next, *sentinel; @@ -238,7 +237,7 @@ nxt_rbtree1_unit_test_find(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) nxt_prefetch(next->left); nxt_prefetch(next->right); - n = nxt_rbtree1_unit_test_compare(node, next); + n = nxt_rbtree1_test_compare(node, next); if (n < 0) { next = next->left; @@ -255,7 +254,7 @@ nxt_rbtree1_unit_test_find(nxt_rbtree1_t *tree, nxt_rbtree1_node_t *node) } -#if (NXT_UNIT_TEST_RTDTSC) +#if (NXT_TEST_RTDTSC) #define NXT_RBT_STEP (21 * nxt_pagesize / 10 / sizeof(nxt_rbtree1_node_t)) @@ -278,8 +277,7 @@ nxt_rbtree1_mb_start(nxt_thread_t *thr) return NXT_ERROR; } - nxt_rbtree1_init(&mb_tree, &mb_sentinel, - nxt_rbtree1_unit_test_insert_value); + nxt_rbtree1_init(&mb_tree, &mb_sentinel, nxt_rbtree1_test_insert_value); key = 0; diff --git a/test/nxt_rbtree_unit_test.c b/test/nxt_rbtree_test.c index 9f38d2c3..41375d92 100644 --- a/test/nxt_rbtree_unit_test.c +++ b/test/nxt_rbtree_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" typedef struct { @@ -13,15 +14,14 @@ typedef struct { } nxt_rbtree_test_t; -static intptr_t nxt_rbtree_unit_test_comparison(nxt_rbtree_node_t *node1, +static intptr_t nxt_rbtree_test_comparison(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2); -static nxt_int_t nxt_rbtree_unit_test_compare(uint32_t key1, uint32_t key2); -static int nxt_cdecl nxt_rbtree_unit_test_sort_cmp(const void *one, - const void *two); +static nxt_int_t nxt_rbtree_test_compare(uint32_t key1, uint32_t key2); +static int nxt_cdecl nxt_rbtree_test_sort_cmp(const void *one, const void *two); nxt_int_t -nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) +nxt_rbtree_test(nxt_thread_t *thr, nxt_uint_t n) { void *mark; uint32_t key, *keys; @@ -33,9 +33,9 @@ nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) nxt_thread_time_update(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree unit test started: %ui", n); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree test started: %ui", n); - nxt_rbtree_init(&tree, nxt_rbtree_unit_test_comparison); + nxt_rbtree_init(&tree, nxt_rbtree_test_comparison); mark = tree.sentinel.right; @@ -59,7 +59,7 @@ nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) items[i].key = key; } - nxt_qsort(keys, n, sizeof(uint32_t), nxt_rbtree_unit_test_sort_cmp); + nxt_qsort(keys, n, sizeof(uint32_t), nxt_rbtree_test_sort_cmp); nxt_thread_time_update(thr); start = nxt_thread_monotonic_time(thr); @@ -72,7 +72,7 @@ nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) node = nxt_rbtree_find(&tree, &items[i].node); if (node != (nxt_rbtree_node_t *) &items[i].node) { - nxt_log_alert(thr->log, "rbtree unit test failed: %08XD not found", + nxt_log_alert(thr->log, "rbtree test failed: %08XD not found", items[i].key); goto fail; } @@ -86,7 +86,7 @@ nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) item = (nxt_rbtree_test_t *) node; if (keys[i] != item->key) { - nxt_log_alert(thr->log, "rbtree unit test failed: %i: %08XD %08XD", + nxt_log_alert(thr->log, "rbtree test failed: %i: %08XD %08XD", i, keys[i], item->key); goto fail; } @@ -96,7 +96,7 @@ nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) } if (i != n) { - nxt_log_alert(thr->log, "rbtree unit test failed: %ui", i); + nxt_log_alert(thr->log, "rbtree test failed: %ui", i); goto fail; } @@ -109,21 +109,21 @@ nxt_rbtree_unit_test(nxt_thread_t *thr, nxt_uint_t n) end = nxt_thread_monotonic_time(thr); if (!nxt_rbtree_is_empty(&tree)) { - nxt_log_alert(thr->log, "rbtree unit test failed: tree is not empty"); + nxt_log_alert(thr->log, "rbtree test failed: tree is not empty"); goto fail; } /* Check that the sentinel callback was not modified. */ if (mark != tree.sentinel.right) { - nxt_log_alert(thr->log, "rbtree sentinel unit test failed"); + nxt_log_alert(thr->log, "rbtree sentinel test failed"); goto fail; } nxt_free(keys); nxt_free(items); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree unit test passed %0.3fs", + nxt_log_error(NXT_LOG_NOTICE, thr->log, "rbtree test passed %0.3fs", (end - start) / 1000000000.0); return NXT_OK; @@ -138,7 +138,7 @@ fail: static intptr_t -nxt_rbtree_unit_test_comparison(nxt_rbtree_node_t *node1, +nxt_rbtree_test_comparison(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2) { nxt_rbtree_test_t *item1, *item2; @@ -146,7 +146,7 @@ nxt_rbtree_unit_test_comparison(nxt_rbtree_node_t *node1, item1 = (nxt_rbtree_test_t *) node1; item2 = (nxt_rbtree_test_t *) node2; - return nxt_rbtree_unit_test_compare(item1->key, item2->key); + return nxt_rbtree_test_compare(item1->key, item2->key); } @@ -157,7 +157,7 @@ nxt_rbtree_unit_test_comparison(nxt_rbtree_node_t *node1, */ static nxt_int_t -nxt_rbtree_unit_test_compare(uint32_t key1, uint32_t key2) +nxt_rbtree_test_compare(uint32_t key1, uint32_t key2) { if (key1 < key2) { return -1; @@ -172,7 +172,7 @@ nxt_rbtree_unit_test_compare(uint32_t key1, uint32_t key2) static int nxt_cdecl -nxt_rbtree_unit_test_sort_cmp(const void *one, const void *two) +nxt_rbtree_test_sort_cmp(const void *one, const void *two) { const uint32_t *first, *second; @@ -191,7 +191,7 @@ nxt_rbtree_unit_test_sort_cmp(const void *one, const void *two) } -#if (NXT_UNIT_TEST_RTDTSC) +#if (NXT_TEST_RTDTSC) #define NXT_RBT_STEP (21 * nxt_pagesize / 10 / sizeof(nxt_rbtree_test_t)) @@ -213,7 +213,7 @@ nxt_rbtree_mb_start(nxt_thread_t *thr) return NXT_ERROR; } - nxt_rbtree_init(&mb_tree, nxt_rbtree_unit_test_comparison); + nxt_rbtree_init(&mb_tree, nxt_rbtree_test_comparison); key = 0; diff --git a/test/nxt_sprintf_unit_test.c b/test/nxt_sprintf_test.c index 02434791..7c6e2019 100644 --- a/test/nxt_sprintf_unit_test.c +++ b/test/nxt_sprintf_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" typedef struct { @@ -39,7 +40,7 @@ nxt_sprintf_test_double(u_char *buf, u_char *end, const char *fmt, nxt_int_t -nxt_sprintf_unit_test(nxt_thread_t *thr) +nxt_sprintf_test(nxt_thread_t *thr) { nxt_int_t ret; nxt_uint_t i; @@ -65,6 +66,6 @@ nxt_sprintf_unit_test(nxt_thread_t *thr) return NXT_ERROR; } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "nxt_sprintf() unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "nxt_sprintf() test passed"); return NXT_OK; } diff --git a/test/nxt_term_parse_unit_test.c b/test/nxt_term_parse_test.c index 818d0e19..83ae4931 100644 --- a/test/nxt_term_parse_unit_test.c +++ b/test/nxt_term_parse_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" typedef struct { @@ -33,7 +34,7 @@ static const nxt_term_parse_test_t terms[] = { nxt_int_t -nxt_term_parse_unit_test(nxt_thread_t *thr) +nxt_term_parse_test(nxt_thread_t *thr) { nxt_int_t val; nxt_uint_t i; @@ -48,12 +49,12 @@ nxt_term_parse_unit_test(nxt_thread_t *thr) if (val != terms[i].value) { nxt_log_alert(thr->log, - "term parse unit test failed: \"%V\": %i %i", + "term parse test failed: \"%V\": %i %i", s, terms[i].value, val); return NXT_ERROR; } } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "term parse unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "term parse test passed"); return NXT_OK; } diff --git a/test/nxt_lib_unit_test.c b/test/nxt_tests.c index bac2258e..655192ab 100644 --- a/test/nxt_lib_unit_test.c +++ b/test/nxt_tests.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" extern char **environ; @@ -27,7 +28,7 @@ main(int argc, char **argv) nxt_task_t task; nxt_thread_t *thr; - if (nxt_lib_start("lib_unit_test", argv, &environ) != NXT_OK) { + if (nxt_lib_start("tests", argv, &environ) != NXT_OK) { return 1; } @@ -37,7 +38,7 @@ main(int argc, char **argv) thr = nxt_thread(); thr->task = &task; -#if (NXT_UNIT_TEST_RTDTSC) +#if (NXT_TEST_RTDTSC) if (nxt_process_argv[1] != NULL && nxt_memcmp(nxt_process_argv[1], "rbm", 3) == 0) @@ -50,14 +51,14 @@ main(int argc, char **argv) return 1; } - if (nxt_lvlhsh_unit_test(thr, 500 * 1000, 0) != NXT_OK) { + if (nxt_lvlhsh_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) { + if (nxt_lvlhsh_test(thr, 500 * 1000, 0) != NXT_OK) { return 1; } @@ -69,91 +70,91 @@ main(int argc, char **argv) #endif - if (nxt_random_unit_test(thr) != NXT_OK) { + if (nxt_random_test(thr) != NXT_OK) { return 1; } - if (nxt_term_parse_unit_test(thr) != NXT_OK) { + if (nxt_term_parse_test(thr) != NXT_OK) { return 1; } - if (nxt_msec_diff_unit_test(thr, nxt_msec_less) != NXT_OK) { + if (nxt_msec_diff_test(thr, nxt_msec_less) != NXT_OK) { return 1; } - if (nxt_rbtree_unit_test(thr, 100 * 1000) != NXT_OK) { + if (nxt_rbtree_test(thr, 100 * 1000) != NXT_OK) { return 1; } - if (nxt_rbtree_unit_test(thr, 1000 * 1000) != NXT_OK) { + if (nxt_rbtree_test(thr, 1000 * 1000) != NXT_OK) { return 1; } - if (nxt_rbtree1_unit_test(thr, 100 * 1000) != NXT_OK) { + if (nxt_rbtree1_test(thr, 100 * 1000) != NXT_OK) { return 1; } - if (nxt_rbtree1_unit_test(thr, 1000 * 1000) != NXT_OK) { + if (nxt_rbtree1_test(thr, 1000 * 1000) != NXT_OK) { return 1; } - if (nxt_mp_unit_test(thr, 100, 40000, 128 - 1) != NXT_OK) { + if (nxt_mp_test(thr, 100, 40000, 128 - 1) != NXT_OK) { return 1; } - if (nxt_mp_unit_test(thr, 100, 1000, 4096 - 1) != NXT_OK) { + if (nxt_mp_test(thr, 100, 1000, 4096 - 1) != NXT_OK) { return 1; } - if (nxt_mp_unit_test(thr, 1000, 100, 64 * 1024 - 1) != NXT_OK) { + if (nxt_mp_test(thr, 1000, 100, 64 * 1024 - 1) != NXT_OK) { return 1; } - if (nxt_mem_zone_unit_test(thr, 100, 20000, 128 - 1) != NXT_OK) { + if (nxt_mem_zone_test(thr, 100, 20000, 128 - 1) != NXT_OK) { return 1; } - if (nxt_mem_zone_unit_test(thr, 100, 10000, 4096 - 1) != NXT_OK) { + if (nxt_mem_zone_test(thr, 100, 10000, 4096 - 1) != NXT_OK) { return 1; } - if (nxt_mem_zone_unit_test(thr, 1000, 40, 64 * 1024 - 1) != NXT_OK) { + if (nxt_mem_zone_test(thr, 1000, 40, 64 * 1024 - 1) != NXT_OK) { return 1; } - if (nxt_lvlhsh_unit_test(thr, 2, 1) != NXT_OK) { + if (nxt_lvlhsh_test(thr, 2, 1) != NXT_OK) { return 1; } - if (nxt_lvlhsh_unit_test(thr, 100 * 1000, 1) != NXT_OK) { + if (nxt_lvlhsh_test(thr, 100 * 1000, 1) != NXT_OK) { return 1; } - if (nxt_lvlhsh_unit_test(thr, 100 * 1000, 0) != NXT_OK) { + if (nxt_lvlhsh_test(thr, 100 * 1000, 0) != NXT_OK) { return 1; } - if (nxt_lvlhsh_unit_test(thr, 1000 * 1000, 1) != NXT_OK) { + if (nxt_lvlhsh_test(thr, 1000 * 1000, 1) != NXT_OK) { return 1; } - if (nxt_gmtime_unit_test(thr) != NXT_OK) { + if (nxt_gmtime_test(thr) != NXT_OK) { return 1; } - if (nxt_sprintf_unit_test(thr) != NXT_OK) { + if (nxt_sprintf_test(thr) != NXT_OK) { return 1; } - if (nxt_malloc_unit_test(thr) != NXT_OK) { + if (nxt_malloc_test(thr) != NXT_OK) { return 1; } - if (nxt_utf8_unit_test(thr) != NXT_OK) { + if (nxt_utf8_test(thr) != NXT_OK) { return 1; } - if (nxt_http_parse_unit_test(thr) != NXT_OK) { + if (nxt_http_parse_test(thr) != NXT_OK) { return 1; } diff --git a/test/nxt_tests.h b/test/nxt_tests.h new file mode 100644 index 00000000..508ddbe4 --- /dev/null +++ b/test/nxt_tests.h @@ -0,0 +1,68 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#ifndef _NXT_TESTS_H_INCLUDED_ +#define _NXT_TESTS_H_INCLUDED_ + + +typedef nxt_bool_t (*nxt_msec_less_t)(nxt_msec_t first, nxt_msec_t second); + + +#define NXT_RBT_NODES 1500 + + +#if (__i386__ || __i386 || __amd64__ || __amd64) +#if (NXT_GCC || NXT_CLANG) + +#define NXT_TEST_RTDTSC 1 + +nxt_inline uint64_t +nxt_rdtsc(void) +{ + uint32_t eax, edx; + + __asm__ volatile ("rdtsc" : "=a" (eax), "=d" (edx)); + + return ((uint64_t) edx << 32) | eax; +} + +#endif +#endif + + +nxt_int_t nxt_term_parse_test(nxt_thread_t *thr); +nxt_int_t nxt_msec_diff_test(nxt_thread_t *thr, nxt_msec_less_t); + +nxt_int_t nxt_rbtree_test(nxt_thread_t *thr, nxt_uint_t n); +nxt_int_t nxt_rbtree1_test(nxt_thread_t *thr, nxt_uint_t n); + +#if (NXT_TEST_RTDTSC) + +nxt_int_t nxt_rbtree_mb_start(nxt_thread_t *thr); +void nxt_rbtree_mb_insert(nxt_thread_t *thr); +void nxt_rbtree_mb_delete(nxt_thread_t *thr); + +nxt_int_t nxt_rbtree1_mb_start(nxt_thread_t *thr); +void nxt_rbtree1_mb_insert(nxt_thread_t *thr); +void nxt_rbtree1_mb_delete(nxt_thread_t *thr); + +#endif + +nxt_int_t nxt_mp_test(nxt_thread_t *thr, nxt_uint_t runs, nxt_uint_t nblocks, + size_t max_size); +nxt_int_t nxt_mem_zone_test(nxt_thread_t *thr, nxt_uint_t runs, + nxt_uint_t nblocks, size_t max_size); +nxt_int_t nxt_lvlhsh_test(nxt_thread_t *thr, nxt_uint_t n, + nxt_bool_t use_pool); + +nxt_int_t nxt_gmtime_test(nxt_thread_t *thr); +nxt_int_t nxt_sprintf_test(nxt_thread_t *thr); +nxt_int_t nxt_malloc_test(nxt_thread_t *thr); +nxt_int_t nxt_utf8_test(nxt_thread_t *thr); +nxt_int_t nxt_http_parse_test(nxt_thread_t *thr); + + +#endif /* _NXT_TESTS_H_INCLUDED_ */ diff --git a/test/nxt_utf8_file_name_test.c b/test/nxt_utf8_file_name_test.c index 9eccc147..dc08f7e5 100644 --- a/test/nxt_utf8_file_name_test.c +++ b/test/nxt_utf8_file_name_test.c @@ -140,6 +140,6 @@ nxt_utf8_file_name_test(nxt_thread_t *thr) nxt_file_delete(uc_file.name); } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "utf8 file name unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "utf8 file name test passed"); return NXT_OK; } diff --git a/test/nxt_utf8_unit_test.c b/test/nxt_utf8_test.c index 3bba9681..c7323876 100644 --- a/test/nxt_utf8_unit_test.c +++ b/test/nxt_utf8_test.c @@ -5,6 +5,7 @@ */ #include <nxt_main.h> +#include "nxt_tests.h" #define NXT_UTF8_START_TEST 0xc2 @@ -78,7 +79,7 @@ nxt_utf8_overlong(nxt_thread_t *thr, u_char *overlong, size_t len) nxt_int_t -nxt_utf8_unit_test(nxt_thread_t *thr) +nxt_utf8_test(nxt_thread_t *thr) { u_char *p, utf8[4]; size_t len; @@ -89,7 +90,7 @@ nxt_utf8_unit_test(nxt_thread_t *thr) nxt_thread_time_update(thr); - nxt_log_error(NXT_LOG_NOTICE, thr->log, "utf8 unit test started"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "utf8 test started"); /* Test valid UTF-8. */ @@ -185,6 +186,6 @@ nxt_utf8_unit_test(nxt_thread_t *thr) return NXT_ERROR; } - nxt_log_error(NXT_LOG_NOTICE, thr->log, "utf8 unit test passed"); + nxt_log_error(NXT_LOG_NOTICE, thr->log, "utf8 test passed"); return NXT_OK; } |