From patchwork Wed Mar 6 19:21:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 779107 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 210AD13E7CE; Wed, 6 Mar 2024 19:21:39 +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=1709752900; cv=none; b=cBEAGeuP2k5b5w5CbH9K1CtH/J0rhIfkr0VUTbmSbi6FfrIFj0vkO/oZSGkqTT5wG5qpaPr9GJ/mFw/QMx4RGkhzub80oVonUtltaCuwEJS3QBHMi/+tW3mDNKGS1+FIFFo2y4V7GYC1bXhjfW9H73JN0uQqSg8x5gRCLhjm5X4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709752900; c=relaxed/simple; bh=xL1xjg+8MEPz55HWswyeT1lYlU+bIX5B5bi0yf4AeHk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NYzJE5L3DYBJb5ZPtK1KGTVz3E59l9Okw5jKv8T+uglgpux0i6xqGYum4tddylHvfdWPc5adLjdj0wXPKl1s2xVXJVVfd+5jqeiqLKoafaMnXncor0Ceee5K8EXWaSglRNsjliy87MZ9QfHIguJUvoohMgabuQJASlmNnt85jqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=txi89XZo; 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="txi89XZo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F118C43399; Wed, 6 Mar 2024 19:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709752899; bh=xL1xjg+8MEPz55HWswyeT1lYlU+bIX5B5bi0yf4AeHk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=txi89XZoa9oeWHO4VtIVwgJfOBk47detNEn8+YOSq91Ko7cTFuYKNvo64uYZG2/hv dwhik06iQ+D/ZsMCPD6TkXkCNtxgkC/FPcT/01jVQS8LcH1YeODIawnihKW3oHzZRS Mz7D/fxP3mlhRV3TaXfIXmdU14TM89jALdoCyxwpZwnAoIREaaytWIdwzJB+ak64J6 thCedDycDuwaFipYwlu7V2K5TwzWb6KAILNZmDfuinj9314mL5tsT/Lr+b1w1ZfJFc g/9a1O60DxYSPYZd5DRlQca/G9KIfS6PbYyiXx0L9DHtezMcBwQ+SH10Lv6pSmtzYL Ra2xvWeILm5dQ== From: Mark Brown Date: Wed, 06 Mar 2024 19:21:25 +0000 Subject: [PATCH 1/2] kselftest: Add mechanism for reporting a KSFT_ result code Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240306-kselftest-tty-tname-v1-1-33505b31629e@kernel.org> References: <20240306-kselftest-tty-tname-v1-0-33505b31629e@kernel.org> In-Reply-To: <20240306-kselftest-tty-tname-v1-0-33505b31629e@kernel.org> To: Shuah Khan , Greg Kroah-Hartman , Jiri Slaby Cc: Michal Sekletar , linux-serial@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2019; i=broonie@kernel.org; h=from:subject:message-id; bh=xL1xjg+8MEPz55HWswyeT1lYlU+bIX5B5bi0yf4AeHk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBl6MI8vS9GOsN+KDt8q42xO9wBTJmy5E7Qy5wvEt1U Kf1hg6KJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZejCPAAKCRAk1otyXVSH0MMrB/ 9iy9164MfH74pl4LQO0WvyXLRut+raf/mTKsW0lab0Pwr8XsmLNyGuE5/7HA3ht5NH6Vwo+oOJo4v3 v3XtAWGh0aTJvztnINY/L5eGUnyuWKbfd3OhJbtoqj29ibNpFLq7zuB/abEFEBtNnrzP2XrZVVsJIi zDJ5qoEvSIkVQOlTOKEjwW0kGACxnBSZXwz5MkmoqHXbA+5+sjHEJRNGVWDvdRzD5WHimvtztcilaI 6bWzi/wGe5HzZnAAqwflljdv9t0I/IsMW/9Vwzf/fgJDYIibDY8pn59Kb0FnyQVf4JEVLNB5c9WUdH Ak7eqXeNojvwZQqlVllleSP2jf0Yye X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Currently there's no helper which a test can use to report it's result as a KSFT_ result code, we can report a boolean pass/fail but not a skip. This is sometimes a useful idiom so let's add a helper ksft_test_result_report() which translates into the relevant report types. Due to the use of va_args in the result reporting functions this is done as a macro rather than an inline function as one might expect, none of the alternatives looked particularly great. Signed-off-by: Mark Brown --- tools/testing/selftests/kselftest.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index a781e6311810..9bc130c269d7 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -20,6 +20,7 @@ * and finally report the pass/fail/skip/xfail state of the test with one of: * * ksft_test_result(condition, fmt, ...); + * ksft_test_result_report(result, fmt, ...); * ksft_test_result_pass(fmt, ...); * ksft_test_result_fail(fmt, ...); * ksft_test_result_skip(fmt, ...); @@ -254,6 +255,27 @@ static inline __printf(1, 2) void ksft_test_result_error(const char *msg, ...) va_end(args); } +/** + * ksft_test_result() - Report test success based on truth of condition + * + * @condition: if true, report test success, otherwise failure. + */ +#define ksft_test_result_report(result, fmt, ...) do { \ + switch (result) { \ + case KSFT_PASS: \ + ksft_test_result_pass(fmt, ##__VA_ARGS__); \ + break; \ + case KSFT_FAIL: \ + ksft_test_result_fail(fmt, ##__VA_ARGS__); \ + break; \ + case KSFT_XFAIL: \ + ksft_test_result_xfail(fmt, ##__VA_ARGS__); \ + break; \ + case KSFT_SKIP: \ + ksft_test_result_skip(fmt, ##__VA_ARGS__); \ + break; \ + } } while (0) + static inline int ksft_exit_pass(void) { ksft_print_cnts(); From patchwork Wed Mar 6 19:21:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 778480 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 5448E1420CC; Wed, 6 Mar 2024 19:21:42 +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=1709752903; cv=none; b=ZMj56J0xa9/tSsIBA+9tYVQE9DQjOeR/jJkamSluBvWq+Q/Y7a1Bu6+SlKp4reEgFs7cL87d5bz9SyeQ+zE/vjqmcaqwBzd6LGVTXzgaQwUMoMRHW/BSi6yQa1bMzfbaGPWbYT0B7BQWgpyGsgBC9Bq0XYTrtg67Y6HXeUx9Qyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709752903; c=relaxed/simple; bh=A1+zHTfoU9rRBcXeGw4a+56qXArSOHtcWNhad8MSClk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O7jlQzaR4vA0tTGtiET2sh2IMpTRIFJcbiG4OOuF31y5z8j1wG14L22o88VzAsVD8f7c/QR7chjy3fovdMhzV06NywTyDJbd0nIt99iwDSiWFj8DOuLZoHb2gNA1QpPMxUXMDESIxxPwzYvJN7tC7yG6s1jsE+aHD6+AW0s2ukw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qxtxDO+5; 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="qxtxDO+5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FC76C433B1; Wed, 6 Mar 2024 19:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709752902; bh=A1+zHTfoU9rRBcXeGw4a+56qXArSOHtcWNhad8MSClk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qxtxDO+5x1xaoF6gStACvvbzzPbtDNuHvZI736JYeE6FoI+gJ7TdgrsgtIN1vTs7k /G1MD/5Ovfio7nu6sh3G7jrgLUCSg4+Z5OE3qwyM2H4n1vkineHoQuufClMFOQT+VS KN9fnNbsbvAhmN206mr6qcmnwm4W9gaLQXbcwO8pKLkiuqiXFsQHhJOK34V7qyep8G o+txlVfI7/lHY9re3ipTVVVUl9nZ4rLYsCt9uGWuk/B0vu+k/vb/qURStqawxr0XwD FJlFJDPTFXrEZTz2wXy5bpea2ZvlK3g/jialcGc/4SF/nGPd8ZisroNS7bjnZ/zewu LqGRjgfDCw3Lg== From: Mark Brown Date: Wed, 06 Mar 2024 19:21:26 +0000 Subject: [PATCH 2/2] kselftest/tty: Report a consistent test name for the one test we run Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240306-kselftest-tty-tname-v1-2-33505b31629e@kernel.org> References: <20240306-kselftest-tty-tname-v1-0-33505b31629e@kernel.org> In-Reply-To: <20240306-kselftest-tty-tname-v1-0-33505b31629e@kernel.org> To: Shuah Khan , Greg Kroah-Hartman , Jiri Slaby Cc: Michal Sekletar , linux-serial@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=3118; i=broonie@kernel.org; h=from:subject:message-id; bh=A1+zHTfoU9rRBcXeGw4a+56qXArSOHtcWNhad8MSClk=; b=owGbwMvMwMWocq27KDak/QLjabUkhtQXh2w23VKO6uMW/nY1qS590U+b+S9qbiu2reOMinVbvuoA 49GLnYzGLAyMXAyyYoosa59lrEoPl9g6/9H8VzCDWJlApjBwcQrARJTN2f/peat13t7icrVtfmM5S9 S7zVenpfkkiebdy5VVY9qW2/Jtn+97zi6LttS6d9ctamXELuT+6Zsc4MSzpDAvu/Nsw3P7gLtZ8gk7 Xpy9tdDXI0a0bq1c8ZK5ilFHL+uXhEq/CeGOuZoq7724Zu33FObANxqTHiuuvbV7d9/F3oUCXQaJa5 u5a7OVdgs7zGr3Vy4JiBXoTt31ukTE+6z8ufZXZS4PrffX3Am/Zsn6LnqOcOGRxvqleewOP88nsf5M KHSf+lD/206RJBG5M9Gl29Xlm28+9Fqez7le+OcDCVFTU7m10ssFy9sDZz0tfb1F9GSOO8/dqubWLg Hr/U97tDV9JRp3bp5itLtD8FgUAA== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Currently the tty_tstamp_update test reports a different exit message for every path it can exit via. This can be confusing for automated systems as the string that gets logged is interpreted as a test name so if the test status changes they can't tell that it's the same test case that was run, they can see that the overall status of the test program is a failure but it's not clear that it was running the same test. Change all the messages that are logged to be diagnostic prints and log the name of the program as the test name. Signed-off-by: Mark Brown --- tools/testing/selftests/tty/tty_tstamp_update.c | 48 +++++++++++++++++-------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/tty/tty_tstamp_update.c b/tools/testing/selftests/tty/tty_tstamp_update.c index 0ee97943dccc..9e1a40f5db17 100644 --- a/tools/testing/selftests/tty/tty_tstamp_update.c +++ b/tools/testing/selftests/tty/tty_tstamp_update.c @@ -47,42 +47,60 @@ int main(int argc, char **argv) int r; char tty[PATH_MAX] = {}; struct stat st1, st2; + int result = KSFT_FAIL; ksft_print_header(); ksft_set_plan(1); r = readlink("/proc/self/fd/0", tty, PATH_MAX); - if (r < 0) - ksft_exit_fail_msg("readlink on /proc/self/fd/0 failed: %m\n"); + if (r < 0) { + ksft_print_msg("readlink on /proc/self/fd/0 failed: %m\n"); + goto out; + } + + if (!tty_valid(tty)) { + ksft_print_msg("invalid tty path '%s'\n", tty); + result = KSFT_SKIP; + goto out; - if (!tty_valid(tty)) - ksft_exit_skip("invalid tty path '%s'\n", tty); + } r = stat(tty, &st1); - if (r < 0) - ksft_exit_fail_msg("stat failed on tty path '%s': %m\n", tty); + if (r < 0) { + ksft_print_msg("stat failed on tty path '%s': %m\n", tty); + goto out; + } /* We need to wait at least 8 seconds in order to observe timestamp change */ /* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fbf47635315ab308c9b58a1ea0906e711a9228de */ sleep(10); r = write_dev_tty(); - if (r < 0) - ksft_exit_fail_msg("failed to write to /dev/tty: %s\n", - strerror(-r)); + if (r < 0) { + ksft_print_msg("failed to write to /dev/tty: %s\n", + strerror(-r)); + goto out; + } r = stat(tty, &st2); - if (r < 0) - ksft_exit_fail_msg("stat failed on tty path '%s': %m\n", tty); + if (r < 0) { + ksft_print_msg("stat failed on tty path '%s': %m\n", tty); + goto out; + } /* We wrote to the terminal so timestamps should have been updated */ if (st1.st_atim.tv_sec == st2.st_atim.tv_sec && st1.st_mtim.tv_sec == st2.st_mtim.tv_sec) { - ksft_test_result_fail("tty timestamps not updated\n"); - ksft_exit_fail(); + ksft_print_msg("tty timestamps not updated\n"); + goto out; } - ksft_test_result_pass( + ksft_print_msg( "timestamps of terminal '%s' updated after write to /dev/tty\n", tty); - return EXIT_SUCCESS; + result = KSFT_PASS; + +out: + ksft_test_result_report(result, "tty_tstamp_update\n"); + + ksft_finished(); }