From patchwork Mon Jun 10 00:26:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 1112773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=android.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=android.com header.i=@android.com header.b="gxRyly0i"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45MYqF6t5bz9s6w for ; Mon, 10 Jun 2019 10:27:05 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 415BA3EAE11 for ; Mon, 10 Jun 2019 02:27:00 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 1C76E3EA5CE for ; Mon, 10 Jun 2019 02:26:26 +0200 (CEST) Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 0F206600840 for ; Mon, 10 Jun 2019 02:26:25 +0200 (CEST) Received: by mail-pg1-x541.google.com with SMTP id 20so4059027pgr.4 for ; Sun, 09 Jun 2019 17:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JVwgAUOkF+UGw2Mt50OZFGOtW4nBNnOHaOn0AkYkMaw=; b=gxRyly0iTo7mlnG2oXK5AZ3UL3CnyyKUjpzxM65EPoV/6/f/iDX/7ZnaSe0XSqObxM qEqms1wYZJyN0/ywyctVLwOKeU+u12rZaZAeiWQ2QzyKK0GFXCD1nEbEfGTMbDjECMc5 JvU2JHg3ePmd298ABtotQ2jw66ShQCxoN7Sx6nooaDtWrSXsbY3hKhjfCO+KsShtcixc d5+6dfYUFx0R7ZOAKfzc1xCvNOWTi2H3vFNraXhY9WiViVF2l395xN81tqy8eZLmbGgK aNbhHMMdPoHgbG6O2vdkDaxLCiauGsu4sLJDrmQLlPsndEujzMxhGFRfFEdG/mZIuCW0 YyyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JVwgAUOkF+UGw2Mt50OZFGOtW4nBNnOHaOn0AkYkMaw=; b=naiG6ENB6aXt5Cp/w2wXK/wQz4dYxlEkpHuMXwFVMdmEbq8Wde14T1ZW9MoOiHaysb 9gO5R0au5RasK/FVySKjiGOw75HolkmMnESVt+nHveccXz8RxXgQI41QxSRXkRBnV4bo ZOfZtpFP80+DepZp7CF/u70RnWQwdLdxBID9lMgObl7c9bTX1edKJsIQ7gzCTQUa7MBR /hwQvtVBL7hiaKZv62Y0mgGQ9pAbycTHpaQ/Txkdv2CK43zKYbERHxGM9PDs4G5DjY+z Py/hW3vbJ90uiXhNwgAlPUizNSbwZ4rj7gkgfjCThLfA0sgUe2PedYfJYeHDV+KnANLp jdTw== X-Gm-Message-State: APjAAAWyS5KHv4Uz1EvrhbMYrCrpdIvX1bUT7jJkS4YcXexqO7oAuIAG cVtDmOEgz+xiaEzHqqjt7uEDS1HnKU0= X-Google-Smtp-Source: APXvYqyNe+lHaz3VkZJfxpLG/XCIr871u5S7xffW9oEaMtX3pYNKLsMrPEOmNlFFMxmwnLTF9CHkhQ== X-Received: by 2002:a63:246:: with SMTP id 67mr13582947pgc.145.1560126383366; Sun, 09 Jun 2019 17:26:23 -0700 (PDT) Received: from sspatil-glaptop2.roam.corp.google.com (c-73-170-36-70.hsd1.ca.comcast.net. [73.170.36.70]) by smtp.gmail.com with ESMTPSA id 18sm5002405pfy.0.2019.06.09.17.26.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 09 Jun 2019 17:26:22 -0700 (PDT) From: Sandeep Patil To: ltp@lists.linux.it Date: Sun, 9 Jun 2019 17:26:10 -0700 Message-Id: <20190610002610.2187-4-sspatil@android.com> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog In-Reply-To: <20190610002610.2187-1-sspatil@android.com> References: <20190610002610.2187-1-sspatil@android.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: chrubis@suze.cz, kernel-team@android.com Subject: [LTP] [PATCH v2 3/3] syscalls/bind01: convert to new library. X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Drop UCLINUX specific tests along the way. Signed-off-by: Sandeep Patil --- v1->v2 ------ - Rebased after commit 'fa6a4e708 ("net: Introduce TST_GET_UNUSED_PORT() macro..)' testcases/kernel/syscalls/bind/bind01.c | 198 ++++++------------------ 1 file changed, 48 insertions(+), 150 deletions(-) diff --git a/testcases/kernel/syscalls/bind/bind01.c b/testcases/kernel/syscalls/bind/bind01.c index d2f50e806..49b5d866e 100644 --- a/testcases/kernel/syscalls/bind/bind01.c +++ b/testcases/kernel/syscalls/bind/bind01.c @@ -1,43 +1,7 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0 /* - * Test Name: bind01 - * - * Test Description: - * Verify that bind() returns the proper errno for various failure cases - * - * Usage: - * bind01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * None. - * + * Copyright (c) International Business Machines Corp., 2001 */ #include @@ -51,104 +15,51 @@ #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" -char *TCID = "bind01"; -int testno; +int inet_socket; +int dev_null; -int s; /* socket descriptor */ struct sockaddr_in sin1, sin2, sin3; -struct sockaddr_un sun1; - -void setup(void), setup0(void), setup1(void), setup2(void), -cleanup(void), cleanup0(void), cleanup1(void); +struct sockaddr_un sun; -struct test_case_t { /* test case structure */ - int domain; /* PF_INET, PF_UNIX, ... */ - int type; /* SOCK_STREAM, SOCK_DGRAM ... */ - int proto; /* protocol number (usually 0 = default) */ +static struct test_case { + int *socket_fd; /* file descriptor for test case */ struct sockaddr *sockaddr; /* socket address buffer */ - int salen; /* bind's 3rd argument */ - int retval; /* syscall return value */ + socklen_t salen; /* bind's 3rd argument */ + int retval; /* expected return value */ int experrno; /* expected errno */ - void (*setup) (void); - void (*cleanup) (void); char *desc; -} tdat[] = { -#ifndef UCLINUX -/* Skip since uClinux does not implement memory protection */ - { - PF_INET, SOCK_STREAM, 0, (struct sockaddr *)-1, - sizeof(struct sockaddr_in), -1, EFAULT, setup0, - cleanup0, "invalid sockaddr"}, -#endif - { - PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin1, - 3, -1, EINVAL, setup0, cleanup0, "invalid salen"}, { - 0, 0, 0, (struct sockaddr *)&sin1, - sizeof(sin1), -1, ENOTSOCK, setup1, cleanup1, - "invalid socket"} - , { - PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin2, - sizeof(sin2), 0, 0, setup0, cleanup0, "INADDR_ANYPORT"} - , { - PF_UNIX, SOCK_STREAM, 0, (struct sockaddr *)&sun1, - sizeof(sun1), -1, EADDRINUSE, setup0, cleanup0, - "UNIX-domain of current directory"} - , { - PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin3, - sizeof(sin3), -1, EADDRNOTAVAIL, setup0, cleanup0, - "non-local address"} -,}; - -int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]); - -int main(int argc, char *argv[]) +} tcases[] = { + { &inet_socket, (struct sockaddr *)&sin1, 3, -1, + EINVAL, "invalid salen" }, + { &dev_null, (struct sockaddr *)&sin1, sizeof(sin1), -1, + ENOTSOCK, "invalid socket" }, + { &inet_socket, (struct sockaddr *)&sin2, sizeof(sin2), 0, + 0, "INADDR_ANYPORT"}, + { &inet_socket, (struct sockaddr *)&sun, sizeof(sun), -1, + EAFNOSUPPORT, "UNIX-domain of current directory" }, + { &inet_socket, (struct sockaddr *)&sin3, sizeof(sin3), -1, + EADDRNOTAVAIL, "non-local address" }, +}; + +void verify_bind(unsigned int nr) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - for (testno = 0; testno < TST_TOTAL; ++testno) { - tdat[testno].setup(); - - TEST(bind - (s, tdat[testno].sockaddr, tdat[testno].salen)); - if (TEST_RETURN > 0) { - TEST_RETURN = 0; - } else { - } - if (TEST_RETURN != tdat[testno].retval || - (TEST_RETURN < 0 && - TEST_ERRNO != tdat[testno].experrno)) { - tst_resm(TFAIL, "%s ; returned" - " %ld (expected %d), errno %d (expected" - " %d)", tdat[testno].desc, - TEST_RETURN, tdat[testno].retval, - TEST_ERRNO, tdat[testno].experrno); - } else { - tst_resm(TPASS, "%s successful", - tdat[testno].desc); - } - tdat[testno].cleanup(); - } + struct test_case *tcase = &tcases[nr]; + + TEST(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen)); + if (TST_RET != tcase->retval && TST_ERR != tcase->experrno) { + tst_res(TFAIL, "%s ; returned" + " %ld (expected %d), errno %d (expected" + " %d)", tcase->desc, TST_RET, tcase->retval, + TST_ERR, tcase->experrno); + } else { + tst_res(TPASS, "%s successful", tcase->desc); } - cleanup(); - - tst_exit(); } -void setup(void) +void test_setup(void) { - - TEST_PAUSE; /* if -p option specified */ - /* initialize sockaddr's */ sin1.sin_family = AF_INET; /* this port must be unused! */ @@ -164,35 +75,22 @@ void setup(void) /* assumes 10.255.254.253 is not a local interface address! */ sin3.sin_addr.s_addr = htonl(0x0AFFFEFD); - sun1.sun_family = AF_UNIX; - strncpy(sun1.sun_path, ".", sizeof(sun1.sun_path)); - -} - -void cleanup(void) -{ -} + sun.sun_family = AF_UNIX; + strncpy(sun.sun_path, ".", sizeof(sun.sun_path)); -void setup0(void) -{ - s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type, - tdat[testno].proto); + inet_socket = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0); + dev_null = SAFE_OPEN("/dev/null", O_WRONLY); } -void cleanup0(void) +void test_cleanup(void) { - (void)close(s); + SAFE_CLOSE(inet_socket); + SAFE_CLOSE(dev_null); } -void setup1(void) -{ - /* setup for the "not a socket" case */ - if ((s = open("/dev/null", O_WRONLY)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "open(/dev/null) failed"); - -} - -void cleanup1(void) -{ - s = -1; -} +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = test_setup, + .cleanup = test_cleanup, + .test = verify_bind, +};