From patchwork Tue Sep 11 10:24:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junchi Chen X-Patchwork-Id: 968371 X-Patchwork-Delegate: petr.vorel@gmail.com 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=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 428TGr58lRz9s4s for ; Tue, 11 Sep 2018 12:23:15 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 216CF3E629F for ; Tue, 11 Sep 2018 04:23:12 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 9C1EB3E625C for ; Tue, 11 Sep 2018 04:23:10 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 63AA820007F for ; Tue, 11 Sep 2018 04:23:06 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 19:23:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,358,1531810800"; d="scan'208";a="73217805" Received: from lckqa-nuc7i5dnhe.sh.intel.com ([10.239.161.22]) by orsmga006.jf.intel.com with ESMTP; 10 Sep 2018 19:22:48 -0700 From: Junchi Chen To: ltp@lists.linux.it Date: Tue, 11 Sep 2018 18:24:03 +0800 Message-Id: <20180911102403.7094-1-junchi.chen@intel.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=DATE_IN_FUTURE_06_12, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH ltp] syscalls/bind03: Modified to test errors separately. 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" To avoid mess with the priority of EADDRINUSE and EINVAL, we split the test to test these two -- one invalid parameter at a time. Signed-off-by: Junchi Chen --- testcases/kernel/syscalls/bind/bind03.c | 47 +++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/testcases/kernel/syscalls/bind/bind03.c b/testcases/kernel/syscalls/bind/bind03.c index 955a69dd2..dda5ca374 100644 --- a/testcases/kernel/syscalls/bind/bind03.c +++ b/testcases/kernel/syscalls/bind/bind03.c @@ -17,58 +17,59 @@ #include "tst_test.h" #include "tst_safe_net.h" -#define SNAME "socket.1" +#define SNAME_A "socket.1" +#define SNAME_B "socket.2" static int sock1, sock2; void run(void) { - struct sockaddr_un sun; + struct sockaddr_un sun1; + struct sockaddr_un sun2; sock1 = SAFE_SOCKET(PF_UNIX, SOCK_STREAM, 0); - memset(&sun, 0, sizeof(sun)); - sun.sun_family = AF_UNIX; - if (sprintf(sun.sun_path, "%s", SNAME) < (int) strlen(SNAME)) { + memset(&sun1, 0, sizeof(sun1)); + memset(&sun2, 0, sizeof(sun2)); + + sun1.sun_family = AF_UNIX; + sun2.sun_family = AF_UNIX; + + if (sprintf(sun1.sun_path, "%s", SNAME_A) < (int) strlen(SNAME_A)) { + tst_res(TFAIL, "sprintf failed"); + return; + } + + if (sprintf(sun2.sun_path, "%s", SNAME_B) < (int) strlen(SNAME_B)) { tst_res(TFAIL, "sprintf failed"); return; } - SAFE_BIND(sock1, (struct sockaddr *)&sun, sizeof(sun)); + SAFE_BIND(sock1, (struct sockaddr *)&sun1, sizeof(sun1)); /* * Once a STREAM UNIX domain socket has been bound, it can't be * rebound. */ - if (bind(sock1, (struct sockaddr *)&sun, sizeof(sun)) == 0) { + if (bind(sock1, (struct sockaddr *)&sun2, sizeof(sun2)) == 0) { tst_res(TFAIL, "re-binding of socket succeeded"); return; } - /* - * The behavious diverse according to kernel version - * for v4.10 or later, the expected error is EADDRINUSE, - * otherwise EINVAL. - */ - if (tst_kvercmp(4, 10, 0) < 0) { - if (errno != EINVAL) { - tst_res(TFAIL | TERRNO, "expected EINVAL"); - return; - } - } else { - if (errno != EADDRINUSE) { - tst_res(TFAIL | TERRNO, "expected EADDRINUSE"); - return; - } + if (errno != EINVAL) { + tst_res(TFAIL | TERRNO, "expected EINVAL"); + return; } + tst_res(TPASS, "bind() failed with EINVAL as expected"); + sock2 = SAFE_SOCKET(PF_UNIX, SOCK_STREAM, 0); /* * Since a socket is already bound to the pathname, it can't be bound * to a second socket. Expected error is EADDRINUSE. */ - if (bind(sock2, (struct sockaddr *)&sun, sizeof(sun)) == 0) { + if (bind(sock2, (struct sockaddr *)&sun1, sizeof(sun1)) == 0) { tst_res(TFAIL, "bind() succeeded with already bound pathname!"); return; }