From patchwork Thu Feb 16 10:15:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 94046 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2433902qgi; Thu, 16 Feb 2017 02:15:51 -0800 (PST) X-Received: by 10.99.99.193 with SMTP id x184mr1828126pgb.226.1487240151702; Thu, 16 Feb 2017 02:15:51 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b11si6537450plk.176.2017.02.16.02.15.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 02:15:51 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-77371-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-77371-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-77371-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type; q=dns; s=default; b=yBw7I6M6ok5gPHnj AJh6Tl2/Na+oYsDKrCMuKR9pF1W6UARxeGwbsWUcZ6VMI1VqtYA2Ubz99NeW2Xpo wYKAWfGCZRpr1a/GJtQjuKMCNUZx+GGwvUafb+QcxYwGHYvYO760nErJ/oTRG9yG BeiGLtAglM1YNDGD1fBW2JJ88jQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type; s=default; bh=uEjz8PfWZgdI1uNRR9vMsU 5eeCo=; b=v1yDXa9v2YUWlorXmAoftHw5pbEcMOrehnGNQsbPVMQDD9Tyv4Dd6h LO7Lupusv9kVSin+LZ4ufZnjDl1VcvC37qX/G2arT1tSioRHbEzWYipEEUQuLJZZ DAMZqJ6IfWBpaRmKeETydhQ7TDPd9J0RSwRL2fdfb1Dkmt1KuZGso= Received: (qmail 104975 invoked by alias); 16 Feb 2017 10:15:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 104964 invoked by uid 89); 16 Feb 2017 10:15:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=627, H*r:104.47.36, H*r:sk:NAM02-S, H*r:sk:mail-sn X-HELO: NAM02-SN1-obe.outbound.protection.outlook.com Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; From: Yury Norov To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Zack Weinberg , Yury Norov Subject: [PATCH] Test errno setup Date: Thu, 16 Feb 2017 15:45:07 +0530 Message-Id: <1487240107-32578-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-ClientProxiedBy: AM4PR02CA0019.eurprd02.prod.outlook.com (10.165.239.157) To DM3PR07MB2252.namprd07.prod.outlook.com (10.164.33.150) X-MS-Office365-Filtering-Correlation-Id: 820c10b0-a1cb-4675-1ac2-08d45654b8a8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM3PR07MB2252; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 3:4qlrAjJ8zkgV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nrw4pMd7NQCK0Gfp/Rznb0sGXCnlIOu/m5JCUdmLck60mlq22a9XFyLzUMiR34xxQ3qk4Y+WlE3M0tH+IH8WZtMIKx/ltgChDaVIkzzwuFcVa3cdbQs4CjMUblRCcaJ4KQ3v4L+cMqVbXw/xIOQ7XtSeWCB917tdAZBzKhqFwENNI8qsHbxh7Ga8RWfy4GWSsC1TLgWmMhSUD2+y0ppmtZNe1niQAE2chZEnVkZ7/+R4MkZRNe4NDAVEfMPPeh/RLXl4OInPIY5QXmUXqfded2hrePnAewA9G0ECKKWopI5xkeFN2YxJzL/XVGwzn4x9At7FZ2bpeVHbCMFqJrZMfwPRzxXG2vsbvUPgk6OMB813Wxgy7mg3TxqpxVTx7/b/OtWiD0HQLNHW6A57Q5sPV0qW0nOF3Z6QoLRqPkqAvVF18CymWLFs0lNQc1jf5QWeSAs/L7vQqZfq9FKrppgADAXO4M6TMFs80muZa1UWv520XUi4H5H5M+ykYO0yRuqwn+IVPGwTSRIVXiDSQoJJC870lNyu2+0o2eokq7zNtJS3lfQ9jpPkze6ryDwdqlKhkjJO9kKCuc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123555025)(20161123560025)(20161123562025)(20161123558025)(6072148); SRVR:DM3PR07MB2252; BCL:0; PCL:0; RULEID:; SRVR:DM3PR07MB2252; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 4:zXe3V5XDeGPWX21jHsn4fkCXeIR3Wayfk++y/WAy2fg/+M/ttEj3LIh7sm6WW0y/XMNfdiTR5OVAQSyiuS46Dci5FfjLzQvnobgtCvh0w9ai0Q2vkNp5kNKwFRs6omm87g4H6AzJ2o01g2vAZOVqUfs8n9V6KVXC/bBfRNO5a9bfc1txn7ualheplHqzjO3nRgNU5ZXJVyAuuqEP2wOEXbBwk8ybnib42dGiS75Yq0cosVK126KgjM+e9wtm7IXb7ydAOR2oCiIuHyfJpSdTxrP44C9UacU4cSZgw64k1fgPSrf53fnIUEsUUcIM69ooXXAf9sQ/456Ye7cDnTJKPs0MbRWi3lVzIqBOESp+D2Gm+8zlthHy1wXoP29dALLIA63xnc/gQO02tydfREGLvJDQYNyWSnqySKWkXoKUfUimfoQartNMTzIJ3kDgnBM++zaYD7ivlhBP4bO2ZgNvAXAQOTIX/2709HcvV9bbSThXi3DccYxpsGJRhJv9HYiAh3iRXD/+MUrL5J734cC8g11wOaWyuCoULunyElpmJTDCDF0JRDFWk/q6DLbrIcEg+cYTkbZFIi5YX3ZeAt+LHP51JV5hOJFuJOr7/xQcdUuIJXdnZ9a+7p3MEBLcrUZYfPBDBga/DdnwqJXC58XT7A== X-Forefront-PRVS: 0220D4B98D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(39450400003)(189002)(43544003)(199003)(189998001)(92566002)(2351001)(25786008)(7736002)(6116002)(42186005)(107886003)(5009440100003)(48376002)(47776003)(305945005)(389900003)(3846002)(110136004)(50466002)(33646002)(38730400002)(66066001)(97736004)(81156014)(53936002)(50986999)(81166006)(50226002)(5660300001)(106356001)(105586002)(2906002)(6916009)(6666003)(101416001)(6496005)(36756003)(4326007)(54906002)(5003940100001)(76506005)(68736007)(2361001)(6486002)(8676002)(3714002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR07MB2252; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 23:hrMurGJ+p8+owJ6LAUJpRUStmHDVpW8vuSYawvvLdoZO5npNUlAj5M/2IL8LOvD4uSfxsi6XiieFKDyG1H/ZLhMv8DRCQkle+RyGHuT+gBXKpVr6fqkxhnaDv473CPDlQK3FOUq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AJhfXwGIuzF6QKXFzw== X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 6:kn3Xv+3tlNmD7SQhE4FA7Ev1GdWQ1v2MWJ2is95a7jxF/TBLHnsH1Xlot57Lere9wOgH8PQy3HjA+QmRBqcNy3Amam3TT/pWZqCXd/QFGBww5P9xd2Af5D2F1sjOSXwuEY7zHoPpBkQwHaZcrcRpyY0G5tmRwCnnBxm4LL61KFx7S34Y9vtSZ7aiQ4C9R1lcSTb3EXasoH2lnBXF8rIXhbeHWOdZXOkWfon/g6jVqyadUK4/UkfJhwVrIejbJpLB4ADD2ssqmx7+xGS0vOYuLGJ9bCIQlbCbhuS9dsWfds+NEGDqBu01i5fBeDqXo7ZWefEOkoQesUxyYKwkAt/6HYsyP585YFRMZ2skDJ3+gjbxm/YjnRLLsj7GpYY6bOGQ/tQAa/wSl7vkWcUenWLDnw==; 5:nOyB2qWCqn22sj3qc+O/3Yucr3e+j9uelWSDVJ1w/suMsGviqKqFpIy+66JtKSzgedwEDSQj1b8tL8fuLopzIPL17VWz71QeBksRyxZ+YyihunzvVNkWDxMVAEjVGiodwHedRHFm7wM5GoSP78Jv5g==; 24:+kynkRXDkfxgmM5LphYKJKnUyXwmCIzwc/wPOof7hHXObz+6rI+pElshCMngcHXaJDCX8miedJ/W3uUbTILlsmLUl6XjJwNYR+jYhtDjxcw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 7:opIy50Uo+HiESSgH2wr/mwMOxbiss0oyPY5uwtUKbY9m74Wp/DlC4f1185hRxQ0mINfjSRt2EabQF4CQraUdwhepUrF353Oj0bVMbZvnNs5sXOCpfZ9Ym7bJpSzUMcXX38rKxhB/ayqspXqbEBOKHJ/2kl5WXNvYptq9rTKrcVIKtVtZ3zMibLG5Az300Afx1HN9yoF1t6WlVju6r0GcsADZzpPsi8xc+9sDlJ0yB53FllLK0kfykcIyT2Lf8aBVtNLub5udLwuYF4TMXyPqFVQN9neouZkgnPN/FAgoRk6bI4CSJ7QQkkM6cTwBCom+F7loCvVC4HgoJmeL1SQCpQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2017 10:15:21.2129 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2252 This patch adds tests for POSIX and Linux specific syscalls that implemented with syscall templates machinery. The reason of tests is to receive the expected error code and test if it's handled properly by glibc code. Yury Norov Zack Weinberg * posix/Makefile: Enable errno test for POSIX syscalls. * posix/test-errno.c: New file. * sysdeps/unix/sysv/linux/Makefile: Enable errno test for Linux syscalls. * sysdeps/unix/sysv/linux/test-errno.c: New file. --- posix/Makefile | 2 +- posix/test-errno.c | 137 +++++++++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/Makefile | 2 +- sysdeps/unix/sysv/linux/test-errno.c | 126 ++++++++++++++++++++++++++++++++ 4 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 posix/test-errno.c create mode 100644 sysdeps/unix/sysv/linux/test-errno.c -- 2.7.4 diff --git a/posix/Makefile b/posix/Makefile index c493f31..1359a64 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -62,7 +62,7 @@ routines := \ get_child_max sched_cpucount sched_cpualloc sched_cpufree aux := init-posix environ -tests := tstgetopt testfnm runtests runptests \ +tests := test-errno tstgetopt testfnm runtests runptests \ tst-preadwrite tst-preadwrite64 test-vfork regexbug1 \ tst-mmap tst-mmap-offset tst-getaddrinfo tst-truncate \ tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \ diff --git a/posix/test-errno.c b/posix/test-errno.c new file mode 100644 index 0000000..7af2490 --- /dev/null +++ b/posix/test-errno.c @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Test that failing system calls do set errno to the correct value. + + This is not an exhaustive test: only system calls that can be + persuaded to fail with a consistent error code and no side effects + are included. Usually these are failures due to invalid arguments, + with errno code EBADF or EINVAL. The order of argument checks is + unspecified, so we must take care to provide arguments that only + allow _one_ failure mode. + + Note that all system calls that can fail with EFAULT are permitted + to deliver a SIGSEGV signal instead, so we avoid supplying invalid + pointers in general, and we do not attempt to test system calls + that can only fail with EFAULT (e.g. gettimeofday, gethostname). + + Also note that root-only system calls (e.g. acct, reboot) may, when + the test is run as an unprivileged user, fail due to insufficient + privileges before bothering to do argument checks, so those are not + tested either. + + Also, system calls that take enum or a set of flags as argument is + not tested if POSIX doesn't specify exact digital values for all + flags, and so any value passed to flags may become valid. + + Some tests assume "/bin/sh" names a file that exists and is not a + directory. */ + +#define test_wrp_rv(rtype, prtype, experr, syscall, ...) \ + (__extension__ ({ \ + errno = 0xdead; \ + rtype ret = syscall (__VA_ARGS__); \ + int err = errno; \ + int fail; \ + if (ret == (rtype) -1 && err == experr) \ + fail = 0; \ + else \ + { \ + fail = 1; \ + if (ret != (rtype) -1) \ + fprintf (stderr, #syscall ": didn't fail as expected" \ + " (return "prtype")\n", ret); \ + else if (err == 0xdead) \ + fputs(#syscall ": didn't update errno\n", stderr); \ + else if (err != experr) \ + fprintf (stderr, #syscall \ + ": errno is: %d (%s) expected: %d (%s)\n", \ + err, strerror (err), experr, strerror (experr)); \ + } \ + fail; \ + })) + +#define test_wrp(experr, syscall, ...) \ + test_wrp_rv(int, "%d", experr, syscall, __VA_ARGS__) + +int +do_test (void) +{ + size_t pagesize = sysconf (_SC_PAGESIZE); + struct statfs sfs; + struct sockaddr sa; + socklen_t sl; + char buf[1]; + struct iovec iov[1] = { { buf, 1 } }; + struct sockaddr_in sin; + sin.sin_family = AF_INET; + sin.sin_port = htons (1026); + sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + struct msghdr msg; + memset(&msg, 0, sizeof msg); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + + int fails = 0; + fails |= test_wrp (EBADF, accept, -1, &sa, &sl); + fails |= test_wrp (EINVAL, access, "/", -1); + fails |= test_wrp (EBADF, bind, -1, (struct sockaddr *)&sin, sizeof sin); + fails |= test_wrp (ENOTDIR, chdir, "/bin/sh"); + fails |= test_wrp (EBADF, close, -1); + fails |= test_wrp (EBADF, connect, -1, (struct sockaddr *)&sin, sizeof sin); + fails |= test_wrp (EBADF, dup, -1); + fails |= test_wrp (EBADF, dup2, -1, -1); + fails |= test_wrp (EBADF, fchdir, -1); + fails |= test_wrp (EBADF, fchmod, -1, 0); + fails |= test_wrp (EBADF, fcntl, -1, 0); + fails |= test_wrp (EBADF, fstatfs, -1, &sfs); + fails |= test_wrp (EBADF, fsync, -1); + fails |= test_wrp (EBADF, ftruncate, -1, 0); + fails |= test_wrp (EINVAL, getgroups, -1, 0); + fails |= test_wrp (EBADF, getpeername, -1, &sa, &sl); + fails |= test_wrp (EBADF, getsockname, -1, &sa, &sl); + fails |= test_wrp (EBADF, getsockopt, -1, 0, 0, buf, &sl); + fails |= test_wrp (EBADF, ioctl, -1, TIOCNOTTY); + fails |= test_wrp (EBADF, listen, -1, 1); + fails |= test_wrp (EBADF, lseek, -1, 0, 0); + fails |= test_wrp (EINVAL, madvise, (void *) -1, -1, 0); + fails |= test_wrp_rv (void *, "%p", EBADF, + mmap, 0, pagesize, PROT_READ, MAP_PRIVATE, -1, 0); + fails |= test_wrp (EINVAL, mprotect, (void *) -1, pagesize, -1); + fails |= test_wrp (EINVAL, msync, (void *) -1, pagesize, -1); + fails |= test_wrp (EINVAL, munmap, (void *) -1, 0); + fails |= test_wrp (EINVAL, open, "/bin/sh", -1, 0); + fails |= test_wrp (EBADF, read, -1, buf, 1); + fails |= test_wrp (EINVAL, readlink, "/", buf, -1); + fails |= test_wrp (EBADF, readv, -1, iov, 1); + fails |= test_wrp (EBADF, recv, -1, buf, 1, 0); + fails |= test_wrp (EBADF, recvfrom, -1, buf, 1, 0, &sa, &sl); + fails |= test_wrp (EBADF, recvmsg, -1, &msg, 0); + fails |= test_wrp (EINVAL, select, -1, 0, 0, 0, 0); + fails |= test_wrp (EBADF, send, -1, buf, 1, 0); + fails |= test_wrp (EBADF, sendmsg, -1, &msg, 0); + fails |= test_wrp (EBADF, sendto, -1, buf, 1, 0, &sa, sl); + fails |= test_wrp (EBADF, setsockopt, -1, 0, 0, buf, sl); + fails |= test_wrp (EBADF, shutdown, -1, SHUT_RD); + fails |= test_wrp (EBADF, write, -1, "Hello", sizeof ("Hello") ); + fails |= test_wrp (EBADF, writev, -1, iov, 1 ); + + return fails; +} + +#define TEST_FUNCTION do_test () +#include "test-skeleton.c" diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 8c4cfd0..cd11f7c 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -43,7 +43,7 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \ bits/mman-linux.h tests += tst-clone tst-clone2 tst-fanotify tst-personality tst-quota \ - tst-sync_file_range tst-syscall-template + tst-sync_file_range tst-syscall-template test-errno # Generate the list of SYS_* macros for the system calls (__NR_* macros). diff --git a/sysdeps/unix/sysv/linux/test-errno.c b/sysdeps/unix/sysv/linux/test-errno.c new file mode 100644 index 0000000..5a2f8a4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/test-errno.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Test that failing system calls do set errno to the correct value. + + This is not an exhaustive test: only system calls that can be + persuaded to fail with a consistent error code and no side effects + are included. Usually these are failures due to invalid arguments, + with errno code EBADF or EINVAL. The order of argument checks is + unspecified, so we must take care to provide arguments that only + allow _one_ failure mode. + + Note that all system calls that can fail with EFAULT are permitted + to deliver a SIGSEGV signal instead, so we avoid supplying invalid + pointers in general, and we do not attempt to test system calls + that can only fail with EFAULT (e.g. gettimeofday, gethostname). + + Also note that root-only system calls (e.g. acct, reboot) may, when + the test is run as an unprivileged user, fail due to insufficient + privileges before bothering to do argument checks, so those are not + tested either. + + Also, system calls that take enum or a set of flags as argument is + not tested if POSIX doesn't specify exact digital values for all + flags, and so any value passed to flags may become valid. + + Some tests assume "/bin/sh" names a file that exists and is not a + directory. */ + +#define test_wrp_rv(rtype, prtype, experr, syscall, ...) \ + (__extension__ ({ \ + errno = 0xdead; \ + rtype ret = syscall (__VA_ARGS__); \ + int err = errno; \ + int fail; \ + if (ret == (rtype) -1 && err == experr) \ + fail = 0; \ + else \ + { \ + fail = 1; \ + if (ret != (rtype) -1) \ + printf (#syscall ": didn't fail as expected" \ + " (return "prtype")\n", ret); \ + else if (err == 0xdead) \ + puts(#syscall ": didn't update errno\n"); \ + else if (err != experr) \ + printf (#syscall \ + ": errno is: %d (%s) expected: %d (%s)\n", \ + err, strerror (err), experr, strerror (experr)); \ + } \ + fail; \ + })) + +#define test_wrp(experr, syscall, ...) \ + test_wrp_rv(int, "%d", experr, syscall, __VA_ARGS__) + +static int +do_test (void) +{ + fd_set rs, ws, es; + int status; + off_t off; + stack_t ss; + struct dqblk dqblk; + struct epoll_event epoll_event; + struct pollfd pollfd; + struct sched_param sch_param; + struct timespec ts; + struct timeval tv; + unsigned char vec[16]; + ss.ss_flags = ~SS_DISABLE; + ts.tv_sec = -1; + + int fails = 0; + fails |= test_wrp (EINVAL, epoll_create, -1); + fails |= test_wrp (EINVAL, epoll_create1, EPOLL_CLOEXEC + 1); + fails |= test_wrp (EBADF, epoll_ctl, -1, EPOLL_CTL_ADD, 0, &epoll_event); + fails |= test_wrp (EBADF, epoll_wait, -1, &epoll_event, 1, 1); + fails |= test_wrp (EBADF, fdatasync, -1); + fails |= test_wrp (EBADF, flock, -1, LOCK_SH); + fails |= test_wrp (ESRCH, getpgid, -1); + fails |= test_wrp (EINVAL, inotify_add_watch, -1, "/", 0); + fails |= test_wrp (EINVAL, mincore, (void *) -1, 0, vec); + fails |= test_wrp (EINVAL, mlock, (void *) -1, 1); // different errors + fails |= test_wrp (EINVAL, nanosleep, &ts, &ts); + fails |= test_wrp (EINVAL, poll, &pollfd, -1, 0); + fails |= test_wrp (ENODEV, quotactl, Q_GETINFO, NULL, -1, (caddr_t) &dqblk); + fails |= test_wrp (EINVAL, sched_getparam, -1, &sch_param); + fails |= test_wrp (EINVAL, sched_getscheduler, -1); + fails |= test_wrp (EINVAL, sched_get_priority_max, -1); + fails |= test_wrp (EINVAL, sched_get_priority_min, -1); + fails |= test_wrp (EINVAL, sched_rr_get_interval, -1, &ts); + fails |= test_wrp (EINVAL, sched_setparam, -1, &sch_param); + fails |= test_wrp (EINVAL, sched_setscheduler, -1, 0, &sch_param); + fails |= test_wrp (EINVAL, select, -1, &rs, &ws, &es, &tv); + fails |= test_wrp (EBADF, sendfile, -1, -1, &off, 0); + fails |= test_wrp (EINVAL, sigaltstack, &ss, NULL); + fails |= test_wrp (ECHILD, wait4, -1, &status, 0, NULL); + + return fails; +} + +#define TEST_FUNCTION do_test () +#include "test-skeleton.c"