From patchwork Tue Apr 28 01:03:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 208551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9ED9C83005 for ; Tue, 28 Apr 2020 01:04:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5B36206D9 for ; Tue, 28 Apr 2020 01:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588035868; bh=g/zxUoV11L3leiURwmH4DyXBiVX/z9vSKwWK/3LSbSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gj/ZIbvBbtg/ySXhWdWg+kxSMpz1DZ8FGfvtBUvSgDLX+4ufonHMGM2/yqUqvWN7L gDMnE7WCUsSorhWdVZ/2OzvAQsOZCD5FBJ4atMijTEoopRYun86A1s1I2eEjpsLssl knLgmepAopLQ9x6c8BIa02fvTdxRxE48fQDzNoho= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726445AbgD1BEA (ORCPT ); Mon, 27 Apr 2020 21:04:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:36606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgD1BD7 (ORCPT ); Mon, 27 Apr 2020 21:03:59 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D127B2087E; Tue, 28 Apr 2020 01:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588035839; bh=g/zxUoV11L3leiURwmH4DyXBiVX/z9vSKwWK/3LSbSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ypE/NOh5NrKs2lYSEgArtTZbdYavf4VBSDG4smMWrW4aKTRSe0nHPjVsM3YWWfjiB SBLc7XG+34A5O9+nUJcoxmynzcWgl7L0qP6kyzZ/BceN2kMbcukfO97uaTIqilqrUa +y4BaWZzkZFdKsEsKDywNFVBbcXo3KfTsYatlQwg= From: Jakub Kicinski To: davem@davemloft.net Cc: keescook@chromium.org, shuah@kernel.org, netdev@vger.kernel.org, luto@amacapital.net, wad@chromium.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Tim.Bird@sony.com, Jakub Kicinski Subject: [PATCH net-next v6 3/5] kselftest: run tests by fixture Date: Mon, 27 Apr 2020 18:03:49 -0700 Message-Id: <20200428010351.331260-4-kuba@kernel.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200428010351.331260-1-kuba@kernel.org> References: <20200428010351.331260-1-kuba@kernel.org> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Now that all tests have a fixture object move from a global list of tests to a list of tests per fixture. Order of tests may change as we will now group and run test fixture by fixture, rather than in declaration order. Signed-off-by: Jakub Kicinski Acked-by: Kees Cook --- v5 (Kees): - move a comment; - remove temporary variable. --- tools/testing/selftests/kselftest_harness.h | 23 +++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index de283fd6fc4d..fa7185e45472 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -659,9 +659,12 @@ } \ } +struct __test_metadata; + /* Contains all the information about a fixture. */ struct __fixture_metadata { const char *name; + struct __test_metadata *tests; struct __fixture_metadata *prev, *next; } _fixture_global __attribute__((unused)) = { .name = "global", @@ -698,7 +701,6 @@ struct __test_metadata { }; /* Storage for the (global) tests to be run. */ -static struct __test_metadata *__test_list; static unsigned int __test_count; /* @@ -713,7 +715,7 @@ static unsigned int __test_count; static inline void __register_test(struct __test_metadata *t) { __test_count++; - __LIST_APPEND(__test_list, t); + __LIST_APPEND(t->fixture->tests, t); } static inline int __bail(int for_realz, bool no_print, __u8 step) @@ -843,6 +845,7 @@ void __run_test(struct __fixture_metadata *f, static int test_harness_run(int __attribute__((unused)) argc, char __attribute__((unused)) **argv) { + struct __fixture_metadata *f; struct __test_metadata *t; int ret = 0; unsigned int count = 0; @@ -851,13 +854,15 @@ static int test_harness_run(int __attribute__((unused)) argc, /* TODO(wad) add optional arguments similar to gtest. */ printf("[==========] Running %u tests from %u test cases.\n", __test_count, __fixture_count + 1); - for (t = __test_list; t; t = t->next) { - count++; - __run_test(t->fixture, t); - if (t->passed) - pass_count++; - else - ret = 1; + for (f = __fixture_list; f; f = f->next) { + for (t = f->tests; t; t = t->next) { + count++; + __run_test(f, t); + if (t->passed) + pass_count++; + else + ret = 1; + } } printf("[==========] %u / %u tests passed.\n", pass_count, count); printf("[ %s ]\n", (ret ? "FAILED" : "PASSED")); From patchwork Tue Apr 28 01:03:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 208552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A97F5C83001 for ; Tue, 28 Apr 2020 01:04:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8273E206D9 for ; Tue, 28 Apr 2020 01:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588035855; bh=hEAM8D7/SUsiKAc+5z81o3UhOC4lXna1wiU4BP9pTCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=C2GLwTIjPdPYJvnkwuDwSl43ws4XseJadXQnCxaOSFWOX0XAG3SQh9BmHvVcJIXaN WVlXLJEWKJqCULivwoiJjSCFFbo0PUvPjH8T0ScM8sEvFfUDHKdPCCp0iilgcw3vl9 ZleS5tuF/Arekmm7ZoI26HZ/qK6y9bTZbHTpmwvU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbgD1BEB (ORCPT ); Mon, 27 Apr 2020 21:04:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:36588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726425AbgD1BEB (ORCPT ); Mon, 27 Apr 2020 21:04:01 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F070E21775; Tue, 28 Apr 2020 01:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588035840; bh=hEAM8D7/SUsiKAc+5z81o3UhOC4lXna1wiU4BP9pTCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jJk2GlbkmARyyuw/vHeG0IrUxQQMRuBe4kDStAkNj63VUEqRVouGjrR43LEwVPmD9 BtJjSj5CoJ0PzdHLDHHfMWvyartD31Wg983OXlxw4Dc7q7ZazYgXJmH+cCghebbBU6 jPg3cX32HKez53Smg2d/j5CLIv1m++0OvQU1Sv/c= From: Jakub Kicinski To: davem@davemloft.net Cc: keescook@chromium.org, shuah@kernel.org, netdev@vger.kernel.org, luto@amacapital.net, wad@chromium.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Tim.Bird@sony.com, Jakub Kicinski Subject: [PATCH net-next v6 5/5] selftests: tls: run all tests for TLS 1.2 and TLS 1.3 Date: Mon, 27 Apr 2020 18:03:51 -0700 Message-Id: <20200428010351.331260-6-kuba@kernel.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200428010351.331260-1-kuba@kernel.org> References: <20200428010351.331260-1-kuba@kernel.org> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org TLS 1.2 and TLS 1.3 differ in the implementation. Use fixture parameters to run all tests for both versions, and remove the one-off TLS 1.2 test. Signed-off-by: Jakub Kicinski Reviewed-by: Kees Cook --- tools/testing/selftests/net/tls.c | 93 ++++++------------------------- 1 file changed, 17 insertions(+), 76 deletions(-) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c index 0ea44d975b6c..c5282e62df75 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -101,6 +101,21 @@ FIXTURE(tls) bool notls; }; +FIXTURE_VARIANT(tls) +{ + unsigned int tls_version; +}; + +FIXTURE_VARIANT_ADD(tls, 12) +{ + .tls_version = TLS_1_2_VERSION, +}; + +FIXTURE_VARIANT_ADD(tls, 13) +{ + .tls_version = TLS_1_3_VERSION, +}; + FIXTURE_SETUP(tls) { struct tls12_crypto_info_aes_gcm_128 tls12; @@ -112,7 +127,7 @@ FIXTURE_SETUP(tls) len = sizeof(addr); memset(&tls12, 0, sizeof(tls12)); - tls12.info.version = TLS_1_3_VERSION; + tls12.info.version = variant->tls_version; tls12.info.cipher_type = TLS_CIPHER_AES_GCM_128; addr.sin_family = AF_INET; @@ -733,7 +748,7 @@ TEST_F(tls, bidir) struct tls12_crypto_info_aes_gcm_128 tls12; memset(&tls12, 0, sizeof(tls12)); - tls12.info.version = TLS_1_3_VERSION; + tls12.info.version = variant->tls_version; tls12.info.cipher_type = TLS_CIPHER_AES_GCM_128; ret = setsockopt(self->fd, SOL_TLS, TLS_RX, &tls12, @@ -1258,78 +1273,4 @@ TEST(keysizes) { close(cfd); } -TEST(tls12) { - int fd, cfd; - bool notls; - - struct tls12_crypto_info_aes_gcm_128 tls12; - struct sockaddr_in addr; - socklen_t len; - int sfd, ret; - - notls = false; - len = sizeof(addr); - - memset(&tls12, 0, sizeof(tls12)); - tls12.info.version = TLS_1_2_VERSION; - tls12.info.cipher_type = TLS_CIPHER_AES_GCM_128; - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = 0; - - fd = socket(AF_INET, SOCK_STREAM, 0); - sfd = socket(AF_INET, SOCK_STREAM, 0); - - ret = bind(sfd, &addr, sizeof(addr)); - ASSERT_EQ(ret, 0); - ret = listen(sfd, 10); - ASSERT_EQ(ret, 0); - - ret = getsockname(sfd, &addr, &len); - ASSERT_EQ(ret, 0); - - ret = connect(fd, &addr, sizeof(addr)); - ASSERT_EQ(ret, 0); - - ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls")); - if (ret != 0) { - notls = true; - printf("Failure setting TCP_ULP, testing without tls\n"); - } - - if (!notls) { - ret = setsockopt(fd, SOL_TLS, TLS_TX, &tls12, - sizeof(tls12)); - ASSERT_EQ(ret, 0); - } - - cfd = accept(sfd, &addr, &len); - ASSERT_GE(cfd, 0); - - if (!notls) { - ret = setsockopt(cfd, IPPROTO_TCP, TCP_ULP, "tls", - sizeof("tls")); - ASSERT_EQ(ret, 0); - - ret = setsockopt(cfd, SOL_TLS, TLS_RX, &tls12, - sizeof(tls12)); - ASSERT_EQ(ret, 0); - } - - close(sfd); - - char const *test_str = "test_read"; - int send_len = 10; - char buf[10]; - - send_len = strlen(test_str) + 1; - EXPECT_EQ(send(fd, test_str, send_len, 0), send_len); - EXPECT_NE(recv(cfd, buf, send_len, 0), -1); - EXPECT_EQ(memcmp(buf, test_str, send_len), 0); - - close(fd); - close(cfd); -} - TEST_HARNESS_MAIN