From patchwork Fri Feb 16 00:41:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559332 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 857163D76; Fri, 16 Feb 2024 00:41:29 +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=1708044089; cv=none; b=o64Arl79oGZfsKl5EgeIG8TlKvLH4vnE+/I22dRp1KEwReumOgakqFFhZ5Ir1gnsVMF2sT/x+lGuhDbAB/7jYLyKUfKGwOEi+mzG1/NjX2peR8Bar+1mJhcSesIIK1Hx60lHmacpLvGgQLYukc0ZfeMkjX+rR/h/HU2nVL1uSSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044089; c=relaxed/simple; bh=jVsyFrRWGb6c8tPeoYyanRLN2VhvxjxD+uPfcRjaW9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QdFX75pmP0nmfQIEcdWu5cydJHTK3k3lEVlPPHvu07zqOlKBV1iF+WVIXg8wTD1pkvCnzhasEo4VsJv7Vb05rRs465LVVoeq45fJu0mHc4Mvcy2ycq46wS1FT067YMOghHOrju9LobJJmkHCLYXzXF9f1v+SPFR7s1+QN1gn69I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JDo+juwK; 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="JDo+juwK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB627C43390; Fri, 16 Feb 2024 00:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044089; bh=jVsyFrRWGb6c8tPeoYyanRLN2VhvxjxD+uPfcRjaW9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDo+juwKtPXmC9zH3YlU1jWHYJFY5hpgIMNZ7v2ZA0SRx1pkgzX5fQhHyxFQZV108 CvWPSWfn2Whu2YcT26T9xLxLxnTj8zFuZgaOrG6EXGedcJyNDKFNY+/Wi48ubMb5GB 46BhDUCNoKT67yjr6IAf70Y2Cu/rbmcr3wOrQQA81kNjVf9zMOhdEWD12xpOhOohS8 CkXoL9xWgaHygeBPnBmhhiTqb+2DqY/eE62MwYM08xxVmDbLsFtlSiQxjigkKYuqGp 8mXsqX/b+USWcDUpNna7BxSyRkgg5Xnm/MrSwCvG2BSsUHhdeKKT5cuR1R4v5bDuRt tKEArd9xJ3j4w== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 1/7] selftests: kselftest_harness: generate test name once Date: Thu, 15 Feb 2024 16:41:16 -0800 Message-ID: <20240216004122.2004689-2-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-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 Signed-off-by: Jakub Kicinski Acked-by: Kees Cook --- 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 04177813930b..b271cb721b81 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 @@ -1140,6 +1141,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; @@ -1149,8 +1152,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); @@ -1174,8 +1179,8 @@ 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] ? @@ -1184,8 +1189,7 @@ void __run_test(struct __fixture_metadata *f, ksft_test_result_xfail("%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 Fri Feb 16 00:41:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559333 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 E75EA610B; Fri, 16 Feb 2024 00:41:29 +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=1708044090; cv=none; b=T5+eI3aPfRBKSWOpYfwlxz5X3SMhXLYe+LpJo+2iL3q6EzpYZx8IV3X/zFGVijWyJWnPCXDTfH9Q0Af7B0a6/bWnz9nUqNmyHokH5ABt1Vcclw2zdFwvtXApK7XeOAlrDpEp3/sJCIOVytYaX9ERIJRSA7G/JR2QG4sRZrFpR14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044090; c=relaxed/simple; bh=e2kuTBmsiR1D/FUlHCgPsqYtv10XyO1EUJ92wvA5Gxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RRO537uPp46lAMMerw4ERo54RkFH5hpPfRY9MmbO13Ji4UaBLLHYiYiwMQsHMI2wocRVBa1kzQijVE8UNU7QaLh2HN7qZj4zedoRQ4pZxRBuQ5qVdIvFWj0wHQhZLDSjl6BmAwJSWGnc//sWgTvSfZwI7wXRtWQ0xNDbxTjAfi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dNajKiMw; 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="dNajKiMw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31641C433F1; Fri, 16 Feb 2024 00:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044089; bh=e2kuTBmsiR1D/FUlHCgPsqYtv10XyO1EUJ92wvA5Gxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dNajKiMwLHNJlBid360VpDgrYxD3/v5WYmVRy3a6asDQEoeWFl524xxYqQP4003i5 +q1ltiToBpdiiyQ2EfrW+3BeA8Kcv1mD1YwcGZCBWWyD846dhD6GPVluAXKO1uJWtD p/dHfqRUD9dv74IQmXTm9rr5zjtD8ZZplQPn1TslkF8RprcaKJmhhj7nAADb+w4VJk wZDNrd6O9Iltqthe230jsAjg8d271XqbPDc9AlDRXeZEbXrEaxsgLrrn4nwat7IbUK kIXWwnjwg7AdlEFTLeEenBX7s7VZ2vbZPVDZ6XTVRP3WOK3oqp0Q2JyY0waNg9ZA4o OChjR58ghUSAw== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 2/7] selftests: kselftest_harness: save full exit code in metadata Date: Thu, 15 Feb 2024 16:41:17 -0800 Message-ID: <20240216004122.2004689-3-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of tracking passed = 0/1 rename the field to exit_code and invert the values so that they match the KSFT_* exit codes. This will allow us to fold SKIP / XFAIL into the same value. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest_harness.h | 52 ++++++++++++--------- tools/testing/selftests/net/tls.c | 2 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index b271cb721b81..70366864ffd9 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -136,7 +136,7 @@ fprintf(TH_LOG_STREAM, "# SKIP %s\n", \ _metadata->results->reason); \ } \ - _metadata->passed = 1; \ + _metadata->exit_code = KSFT_PASS; \ _metadata->skip = 1; \ _metadata->trigger = 0; \ statement; \ @@ -163,7 +163,7 @@ fprintf(TH_LOG_STREAM, "# XFAIL %s\n", \ _metadata->results->reason); \ } \ - _metadata->passed = 1; \ + _metadata->exit_code = KSFT_PASS; \ _metadata->xfail = 1; \ _metadata->trigger = 0; \ statement; \ @@ -416,7 +416,7 @@ if (setjmp(_metadata->env) == 0) { \ fixture_name##_setup(_metadata, &self, variant->data); \ /* Let setup failure terminate early. */ \ - if (!_metadata->passed || _metadata->skip) \ + if (!__test_passed(_metadata) || _metadata->skip) \ return; \ _metadata->setup_completed = true; \ fixture_name##_##test_name(_metadata, &self, variant->data); \ @@ -723,7 +723,7 @@ __bail(_assert, _metadata)) #define __INC_STEP(_metadata) \ - if (_metadata->passed) \ + if (__test_passed(_metadata)) \ _metadata->results->step++; #define is_signed_type(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1)) @@ -769,7 +769,7 @@ break; \ } \ } \ - _metadata->passed = 0; \ + _metadata->exit_code = KSFT_FAIL; \ /* Ensure the optional handler is triggered */ \ _metadata->trigger = 1; \ } \ @@ -781,7 +781,7 @@ if (_assert) __INC_STEP(_metadata); \ if (!(strcmp(__exp, __seen) _t 0)) { \ __TH_LOG("Expected '%s' %s '%s'.", __exp, #_t, __seen); \ - _metadata->passed = 0; \ + _metadata->exit_code = KSFT_FAIL; \ _metadata->trigger = 1; \ } \ } while (0); OPTIONAL_HANDLER(_assert) @@ -860,7 +860,7 @@ struct __test_metadata { pid_t pid; /* pid of test when being run */ struct __fixture_metadata *fixture; int termsig; - int passed; + int exit_code; int skip; /* did SKIP get used? */ int xfail; /* did XFAIL get used? */ int trigger; /* extra handler after the evaluation */ @@ -874,6 +874,12 @@ struct __test_metadata { struct __test_metadata *prev, *next; }; +static inline bool __test_passed(struct __test_metadata *metadata) +{ + return metadata->exit_code != KSFT_FAIL && + metadata->exit_code <= KSFT_SKIP; +} + /* * Since constructors are called in reverse order, reverse the test * list so tests are run in source declaration order. @@ -941,7 +947,7 @@ void __wait_for_test(struct __test_metadata *t) int status; if (sigaction(SIGALRM, &action, &saved_action)) { - t->passed = 0; + t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, "# %s: unable to install SIGALRM handler\n", t->name); @@ -953,7 +959,7 @@ void __wait_for_test(struct __test_metadata *t) waitpid(t->pid, &status, 0); alarm(0); if (sigaction(SIGALRM, &saved_action, NULL)) { - t->passed = 0; + t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, "# %s: unable to uninstall SIGALRM handler\n", t->name); @@ -962,19 +968,19 @@ void __wait_for_test(struct __test_metadata *t) __active_test = NULL; if (t->timed_out) { - t->passed = 0; + t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, "# %s: Test terminated by timeout\n", t->name); } else if (WIFEXITED(status)) { if (WEXITSTATUS(status) == KSFT_SKIP) { /* SKIP */ - t->passed = 1; + t->exit_code = KSFT_PASS; t->skip = 1; } else if (WEXITSTATUS(status) == KSFT_XFAIL) { - t->passed = 1; + t->exit_code = KSFT_PASS; t->xfail = 1; } else if (t->termsig != -1) { - t->passed = 0; + t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, "# %s: Test exited normally instead of by signal (code: %d)\n", t->name, @@ -983,11 +989,11 @@ void __wait_for_test(struct __test_metadata *t) switch (WEXITSTATUS(status)) { /* Success */ case KSFT_PASS: - t->passed = 1; + t->exit_code = KSFT_PASS; break; /* Other failure, assume step report. */ default: - t->passed = 0; + t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, "# %s: Test failed at step #%d\n", t->name, @@ -995,13 +1001,13 @@ void __wait_for_test(struct __test_metadata *t) } } } else if (WIFSIGNALED(status)) { - t->passed = 0; + t->exit_code = KSFT_FAIL; if (WTERMSIG(status) == SIGABRT) { fprintf(TH_LOG_STREAM, "# %s: Test terminated by assertion\n", t->name); } else if (WTERMSIG(status) == t->termsig) { - t->passed = 1; + t->exit_code = KSFT_PASS; } else { fprintf(TH_LOG_STREAM, "# %s: Test terminated unexpectedly by signal %d\n", @@ -1144,7 +1150,7 @@ void __run_test(struct __fixture_metadata *f, char test_name[LINE_MAX]; /* reset test struct */ - t->passed = 1; + t->exit_code = KSFT_PASS; t->skip = 0; t->xfail = 0; t->trigger = 0; @@ -1164,7 +1170,7 @@ void __run_test(struct __fixture_metadata *f, t->pid = fork(); if (t->pid < 0) { ksft_print_msg("ERROR SPAWNING TEST CHILD\n"); - t->passed = 0; + t->exit_code = KSFT_FAIL; } else if (t->pid == 0) { setpgrp(); t->fn(t, variant); @@ -1172,7 +1178,7 @@ void __run_test(struct __fixture_metadata *f, _exit(KSFT_SKIP); if (t->xfail) _exit(KSFT_XFAIL); - if (t->passed) + if (__test_passed(t)) _exit(KSFT_PASS); /* Something else happened. */ _exit(KSFT_FAIL); @@ -1180,7 +1186,7 @@ void __run_test(struct __fixture_metadata *f, __wait_for_test(t); } ksft_print_msg(" %4s %s\n", - t->passed ? "OK" : "FAIL", test_name); + __test_passed(t) ? "OK" : "FAIL", test_name); if (t->skip) ksft_test_result_skip("%s\n", t->results->reason[0] ? @@ -1189,7 +1195,7 @@ void __run_test(struct __fixture_metadata *f, ksft_test_result_xfail("%s\n", t->results->reason[0] ? t->results->reason : "unknown"); else - ksft_test_result(t->passed, "%s\n", test_name); + ksft_test_result(__test_passed(t), "%s\n", test_name); } static int test_harness_run(int argc, char **argv) @@ -1237,7 +1243,7 @@ static int test_harness_run(int argc, char **argv) t->results = results; __run_test(f, v, t); t->results = NULL; - if (t->passed) + if (__test_passed(t)) pass_count++; else ret = 1; diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c index 49c84602707f..046d1ccedcf3 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -1882,7 +1882,7 @@ TEST_F(tls_err, poll_partial_rec_async) pfd.events = POLLIN; EXPECT_EQ(poll(&pfd, 1, 20), 1); - exit(!_metadata->passed); + exit(!__test_passed(_metadata)); } } From patchwork Fri Feb 16 00:41:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559334 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 348C28BF6; Fri, 16 Feb 2024 00:41:30 +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=1708044090; cv=none; b=oc5R4eCMhKoUgXtkKjKJKRf27R243qle6aiaHzz5i0fZSuCcmfkuTnJf0x3kfaqsOYRwONVyWeoi/vqm/nf4dqNAgXwtOgDckTWfy7pDLa07Kp3JVu8maVpoEBMze7pJqgKGK/8tY2f3UDbIYqTsQC4+LSlcK44JjixyzY/QcxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044090; c=relaxed/simple; bh=xut8vW9q8UtF2Rvvr2ccXXFedhbCgL5XgKPyM3C/aMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FlWXp4cM86zUOinKhxVzVetqFhI3sH87Zs0rL0YfeJ3vpHJirbz0M4yYXMkH60FU/b4I860CghPID72h2kCxd27DSkbb6RfrKmPgMfuhiQkgV6DP8lT/H5b6k4C+aMr+QEnctMHl1LQl8zcKu6TV4GnXEyUa1/2JE+M4li94h8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Guzd6/b0; 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="Guzd6/b0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA6ACC43390; Fri, 16 Feb 2024 00:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044090; bh=xut8vW9q8UtF2Rvvr2ccXXFedhbCgL5XgKPyM3C/aMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Guzd6/b0xlm2nC7VJTX/faz0yGWvCGFuKX9Awl1xdZuOzOfTbhmOldUBOE16PeOGX 51fFQwXS8c6XT8TK8iUwyOt9EIhm3MXvJ9FzrASMzUX9JZQ9DH57meLLVjxwb2kdZ3 qmxwBxN+W4wRQouA1l36efODmrnmPND5uwoL9eaZ5PR6awOPwdgKUxuQk7sv3lMwGq XCWlfcOfdXeSliNIDBwaWO+lrK5hYKJKPM2Gumvnp9XThcjUenwH54Ih18h6Us7LwG 7X/WfAM0nxG+usG/5IJ776PCt9yyFfvbVWdNoqGgiuVCfKqe5gzvBz6GsWi7S10boZ lIGit5XMErlRA== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 3/7] selftests: kselftest_harness: use exit code to store skip and xfail Date: Thu, 15 Feb 2024 16:41:18 -0800 Message-ID: <20240216004122.2004689-4-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-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 / xfail with combination of exit_code being 0 (KSFT_PASS). This are just basic KSFT / KTAP semantics. Store the right KSFT_* code in exit_code directly. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest_harness.h | 35 ++++++--------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 70366864ffd9..6923cd7060fc 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) @@ -163,8 +162,7 @@ fprintf(TH_LOG_STREAM, "# XFAIL %s\n", \ _metadata->results->reason); \ } \ - _metadata->exit_code = KSFT_PASS; \ - _metadata->xfail = 1; \ + _metadata->exit_code = KSFT_XFAIL; \ _metadata->trigger = 0; \ statement; \ } while (0) @@ -416,7 +414,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); \ @@ -861,8 +859,6 @@ struct __test_metadata { struct __fixture_metadata *fixture; int termsig; int exit_code; - int skip; /* did SKIP get used? */ - int xfail; /* did XFAIL 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? */ @@ -972,13 +968,9 @@ void __wait_for_test(struct __test_metadata *t) fprintf(TH_LOG_STREAM, "# %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; - } else if (WEXITSTATUS(status) == KSFT_XFAIL) { - t->exit_code = KSFT_PASS; - t->xfail = 1; + if (WEXITSTATUS(status) == KSFT_SKIP || + WEXITSTATUS(status) == KSFT_XFAIL) { + t->exit_code = WEXITSTATUS(status); } else if (t->termsig != -1) { t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, @@ -1151,8 +1143,6 @@ void __run_test(struct __fixture_metadata *f, /* reset test struct */ t->exit_code = KSFT_PASS; - t->skip = 0; - t->xfail = 0; t->trigger = 0; t->no_print = 0; memset(t->results->reason, 0, sizeof(t->results->reason)); @@ -1174,24 +1164,17 @@ void __run_test(struct __fixture_metadata *f, } else if (t->pid == 0) { setpgrp(); t->fn(t, variant); - if (t->skip) - _exit(KSFT_SKIP); - if (t->xfail) - _exit(KSFT_XFAIL); - 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 if (t->xfail) + else if (t->exit_code == KSFT_XFAIL) ksft_test_result_xfail("%s\n", t->results->reason[0] ? t->results->reason : "unknown"); else From patchwork Fri Feb 16 00:41:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559335 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 ADA52946F; Fri, 16 Feb 2024 00:41:30 +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=1708044090; cv=none; b=tGDUu+MdMeIEsA7mVb0Lt636xp7jaEW3oM/1Ev9+O/4P6VaWR3ww8EXCfCGkO0QlLZ7m4Tcp0o2AGBsnS7Mwa5HvOW/IyYBIfr85GwmsrFu4+b6/WQCeA2dmFo43ceGRS5SqLgmUVkZMc6UhcBdqxlYPsB7hllH0zFAgvIxva4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044090; c=relaxed/simple; bh=20msBFwZRtEP1FinTrpQIFSjg5lTxL3Pw4Rt2jZCeq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H1iyS4KH9ZlzGq1ot7jbCkfN7KyfpknzwJQQK5gICcT/GMncQHlRC2noCyJ3fCeudE6at81lwlZx+MtqexSKEYKp81PYEUV8OKtb1O780GfYJFIZen2oKpB46rK9LV1qFi6HhOizGcfpAjYFJFLF1u7KsQx5lsZIQhL6/mMmq5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UquN38Jy; 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="UquN38Jy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33489C43399; Fri, 16 Feb 2024 00:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044090; bh=20msBFwZRtEP1FinTrpQIFSjg5lTxL3Pw4Rt2jZCeq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UquN38Jy3QZ/UEqBwJiDkNUuVivDG7bfxQrGpXk6O7geaMZt95w2/HQFH8WCf263f 4CN85HIaixARms0x7xj2/4+9MKAaIrbd4Ok1/1jv5O73pO1u02NLW3MdNvzo4EfVHk 1LXcSJChMmxCmMG5/WtDi297QukyXqTy8DpWfyugu+2zYUXKuBSJj5xjrrvsUZZd0y nny9i1xwBBolw5IPqrLX31mB49eUtzaVu+zwGyNjIGsFabaEzTvfJppsURGehJh0IU pjSa/3/HDOgQL3wnVRXqTnyH7kXeFKeOtcEzicayjDPkCna1s+rq3cOVGqBrVBsVN7 iVYu0ySVDxpQQ== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 4/7] selftests: kselftest: add ksft_test_result_code(), handling all exit codes Date: Thu, 15 Feb 2024 16:41:19 -0800 Message-ID: <20240216004122.2004689-5-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For generic test harness code it's more useful to deal with exit codes directly, rather than having to switch on them and call the right ksft_test_result_*() helper. Add such function to kselftest.h. Note that "directive" and "diagnostic" are what ktap docs call those parts of the message. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest.h | 39 +++++++++++++++++++++ tools/testing/selftests/kselftest_harness.h | 14 ++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index a781e6311810..12ad7f8dfe3a 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -25,6 +25,7 @@ * ksft_test_result_skip(fmt, ...); * ksft_test_result_xfail(fmt, ...); * ksft_test_result_error(fmt, ...); + * ksft_test_result_code(exit_code, test_name, fmt, ...); * * When all tests are finished, clean up and exit the program with one of: * @@ -254,6 +255,44 @@ 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, ...) +{ + const char *tap_code = "ok"; + const char *directive = ""; + int saved_errno = errno; + va_list args; + + switch (exit_code) { + case KSFT_PASS: + ksft_cnt.ksft_pass++; + break; + case KSFT_XFAIL: + directive = " # XFAIL "; + ksft_cnt.ksft_xfail++; + break; + case KSFT_XPASS: + directive = " # XPASS "; + ksft_cnt.ksft_xpass++; + break; + case KSFT_SKIP: + directive = " # SKIP "; + ksft_cnt.ksft_xskip++; + break; + case KSFT_FAIL: + default: + tap_code = "not ok"; + ksft_cnt.ksft_fail++; + break; + } + + va_start(args, msg); + printf("%s %u%s", tap_code, ksft_test_num(), directive); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + static inline int ksft_exit_pass(void) { ksft_print_cnts(); diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 6923cd7060fc..79a3fec0cefa 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1140,6 +1140,7 @@ void __run_test(struct __fixture_metadata *f, struct __test_metadata *t) { char test_name[LINE_MAX]; + const char *diagnostic; /* reset test struct */ t->exit_code = KSFT_PASS; @@ -1171,12 +1172,13 @@ void __run_test(struct __fixture_metadata *f, ksft_print_msg(" %4s %s\n", __test_passed(t) ? "OK" : "FAIL", test_name); - if (t->exit_code == KSFT_SKIP) - ksft_test_result_skip("%s\n", t->results->reason[0] ? - t->results->reason : "unknown"); - else if (t->exit_code == KSFT_XFAIL) - ksft_test_result_xfail("%s\n", t->results->reason[0] ? - t->results->reason : "unknown"); + if (t->results->reason[0]) + diagnostic = t->results->reason; + else + diagnostic = "unknown"; + + if (t->exit_code == KSFT_SKIP || t->exit_code == KSFT_XFAIL) + ksft_test_result_code(t->exit_code, "%s\n", diagnostic); else ksft_test_result(__test_passed(t), "%s\n", test_name); } From patchwork Fri Feb 16 00:41:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559336 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 92F51D2F0; Fri, 16 Feb 2024 00:41:31 +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=1708044091; cv=none; b=mAolvvlQVmgVSTKkZqf6lfcYm/CxD2lbDyNt2FnQXFgRKY8oe7cQToe9XTxERP46cGOMtR/8SI8YAH3KfGL1MNl1uUSwjGVTMV5bdWrh5h6zY04HE7qWHkG3o5haTpYH5ivRYPa9lUJ/GZokmJvYSb6VHWlf0HkEZX1OZStXL/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044091; c=relaxed/simple; bh=PUYSnoEiqdY/3A4RqbDDuJYK260acc9oXybD55EpoQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OIU6qEMYLQHvJlUGQ9zJ6dQZLHW0Xi0/gbplM6APHr4cT1OAAMx7Aw4Eaw8Su6W6SGcpoU71+iu4QtQ48RSw0V32hTeBd9AE3wQpwjQLyslSD0zfOp3oyX4Z4sxOpiRv3k0yDecGcwidFWC9O5BynOZEHKjybtq+63FxRC5iXT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CMw2+K92; 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="CMw2+K92" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFA07C433C7; Fri, 16 Feb 2024 00:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044091; bh=PUYSnoEiqdY/3A4RqbDDuJYK260acc9oXybD55EpoQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMw2+K92CX49nkW1XEBPNbb5daXNgI3ZHSnFnA+kB/ZKQbhG4uCcHFTxqt6xpVt0v +VN4tIvo2AO2dU5OYJp2k2moXXhIQWVho2uMuMha/OtUbSzH26Xstx3BXW1plU2HSM VvM2c+xfFaCy3cpv6FtjIKFkhUoH7CE9rciRxMxOwfaccIUyZAqtxfMUumPLjBDZza w0cqTxEepBN2+mvizn5kqeNTo6ezcm41Y/BsEsFZul3e0K5JbwCI40iWntRNN2rysS g5+MRkreHKmYSxTcqXWRaI+hz6CMuIu+pf0iFJgoyZdNRxjiAv6KRGrNhHnCW/V19P eBXQ4V7ou6C0Q== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 5/7] selftests: kselftest_harness: print test name for SKIP and XFAIL Date: Thu, 15 Feb 2024 16:41:20 -0800 Message-ID: <20240216004122.2004689-6-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-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 XFAIL, 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 79a3fec0cefa..beae50fd5ac3 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1178,7 +1178,8 @@ void __run_test(struct __fixture_metadata *f, diagnostic = "unknown"; if (t->exit_code == KSFT_SKIP || t->exit_code == KSFT_XFAIL) - 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 Fri Feb 16 00:41:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559337 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 DFDF4D520; Fri, 16 Feb 2024 00:41:31 +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=1708044092; cv=none; b=NFaWMU1olNwySLd4t6dVk1B1p0BMYoMacCIunKyFrQmIeZDgNvCXELZZ9aW5cNr8ArX3/DxJdR7Z6l1HLtYupVk5O/IAgT4GlDOFPIRg3LspUxhkeR/pUUQQp0SULgqvUFAeIS+mj3ZjtyZ80B3HsU5ECV2EUJXWujOebFVOhqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044092; c=relaxed/simple; bh=IOHIxewUik/BAcxqFdDqAKGAdsCDzq+9/PLMINaoM3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p0lv0v6N9vWKPEckg1H3YBCsDiuiZvb2FWqSXCkC8KeTe2dedh+XwnxjhcU/bt+mC675JMoRu3ngeuhub5FmLXVLw5YeuyvhQ9OQt4axC2C8cluBDAp+Mzcmk8FR0iBIlcL+eFwDJgORNGguY9NX8vhMXSAYzNIPksCrchwzLgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m34xrjnM; 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="m34xrjnM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35438C43394; Fri, 16 Feb 2024 00:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044091; bh=IOHIxewUik/BAcxqFdDqAKGAdsCDzq+9/PLMINaoM3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m34xrjnMt6Tp1ZLyegi9rnWQnbFLrKkLxwAbJpC2uoRz/z/YzwcNd/yb+7bexdh0o Hqnz4uYpqwdBXJQJTlMor91LJL4oj7G7DB6TlOWEPT3KMZlMVg4KdmmFNTcwm7YvX0 uIhduo27pfXjyulMSBziCmHKWz6544FqLA97lv51aoD1DLIFthAglbt9ZCH39IlFTE qLOZvjUWRVO3cITAMV1F+/H6xvo5Hq5WDDEJtL0ucSsMyk4AOkORRWKsu10v5YkbkE 2NkKOL3xpnn9levNneRaq4NHHXW3Eyyg6l0koO+kKP8ymGn/xoviPkicI9AWDMJcKb OT3RFb+Q6J57g== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 6/7] selftests: kselftest_harness: let ksft_test_result_code() handle line termination Date: Thu, 15 Feb 2024 16:41:21 -0800 Message-ID: <20240216004122.2004689-7-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to the spec we should always print a # if we add a diagnostic message. Having the caller pass in the new line as part of diagnostic message makes handling this a bit counter-intuitive. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest.h | 5 +++++ tools/testing/selftests/kselftest_harness.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 25e29626566e..541bf192e30e 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -287,10 +287,15 @@ void ksft_test_result_code(int exit_code, const char *test_name, break; } + /* Docs seem to call for double space if directive is absent */ + if (!directive[0] && msg[0]) + directive = " # "; + va_start(args, msg); printf("%s %u %s%s", tap_code, ksft_test_num(), test_name, directive); errno = saved_errno; vprintf(msg, args); + printf("\n"); va_end(args); } diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index beae50fd5ac3..5fca75e180b8 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1179,7 +1179,7 @@ void __run_test(struct __fixture_metadata *f, if (t->exit_code == KSFT_SKIP || t->exit_code == KSFT_XFAIL) ksft_test_result_code(t->exit_code, test_name, - "%s\n", diagnostic); + "%s", diagnostic); else ksft_test_result(__test_passed(t), "%s\n", test_name); } From patchwork Fri Feb 16 00:41:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13559338 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 30F81946F; Fri, 16 Feb 2024 00:41:32 +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=1708044092; cv=none; b=DwDLdjAD0qVzpUxKj7DVEOPXHTKjeMjaJXPd6P5yFQM3Ls8ac8y759LVOJNsDyORnYrgGv4AtTrOP6bhC2PDy3mwTLtluE3eoL6b6b91ibjKytijXTP1OSEDp0r+z68bFwq7rag/pnDGaCApeOKO17FCPPF0KURgxnxWjBZ06Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708044092; c=relaxed/simple; bh=hO1c5nGTovIvhjqxDgR/7VZPe6HATF0p1iglGL7g2mQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sbY+jevS63MUOXlSy3kNIH6k2HP3QFPQg5Frkn0eJGIWJCKkToVXCTLriUbMxXeqeSSfEl2NIZiWO7DkNn97lPcEektOP9QBxRWHp40yGr599LcyRS6Z0fG7ulGcRMV2LJ2pfJKRMmJ9qeNHvHqoWLoSjkTqJ8/XEbanBSqDais= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AQ/u6HGl; 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="AQ/u6HGl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFA6DC433A6; Fri, 16 Feb 2024 00:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708044092; bh=hO1c5nGTovIvhjqxDgR/7VZPe6HATF0p1iglGL7g2mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AQ/u6HGlqBbE386G5Mpr0vYotn/Z/vsWAVwpPKB4iy9FsIaclTc7UkKRADomAhxLO Whzc+fmxnyvTW4SfG1qdqgMG95Mn8gx2u2aTMHoFPiDPwGtI+XiHTZypHbS3+lySlZ H3rQCvYv15GBOafdSNr4rjzCHozllTWCYmDQgFnUtHpMqb+8Ril7OWVsSFCvVN9Hrs VIoYf6FU/curNbhAqaGAZR1YZvmeDppjYHhYNksicCWybwDKyumRs8s/Ii+4j1pQdE MOomQcxmeI74pkRf6LOvbazNM2wjMeOsZGseSz2lsy4O0EZ6cVSVwudSSZ4aFSMXX1 8SVyfBTV1Q+TQ== From: Jakub Kicinski To: jakub@cloudflare.com Cc: shuah@kernel.org, keescook@chromium.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jakub Kicinski Subject: [RFC 7/7] selftests: kselftest_harness: let PASS / FAIL provide diagnostic Date: Thu, 15 Feb 2024 16:41:22 -0800 Message-ID: <20240216004122.2004689-8-kuba@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org> References: <20240216004122.2004689-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 for free. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/kselftest_harness.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 5fca75e180b8..202f599c1462 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1174,14 +1174,12 @@ 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 = ""; else diagnostic = "unknown"; - if (t->exit_code == KSFT_SKIP || t->exit_code == KSFT_XFAIL) - 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, "%s", diagnostic); } static int test_harness_run(int argc, char **argv)