From patchwork Sat Feb 18 09:47:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 94172 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp538971qgi; Sat, 18 Feb 2017 01:49:11 -0800 (PST) X-Received: by 10.98.110.194 with SMTP id j185mr14459940pfc.157.1487411351133; Sat, 18 Feb 2017 01:49:11 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id z31si12734857plb.153.2017.02.18.01.49.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 01:49:11 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-77426-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-77426-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-77426-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=XQPuj2CRwX72bdS7 RRFNKpMrFbbt8IZB1HF0XjXmF46D4F4alMKAGqh1iUVto7luHq3N/jHxA974v6/0 nplq+JkLxrFKQ6kqligxHa/0bdDCiOCdJfGrYpFYwDKHnF/lUlH+ulclq46bYUlo EAAwW4Ky/CeD2PSedO05EFIEE4Q= 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=kWcFyW15Ru47kfN1TuAGc+ 7vjOE=; b=Ck7OLHh00KQRYkR6oPzKz7Dc/k+rumJIlhqnRz9a5Y+JVVWW6gD2Y2 1P2ujb27LEDHRsIP6I9iwye5H2QuQoRNNnMcYcAOXUlz9s26o1rCBJAOs7a2uBLh c2Is//B3z9NVpZgi7QKargpQZLQPyB5MkJHepPMzVHAg8eZqnbUfY= Received: (qmail 91112 invoked by alias); 18 Feb 2017 09:48:48 -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 90909 invoked by uid 89); 18 Feb 2017 09:48:31 -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=H*r:sk:NAM01-S, H*r:104.47.32 X-HELO: NAM01-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 , Carlos O'Donell , Wainer dos Santos Moschetta , Yury Norov Subject: [PATCH v2] Test errno setup Date: Sat, 18 Feb 2017 15:17:54 +0530 Message-Id: <1487411274-21877-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-ClientProxiedBy: VI1PR0901CA0053.eurprd09.prod.outlook.com (10.167.203.149) To DM3PR07MB2250.namprd07.prod.outlook.com (10.164.33.148) X-MS-Office365-Filtering-Correlation-Id: c56732e2-91f7-49a9-969d-08d457e340d6 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM3PR07MB2250; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 3:m+Nc1PzibRL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SsNlQyiApKYHuyIVoEJHMy4ReOxeX+sG9eBCIN1GkyLwsAVcC+cbfaCskUvGGjFOmvHvUsUWOTEZT8DORRehu6F1R+8gPN+W32imoQdx/AaCq0G94mxIUeb3ucmncKHRWe1iYoPHzote5cv2QmP6sboSz6r4JtObNBbxJQoL+IZZu41qmOsqj2wJzpP4pTGicI+kq+BYWNDH8FM221+nSQniAh6rC2sVsE627/PbLA48/EYYBMD+FeAktwa2MPO/s6jqRwJ7ht1VlwE5zvcyA48HPFyVFzZjOzoHcRSr0u3lp02DSnuYHiEqEXV5padawNaEOJwesir34mmXo5Kww8G09MtvupxXoe+K2lD8Na2EKSOIW50zjt6ZXN7Ey0JYWdD4kmlxNY/0bqfhGY/v1YigpvfNzFHGhMa34EYjTwIxqxaSKAVK78GJb+OjlKkAb+n6JhQP5RMgjUWPvDTbtCZCkwwWYTZmrrj1OZLTJu08boyOYhczmpOonNAsBjVmZEsMh072UsYNcgzx8gjs1FLbYjkbclXF4eg9ZHTDRiBtOpRqCsZuW7bqtnimAPf2lDjQ0eKZU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030)(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123560025)(20161123555025)(20161123558025)(20161123562025)(20161123564025)(6072148); SRVR:DM3PR07MB2250; BCL:0; PCL:0; RULEID:; SRVR:DM3PR07MB2250; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 4:suCdqe2qktD9dSUiaSMWgccAwsbLQT/iuuFmML3eTWFq8Z7x8MsU+kpRnMA2rZF8DIBkwuxag02ZMPVJ2IJn61KThdtU+xM9R161Jacms7CEkZatlHCRFd3TsioUsFroxsCh1e8p23CC4PUVscj1yvcY8nhZToruPtP0bBQRfvQaB7Av7zD1LPC0eAHgo3Fq7famDl7E8eQb+bxpBWbd1HqV/T9S6LcFviu8i4oQVMpS1brJbQzOZrWJmYYbEZxBGMvwBAiMYO2xUj4L/BjGI4xOIREwkgxV6z/QQGiiPrLyP5H3NdJVSQI57gml28PzcZHo/Tv2slVXYnVUuKoV+NS1jHZZAgit0mgyMirxERvtufb2Ggk59yWfZLvdZ0+u3slYt4+s37CbV9oMaW+BeMgsHU6/PUZYMhH1F7cl6LLC07t0V4jGgUpRnKKAD2IoM3R06zOQm5GQgfrnWvUA4VB751MvFmr2lbWwnYAInbeCLh2Rcfy8JvehiceN9xZIiFVPlVK7kXiuXLFFZllDlVTlp9GpYHIBC0x97rDiIbktloHdQwmjwSXwT0pGrSR6xDCGRcgUPqZXArK0DeklCNVo3DZ7tRP72rwV0J48Hx/4o2erG7ByeYDTbYf8vjNIptt7mUfTP7sMN+NsNDBZicV6ae7KiMdeJmgXHg3QIhU0XHK1y87XjNlpFzJHN5cUgYq6ybyvItLHDmA7eXokropLEb60uxE+sJiQknOiyjE= X-Forefront-PRVS: 02229A4115 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(39450400003)(199003)(43544003)(189002)(189998001)(68736007)(5003940100001)(6496005)(92566002)(2361001)(33646002)(48376002)(36756003)(97736004)(50466002)(106356001)(575784001)(101416001)(6486002)(25786008)(6306002)(2906002)(42186005)(2351001)(4326007)(105586002)(6116002)(3846002)(54906002)(76506005)(7736002)(53936002)(50226002)(47776003)(6666003)(6916009)(38730400002)(110136004)(305945005)(81156014)(81166006)(107886003)(8676002)(50986999)(66066001)(5660300001)(3714002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR07MB2250; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 23:BBK/x3rUaz7DRNxXnHh5Nz3YfLLAqljPnla0sYvimOMo0Wswkh55KbG+K4/k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cvk0ppV+sC7hDlzBVeC4rLm8Aju+D2DC4NiHR4v7kLfw/nv5KoSvVc4fow894vBOSagO0NfSWy+UBD69stzlLPg== X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 6:n1EiyOBpxywcNjDgyG+Q0BfOoLB1IeNkhfO1UvtH//nOslXt6bNoBYVJaFvl+45pNmvhQmgaLWk+h6yXmw1d1V1A2fR8CnfKkgWJL4ozdsVeqPDHccjzJ1GTZyanVpwunnThY7JFvjWY4Uz23w5+IqChL8ow2cJiKT955TKpJKbCU5OAs2K1fHJ7Qy25tL3PIE2o8wiVC1SgDc8XfckyckPemOnIhOoO5kzMSx4iv2YyYc99nw69c7yVW9gExc4j6abzBfWzzoiOQDAkxV/UobOoo3nuocXsL94Mc2oTEPInMJXBMWbifepf11/reDk+dbTQosSvM+YXbTStsaKx0ledmTjEJmZYEIrA8jE6YqwUeZFg+Gq/b8FmlJEnfIjQ5r9/rUtRZg1AP8YhB3c03w==; 5:7A11kUbaSHZRT5TfJ87R5NTCD7XlZP3OfKRaAKjTjyWns8/4R93lr1chMnPRCWjDVegCxwyv0bvb+XBXsAoYha7hNDHaRx/N2yDaHf2KMppaHsDWyyEBL+E7WZylOks/hl7+fCms1ROKlUxYwrCpGA==; 24:GaEBTAScrs/XTBB02nqsj0JHj9CQPRhcGZsxZRyGBKYN7SWvkKzzXMPnCcf1Zy1gBWFqvBfas4QAtUqcQUZ+l1tUoxiHHRLr7P/t7Yvuqg4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 7:OlSgJAe075mv2g5TyJyDk3+X3FS+YjCHqPIkBCNoyglfQTdSSO45ezXIYc5LbHp45C1DEJsNGe9Hd1yrYkcTRUGN3EPuBlo0Tyu5gMm6v5GdsIpaz/jl6fayzZ1FNva3T9mv6k5Lih/VjKwxic0ZA6Yo1ddNuJIwlym1Imc9euKtwU4DuasD4civ3/VzzdA2mu5efQVMEmGjd94HAnP2Msnr9wzloxf3UNri3Gmviro4Hnt6uG8ko8CXq2XGCTBmAv0/2BxaAoJRBCVF/6lIXX8PfcB8wM8kNXUgFnsW2/7etV1aMiKXfwZVgcTN3R3qnnpDadGA/pXfLsPDxK757g== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2017 09:48:10.7611 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2250 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. v1: https://sourceware.org/ml/libc-alpha/2017-02/msg00276.html v2: added FSF copyright headers; support/test-driver.c is used instead of test-skeleton.c; fixed misspeling in description; 'FAIL' prefix added in test wrapper macro fail paths. 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 | 153 +++++++++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/Makefile | 2 +- sysdeps/unix/sysv/linux/test-errno.c | 142 ++++++++++++++++++++++++++++++++ 4 files changed, 297 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 8f23d64..ae17646 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..d484d02 --- /dev/null +++ b/posix/test-errno.c @@ -0,0 +1,153 @@ +/* Test that failing system calls do set errno to the correct value. + + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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 binary 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 ("FAIL: " #syscall ": didn't fail as expected" \ + " (return "prtype")\n", ret); \ + else if (err == 0xdead) \ + puts("FAIL: " #syscall ": didn't update errno\n"); \ + else if (err != experr) \ + printf ("FAIL: " #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) +{ + 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; +} + +#include "support/test-driver.c" diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index b3d6866..3c0c89f 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-sync_file_range 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..b768ff0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/test-errno.c @@ -0,0 +1,142 @@ +/* Test that failing system calls do set errno to the correct value. + + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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 binary 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 ("FAIL: " #syscall ": didn't fail as expected" \ + " (return "prtype")\n", ret); \ + else if (err == 0xdead) \ + puts("FAIL: " #syscall ": didn't update errno\n"); \ + else if (err != experr) \ + printf ("FAIL: " #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; +} + +#include "support/test-driver.c"