diff options
Diffstat (limited to 'usr/src/test')
-rw-r--r-- | usr/src/test/os-tests/runfiles/default.run | 3 | ||||
-rw-r--r-- | usr/src/test/os-tests/tests/Makefile | 1 | ||||
-rw-r--r-- | usr/src/test/os-tests/tests/syscall/Makefile | 55 | ||||
-rw-r--r-- | usr/src/test/os-tests/tests/syscall/open.c | 102 |
4 files changed, 161 insertions, 0 deletions
diff --git a/usr/src/test/os-tests/runfiles/default.run b/usr/src/test/os-tests/runfiles/default.run index 72158c8bc2..f2f66ab4d7 100644 --- a/usr/src/test/os-tests/runfiles/default.run +++ b/usr/src/test/os-tests/runfiles/default.run @@ -76,6 +76,9 @@ user = root tests = ['conn', 'dgram', 'drop_priv', 'nosignal', 'rights.32', 'rights.64', 'sockpair'] +[/opt/os-tests/tests/syscall] +tests = ['open.32', 'open.64'] + [/opt/os-tests/tests/pf_key] user = root timeout = 180 diff --git a/usr/src/test/os-tests/tests/Makefile b/usr/src/test/os-tests/tests/Makefile index 7396e135c9..190c61e134 100644 --- a/usr/src/test/os-tests/tests/Makefile +++ b/usr/src/test/os-tests/tests/Makefile @@ -29,6 +29,7 @@ SUBDIRS = \ sockfs \ spoof-ras \ stress \ + syscall \ timer \ tmpfs \ uccid \ diff --git a/usr/src/test/os-tests/tests/syscall/Makefile b/usr/src/test/os-tests/tests/syscall/Makefile new file mode 100644 index 0000000000..b4ba83a18b --- /dev/null +++ b/usr/src/test/os-tests/tests/syscall/Makefile @@ -0,0 +1,55 @@ +# +# 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 2020 Joyent, Inc. +# + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/test/Makefile.com + +PROGS = open + +CSTD = $(CSTD_GNU99) + +ROOTOPTPKG = $(ROOT)/opt/os-tests +TESTDIR = $(ROOTOPTPKG)/tests/syscall + +PROGS32 = $(PROGS:%=%.32) +PROGS64 = $(PROGS:%=%.64) +CMDS = $(PROGS32) $(PROGS64) +$(CMDS) := FILEMODE = 0555 + +TESTDIRPROGS = $(PROGS32:%=$(TESTDIR)/%) \ + $(PROGS64:%=$(TESTDIR)/%) + +all: $(PROGS32) $(PROGS64) + +install: all $(TESTDIR) $(TESTDIRPROGS) + +clobber: clean + +clean: + -$(RM) $(CMDS) + +$(TESTDIR): + $(INS.dir) + +$(TESTDIR)/%: % + $(INS.file) + +%.64: %.c + $(LINK64.c) -o $@ $< $(LDLIBS64) + $(POST_PROCESS) + +%.32: %.c + $(LINK.c) -o $@ $< $(LDLIBS) + $(POST_PROCESS) diff --git a/usr/src/test/os-tests/tests/syscall/open.c b/usr/src/test/os-tests/tests/syscall/open.c new file mode 100644 index 0000000000..e7f826b2a5 --- /dev/null +++ b/usr/src/test/os-tests/tests/syscall/open.c @@ -0,0 +1,102 @@ +/* + * 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 2020 Joyent, Inc. + */ + +/* + * Test the open(2) syscall. + * + * Currently only tests O_DIRECT pass/fail based on the known support in the + * underlying file system. + * + * Note: there is a test for the O_DIRECTORY flag in the directory above this + * which could be consolidated into this code at some point. + */ + +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/statvfs.h> +#include <sys/param.h> +#include <fcntl.h> +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> + +static void +o_direct_test(const char *dir) +{ + int fd; + struct statvfs64 buf; + char tmpname[MAXPATHLEN]; + char *path; + + boolean_t pass; + + (void) snprintf(tmpname, sizeof (tmpname), "%s/otstXXXXXX", dir); + if ((path = mktemp(tmpname)) == NULL) { + (void) printf("FAILED: unable to create temp file name\n"); + exit(1); + } + + if (statvfs64(dir, &buf) == -1) { + perror("statvfs failed"); + exit(1); + } + + if (strcmp(buf.f_basetype, "zfs") == 0) { + pass = B_TRUE; + } else if (strcmp(buf.f_basetype, "tmpfs") == 0) { + pass = B_FALSE; + } else { + (void) printf("SKIP: expected 'zfs' or 'tmpfs'\n"); + return; + } + + fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_DIRECT, 0644); + if (fd >= 0) { + (void) close(fd); + (void) unlink(path); + if (!pass) { + (void) printf("FAILED: O_DIRECT on %s/tst_open is " + "expected to fail\n", dir); + exit(1); + } + } else { + if (pass) { + (void) printf("FAILED: O_DIRECT on %s/tst_open is " + "expected to succeed\n", dir); + exit(1); + } + + if (errno != EINVAL) { + (void) printf("FAILED: expected EINVAL, got %d\n", + errno); + exit(1); + } + } +} + +int +main(void) +{ + /* On typical illumos distros, /tmp is tmpfs, O_DIRECT should fail */ + o_direct_test("/tmp"); + + /* On typical illumos distros, /var is zfs, O_DIRECT should pass */ + o_direct_test("/var/tmp"); + + (void) printf("PASS\n"); + return (0); +} |