summaryrefslogtreecommitdiff
path: root/usr/src/test/libc-tests/tests
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/test/libc-tests/tests')
-rw-r--r--usr/src/test/libc-tests/tests/Makefile3
-rw-r--r--usr/src/test/libc-tests/tests/err/Makefile59
-rw-r--r--usr/src/test/libc-tests/tests/err/data/E.0.3.46
-rw-r--r--usr/src/test/libc-tests/tests/err/data/E.1.5.66
-rw-r--r--usr/src/test/libc-tests/tests/err/data/E.2.7.86
-rw-r--r--usr/src/test/libc-tests/tests/err/data/E.3.9.106
-rw-r--r--usr/src/test/libc-tests/tests/err/data/E.4.11.126
-rw-r--r--usr/src/test/libc-tests/tests/err/data/E.5.13.146
-rw-r--r--usr/src/test/libc-tests/tests/err/data/W.0.3.46
-rw-r--r--usr/src/test/libc-tests/tests/err/data/W.1.5.66
-rw-r--r--usr/src/test/libc-tests/tests/err/data/W.2.7.86
-rw-r--r--usr/src/test/libc-tests/tests/err/data/W.3.9.106
-rw-r--r--usr/src/test/libc-tests/tests/err/data/W.4.11.126
-rw-r--r--usr/src/test/libc-tests/tests/err/data/W.5.13.146
-rw-r--r--usr/src/test/libc-tests/tests/err/err.c190
-rwxr-xr-xusr/src/test/libc-tests/tests/err/err.ksh90
16 files changed, 413 insertions, 1 deletions
diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile
index 16e4236a9f..16c002e0ef 100644
--- a/usr/src/test/libc-tests/tests/Makefile
+++ b/usr/src/test/libc-tests/tests/Makefile
@@ -13,11 +13,12 @@
# Copyright (c) 2012 by Delphix. All rights reserved.
# Copyright 2015 Garrett D'Amore <garrett@damore.org>
# Copyright 2019 Joyent, Inc.
-# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
+# Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
#
SUBDIRS = \
catopen \
+ err \
fpround \
i18n \
newlocale \
diff --git a/usr/src/test/libc-tests/tests/err/Makefile b/usr/src/test/libc-tests/tests/err/Makefile
new file mode 100644
index 0000000000..0ead20c66c
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/Makefile
@@ -0,0 +1,59 @@
+#
+# 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 2022 OmniOS Community Edition (OmniOSce) Association.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/libc-tests
+TESTDIR = $(ROOTOPTPKG)/tests/err
+DATADIR= $(TESTDIR)/data
+
+PROGS = err
+SCRIPTS = err.ksh
+DATA :sh= (cd data; print *)
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%)
+TESTDATA= $(DATA:%=$(DATADIR)/%)
+
+$(CMDS) := FILEMODE = 0555
+$(TESTDATA) := FILEMODE = 0444
+
+CSTD = $(CSTD_GNU99)
+
+all: $(PROGS)
+
+install: all $(CMDS) $(TESTDATA)
+
+clobber: clean
+ -$(RM) $(PROGS)
+
+clean:
+ -$(RM) *.o
+
+$(CMDS): $(TESTDIR) $(PROGS)
+
+$(TESTDATA): $(DATADIR)
+
+$(TESTDIR) $(DATADIR):
+ $(INS.dir)
+
+$(TESTDIR)/%: %
+ $(INS.file)
+
+$(DATADIR)/%: data/%
+ $(INS.file)
+
diff --git a/usr/src/test/libc-tests/tests/err/data/E.0.3.4 b/usr/src/test/libc-tests/tests/err/data/E.0.3.4
new file mode 100644
index 0000000000..007e296a31
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/E.0.3.4
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: E/0/4: No such process
+::EXIT::
+4
diff --git a/usr/src/test/libc-tests/tests/err/data/E.1.5.6 b/usr/src/test/libc-tests/tests/err/data/E.1.5.6
new file mode 100644
index 0000000000..a6bd4581ce
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/E.1.5.6
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: E/1/6: I/O error
+::EXIT::
+6
diff --git a/usr/src/test/libc-tests/tests/err/data/E.2.7.8 b/usr/src/test/libc-tests/tests/err/data/E.2.7.8
new file mode 100644
index 0000000000..292a5da1da
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/E.2.7.8
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: E/2/8
+::EXIT::
+8
diff --git a/usr/src/test/libc-tests/tests/err/data/E.3.9.10 b/usr/src/test/libc-tests/tests/err/data/E.3.9.10
new file mode 100644
index 0000000000..2e3dc109b6
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/E.3.9.10
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: E/3/10: Bad file number
+::EXIT::
+10
diff --git a/usr/src/test/libc-tests/tests/err/data/E.4.11.12 b/usr/src/test/libc-tests/tests/err/data/E.4.11.12
new file mode 100644
index 0000000000..67541715f1
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/E.4.11.12
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: E/4/12: Resource temporarily unavailable
+::EXIT::
+12
diff --git a/usr/src/test/libc-tests/tests/err/data/E.5.13.14 b/usr/src/test/libc-tests/tests/err/data/E.5.13.14
new file mode 100644
index 0000000000..9432ba855d
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/E.5.13.14
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: E/5/14
+::EXIT::
+14
diff --git a/usr/src/test/libc-tests/tests/err/data/W.0.3.4 b/usr/src/test/libc-tests/tests/err/data/W.0.3.4
new file mode 100644
index 0000000000..d3c1b1cd9d
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/W.0.3.4
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: W/0: No such process
+::EXIT::
+0
diff --git a/usr/src/test/libc-tests/tests/err/data/W.1.5.6 b/usr/src/test/libc-tests/tests/err/data/W.1.5.6
new file mode 100644
index 0000000000..45eb11ed5e
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/W.1.5.6
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: W/1: I/O error
+::EXIT::
+0
diff --git a/usr/src/test/libc-tests/tests/err/data/W.2.7.8 b/usr/src/test/libc-tests/tests/err/data/W.2.7.8
new file mode 100644
index 0000000000..0ef50e0f59
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/W.2.7.8
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: W/2
+::EXIT::
+0
diff --git a/usr/src/test/libc-tests/tests/err/data/W.3.9.10 b/usr/src/test/libc-tests/tests/err/data/W.3.9.10
new file mode 100644
index 0000000000..0c062b6c02
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/W.3.9.10
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: W/3: Bad file number
+::EXIT::
+0
diff --git a/usr/src/test/libc-tests/tests/err/data/W.4.11.12 b/usr/src/test/libc-tests/tests/err/data/W.4.11.12
new file mode 100644
index 0000000000..6bb8f74490
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/W.4.11.12
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: W/4: Resource temporarily unavailable
+::EXIT::
+0
diff --git a/usr/src/test/libc-tests/tests/err/data/W.5.13.14 b/usr/src/test/libc-tests/tests/err/data/W.5.13.14
new file mode 100644
index 0000000000..265b173a97
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/data/W.5.13.14
@@ -0,0 +1,6 @@
+::STDOUT::
+
+::STDERR::
+err: W/5
+::EXIT::
+0
diff --git a/usr/src/test/libc-tests/tests/err/err.c b/usr/src/test/libc-tests/tests/err/err.c
new file mode 100644
index 0000000000..b39e209a68
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/err.c
@@ -0,0 +1,190 @@
+/*
+ * 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 2022 OmniOS Community Edition (OmniOSce) Association.
+ */
+
+/*
+ * This file exercises the various err(3C)/warn(3C) functions and produces
+ * output that is checked by the corresponding err.ksh script.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <err.h>
+#include <sys/debug.h>
+
+static FILE *stream = stderr;
+
+typedef enum variant {
+ VARIANT_ = 0, /* warn(), err() */
+ VARIANT_C, /* warnc(), errc() */
+ VARIANT_X, /* warnx(), errx() */
+ VARIANT_V, /* vwarn(), verr() */
+ VARIANT_VC, /* vwarnc(), verrc() */
+ VARIANT_VX, /* vwarnx(), verrx() */
+} variant_t;
+
+void
+usage(void)
+{
+ (void) fprintf(stderr,
+ "usage: err [-e errno] [-x code] [-v variant]\n");
+ exit(EXIT_FAILURE);
+}
+
+void
+callback_func(int code)
+{
+ (void) fprintf(stream, "CALLBACK %d\n", code);
+}
+
+void
+xtest(variant_t variant, int errcode, int exitcode, const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+
+ switch (variant) {
+ case VARIANT_V:
+ errno = errcode;
+ if (exitcode != 0)
+ verr(exitcode, fmt, va);
+ else
+ vwarn(fmt, va);
+ break;
+ case VARIANT_VC:
+ errno = 0;
+ if (exitcode != 0)
+ verrc(exitcode, errcode, fmt, va);
+ else
+ vwarnc(errcode, fmt, va);
+ break;
+ case VARIANT_VX:
+ if (exitcode != 0)
+ verrx(exitcode, fmt, va);
+ else
+ vwarnx(fmt, va);
+ break;
+ default:
+ errx(EXIT_FAILURE, "Unhandled variant in %s", __func__);
+ }
+
+ va_end(va);
+}
+
+int
+main(int argc, char **argv)
+{
+ int errcode = 0;
+ int exitcode = 0;
+ variant_t variant = VARIANT_;
+ const char *errstr;
+ long long num;
+ int ch;
+
+ /*
+ * -e specify errno for the test
+ * -v select variant to test
+ * -x specify exit code for the test
+ */
+ while ((ch = getopt(argc, argv, "e:v:x:")) != -1) {
+ switch (ch) {
+ case 'e':
+ num = strtonum(optarg, 0, 127, &errstr);
+ if (errstr != NULL)
+ errx(EXIT_FAILURE, "-x: %s", errstr);
+ errcode = (int)num;
+ break;
+ case 'v':
+ num = strtonum(optarg, 0, VARIANT_VX, &errstr);
+ if (errstr != NULL)
+ errx(EXIT_FAILURE, "-v: %s", errstr);
+ switch (num) {
+ case VARIANT_:
+ variant = VARIANT_;
+ break;
+ case VARIANT_C:
+ variant = VARIANT_C;
+ break;
+ case VARIANT_X:
+ variant = VARIANT_X;
+ break;
+ case VARIANT_V:
+ variant = VARIANT_V;
+ break;
+ case VARIANT_VC:
+ variant = VARIANT_VC;
+ break;
+ case VARIANT_VX:
+ variant = VARIANT_VX;
+ break;
+ default:
+ errx(EXIT_FAILURE, "Unknown variant %ld", num);
+ }
+ break;
+ case 'x':
+ num = strtonum(optarg, 0, 127, &errstr);
+ if (errstr != NULL)
+ errx(EXIT_FAILURE, "-x: %s", errstr);
+ exitcode = (int)num;
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc > 0)
+ errx(EXIT_FAILURE, "Unexpected argument '%s'.", argv[1]);
+
+ switch (variant) {
+ case VARIANT_:
+ errno = errcode;
+ if (exitcode != 0)
+ err(exitcode, "E/%d/%d", variant, exitcode);
+ else
+ warn("W/%d", variant);
+ break;
+ case VARIANT_C:
+ errno = 0;
+ if (exitcode != 0)
+ errc(exitcode, errcode, "E/%d/%d", variant, exitcode);
+ else
+ warnc(errcode, "W/%d", variant);
+ break;
+ case VARIANT_X:
+ if (exitcode != 0)
+ errx(exitcode, "E/%d/%d", variant, exitcode);
+ else
+ warnx("W/%d", variant);
+ break;
+ case VARIANT_V:
+ case VARIANT_VC:
+ case VARIANT_VX:
+ if (exitcode != 0) {
+ xtest(variant, errcode, exitcode, "E/%d/%d", variant,
+ exitcode);
+ } else {
+ xtest(variant, errcode, exitcode, "W/%d", variant);
+ }
+ break;
+ }
+
+ return (0);
+}
diff --git a/usr/src/test/libc-tests/tests/err/err.ksh b/usr/src/test/libc-tests/tests/err/err.ksh
new file mode 100755
index 0000000000..fcb713633c
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/err/err.ksh
@@ -0,0 +1,90 @@
+#!/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 2022 OmniOS Community Edition (OmniOSce) Association.
+
+set -o errexit
+set -o pipefail
+
+builtin print
+
+typeset -r ROOT=$(dirname $0)
+typeset -ri MAX_VARIANT=5
+
+typeset -i failures=0
+
+function fatal
+{
+ echo "Test Failed: $@" >&2
+ exit 1
+}
+
+function fail
+{
+ ((failures++))
+ echo "FAIL: $*" >&2
+}
+
+function pass
+{
+ echo "PASS: $*"
+}
+
+function run
+{
+ typeset key="$1"
+ typeset keyf="$ROOT/data/$key"
+ shift;
+
+ stderr=${ { stdout=$("$@"); } 2>&1; }
+ exit=$?
+ output=${
+ cat <<- EOM
+ ::STDOUT::
+ $stdout
+ ::STDERR::
+ $stderr
+ ::EXIT::
+ $exit
+ EOM
+ }
+ if [[ -r "$keyf" ]]; then
+ expect=$(<$keyf)
+ else
+ fatal "Data file $keyf is not readable"
+ fi
+
+ if [[ "$expect" != "$output" ]]; then
+ fail "$key"
+ diff -u <(print "$output") <(print "$expect") || true
+ else
+ pass "$key"
+ fi
+}
+
+for v in {0..$MAX_VARIANT}; do
+ ((errcode = 3 + v * 2))
+ ((exitcode = 4 + v * 2))
+ key="${v}.${errcode}.${exitcode}"
+
+ # err(3C) family
+ cmd="$ROOT/err -v $v -e $errcode -x $exitcode"
+ run "E.$key" $cmd
+
+ # warn(3C) family
+ cmd="$ROOT/err -v $v -e $errcode"
+ run "W.$key" $cmd
+done
+
+exit $failures
+