From patchwork Fri Sep 28 16:18:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vakul Garg X-Patchwork-Id: 10620153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CD1615A7 for ; Fri, 28 Sep 2018 16:18:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF3322BE0D for ; Fri, 28 Sep 2018 16:18:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2E8F2BE3F; Fri, 28 Sep 2018 16:18:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B88982BE2D for ; Fri, 28 Sep 2018 16:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728920AbeI1WnU (ORCPT ); Fri, 28 Sep 2018 18:43:20 -0400 Received: from mail-db5eur01on0060.outbound.protection.outlook.com ([104.47.2.60]:19904 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726121AbeI1WnT (ORCPT ); Fri, 28 Sep 2018 18:43:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UVJtdgQdaIS1lmiqZ843v6NgzKKPr7mymocEwXzeMMU=; b=oDvzsk3wUHwgeuDdLr0pzbp1RQRnF1wmypIY47+lc30eKTa2xPULwC4zeDWybXiMz4Z2yM9c/laXvtHDDOQtx3xRzgrIsl9CZQh4CQqUZnEerUBCd0JH16mOGqfYlBkvZKi7B/cfzOYLAWwEm7DyeZncVMLw6nI5MVlB4JCiyfo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vakul.garg@nxp.com; Received: from lti.ap.freescale.net (14.143.30.134) by AM0PR04MB4243.eurprd04.prod.outlook.com (2603:10a6:208:66::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 28 Sep 2018 16:18:41 +0000 From: Vakul Garg To: netdev@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, shuah@kernel.org, davejwatson@fb.com, davem@davemloft.net, doronrk@fb.com, Vakul Garg Subject: [PATCH net-next] selftests/tls: Fix recv(MSG_PEEK) & splice() test cases Date: Fri, 28 Sep 2018 21:48:08 +0530 Message-Id: <20180928161808.10363-1-vakul.garg@nxp.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 X-Originating-IP: [14.143.30.134] X-ClientProxiedBy: BM1PR0101CA0026.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1a::12) To AM0PR04MB4243.eurprd04.prod.outlook.com (2603:10a6:208:66::29) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 79a33dda-f244-4536-aa3d-08d6255e0f5d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM0PR04MB4243; X-Microsoft-Exchange-Diagnostics: 1;AM0PR04MB4243;3:c1um3I9j89E8Go8s42s2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by8VztTVB0QZyavFaYNX0Ew79qUuNfoDreLtPPnHb16RSnM9sdpNxOykcRLU7jghL4N6Kil9ed/iBMlmQbAeBco77mdw0pi6Tj+GCKPDOI72Q1URIp9ScjDGTLwMKM8GloxPXWiE1odo91emnNZHGJwpvoYeUNp42NR8xrNktGz2GA9vAKkgh8hSh6+ss/FB5W3tFvhCSGCcjJjUwK234kO60qouTMq6eItbsmABEmVjntCDa+yBNxpvK1dI7oAXlFjl6mm1dg+oqGMgTVxRlqgV6uYImd7GyGK0DJZMrOFTcj9C39/hcLdy/HeVcNNknOQNAwRa;4:zvKzPiQP5XT2rUHS+UMP/viSx/KZTRUiQRwwDhWck9okCYIR7FiMsykxh4gBk9l4dFACHZEt9wZu/N/LZJrwrDYS3oylIlvfrpQHIwzMs+olHBOwuxIfEIswKmmellj9BeaFiaVtvkL46rh/cZP7JnZLDi/9BLv1imJ+VgtdbDgbiNf74APESjl8NjbM6oRlWcHC2sSvL2scfjzj2iNXcYCnKtdJiRS/yUxRhKCM0JEnxdojUk/ehp3Ts9E+YFP8tbmzznBfHDAsCAcRUxv+6yvragreDh4OTDLdXsV8YA0GY+6RrW455+DNiJfcAyuZ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231355)(944501410)(52105095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051);SRVR:AM0PR04MB4243;BCL:0;PCL:0;RULEID:;SRVR:AM0PR04MB4243; X-Forefront-PRVS: 0809C12563 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(396003)(136003)(346002)(376002)(39860400002)(366004)(199004)(189003)(956004)(106356001)(105586002)(52116002)(6116002)(3846002)(486006)(44832011)(36756003)(5660300001)(476003)(2351001)(6666003)(4326008)(53936002)(2616005)(97736004)(6512007)(6916009)(6486002)(51416003)(5009440100003)(50466002)(25786009)(48376002)(1076002)(316002)(16586007)(186003)(16526019)(50226002)(8676002)(2361001)(8936002)(81156014)(68736007)(47776003)(26005)(6506007)(86362001)(305945005)(2906002)(478600001)(34290500001)(386003)(81166006)(7736002)(66066001)(55236004)(110426005);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4243;H:lti.ap.freescale.net;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;AM0PR04MB4243;23:o0lwBmuMKezhLJIxQrrdrYcqJK/RbrsGSAzs7rvJ5rk1I5qUC+jAjvn/HqRzs+H7bKrzTOEVLGCGmGz6Qe+VJLCSVtYnq8QIrsigJtIE9CT5ZNDMbHwmJY8N30NpwtfaiEipLF77t/nGbyMjaC0F0mtkCd0SEo66RXj2CFnsWA6dO8jPThkFAYVYRSm/uhwwcKKYPVQOpTokIjPKB3TaRUb7ge0+u2nYru28uorBihWO2dTWwzxh4LIqiNHsa3tGMj8ZoItGjwK7fkiPG7TyZOzhpDXhKsK8Qqnji8cgtNn+AeIxSRRoDH/pw8GQHDILtClu7HunzT/6J4n6x8uHODcpS9DFKlzrUG5U0mOSfLqvx1S4Un3NlujprHjEE5XRGpL1rZd9Oh3Y136soZpLrcDCOQ57mBjUHNwJd3LCwKXvElK/NL6Cw32eRWvfrGOedMD5J+NsHQZPwd3ZM0QD17tknXlzaJTmemeqHguCxv5uxz7aby6a6fx52mixLW39Nw2m5lr7K5NiTnDMWpjqem0KIvkBxBz0HInk7aOHATluvI4TqiomNTqnPOrSvpqnhZdWJd+/Ch8j4KtiIr+RV7bfDQl2pyrynxuSyUeOTdwQmGxzbexgmqKuvAPMtevq4lJOwB1gmuV3R5a02XnBO8NEI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3MA1zvgB8vdRBr2FIG6Nh0kT6uLYvRfqYVRglJGzx5qEauVrYOlSkos1EotqnAStfeSb75Qk+TQ3/QrhawHKrW7SYp7gz794pCGui28kaF6VYyXct9avX4iFxRNGS3pBQPgwu7MmKZsb3abJ1ruPDPSzKaLg3lwOse9e0vS/OlnA314SFQziuAsMwB1Ro1v7mXlPWKGf/JZ8m8CvZQDN/eTM5R+zF8ToUPoVyowUsj+eobHUNSCtcL2FjXj8DfYV7bmhlxKwtnfcvczQLX/ANFGv7uUb3dTC2bl2NEth/Fr+24Ea7LfAGyXDe57JTEFW18mTUyBC3DLjdI8Ckh/159PYWWFsDqLHPIdFjgt1w1NE51aKvGERd+4Myk5k/EZmcjTO3nbNtXhDvr3PurwmizVlEMIZEMpTxRp1rPv1b23ddEdVK0dgKeZPJ/JRg==;5:e4A3Mb4CVvdtlQRNZ/dRpvAyyOBbK4lUrI6iDhzvWVw3rqSOQVi+pHU/bs+stg+pV6efCOJa2ZGTeqGnETG/JaQG1giLfJ4uVr9z+JmtIDiHf4Fm2kwhHEcwO1zfIsKMGoYGdWqEg/9IDoB7pkRZ6LFW5Dxs5v3/eD7XS1sfl9k=;7:vk9+eo4Rc5mG628Prdchzi9zn4CxHzF/RrznyKSU3ckcn4+jQ1tiWdyNiBgQRu0seOWZYaNLfUCAoKGo7BeMXY/VtKON3ZPGDGjlYJQboCEhXF00a7qWeA97KFU08pvedcgJA3XKyxNKYjXqfFQLwiOW8JKKkrSqr0OFW2KY2jFz7A11th6czUr9vHLIqsQEPj7ALM3IbQXDTq31EUp1U2OfN0L0r+y8pjsInNehsr2S1i+h77vyF03sWtZ4RT4p SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2018 16:18:41.9353 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79a33dda-f244-4536-aa3d-08d6255e0f5d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4243 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP TLS test cases splice_from_pipe, send_and_splice & recv_peek_multiple_records expect to receive a given nummber of bytes and then compare them against the number of bytes which were sent. Therefore, system call recv() must not return before receiving the requested number of bytes, otherwise the subsequent memcmp() fails. This patch passes MSG_WAITALL flag to recv() so that it does not return prematurely before requested number of bytes are copied to receive buffer. Signed-off-by: Vakul Garg --- tools/testing/selftests/net/tls.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c index 11d54c36ae49..fac68d710f35 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -288,7 +288,7 @@ TEST_F(tls, splice_from_pipe) ASSERT_GE(pipe(p), 0); EXPECT_GE(write(p[1], mem_send, send_len), 0); EXPECT_GE(splice(p[0], NULL, self->fd, NULL, send_len, 0), 0); - EXPECT_GE(recv(self->cfd, mem_recv, send_len, 0), 0); + EXPECT_EQ(recv(self->cfd, mem_recv, send_len, MSG_WAITALL), send_len); EXPECT_EQ(memcmp(mem_send, mem_recv, send_len), 0); } @@ -322,13 +322,13 @@ TEST_F(tls, send_and_splice) ASSERT_GE(pipe(p), 0); EXPECT_EQ(send(self->fd, test_str, send_len2, 0), send_len2); - EXPECT_NE(recv(self->cfd, buf, send_len2, 0), -1); + EXPECT_EQ(recv(self->cfd, buf, send_len2, MSG_WAITALL), send_len2); EXPECT_EQ(memcmp(test_str, buf, send_len2), 0); EXPECT_GE(write(p[1], mem_send, send_len), send_len); EXPECT_GE(splice(p[0], NULL, self->fd, NULL, send_len, 0), send_len); - EXPECT_GE(recv(self->cfd, mem_recv, send_len, 0), 0); + EXPECT_EQ(recv(self->cfd, mem_recv, send_len, MSG_WAITALL), send_len); EXPECT_EQ(memcmp(mem_send, mem_recv, send_len), 0); } @@ -516,17 +516,17 @@ TEST_F(tls, recv_peek_multiple_records) len = strlen(test_str_second) + 1; EXPECT_EQ(send(self->fd, test_str_second, len, 0), len); - len = sizeof(buf); + len = strlen(test_str_first); memset(buf, 0, len); - EXPECT_NE(recv(self->cfd, buf, len, MSG_PEEK), -1); + EXPECT_EQ(recv(self->cfd, buf, len, MSG_PEEK | MSG_WAITALL), len); /* MSG_PEEK can only peek into the current record. */ - len = strlen(test_str_first) + 1; + len = strlen(test_str_first); EXPECT_EQ(memcmp(test_str_first, buf, len), 0); - len = sizeof(buf); + len = strlen(test_str) + 1; memset(buf, 0, len); - EXPECT_NE(recv(self->cfd, buf, len, 0), -1); + EXPECT_EQ(recv(self->cfd, buf, len, MSG_WAITALL), len); /* Non-MSG_PEEK will advance strparser (and therefore record) * however. @@ -543,9 +543,9 @@ TEST_F(tls, recv_peek_multiple_records) len = strlen(test_str_second) + 1; EXPECT_EQ(send(self->fd, test_str_second, len, 0), len); - len = sizeof(buf); + len = strlen(test_str) + 1; memset(buf, 0, len); - EXPECT_NE(recv(self->cfd, buf, len, MSG_PEEK), -1); + EXPECT_EQ(recv(self->cfd, buf, len, MSG_PEEK | MSG_WAITALL), len); len = strlen(test_str) + 1; EXPECT_EQ(memcmp(test_str, buf, len), 0);