From patchwork Tue Feb 20 19:22:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 774409 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 582BA14A4EA; Tue, 20 Feb 2024 19:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456967; cv=none; b=WMtASy8T+SEOYTKg3l58XU0qCpGsRCmWpftlNbB5AB1/h1Gj2UXNATvS7fNfTHqlSGQeCaw+UY049TgwHK5sbVg3Q5M3HpqphfA+gAERay1uebYqpmbPKIkM1r1BBU2cxcafL3kluALEXTAzNclCQzu8Rl6MiW9ObQL8SZGzrvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456967; c=relaxed/simple; bh=QFefN2pMJk3wF8CJAX8FXQUW7G2GGo/zUOy3/fKo+Jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uo7Rf5YReXukZC3kz+UfcD28orZ+sMbmrmDuIasdKUI5syU/Mth0bKPJ/nsT02DjppJv4SJc6jFGV8VU+W94kFBp4BYVHkCaWo2HV4ba8TIKEjG/28r5bgq65WBQCDliR2aCBH/WvBWJ4nA65/PRCZioDMfNjVMmzNIMrgclvXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kSf2H14R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kSf2H14R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63FF2C433F1; Tue, 20 Feb 2024 19:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708456966; bh=QFefN2pMJk3wF8CJAX8FXQUW7G2GGo/zUOy3/fKo+Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kSf2H14R17b9wRAMRCwaQoK+jbbx2y3e+w5Tbf9VJWWb01idSvCdAmZhRrVcNjNVP 53XUW4IwJajjIVl+Br3A2gD0lDYB7UkDvloq31KYtO+qC4W192NjM0N58eOBpcXLLu GkPCW1ahPTAcMsu1Dm9JChB9GfJL2r3O2Z5RJ1ak03jaCQW/1rVed7MvjYW/+8f9Xn J4Rgj6mm3tWdXG1gc58dsZujxzgqxIr5mWnysBjwStQH34MK6Xr7M6ZafOzH/si971 RT1gpFcQ4tjPOpFBgXFyF1oTjPAAzkNVp9oYVC7586gIa3YNvVGk+8uxlijXo0s65V n16xlKAX/LeCg== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, mic@digikod.net, linux-security-module@vger.kernel.org, keescook@chromium.org, jakub@cloudflare.com, Jakub Kicinski , luto@amacapital.net, wad@chromium.org Subject: [PATCH net-next v3 01/11] selftests: kselftest_harness: pass step via shared memory Date: Tue, 20 Feb 2024 11:22:25 -0800 Message-ID: <20240220192235.2953484-2-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org> References: <20240220192235.2953484-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit 0ef67a888375 ("selftests/harness: Report skip reason") added shared memory to communicate between harness and test. Use that instead of exit codes to send the failing step back to the harness. The exit codes are limited and because of the step passing we can't use the full range of KSFT_* exit codes. Acked-by: Kees Cook Tested-by: Jakub Sitnicki Signed-off-by: Jakub Kicinski --- CC: mic@digikod.net CC: luto@amacapital.net CC: wad@chromium.org CC: shuah@kernel.org CC: linux-kselftest@vger.kernel.org CC: linux-security-module@vger.kernel.org --- tools/testing/selftests/kselftest_harness.h | 21 ++++++++++----------- tools/testing/selftests/landlock/common.h | 5 ++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index e05ac8261046..98bdedf9a53a 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -101,8 +101,8 @@ * ASSERT_* number for which the test failed. This behavior can be enabled by * writing `_metadata->no_print = true;` before the check sequence that is * unable to print. When an error occur, instead of printing an error message - * and calling `abort(3)`, the test process call `_exit(2)` with the assert - * number as argument, which is then printed by the parent process. + * and calling `abort(3)`, the test process call `_exit(2)` and pass the error + * to be printed to the parent process via shared memory. */ #define TH_LOG(fmt, ...) do { \ if (TH_LOG_ENABLED) \ @@ -695,9 +695,8 @@ __bail(_assert, _metadata)) #define __INC_STEP(_metadata) \ - /* Keep "step" below 255 (which is used for "SKIP" reporting). */ \ - if (_metadata->passed && _metadata->step < 253) \ - _metadata->step++; + if (_metadata->passed) \ + _metadata->results->step++; #define is_signed_type(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1)) @@ -784,6 +783,7 @@ struct __test_results { char reason[1024]; /* Reason for test result */ + unsigned int step; /* Test step reached without failure */ }; struct __test_metadata; @@ -837,7 +837,6 @@ struct __test_metadata { int trigger; /* extra handler after the evaluation */ int timeout; /* seconds to wait for test timeout */ bool timed_out; /* did this test timeout instead of exiting? */ - __u8 step; bool no_print; /* manual trigger when TH_LOG_STREAM is not available */ bool aborted; /* stopped test due to failed ASSERT */ bool setup_completed; /* did setup finish? */ @@ -875,7 +874,7 @@ static inline void __test_check_assert(struct __test_metadata *t) { if (t->aborted) { if (t->no_print) - _exit(t->step); + _exit(1); abort(); } } @@ -960,7 +959,7 @@ void __wait_for_test(struct __test_metadata *t) fprintf(TH_LOG_STREAM, "# %s: Test failed at step #%d\n", t->name, - WEXITSTATUS(status)); + t->results->step); } } } else if (WIFSIGNALED(status)) { @@ -1114,9 +1113,9 @@ void __run_test(struct __fixture_metadata *f, t->passed = 1; t->skip = 0; t->trigger = 0; - t->step = 1; t->no_print = 0; memset(t->results->reason, 0, sizeof(t->results->reason)); + t->results->step = 1; ksft_print_msg(" RUN %s%s%s.%s ...\n", f->name, variant->name[0] ? "." : "", variant->name, t->name); @@ -1137,8 +1136,8 @@ void __run_test(struct __fixture_metadata *f, /* Pass is exit 0 */ if (t->passed) _exit(0); - /* Something else happened, report the step. */ - _exit(t->step); + /* Something else happened. */ + _exit(1); } else { __wait_for_test(t); } diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h index e64bbdf0e86e..c15e22abdca6 100644 --- a/tools/testing/selftests/landlock/common.h +++ b/tools/testing/selftests/landlock/common.h @@ -50,13 +50,13 @@ _exit(255); \ if (_metadata->passed) \ _exit(0); \ - _exit(_metadata->step); \ + _exit(1); \ } \ if (child != waitpid(child, &status, 0)) \ abort(); \ if (WIFSIGNALED(status) || !WIFEXITED(status)) { \ _metadata->passed = 0; \ - _metadata->step = 1; \ + _metadata->results->step = 1; \ return; \ } \ switch (WEXITSTATUS(status)) { \ @@ -69,7 +69,6 @@ break; \ default: \ _metadata->passed = 0; \ - _metadata->step = WEXITSTATUS(status); \ break; \ } \ } \ From patchwork Tue Feb 20 19:22:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 774408 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4EF014A4E2; Tue, 20 Feb 2024 19:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456968; cv=none; b=KD2ELl8PHHPx0J+WciF9FQb3qJgBD3v2XTuFslcCnhFmIUr0HooejL5ubDip61hWTuBbqBv9zLjF9pBd6Xp7peMQwFM9lK11xkPkh16Gz1zN0D6g1SHun0l/+U+XUZ7Muq+coA0uwH/CdO7qyS1GMy8o2ZEEJMWMoXsdNfjiHso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456968; c=relaxed/simple; bh=i7OQ0CBPUvcZuB1M/xw7S8wpiJMS1dvOsrgRmQy3mEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TehmCCE+8Vqw92y7I0s7j+XZzcK/GUPFuBC04x9V3iBmnBZ0dlgym3tddORzb7azNB6QJUcaFIR4BTpK7Kamvrhk0JHujpJcCaxV9hOeyB2NlxKGK15IVz8mrEp89yTDguPON/ta6k1Z6nyzvyH4lXRk/oTUjRLOALtBh5D9mOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XYfzcEMD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XYfzcEMD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A88ACC43390; Tue, 20 Feb 2024 19:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708456968; bh=i7OQ0CBPUvcZuB1M/xw7S8wpiJMS1dvOsrgRmQy3mEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYfzcEMDSxpyolsXWnaoC/5SujI3JSi38UCTNU5oQRkSW3yEEe/x5uoW9lpvadSAN mnnFwC+uQwDPQuyNV+FcdLMZqyEli6BVFXfSFud8Tdy1TjVAaFxgmysKkUj6xRKDhR 7LAHYhD+ULh7CMcQFjQK+PkBBXDLsvm69TVf0n+V7wZGbr+SOkfuxu7pQCd7I2il03 NVAZ9dbdp0eUZMQGyBkyctd5bF65dkBQc6PjERuN8avXCGoPKS7jIM/Q4JaT8JK8e2 c6N301DF6Sv62OJvBhf0XEzZu3IAi95O2qjuVyla/WOCgML40ZaekDXfcLgPcEwoS6 mYlQ+HX7YpZ5A== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, mic@digikod.net, linux-security-module@vger.kernel.org, keescook@chromium.org, jakub@cloudflare.com, Jakub Kicinski Subject: [PATCH net-next v3 03/11] selftests: kselftest_harness: generate test name once Date: Tue, 20 Feb 2024 11:22:27 -0800 Message-ID: <20240220192235.2953484-4-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org> References: <20240220192235.2953484-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since we added variant support generating full test case name takes 4 string arguments. We're about to need it in another two places. Stop the duplication and print once into a temporary buffer. Suggested-by: Jakub Sitnicki Acked-by: Kees Cook Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest_harness.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 618b41eac749..8fc24a728240 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -1109,6 +1110,8 @@ void __run_test(struct __fixture_metadata *f, struct __fixture_variant_metadata *variant, struct __test_metadata *t) { + char test_name[LINE_MAX]; + /* reset test struct */ t->passed = 1; t->skip = 0; @@ -1117,8 +1120,10 @@ void __run_test(struct __fixture_metadata *f, memset(t->results->reason, 0, sizeof(t->results->reason)); t->results->step = 1; - ksft_print_msg(" RUN %s%s%s.%s ...\n", - f->name, variant->name[0] ? "." : "", variant->name, t->name); + snprintf(test_name, sizeof(test_name), "%s%s%s.%s", + f->name, variant->name[0] ? "." : "", variant->name, t->name); + + ksft_print_msg(" RUN %s ...\n", test_name); /* Make sure output buffers are flushed before fork */ fflush(stdout); @@ -1140,15 +1145,14 @@ void __run_test(struct __fixture_metadata *f, } else { __wait_for_test(t); } - ksft_print_msg(" %4s %s%s%s.%s\n", t->passed ? "OK" : "FAIL", - f->name, variant->name[0] ? "." : "", variant->name, t->name); + ksft_print_msg(" %4s %s\n", + t->passed ? "OK" : "FAIL", test_name); if (t->skip) ksft_test_result_skip("%s\n", t->results->reason[0] ? t->results->reason : "unknown"); else - ksft_test_result(t->passed, "%s%s%s.%s\n", - f->name, variant->name[0] ? "." : "", variant->name, t->name); + ksft_test_result(t->passed, "%s\n", test_name); } static int test_harness_run(int argc, char **argv) From patchwork Tue Feb 20 19:22:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 774407 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B98CC14D435; Tue, 20 Feb 2024 19:22:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456969; cv=none; b=ivhyFpuw5Ykbu27TH3skF2hZJOesyjE73YtZR/lya6adFqsAf7oOSxCSFvhjpNO/QVnjg/itDz+1ZWV/Jz6CpLfMVeljvp2TaxcbfaN6tyYJnAm69CgtCkWAB5cEIGkhPB7PNAdtFSVDRmNxxu3ozaMTYPN3Syr1kclFuJPq+q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456969; c=relaxed/simple; bh=yQO677NdufTEtYEpl+ewTAnUbcerKSpLBt1eERj1/SQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q+zMWLokMk713Or0j2H63sIgQqU76yRbLaOPtTL5xuxSKSRWJKtQW3++qxGhd3EXEuxsfqxPxIufjbA5N4tSxvp1ktPsllKolkoD0e0YE9kdYNpUDyau1BT7awlb5KyFwTHotNMxVOVwE4Fro4R62KAGtkR7r8w2sh02cO6+VUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F43OqDMN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F43OqDMN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D41B2C43399; Tue, 20 Feb 2024 19:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708456969; bh=yQO677NdufTEtYEpl+ewTAnUbcerKSpLBt1eERj1/SQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F43OqDMNXUy78B8/sXZBH+lBUw2CKY4zXUZL3Mvu1zbeFsYzB8jU84XpxKdKThfJI gAni/U3xQPSMXVXbBvXeYwcus4/eDsW8BDRMZvUPUTZV7DH+T/VsYhpy4opEMh0N/P l9LLdV1DS+BBEfYGu77fM7OKpCPy02jut2qLV3fbNcb2mkvzLyELcBF2SAtQGRFG65 kOou316kcnD06WlQs3wcH450VTkIfK+wqD9vYNWnK3Cc9aAAwzW8UApjH2DHL3E4jF QGPKU9RdKVdr8QFuZLG3oc27sGOSPOD5qgzLiKYcsRJ+XPswKkCb2nMZ4iPu3dN8An 2P/ylWITiYEOw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, mic@digikod.net, linux-security-module@vger.kernel.org, keescook@chromium.org, jakub@cloudflare.com, Jakub Kicinski Subject: [PATCH net-next v3 05/11] selftests: kselftest_harness: use exit code to store skip Date: Tue, 20 Feb 2024 11:22:29 -0800 Message-ID: <20240220192235.2953484-6-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org> References: <20240220192235.2953484-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We always use skip in combination with exit_code being 0 (KSFT_PASS). This are basic KSFT / KTAP semantics. Store the right KSFT_* code in exit_code directly. This makes it easier to support tests reporting other extended KSFT_* codes like XFAIL / XPASS. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest_harness.h | 20 +++++--------------- tools/testing/selftests/landlock/common.h | 5 +---- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index bbb339642a72..42ec3ca29c4b 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -136,8 +136,7 @@ fprintf(TH_LOG_STREAM, "# SKIP %s\n", \ _metadata->results->reason); \ } \ - _metadata->exit_code = KSFT_PASS; \ - _metadata->skip = 1; \ + _metadata->exit_code = KSFT_SKIP; \ _metadata->trigger = 0; \ statement; \ } while (0) @@ -389,7 +388,7 @@ if (setjmp(_metadata->env) == 0) { \ fixture_name##_setup(_metadata, &self, variant->data); \ /* Let setup failure terminate early. */ \ - if (!__test_passed(_metadata) || _metadata->skip) \ + if (_metadata->exit_code) \ return; \ _metadata->setup_completed = true; \ fixture_name##_##test_name(_metadata, &self, variant->data); \ @@ -834,7 +833,6 @@ struct __test_metadata { struct __fixture_metadata *fixture; int termsig; int exit_code; - int skip; /* did SKIP get used? */ int trigger; /* extra handler after the evaluation */ int timeout; /* seconds to wait for test timeout */ bool timed_out; /* did this test timeout instead of exiting? */ @@ -945,9 +943,7 @@ void __wait_for_test(struct __test_metadata *t) "# %s: Test terminated by timeout\n", t->name); } else if (WIFEXITED(status)) { if (WEXITSTATUS(status) == KSFT_SKIP) { - /* SKIP */ - t->exit_code = KSFT_PASS; - t->skip = 1; + t->exit_code = WEXITSTATUS(status); } else if (t->termsig != -1) { t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, @@ -1120,7 +1116,6 @@ void __run_test(struct __fixture_metadata *f, /* reset test struct */ t->exit_code = KSFT_PASS; - t->skip = 0; t->trigger = 0; t->no_print = 0; memset(t->results->reason, 0, sizeof(t->results->reason)); @@ -1142,19 +1137,14 @@ void __run_test(struct __fixture_metadata *f, } else if (t->pid == 0) { setpgrp(); t->fn(t, variant); - if (t->skip) - _exit(KSFT_SKIP); - if (__test_passed(t)) - _exit(KSFT_PASS); - /* Something else happened. */ - _exit(KSFT_FAIL); + _exit(t->exit_code); } else { __wait_for_test(t); } ksft_print_msg(" %4s %s\n", __test_passed(t) ? "OK" : "FAIL", test_name); - if (t->skip) + if (t->exit_code == KSFT_SKIP) ksft_test_result_skip("%s\n", t->results->reason[0] ? t->results->reason : "unknown"); else diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h index 89f8183bd8f5..56c5b5c5676a 100644 --- a/tools/testing/selftests/landlock/common.h +++ b/tools/testing/selftests/landlock/common.h @@ -57,11 +57,8 @@ } \ switch (WEXITSTATUS(status)) { \ case KSFT_PASS: \ - _metadata->exit_code = KSFT_PASS; \ - break; \ case KSFT_SKIP: \ - _metadata->exit_code = KSFT_PASS; \ - _metadata->skip = 1; \ + _metadata->exit_code = WEXITSTATUS(status); \ break; \ default: \ _metadata->exit_code = KSFT_FAIL; \ From patchwork Tue Feb 20 19:22:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 774406 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC11E14E2C3; Tue, 20 Feb 2024 19:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456970; cv=none; b=a5otnL88jEKQdLYIRGNXcWo2xCel333irgmrKlgcqJHPg2/RjVzBjb2/H2XC2h2PeBX/A5u0pZg86BV4BHLm3UaVItdke/F6k/zYXKBAl04/WYhMS4p5YVQzn1EA8qDsNKV5Y3LXIRNOJz63e3JaRLvo0Mv3ogt1fC/AJSe9yfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456970; c=relaxed/simple; bh=dOHmxdg3EP760oxxQuwhluOWp5ADJEFGi+z4Te1Ix98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fcmJQuW7TPfHduMWrPtt+55YIUAptn9uc0m4PQtIa3BKjoXE9grPSqZRzzpp0Fa6GSD5N8asSSkzIQgwoJR091xsRwDLEW5iGlBtr6uXvqvd1nxReBWSfIvXbaxYWwbbr8tOlz34bEkgYBgG/YKOtZAkgOZVvI737TpsIctzCEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EzhjzG7l; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EzhjzG7l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02831C433F1; Tue, 20 Feb 2024 19:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708456970; bh=dOHmxdg3EP760oxxQuwhluOWp5ADJEFGi+z4Te1Ix98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EzhjzG7lxvTipRQSfDA59QNrA/VebCwHM591nOKvV+80vxub9BgqGaWauDmDFayow 7SPiWjoxu5wcLupYoezmoL+Dj2bX3AmW2afJEVc4MV1zZC1LRdBP5HLnBm9SR5ve0q b8wnGd6SKVWLaY6dLpiVRvBrEhWBHsFF6DBhmQkZ73Ix9BuyQP05Cs0MNn1byVv/rt HSf1ZxDib0fNy7+Av4lQhUaU31e1kKWMDMdW5x2TGCFG46uxyVULJmzRsSlZGb6237 I/QygWWXJfVRQzvn8+y3YWKK5PuvyLGvlmtRgElcVNekk0F/iC9fULWX+Xf+HB4gRc LojDXgWvSG9wQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, mic@digikod.net, linux-security-module@vger.kernel.org, keescook@chromium.org, jakub@cloudflare.com, Jakub Kicinski Subject: [PATCH net-next v3 07/11] selftests: kselftest_harness: print test name for SKIP Date: Tue, 20 Feb 2024 11:22:31 -0800 Message-ID: <20240220192235.2953484-8-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org> References: <20240220192235.2953484-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Jakub points out that for parsers it's rather useful to always have the test name on the result line. Currently if we SKIP (or soon XFAIL or XPASS), we will print: ok 17 # SKIP SCTP doesn't support IP_BIND_ADDRESS_NO_PORT ^ no test name Always print the test name. KTAP format seems to allow or even call for it, per: https://docs.kernel.org/dev-tools/ktap.html Suggested-by: Jakub Sitnicki Link: https://lore.kernel.org/all/87jzn6lnou.fsf@cloudflare.com/ Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest.h | 7 ++++--- tools/testing/selftests/kselftest_harness.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 12ad7f8dfe3a..25e29626566e 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -255,8 +255,9 @@ static inline __printf(1, 2) void ksft_test_result_error(const char *msg, ...) va_end(args); } -static inline __printf(2, 3) -void ksft_test_result_code(int exit_code, const char *msg, ...) +static inline __printf(3, 4) +void ksft_test_result_code(int exit_code, const char *test_name, + const char *msg, ...) { const char *tap_code = "ok"; const char *directive = ""; @@ -287,7 +288,7 @@ void ksft_test_result_code(int exit_code, const char *msg, ...) } va_start(args, msg); - printf("%s %u%s", tap_code, ksft_test_num(), directive); + printf("%s %u %s%s", tap_code, ksft_test_num(), test_name, directive); errno = saved_errno; vprintf(msg, args); va_end(args); diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 684c5676dfcb..a1a794e4b8f6 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1151,7 +1151,8 @@ void __run_test(struct __fixture_metadata *f, diagnostic = "unknown"; if (t->exit_code == KSFT_SKIP) - ksft_test_result_code(t->exit_code, "%s\n", diagnostic); + ksft_test_result_code(t->exit_code, test_name, + "%s\n", diagnostic); else ksft_test_result(__test_passed(t), "%s\n", test_name); } From patchwork Tue Feb 20 19:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 774405 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E680714E2FC; Tue, 20 Feb 2024 19:22:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456972; cv=none; b=SVeFj7rsIHX+Viyrhm3iP3coNYrr11bcXMLSVIV/k0DafY5S2lAP7hIUUbOREiq5GRSuN9X1A3IgacsE+cxvhpJyfmbaYA8xFlPtzB2Ck9gNBbeZ9kukYg4hnMBgL/q6HOvudhRgykBW/h/vG1X121KOqazLJD9wVCEffQ/ASCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456972; c=relaxed/simple; bh=9Wj3EGg1bJZZ78CqquR3OBcBaDowmip0RKN2lao/f3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qQ5KU3K/gO0HvVrCfrRO7q8+JNHbX62GDnj8MW2y3+/BlfAsOciw1GbQE1plYAiFiQ4JLiLSi2GXv9nOr0QwhkapBxTSxzZCaO0OIY0ozZLTgxwbjTrmtfdbLto0Du8MO2uFexgwCepRny0NhYuu5IJDlWp4wAcHpY8+6LepcrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VzKOQD48; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VzKOQD48" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29AEBC433A6; Tue, 20 Feb 2024 19:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708456971; bh=9Wj3EGg1bJZZ78CqquR3OBcBaDowmip0RKN2lao/f3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VzKOQD48qaw1EA/D+lYIcRBeFLcCHN/vIkeocRaQzEcokFnYb1vvT+zomxN1NJxAB UezFBNUtGDmIqvkeVA1pm+MlKlEEg2vJBg7VhFrW1rRLVz26SAwnu+Jm+kQf1UnGL9 e6N8/RUAKx1n1nit8qir7VOyTt32mLfR+JLgotDCaAmgcR5N9GG5YQrGkZvLH24k7u LMgQZ/eK7LRLLID/iqQ869Gktb2gtECkSWVXvfAGs0kiVTzkKetGpNzj8tlYVkMddj ynaxvcQR7Zbp24jfghoA1BMOwSEC9NOfAfym5dH7BEnUgLm6PWBFiH/oQ0SXO2JUlb Fo2mLaDlHxbAw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, mic@digikod.net, linux-security-module@vger.kernel.org, keescook@chromium.org, jakub@cloudflare.com, Jakub Kicinski Subject: [PATCH net-next v3 09/11] selftests: kselftest_harness: let PASS / FAIL provide diagnostic Date: Tue, 20 Feb 2024 11:22:33 -0800 Message-ID: <20240220192235.2953484-10-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org> References: <20240220192235.2953484-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Switch to printing KTAP line for PASS / FAIL with ksft_test_result_code(), this gives us the ability to report diagnostic messages. Signed-off-by: Jakub Kicinski Reviewed-by: Kees Cook --- tools/testing/selftests/kselftest_harness.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 6157a7b059c6..7c3d19bf4220 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1147,14 +1147,13 @@ void __run_test(struct __fixture_metadata *f, if (t->results->reason[0]) diagnostic = t->results->reason; + else if (t->exit_code == KSFT_PASS || t->exit_code == KSFT_FAIL) + diagnostic = NULL; else diagnostic = "unknown"; - if (t->exit_code == KSFT_SKIP) - ksft_test_result_code(t->exit_code, test_name, - "%s", diagnostic); - else - ksft_test_result(__test_passed(t), "%s\n", test_name); + ksft_test_result_code(t->exit_code, test_name, + diagnostic ? "%s" : "", diagnostic); } static int test_harness_run(int argc, char **argv) From patchwork Tue Feb 20 19:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 774404 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A14514F9E4; Tue, 20 Feb 2024 19:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456973; cv=none; b=owV77To9qknZN9WDySc+QmVrVteKS5Eph0u4LzbFPJYxnWAeRQwG6d+zoH1aI/QU4Xy2Q+RGiDKYofj4uCkMpppb2XpHILgQTSEOUXIZW3JCKDj+4lTvW7k2f6EEmNGfIdbC3yvZEUJ3UOZ8mQBctiugK5PtVOXC85LFV4/cQoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456973; c=relaxed/simple; bh=lOTPndp0IMsasoyW4JuCFzuHcrAfQnrv/Lkla2nksNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNF7Tna3zyE4/whvt9YlTUaB9xFtFZnqWrxFTypMPgSem4IZlTIe/z0pGTAf5d7o/7WQvPEa6tiY7XuJltGn7aOu1hK3qqv7FCFsduXeOamfXErqlO8uzm1RscII1tinzPossiUb6WyIQSv7F5stVcuMf0nYrJypSxCzPijTp94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uKEf/j0a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uKEf/j0a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BBFFC43143; Tue, 20 Feb 2024 19:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708456972; bh=lOTPndp0IMsasoyW4JuCFzuHcrAfQnrv/Lkla2nksNI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uKEf/j0aeJoxPfj9bSOxbHe+O+B02D2jn5fLRP7aUssAYd6ZijPIeBYKU0rJ8/iQ7 +O6v1QcgmigQpGUEldp0Ss1vELEGERn+Lq8HIJTyUu76HNqDPCA76uB9/NUdbMIenr /6YnMqq2lV8xaaeqECAkwdVAP4nxjrtnXv9GkDxLAa8QRvJmi6FIggf8xZQGAUXjfZ zY6IVY2b0EBMOQLoFg7ZcX/w7ZCSgJXSL5+YmAU54A0d2iUWjaRtjNbgdoZw39A+eu sBnjHkxGoz0awabFldSnuxVmsdXnBQlxJB63jerpj+N6PBa1xWnfavGxutY2AzhmFZ zOsltWyUVXE9g== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, mic@digikod.net, linux-security-module@vger.kernel.org, keescook@chromium.org, jakub@cloudflare.com, Jakub Kicinski Subject: [PATCH net-next v3 11/11] selftests: ip_local_port_range: use XFAIL instead of SKIP Date: Tue, 20 Feb 2024 11:22:35 -0800 Message-ID: <20240220192235.2953484-12-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org> References: <20240220192235.2953484-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 SCTP does not support IP_LOCAL_PORT_RANGE and we know it, so use XFAIL instead of SKIP. Reviewed-by: Kees Cook Tested-by: Jakub Sitnicki Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/ip_local_port_range.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/ip_local_port_range.c b/tools/testing/selftests/net/ip_local_port_range.c index 6ebd58869a63..193b82745fd8 100644 --- a/tools/testing/selftests/net/ip_local_port_range.c +++ b/tools/testing/selftests/net/ip_local_port_range.c @@ -365,9 +365,6 @@ TEST_F(ip_local_port_range, late_bind) __u32 range; __u16 port; - if (variant->so_protocol == IPPROTO_SCTP) - SKIP(return, "SCTP doesn't support IP_BIND_ADDRESS_NO_PORT"); - fd = socket(variant->so_domain, variant->so_type, 0); ASSERT_GE(fd, 0) TH_LOG("socket failed"); @@ -414,6 +411,9 @@ TEST_F(ip_local_port_range, late_bind) ASSERT_TRUE(!err) TH_LOG("close failed"); } +XFAIL_ADD(ip_local_port_range, ip4_stcp, late_bind); +XFAIL_ADD(ip_local_port_range, ip6_stcp, late_bind); + TEST_F(ip_local_port_range, get_port_range) { __u16 lo, hi;