From patchwork Mon Mar 16 22:56:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 222434 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,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 6E7FDC2BB1D for ; Mon, 16 Mar 2020 22:57:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3ADC520679 for ; Mon, 16 Mar 2020 22:57:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399445; bh=dBsWz9addWONFKhna+kM5dhqeNsPSINqhlpIe9wHGnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zcjnEH9F68O7/5hokXqw06uBj0l5krFhTB794e0+DZTl+l63/z5p2MZaW5SOYxDSX +UUIiTGl5FCsH0CViXaNdY/9cpzH/zzt8y8W50szrVoLIHxK42yh6NBkuMrV0CZ5Mk Pa1rzVtaqinDgE2ZzXCyumaAvvHUgZPjbDxMb3oc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732899AbgCPW44 (ORCPT ); Mon, 16 Mar 2020 18:56:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:60116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732865AbgCPW4z (ORCPT ); Mon, 16 Mar 2020 18:56:55 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.1]) (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 03204206E2; Mon, 16 Mar 2020 22:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399415; bh=dBsWz9addWONFKhna+kM5dhqeNsPSINqhlpIe9wHGnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JsktEZ2KZrsXnfehohqXKiicv/WTjqA2HvjEEo/v/XupU0LuhDIZSTvQWdiQ3RpPk sk3IJR/RWPgyt29eEa7diZloXtUY+YsBNRjyFVGsc3m8/zdhZPdIQHhJ8ADfhdl5o3 ObQgekkNw3JiOa4Q7cmjcwvx6vOi9nMM+RX4hXrc= From: Jakub Kicinski To: shuah@kernel.org, keescook@chromium.org Cc: luto@amacapital.net, wad@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Tim.Bird@sony.com, Jakub Kicinski Subject: [PATCH v3 1/6] selftests/seccomp: use correct FIXTURE macro Date: Mon, 16 Mar 2020 15:56:41 -0700 Message-Id: <20200316225647.3129354-2-kuba@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316225647.3129354-1-kuba@kernel.org> References: <20200316225647.3129354-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Quoting kdoc: FIXTURE_DATA: * This call may be used when the type of the fixture data * is needed. In general, this should not be needed unless * the *self* is being passed to a helper directly. FIXTURE: * Defines the data provided to TEST_F()-defined tests as *self*. It should be * populated and cleaned up using FIXTURE_SETUP() and FIXTURE_TEARDOWN(). seccomp should use FIXTURE to declare types. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/seccomp/seccomp_bpf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index ee1b727ede04..7bf82fb07f67 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -909,7 +909,7 @@ TEST(ERRNO_order) EXPECT_EQ(12, errno); } -FIXTURE_DATA(TRAP) { +FIXTURE(TRAP) { struct sock_fprog prog; }; @@ -1020,7 +1020,7 @@ TEST_F(TRAP, handler) EXPECT_NE(0, (unsigned long)sigsys->_call_addr); } -FIXTURE_DATA(precedence) { +FIXTURE(precedence) { struct sock_fprog allow; struct sock_fprog log; struct sock_fprog trace; @@ -1509,7 +1509,7 @@ void tracer_poke(struct __test_metadata *_metadata, pid_t tracee, int status, EXPECT_EQ(0, ret); } -FIXTURE_DATA(TRACE_poke) { +FIXTURE(TRACE_poke) { struct sock_fprog prog; pid_t tracer; long poked; @@ -1817,7 +1817,7 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee, change_syscall(_metadata, tracee, -1, -ESRCH); } -FIXTURE_DATA(TRACE_syscall) { +FIXTURE(TRACE_syscall) { struct sock_fprog prog; pid_t tracer, mytid, mypid, parent; }; @@ -2321,7 +2321,7 @@ struct tsync_sibling { } \ } while (0) -FIXTURE_DATA(TSYNC) { +FIXTURE(TSYNC) { struct sock_fprog root_prog, apply_prog; struct tsync_sibling sibling[TSYNC_SIBLINGS]; sem_t started; From patchwork Mon Mar 16 22:56:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 222437 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, USER_AGENT_GIT autolearn=ham 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 03E7AC2BB1D for ; Mon, 16 Mar 2020 22:56:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CFDA1205ED for ; Mon, 16 Mar 2020 22:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399418; bh=KdS4RMI+OlO1mZZ760HpkNw0mD5vL6J8lZuSvxr4g2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=cH11axXF3Ho/wpHK0apu5OdzzIxCYEvZ0bDRgp9oF+pIIAqSKWyzkp1CstuRxk0Dn B4ZdtgxHbM0gWiWkne45tbLsj0VECZzgJEmEIKWMbJp7EfsMgaSvyLSMoaBhR/WcGB e2k2XhpTih2GntqoYVtIrd41TnuUxbAL474SEJrU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732917AbgCPW45 (ORCPT ); Mon, 16 Mar 2020 18:56:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:60134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732901AbgCPW44 (ORCPT ); Mon, 16 Mar 2020 18:56:56 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.1]) (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 848B620724; Mon, 16 Mar 2020 22:56:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399416; bh=KdS4RMI+OlO1mZZ760HpkNw0mD5vL6J8lZuSvxr4g2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rHnnmF82YVF8pEREsRVlQhzNlvi5A6Y+dsupVocbNclYPaFwCQoRZyadVUaLwcJeF JaVTNEPWSAXCQqELThYvXBsX9e3xXHsLuqUVxQuMiCQ/xcse8uOM70JB/rH7GKVMuG Pkz9gw+NlccVDJdv/a/2yFhT3+eexZM/FwTi6RDI= From: Jakub Kicinski To: shuah@kernel.org, keescook@chromium.org Cc: luto@amacapital.net, wad@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Tim.Bird@sony.com, Jakub Kicinski Subject: [PATCH v3 2/6] kselftest: factor out list manipulation to a helper Date: Mon, 16 Mar 2020 15:56:42 -0700 Message-Id: <20200316225647.3129354-3-kuba@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316225647.3129354-1-kuba@kernel.org> References: <20200316225647.3129354-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Kees suggest to factor out the list append code to a macro, since following commits need it, which leads to code duplication. Suggested-by: Kees Cook Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest_harness.h | 42 ++++++++++++--------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 5336b26506ab..aaf58fffc8f7 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -631,6 +631,29 @@ } \ } while (0); OPTIONAL_HANDLER(_assert) +/* List helpers */ +#define __LIST_APPEND(head, item) \ +{ \ + /* Circular linked list where only prev is circular. */ \ + if (head == NULL) { \ + head = item; \ + item->next = NULL; \ + item->prev = item; \ + return; \ + } \ + if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { \ + item->next = NULL; \ + item->prev = head->prev; \ + item->prev->next = item; \ + head->prev = item; \ + } else { \ + item->next = head; \ + item->next->prev = item; \ + item->prev = item; \ + head = item; \ + } \ +} + /* Contains all the information for test execution and status checking. */ struct __test_metadata { const char *name; @@ -665,24 +688,7 @@ static int __constructor_order; static inline void __register_test(struct __test_metadata *t) { __test_count++; - /* Circular linked list where only prev is circular. */ - if (__test_list == NULL) { - __test_list = t; - t->next = NULL; - t->prev = t; - return; - } - if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { - t->next = NULL; - t->prev = __test_list->prev; - t->prev->next = t; - __test_list->prev = t; - } else { - t->next = __test_list; - t->next->prev = t; - t->prev = t; - __test_list = t; - } + __LIST_APPEND(__test_list, t); } static inline int __bail(int for_realz, bool no_print, __u8 step) From patchwork Mon Mar 16 22:56:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 222435 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=-7.3 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,UNWANTED_LANGUAGE_BODY,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 DA354C4CECE for ; Mon, 16 Mar 2020 22:57:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B111620679 for ; Mon, 16 Mar 2020 22:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399435; bh=45fsYffh3Uo6wUAOX3qL24WDiWQ9Qas3Ng0BML8C6MM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=f0Kb8235DBjMBvoYAmg+gR4UdHyU4RDDKP2k8InMYILErNYkm6vTT/bPR6leXahH/ XQTVrVpJ3MLh6PmSW1bRUmvHZ5GVUzbKAWfEHrdPjFJG+bg8eOrQQvsSnvBVRyU8Ia zM8xMXEzpMoexFwE0aofL6UQY20HokjC9S7Y3icA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732937AbgCPW46 (ORCPT ); Mon, 16 Mar 2020 18:56:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:60206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732912AbgCPW46 (ORCPT ); Mon, 16 Mar 2020 18:56:58 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.1]) (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 2AB452076B; Mon, 16 Mar 2020 22:56:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399417; bh=45fsYffh3Uo6wUAOX3qL24WDiWQ9Qas3Ng0BML8C6MM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gkBN3NywToShhOuxRmmj/jNz3qh3Mtw9cfwRhurbVCQWMrnjC/jQiJrycXB3HqunT wZ5LjLDsTjSMhIRSolxuHdmh/FpVt6B4TMtqSZkNykojtMC0NFma3XXAIG9GmsMBqO HiM75j8lvQwFnf9V2q7TYY11K8Kw15oMo/CXJFhQ= From: Jakub Kicinski To: shuah@kernel.org, keescook@chromium.org Cc: luto@amacapital.net, wad@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Tim.Bird@sony.com, Jakub Kicinski Subject: [PATCH v3 4/6] kselftest: run tests by fixture Date: Mon, 16 Mar 2020 15:56:44 -0700 Message-Id: <20200316225647.3129354-5-kuba@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316225647.3129354-1-kuba@kernel.org> References: <20200316225647.3129354-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 --- tools/testing/selftests/kselftest_harness.h | 32 +++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 0f68943d6f04..36ab1b92eb35 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -660,8 +660,11 @@ } /* Contains all the information about a fixture */ +struct __test_metadata; + struct __fixture_metadata { const char *name; + struct __test_metadata *tests; struct __fixture_metadata *prev, *next; } _fixture_global __attribute__((unused)) = { .name = "global", @@ -696,7 +699,6 @@ struct __test_metadata { }; /* Storage for the (global) tests to be run. */ -static struct __test_metadata *__test_list; static unsigned int __test_count; /* @@ -710,8 +712,10 @@ static unsigned int __test_count; */ static inline void __register_test(struct __test_metadata *t) { + struct __fixture_metadata *f = t->fixture; + __test_count++; - __LIST_APPEND(__test_list, t); + __LIST_APPEND(f->tests, t); } static inline int __bail(int for_realz, bool no_print, __u8 step) @@ -724,14 +728,15 @@ static inline int __bail(int for_realz, bool no_print, __u8 step) return 0; } -void __run_test(struct __test_metadata *t) +void __run_test(struct __fixture_metadata *f, + struct __test_metadata *t) { pid_t child_pid; int status; t->passed = 1; t->trigger = 0; - printf("[ RUN ] %s.%s\n", t->fixture->name, t->name); + printf("[ RUN ] %s.%s\n", f->name, t->name); alarm(t->timeout); child_pid = fork(); if (child_pid < 0) { @@ -781,13 +786,14 @@ void __run_test(struct __test_metadata *t) } } printf("[ %4s ] %s.%s\n", (t->passed ? "OK" : "FAIL"), - t->fixture->name, t->name); + f->name, t->name); alarm(0); } 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; @@ -796,13 +802,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); - 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 Mon Mar 16 22:56:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 222436 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,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 19E23C18E5B for ; Mon, 16 Mar 2020 22:57:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E57DB205ED for ; Mon, 16 Mar 2020 22:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399428; bh=3nAKjWdCZeBeNiqg6OAGcwbLIEhlA/etmJ18+qXfLrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=HWR2YI5cJVqAujlDOLInVN5Uyx4Gtap9BiFLQA2sQ+J1ah9kq9POG5td2qngxTEsx cAGAKowHpty7f1tIoQKrse4TUlEfmNUVMA3ZDhRhpY2Vvu3pH/f2TuIib9fM87f4Rt +TWNatKDTb/r9HEUZDEgZ2Fr8UnL2DUn8swmoieU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732986AbgCPW5F (ORCPT ); Mon, 16 Mar 2020 18:57:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:60338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732959AbgCPW5C (ORCPT ); Mon, 16 Mar 2020 18:57:02 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.1]) (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 95FCA20736; Mon, 16 Mar 2020 22:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584399421; bh=3nAKjWdCZeBeNiqg6OAGcwbLIEhlA/etmJ18+qXfLrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4JN9/1Fq2VH4gi5n2KN9r9yklIktRnGToJRo/hvxjnYnflI5u1hMuLGkz3YJkmZ4 qFBQU8Ja4rD9NZd7ZoWuUHQgoclaWaa5quFghLTH6QjbQgRjsAy4ag3X1HL6DBO+qA BOq5L+U88YXPRARAUsxWx4OaMKNTaNujHQboM/E4= From: Jakub Kicinski To: shuah@kernel.org, keescook@chromium.org Cc: luto@amacapital.net, wad@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Tim.Bird@sony.com, Jakub Kicinski Subject: [PATCH v3 6/6] selftests: tls: run all tests for TLS 1.2 and TLS 1.3 Date: Mon, 16 Mar 2020 15:56:47 -0700 Message-Id: <20200316225647.3129354-8-kuba@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316225647.3129354-1-kuba@kernel.org> References: <20200316225647.3129354-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 --- 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