diff options
Diffstat (limited to 'usr/src/test')
19 files changed, 1199 insertions, 24 deletions
diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run index 6cc36ee305..801558459a 100644 --- a/usr/src/test/libc-tests/runfiles/default.run +++ b/usr/src/test/libc-tests/runfiles/default.run @@ -60,6 +60,8 @@ outputdir = /var/tmp/test_results [/opt/libc-tests/tests/call_once.32] [/opt/libc-tests/tests/call_once.64] [/opt/libc-tests/tests/catopen] +[/opt/libc-tests/tests/env-OS-4089.32] +[/opt/libc-tests/tests/env-OS-4089.64] [/opt/libc-tests/tests/endian.32] [/opt/libc-tests/tests/endian.64] [/opt/libc-tests/tests/quick_exit] diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index f8e539234c..f6fed9445e 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -29,6 +29,7 @@ SUBDIRS = \ wctype PROGS = \ + env-OS-4089 \ aligned_alloc \ c11_threads \ c11_tss \ diff --git a/usr/src/test/libc-tests/tests/env-OS-4089.c b/usr/src/test/libc-tests/tests/env-OS-4089.c new file mode 100644 index 0000000000..0f52201c79 --- /dev/null +++ b/usr/src/test/libc-tests/tests/env-OS-4089.c @@ -0,0 +1,73 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2016 Joyent, Inc. + */ + +/* + * Regression test for OS-4089 where doing a putenv() call without an '=' sign + * may lead to a segmentation fault when doing a getenv() depending on the + * circumstances of the environment's layout. Verify putenv() mimics + * unsetenv(). + */ + +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <sys/debug.h> + +int +main(void) +{ + if (putenv("FOO=bar") != 0) { + fprintf(stderr, "failed to put FOO into the environment: %s\n", + strerror(errno)); + return (1); + } + + if (getenv("FOO") == NULL) { + fprintf(stderr, "failed to retrieve FOO from the " + "environment!\n"); + return (1); + } + + VERIFY0(unsetenv("FOO")); + + if (getenv("FOO") != NULL) { + fprintf(stderr, "Somehow retrieved FOO from the " + "environment after unsetenv()!\n"); + return (1); + } + + if (putenv("FOO=bar") != 0) { + fprintf(stderr, "failed to put FOO into the environment: %s\n", + strerror(errno)); + return (1); + } + + if (getenv("FOO") == NULL) { + fprintf(stderr, "failed to retrieve FOO from the " + "environment!\n"); + return (1); + } + + VERIFY0(putenv("FOO")); + + if (getenv("FOO") != NULL) { + fprintf(stderr, "Somehow retrieved FOO from the " + "environment after putenv()!\n"); + return (1); + } + + return (0); +} diff --git a/usr/src/test/libc-tests/tests/random/Makefile b/usr/src/test/libc-tests/tests/random/Makefile index ed480dacb9..c1a1a18e1f 100644 --- a/usr/src/test/libc-tests/tests/random/Makefile +++ b/usr/src/test/libc-tests/tests/random/Makefile @@ -17,7 +17,6 @@ include $(SRC)/Makefile.master ROOTOPTPKG = $(ROOT)/opt/libc-tests TESTDIR = $(ROOTOPTPKG)/tests/random -ROOTBINDIR = $(ROOTOPTPKG)/bin PROGS = arc4random \ arc4random_prefork \ @@ -74,17 +73,12 @@ arc4random_preforksig: arc4random_forksig.c $(POST_PROCESS) chacha: chacha_tv.c - $(COMPILE.c) -DKEYSTREAM_ONLY -I$(SRC)/common/crypto/chacha -o chacha.o -c $(SRC)/common/crypto/chacha/chacha.c + $(COMPILE.c) -DKEYSTREAM_ONLY -I$(SRC)/common/crypto/chacha \ + -o chacha.o -c $(SRC)/common/crypto/chacha/chacha.c $(COMPILE.c) -I$(SRC)/common/crypto/chacha -o chacha_tv.o -c chacha_tv.c $(LINK.c) -o $@ chacha_tv.o chacha.o $(LDLIBS) $(POST_PROCESS) -$(ROOTBINDIR): - $(INS.dir) - -$(ROOTBINDIR)/%: % - $(INS.file) - $(TESTDIR): $(INS.dir) diff --git a/usr/src/test/test-runner/cmd/Makefile b/usr/src/test/test-runner/cmd/Makefile index 33e7a61275..948aea9ed8 100644 --- a/usr/src/test/test-runner/cmd/Makefile +++ b/usr/src/test/test-runner/cmd/Makefile @@ -34,4 +34,6 @@ $(ROOTBIN): $(INS.dir) $(ROOTBIN)/%: %.py - $(INS.rename) + $(RM) $@ + $(SED.py) $< > $@ + $(CHMOD) 0555 $@ diff --git a/usr/src/test/test-runner/cmd/run.py b/usr/src/test/test-runner/cmd/run.py index 44bb9a3f5a..0609a89aff 100644 --- a/usr/src/test/test-runner/cmd/run.py +++ b/usr/src/test/test-runner/cmd/run.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.6 +#!ON_PYTHON_26 # # This file and its contents are supplied under the terms of the diff --git a/usr/src/test/util-tests/runfiles/default.run b/usr/src/test/util-tests/runfiles/default.run index 3f7498e23b..dcdbf43f95 100644 --- a/usr/src/test/util-tests/runfiles/default.run +++ b/usr/src/test/util-tests/runfiles/default.run @@ -24,9 +24,14 @@ outputdir = /var/tmp/test_results [/opt/util-tests/tests/printf_test] [/opt/util-tests/tests/allowed-ips] +[/opt/util-tests/tests/vnic-mtu] +[/opt/util-tests/tests/bunyan] [/opt/util-tests/tests/xargs_test] +[/opt/util-tests/tests/mqt] +[/opt/util-tests/tests/wqt] + [/opt/util-tests/tests/libnvpair_json] tests = ['json_00_blank', 'json_01_boolean', 'json_02_numbers', 'json_03_empty_arrays', 'json_04_number_arrays', 'json_05_strings', diff --git a/usr/src/test/util-tests/tests/Makefile b/usr/src/test/util-tests/tests/Makefile index 4709c7adcd..739b79893f 100644 --- a/usr/src/test/util-tests/tests/Makefile +++ b/usr/src/test/util-tests/tests/Makefile @@ -14,7 +14,6 @@ # Copyright 2014 Garrett D'Amore <garrett@damore.org> # -SUBDIRS = dladm printf xargs -SUBDIRS = dladm libnvpair_json printf xargs +SUBDIRS = dladm libnvpair_json printf xargs mergeq workq include $(SRC)/test/Makefile.com diff --git a/usr/src/test/util-tests/tests/bunyan/Makefile b/usr/src/test/util-tests/tests/bunyan/Makefile new file mode 100644 index 0000000000..5f58bf1614 --- /dev/null +++ b/usr/src/test/util-tests/tests/bunyan/Makefile @@ -0,0 +1,68 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2015 Joyent, Inc. +# + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/util-tests +TESTDIR = $(ROOTOPTPKG)/tests/bunyan +TESTBIN = $(ROOTOPTPKG)/bin + +PROG = btest + +SCRIPTS = \ + bunyan + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/test/Makefile.com + +OBJS = $(PROG:%=%.o) +SRCS = $(OBJS:%.o=%.c) + +CMDS = $(PROG:%=$(TESTBIN)/%) $(SCRIPTS:%=$(TESTDIR)/%) +$(CMDS) := FILEMODE = 0555 + +DIRS = $(TESTDIR) $(TESTBIN) + +LDLIBS += -lbunyan + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +install: all $(CMDS) + +lint: + +clobber: clean + -$(RM) $(PROG) + +clean: + -$(RM) $(OBJS) + +$(CMDS): $(DIRS) + +$(DIRS): + $(INS.dir) + +$(TESTDIR)/%: %.ksh + $(INS.rename) + +$(TESTDIR)/%: % + $(INS.file) + +$(TESTBIN)/%: % + $(INS.file) diff --git a/usr/src/test/util-tests/tests/bunyan/btest.c b/usr/src/test/util-tests/tests/bunyan/btest.c new file mode 100644 index 0000000000..5239e91f1e --- /dev/null +++ b/usr/src/test/util-tests/tests/bunyan/btest.c @@ -0,0 +1,312 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2014, Joyent, Inc. + */ + +#include <stdio.h> +#include <assert.h> +#include <bunyan.h> +#include <netinet/in.h> +#include <strings.h> + +static void +create_handles(void) +{ + bunyan_logger_t *a, *b, *c; + + assert(bunyan_init("foo", &a) == 0); + assert(bunyan_init("foo", &b) == 0); + assert(bunyan_init("foo", &c) == 0); + bunyan_fini(a); + bunyan_fini(b); + bunyan_fini(c); +} + +static void +create_stream(void) +{ + bunyan_logger_t *a; + + assert(bunyan_init("foo", &a) == 0); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "baz", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == EEXIST); + assert(bunyan_stream_add(a, "baz", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == EEXIST); + assert(bunyan_stream_remove(a, "baz") == 0); + assert(bunyan_stream_remove(a, "baz") == ENOENT); + assert(bunyan_stream_remove(a, "foobaz") == ENOENT); + assert(bunyan_stream_remove(a, "blah") == ENOENT); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == EEXIST); + assert(bunyan_stream_add(a, "baz", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "debug", BUNYAN_L_DEBUG, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "info", BUNYAN_L_INFO, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "warn", BUNYAN_L_WARN, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "error", BUNYAN_L_ERROR, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_stream_add(a, "fatal", BUNYAN_L_FATAL, + bunyan_stream_fd, (void *)1) == 0); + + bunyan_fini(a); +} + +static void +create_key(void) +{ + bunyan_logger_t *a; + struct in_addr v4; + struct in6_addr v6; + + assert(bunyan_init("foo", &a) == 0); + assert(bunyan_key_remove(a, "blah") == ENOENT); + assert(bunyan_key_add(a, BUNYAN_T_END) == 0); + + assert(bunyan_key_add(a, BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + + assert(bunyan_key_remove(a, "s") == 0); + assert(bunyan_key_remove(a, "s") == ENOENT); + assert(bunyan_key_remove(a, "p") == 0); + assert(bunyan_key_remove(a, "p") == ENOENT); + assert(bunyan_key_remove(a, "v4") == 0); + assert(bunyan_key_remove(a, "v4") == ENOENT); + assert(bunyan_key_remove(a, "v6") == 0); + assert(bunyan_key_remove(a, "v6") == ENOENT); + assert(bunyan_key_remove(a, "b") == 0); + assert(bunyan_key_remove(a, "b") == ENOENT); + assert(bunyan_key_remove(a, "i32") == 0); + assert(bunyan_key_remove(a, "i32") == ENOENT); + assert(bunyan_key_remove(a, "i64") == 0); + assert(bunyan_key_remove(a, "i64") == ENOENT); + assert(bunyan_key_remove(a, "u32") == 0); + assert(bunyan_key_remove(a, "u32") == ENOENT); + assert(bunyan_key_remove(a, "u64") == 0); + assert(bunyan_key_remove(a, "u64") == ENOENT); + assert(bunyan_key_remove(a, "d") == 0); + assert(bunyan_key_remove(a, "d") == ENOENT); + assert(bunyan_key_remove(a, "i64s") == 0); + assert(bunyan_key_remove(a, "i64s") == ENOENT); + assert(bunyan_key_remove(a, "u64s") == 0); + assert(bunyan_key_remove(a, "u64s") == ENOENT); + + bunyan_fini(a); +} + +static void +bad_level(void) +{ + bunyan_logger_t *a; + + assert(bunyan_init("bad level", &a) == 0); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_TRACE - 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_TRACE + 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_DEBUG - 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_INFO + 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_WARN - 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_ERROR + 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", BUNYAN_L_FATAL - 1, + bunyan_stream_fd, (void *)1) == EINVAL); + assert(bunyan_stream_add(a, "bar", -5, + bunyan_stream_fd, (void *)1) == EINVAL); + + bunyan_fini(a); +} + +static void +basic_log(void) +{ + bunyan_logger_t *a; + + assert(bunyan_init("basic", &a) == 0); + assert(bunyan_stream_add(a, "foo", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_trace(a, "trace", BUNYAN_T_END) == 0); + assert(bunyan_debug(a, "debug", BUNYAN_T_END) == 0); + assert(bunyan_info(a, "info", BUNYAN_T_END) == 0); + assert(bunyan_warn(a, "warn", BUNYAN_T_END) == 0); + assert(bunyan_error(a, "error", BUNYAN_T_END) == 0); + assert(bunyan_fatal(a, "fatal", BUNYAN_T_END) == 0); + + bunyan_fini(a); +} + +static void +crazy_log(void) +{ + bunyan_logger_t *a; + struct in_addr v4; + struct in6_addr v6; + + bzero(&v4, sizeof (struct in_addr)); + bzero(&v6, sizeof (struct in6_addr)); + + assert(bunyan_init("basic", &a) == 0); + assert(bunyan_stream_add(a, "foo", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_trace(a, "trace", BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + assert(bunyan_debug(a, "debug", BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + assert(bunyan_info(a, "info", BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + assert(bunyan_warn(a, "warn", BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + assert(bunyan_error(a, "error", BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + assert(bunyan_fatal(a, "fatal", BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + + bunyan_fini(a); +} + +static void +child_log(void) +{ + bunyan_logger_t *a, *child; + struct in_addr v4; + struct in6_addr v6; + + bzero(&v4, sizeof (struct in_addr)); + bzero(&v6, sizeof (struct in6_addr)); + + assert(bunyan_init("child", &a) == 0); + assert(bunyan_stream_add(a, "foo", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_child(a, &child, BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + + bunyan_fini(a); + assert(bunyan_trace(child, "trace", BUNYAN_T_END) == 0); + assert(bunyan_debug(child, "debug", BUNYAN_T_END) == 0); + assert(bunyan_info(child, "info", BUNYAN_T_END) == 0); + assert(bunyan_warn(child, "warn", BUNYAN_T_END) == 0); + assert(bunyan_error(child, "error", BUNYAN_T_END) == 0); + assert(bunyan_fatal(child, "fatal", BUNYAN_T_END) == 0); + + bunyan_fini(child); +} + +static void +crazy_child(void) +{ + bunyan_logger_t *a, *child; + struct in_addr v4; + struct in6_addr v6; + + bzero(&v4, sizeof (struct in_addr)); + bzero(&v6, sizeof (struct in6_addr)); + + assert(bunyan_init("crazy child", &a) == 0); + assert(bunyan_stream_add(a, "foo", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_key_add(a, BUNYAN_T_STRING, "s", "foo", + BUNYAN_T_POINTER, "p", (void *)a, BUNYAN_T_IP, "v4", &v4, + BUNYAN_T_IP6, "v6", &v6, BUNYAN_T_BOOLEAN, "b", B_TRUE, + BUNYAN_T_INT32, "i32", 69, BUNYAN_T_INT64, "i64", (uint64_t)6969, + BUNYAN_T_UINT32, "u32", 23, BUNYAN_T_UINT64, "u64", (uint64_t)2323, + BUNYAN_T_DOUBLE, "d", 3.14, + BUNYAN_T_INT64STR, "i64s", (uint64_t)12345, + BUNYAN_T_UINT64STR, "u64s", (uint64_t)54321, BUNYAN_T_END) == 0); + assert(bunyan_child(a, &child, BUNYAN_T_END) == 0); + bunyan_fini(a); + + assert(bunyan_stream_remove(child, "foo") == 0); + assert(bunyan_stream_add(child, "bar", BUNYAN_L_TRACE, + bunyan_stream_fd, (void *)1) == 0); + assert(bunyan_key_remove(child, "u64s") == 0); + assert(bunyan_trace(child, "trace", BUNYAN_T_END) == 0); + assert(bunyan_debug(child, "debug", BUNYAN_T_END) == 0); + assert(bunyan_info(child, "info", BUNYAN_T_END) == 0); + assert(bunyan_warn(child, "warn", BUNYAN_T_END) == 0); + assert(bunyan_error(child, "error", BUNYAN_T_END) == 0); + assert(bunyan_fatal(child, "fatal", BUNYAN_T_END) == 0); + + bunyan_fini(child); +} + +int +main(void) +{ + create_handles(); + create_stream(); + create_key(); + bad_level(); + basic_log(); + crazy_log(); + child_log(); + crazy_child(); + + return (0); +} diff --git a/usr/src/test/util-tests/tests/bunyan/bunyan.ksh b/usr/src/test/util-tests/tests/bunyan/bunyan.ksh new file mode 100644 index 0000000000..4ec0f4bd62 --- /dev/null +++ b/usr/src/test/util-tests/tests/bunyan/bunyan.ksh @@ -0,0 +1,26 @@ +#! /usr/bin/ksh +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2014, Joyent, Inc. +# + +# +# Simple wrapper for the classic test.out +# + +set -o errexit + +btest_root=$(dirname $0)/../.. +btest_bin=$btest_root/bin/btest + +LD_PRELOAD=libumem.so UMEM_DEBUG=default $btest_bin >/dev/null diff --git a/usr/src/test/util-tests/tests/dladm/Makefile b/usr/src/test/util-tests/tests/dladm/Makefile index df3997656c..a71332b016 100644 --- a/usr/src/test/util-tests/tests/dladm/Makefile +++ b/usr/src/test/util-tests/tests/dladm/Makefile @@ -17,7 +17,7 @@ include $(SRC)/cmd/Makefile.cmd include $(SRC)/test/Makefile.com ROOTOPTPKG = $(ROOT)/opt/util-tests/tests -PROG = allowed-ips +PROG = allowed-ips vnic-mtu ROOTPROG = $(PROG:%=$(ROOTOPTPKG)/%) diff --git a/usr/src/test/util-tests/tests/dladm/vnic-mtu.ksh b/usr/src/test/util-tests/tests/dladm/vnic-mtu.ksh new file mode 100644 index 0000000000..49daa74f3b --- /dev/null +++ b/usr/src/test/util-tests/tests/dladm/vnic-mtu.ksh @@ -0,0 +1,116 @@ +#!/bin/ksh +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2015 Joyent, Inc. +# + +# +# The purpose of this is to test the MTU property on VNICs, using both +# temporary and persistent properties. To do this, we create an +# Etherstub and then create various VNICs on top of it. +# + +vm_arg0="$(basename $0)" +vm_stub="teststub$$" +vm_vnic="testvnic$$" + +VM_MTU_MIN=576 +VM_MTU_MAX=9000 + +fatal() +{ + typeset msg="$*" + [[ -z "$msg" ]] && msg="failed" + echo "TEST_FAIL: $vm_arg0: $msg" >&2 + + # Try to clean up just in case + dladm delete-vnic $vm_vnic 2>/dev/null + dladm delete-etherstub $vm_stub 2>/dev/null + exit 1 +} + +# +# Validate that the MTU of the datalink dev has the MTU that we expect +# +validate_mtu() +{ + typeset dev=$1 + typeset mtu=$2 + typeset val + + [[ -z "$dev" ]] && fatal "missing required device" + [[ -z "$mtu" ]] && fatal "missing required mtu" + val=$(dladm show-linkprop -c -p mtu -o value $dev) + [[ $? -eq 0 ]] || fatal "failed to get MTU for $dev" + (( $val == $mtu )) || fatal \ + "mtu mismatch on $dev: expected $mtu, got $val" +} + +delete_stub() +{ + dladm delete-etherstub $vm_stub || fatal \ + "failed to delete stub $vm_stub" +} + +create_stub() +{ + dladm create-etherstub $vm_stub || fatal \ + "failed to create stub" + validate_mtu $vm_stub $VM_MTU_MAX +} + +delete_vnic() +{ + dladm delete-vnic $vm_vnic || fatal "failed to delete vnic $vm_vnic" +} + +test_vnic_pass() +{ + typeset mtu=$1 + typeset flags=$2 + + [[ -z "$mtu" ]] && fatal "missing required mtu" + dladm create-vnic $flags -l $vm_stub -p mtu=$mtu $vm_vnic || fatal \ + "failed tocreate vnic: $vm_vnic" + validate_mtu "$vm_vnic" "$mtu" + delete_vnic +} + +test_vnic_fail() +{ + typeset mtu=$1 + typeset flags=$2 + + [[ -z "$mtu" ]] && fatal "missing required mtu" + dladm create-vnic $flags -l $vm_stub -p mtu=$mtu \ + $vm_vnic 2>/dev/null && fatal \ + "created vnic with mtu $mtu, but failure expected" +} + +test_pass() +{ + typeset flags=$1 + + create_stub + test_vnic_pass 1500 $flags + test_vnic_pass 1400 $flags + test_vnic_pass $VM_MTU_MIN $flags + test_vnic_pass $VM_MTU_MAX $flags + test_vnic_fail $((($VM_MTU_MIN - 1))) $flags + test_vnic_fail $((($VM_MTU_MAX + 1))) $flags + delete_stub +} + +test_pass "-t" +test_pass +echo "TEST PASS: $vm_arg0" diff --git a/usr/src/test/util-tests/tests/libnvpair_json/Makefile b/usr/src/test/util-tests/tests/libnvpair_json/Makefile index d1d3585b02..3b48e0b630 100644 --- a/usr/src/test/util-tests/tests/libnvpair_json/Makefile +++ b/usr/src/test/util-tests/tests/libnvpair_json/Makefile @@ -10,14 +10,14 @@ # # -# Copyright (c) 2014 Joyent, Inc. +# Copyright 2015 Joyent, Inc. # include $(SRC)/Makefile.master ROOTOPTPKG = $(ROOT)/opt/util-tests TESTDIR = $(ROOTOPTPKG)/tests/libnvpair_json -ROOTBINDIR = $(ROOTOPTPKG)/bin +TESTBIN = $(ROOTOPTPKG)/bin PROG = print_json @@ -38,9 +38,11 @@ include $(SRC)/test/Makefile.com OBJS = $(PROG:%=%.o) SRCS = $(OBJS:%.o=%.c) -CMDS = $(PROG:%=$(ROOTBINDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%) +CMDS = $(PROG:%=$(TESTBIN)/%) $(SCRIPTS:%=$(TESTDIR)/%) $(CMDS) := FILEMODE = 0555 +DIRS = $(TESTDIR) $(TESTBIN) + LDLIBS += -lnvpair LINTFLAGS += -erroff=E_FUNC_ARG_UNUSED @@ -61,16 +63,13 @@ clobber: clean clean: -$(RM) $(OBJS) -$(CMDS): $(TESTDIR) $(PROG) +$(CMDS): $(DIRS) -$(ROOTBINDIR): - $(INS.dir) - -$(ROOTBINDIR)/%: % - $(INS.file) - -$(TESTDIR): +$(DIRS): $(INS.dir) $(TESTDIR)/%: %.ksh $(INS.rename) + +$(TESTBIN)/%: % + $(INS.file) diff --git a/usr/src/test/util-tests/tests/libnvpair_json/json_08_large_data.ksh b/usr/src/test/util-tests/tests/libnvpair_json/json_08_large_data.ksh new file mode 100644 index 0000000000..ca19e10d06 --- /dev/null +++ b/usr/src/test/util-tests/tests/libnvpair_json/json_08_large_data.ksh @@ -0,0 +1,37 @@ +#!/bin/ksh +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2015, Joyent, Inc. +# + +DIR=$(dirname $(whence $0)) +. ${DIR}/json_common + +BASELINE="$(cat <<EOF +{\ +"o":[\ +$(for i in {1..50}; do + printf '"%s",' 'some_very_big_string_that_takes_up_space' +done)\ +"end"\ +]\ +} +EOF)" + +OUTPUT="$(${DIR}/../../bin/print_json <<-EOF +add_string_array "o" $(for i in {1..50}; do + printf '"%s" ' 'some_very_big_string_that_takes_up_space' +done)"end"; +EOF)" + +complete diff --git a/usr/src/test/util-tests/tests/mergeq/Makefile b/usr/src/test/util-tests/tests/mergeq/Makefile new file mode 100644 index 0000000000..ef6c6abb99 --- /dev/null +++ b/usr/src/test/util-tests/tests/mergeq/Makefile @@ -0,0 +1,64 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2015 Joyent, Inc. +# + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/util-tests +TESTDIR = $(ROOTOPTPKG)/tests/mergeq + +PROG = mqt +OBJS = mqt.o mergeq.o + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/cmd/Makefile.ctf +include $(SRC)/test/Makefile.com + +CMDS = $(PROG:%=$(TESTDIR)/%) +$(CMDS) := FILEMODE = 0555 + +CPPFLAGS += -I$(SRC)/lib/mergeq -D_REENTRANT +LDLIBS += -lumem + +all: $(PROG) + +install: all $(CMDS) + +lint: lint_SRCS + +clobber: clean + -$(RM) $(PROG) + +clean: + -$(RM) $(OBJS) + +%.o: %.c + $(COMPILE.c) -o $@ -c $< + $(POST_PROCESS_O) + +%.o: $(SRC)/lib/mergeq/%.c + $(COMPILE.c) -o $@ -c $< + $(POST_PROCESS_O) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +$(CMDS): $(TESTDIR) $(PROG) + +$(TESTDIR): + $(INS.dir) + +$(TESTDIR)/%: % + $(INS.file) diff --git a/usr/src/test/util-tests/tests/mergeq/mqt.c b/usr/src/test/util-tests/tests/mergeq/mqt.c new file mode 100644 index 0000000000..e61e9173d2 --- /dev/null +++ b/usr/src/test/util-tests/tests/mergeq/mqt.c @@ -0,0 +1,217 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2015 Joyent, Inc. + */ + +/* + * mergeq testing routines + */ + +#include <mergeq.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> + +const char * +_umem_debug_init() +{ + return ("default,verbose"); +} + +const char * +_umem_logging_init(void) +{ + return ("fail,contents"); +} + +void * +mergeq_alloc(size_t size) +{ + return (malloc(size)); +} + +/*ARGSUSED*/ +void +mergeq_free(void *buf, size_t size) +{ + free(buf); +} + +static int +mqt_int(void *first, void *second, void **outp, void *arg) +{ + uintptr_t a, b, c; + a = (uintptr_t)first; + b = (uintptr_t)second; + c = a + b; + *outp = (void *)c; + + return (0); +} + +static int +mqt_append(void *first, void *second, void **outp, void *arg) +{ + char *out; + + /* Yes, this leaks, don't worry about it for the test */ + if (asprintf(&out, "%s%s", first, second) != -1) { + *outp = out; + return (0); + } + return (-1); +} + +static int +mqt_fatal(void *first, void *second, void **outp, void *arg) +{ + return (-1); +} + +/* + * Test structures and cases. We really want mq_args to be a flexible array + * member, but then we cant initialize it. Thus we set a fixed size number of + * entries. + */ +typedef struct mq_test { + const char *mq_desc; /* test description/name */ + mergeq_proc_f *mq_proc; /* processing function */ + int mq_rval; /* mergeq_merge return value */ + int mq_uerr; /* user error, if any */ + boolean_t mq_strcmp; /* use strcmp rather than == */ + void *mq_result; /* expected result */ + void **mq_args; /* argument array */ +} mq_test_t; + +static void *mqt_empty_args[] = { NULL }; +static void *mqt_single_args[] = { (void *)42, NULL }; +static void *mqt_double_args[] = { (void *)42, (void *)27, NULL }; +static void *mqt_wrap_args[] = { + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, NULL +}; +static void *mqt_grow_args[] = { + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, NULL +}; +static void *mqt_order_args[] = { "l", "e", "g", "e", "n", "d", " ", "o", "f", + " ", "z", "e", "l", "d", "a", NULL }; + + +static mq_test_t mq_tests[] = { + { "empty", mqt_int, 0, 0, B_FALSE, NULL, mqt_empty_args }, + { "single", mqt_int, 0, 0, B_FALSE, (void *)42, mqt_single_args }, + { "double", mqt_int, 0, 0, B_FALSE, (void *)69, mqt_double_args }, + { "wrap", mqt_int, 0, 0, B_FALSE, (void *)64, mqt_wrap_args }, + { "grow", mqt_int, 0, 0, B_FALSE, (void *)92, mqt_grow_args }, + { "fatal", mqt_fatal, MERGEQ_UERROR, -1, B_FALSE, NULL, + mqt_double_args }, + { "order", mqt_append, 0, 0, B_TRUE, "alegend of zeld", mqt_order_args } +}; + +#define NMQ_TESTS (sizeof (mq_tests) / sizeof (mq_test_t)) + +static void +mq_test_run(mergeq_t *mqp, mq_test_t *mqt) +{ + int ret, err; + void **itemp = mqt->mq_args; + void *out; + + while (*itemp != NULL) { + if ((ret = mergeq_add(mqp, *itemp)) != 0) { + (void) fprintf(stderr, + "test %s: failed to add item: %s\n", + mqt->mq_desc, strerror(errno)); + exit(1); + } + itemp++; + } + + ret = mergeq_merge(mqp, mqt->mq_proc, NULL, &out, &err); + if (ret != mqt->mq_rval) { + (void) fprintf(stderr, "test %s: got incorrect rval. " + "Expected %d, got %d\n", mqt->mq_desc, mqt->mq_rval, ret); + exit(1); + } + + if (ret == MERGEQ_UERROR && err != mqt->mq_uerr) { + (void) fprintf(stderr, "test %s: got incorrect user error. " + "Expected %d, got %d\n", mqt->mq_desc, mqt->mq_uerr, err); + exit(1); + } + + if (ret == 0) { + if (mqt->mq_strcmp == B_TRUE && + strcmp(out, mqt->mq_result) != 0) { + (void) fprintf(stderr, "test %s: got unexpected " + "result: %s, expected %s\n", mqt->mq_desc, out, + mqt->mq_result); + exit(1); + } else if (mqt->mq_strcmp == B_FALSE && out != mqt->mq_result) { + (void) fprintf(stderr, "test %s: got unexpected " + "result: %p, expected %p\n", mqt->mq_desc, out, + mqt->mq_result); + exit(1); + } + } +} + +int +main(void) +{ + int ret, i, t; + mergeq_t *mqp; + int nthreads[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, -1 }; + + for (t = 0; nthreads[t] != -1; t++) { + printf("Beginning tests with %d threads\n", nthreads[t]); + if ((ret = mergeq_init(&mqp, nthreads[t])) != 0) { + fprintf(stderr, "failed to init mergeq: %s\n", + strerror(errno)); + return (1); + } + + for (i = 0; i < NMQ_TESTS; i++) { + mq_test_run(mqp, &mq_tests[i]); + } + + mergeq_fini(mqp); + } + + return (0); +} diff --git a/usr/src/test/util-tests/tests/workq/Makefile b/usr/src/test/util-tests/tests/workq/Makefile new file mode 100644 index 0000000000..ab5455fd86 --- /dev/null +++ b/usr/src/test/util-tests/tests/workq/Makefile @@ -0,0 +1,64 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2015 Joyent, Inc. +# + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/util-tests +TESTDIR = $(ROOTOPTPKG)/tests/mergeq + +PROG = wqt +OBJS = wqt.o workq.o + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/cmd/Makefile.ctf +include $(SRC)/test/Makefile.com + +CMDS = $(PROG:%=$(TESTDIR)/%) +$(CMDS) := FILEMODE = 0555 + +CPPFLAGS += -I$(SRC)/lib/mergeq -D_REENTRANT +LDLIBS += -lumem + +all: $(PROG) + +install: all $(CMDS) + +lint: lint_SRCS + +clobber: clean + -$(RM) $(PROG) + +clean: + -$(RM) $(OBJS) + +%.o: %.c + $(COMPILE.c) -o $@ -c $< + $(POST_PROCESS_O) + +%.o: $(SRC)/lib/mergeq/%.c + $(COMPILE.c) -o $@ -c $< + $(POST_PROCESS_O) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +$(CMDS): $(TESTDIR) $(PROG) + +$(TESTDIR): + $(INS.dir) + +$(TESTDIR)/%: % + $(INS.file) diff --git a/usr/src/test/util-tests/tests/workq/wqt.c b/usr/src/test/util-tests/tests/workq/wqt.c new file mode 100644 index 0000000000..bda0b4a9e5 --- /dev/null +++ b/usr/src/test/util-tests/tests/workq/wqt.c @@ -0,0 +1,196 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2015 Joyent, Inc. + */ + +/* + * workq testing routines + * + * What we want to guarantee is that every function is executed exactly once. To + * that end we have the callback function basically increment a global in the + * test around a mutex. + */ + +#include <workq.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <thread.h> +#include <synch.h> + +mutex_t wqt_lock = ERRORCHECKMUTEX; +uintptr_t wqt_count; + +const char * +_umem_debug_init() +{ + return ("default,verbose"); +} + +const char * +_umem_logging_init(void) +{ + return ("fail,contents"); +} + +void * +workq_alloc(size_t size) +{ + return (malloc(size)); +} + +/*ARGSUSED*/ +void +workq_free(void *buf, size_t size) +{ + free(buf); +} + +/*ARGSUSED*/ +int +wqt_fatal(void *item, void *arg) +{ + return (-1); +} + +int +wqt_add(void *item, void *arg) +{ + uintptr_t a = (uintptr_t)item; + + mutex_enter(&wqt_lock); + wqt_count += a; + mutex_exit(&wqt_lock); + + return (0); +} + +typedef struct wq_test { + const char *wq_desc; /* test description/name */ + workq_proc_f *wq_proc; /* processing function */ + int wq_rval; /* workq_work return value */ + int wq_uerr; /* user error, if any */ + uintptr_t wq_sum; /* expected sum */ + void **wq_args; /* argument array */ +} wq_test_t; + +static void *wqt_empty_args[] = { NULL }; +static void *wqt_single_args[] = { (void *)42, NULL }; +static void *wqt_double_args[] = { (void *)42, (void *)27, NULL }; +static void *wqt_wrap_args[] = { + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, NULL +}; +static void *wqt_grow_args[] = { + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, (void *)1, + (void *)1, (void *)1, NULL +}; + +static wq_test_t wq_tests[] = { + { "empty", wqt_add, 0, 0, NULL, wqt_empty_args }, + { "single", wqt_add, 0, 0, 42, wqt_single_args }, + { "double", wqt_add, 0, 0, 69, wqt_double_args }, + { "wrap", wqt_add, 0, 0, 64, wqt_wrap_args }, + { "grow", wqt_add, 0, 0, 92, wqt_grow_args }, + { "fatal", wqt_fatal, WORKQ_UERROR, -1, -1, wqt_double_args } +}; + +#define NWQ_TESTS (sizeof (wq_tests) / sizeof (wq_test_t)) + +static void +wq_test_run(workq_t *wqp, wq_test_t *wqt) +{ + int ret, err; + void **itemp = wqt->wq_args; + + while (*itemp != NULL) { + if ((ret = workq_add(wqp, *itemp)) != 0) { + (void) fprintf(stderr, "test %s: failed to add item: " + "%s\n", wqt->wq_desc, strerror(errno)); + exit(1); + } + itemp++; + } + + wqt_count = 0; + ret = workq_work(wqp, wqt->wq_proc, NULL, &err); + if (ret != wqt->wq_rval) { + (void) fprintf(stderr, "test %s: got incorrect rval. " + "Expected %d, got %d (%d)\n", wqt->wq_desc, wqt->wq_rval, + ret, errno); + exit(1); + } + + if (ret == WORKQ_UERROR && err != wqt->wq_uerr) { + (void) fprintf(stderr, "test %s: got incorrect user error. " + "Expected %d, got %d\n", wqt->wq_desc, wqt->wq_uerr, err); + exit(1); + } + + if (ret == 0 && wqt_count != wqt->wq_sum) { + (void) fprintf(stderr, "test %s: got unexpected " + "result: %d, expected %d\n", wqt->wq_desc, wqt_count, + wqt->wq_sum); + exit(1); + } +} + +int +main(void) +{ + int ret, i, t; + workq_t *wqp; + int nthreads[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, -1 }; + + for (t = 0; nthreads[t] != -1; t++) { + printf("Beginning tests with %d threads\n", nthreads[t]); + if ((ret = workq_init(&wqp, nthreads[t])) != 0) { + fprintf(stderr, "failed to init workq: %s\n", + strerror(errno)); + return (1); + } + + for (i = 0; i < NWQ_TESTS; i++) { + wq_test_run(wqp, &wq_tests[i]); + } + + workq_fini(wqp); + } + + + return (0); +} |