From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Shuah Khan <shuah@kernel.org>,
Muhammad Usama Anjum <usama.anjum@collabora.com>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: kernel@collabora.com, "Chang S . Bae" <chang.seok.bae@intel.com>,
Binbin Wu <binbin.wu@linux.intel.com>,
Ingo Molnar <mingo@kernel.org>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH v3 2/4] selftests: x86: corrupt_xstate_header: remove manual counting and increase maintainability
Date: Thu, 18 Jul 2024 16:32:20 +0500 [thread overview]
Message-ID: <20240718113222.867116-3-usama.anjum@collabora.com> (raw)
In-Reply-To: <20240718113222.867116-1-usama.anjum@collabora.com>
Correct the skip, pass and fail return codes. Otherwise the test always
return 0. After the chaanges, correct number of stats about passed or
failed tests is being returned. Also print logs in standard format.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
Changes since v1:
- correct description of the patch
Changes since v2:
- Update description of the patch and add before/after output
Before:
# selftests: x86: corrupt_xstate_header_64
# [RUN] Send ourselves a signal
# Wreck XSTATE header
# Got SIGSEGV
# [OK] Back from the signal. Now schedule.
# [OK] Back in the main thread.
ok 41 selftests: x86: corrupt_xstate_header_64
After:
# selftests: x86: corrupt_xstate_header_64
# TAP version 13
# 1..2
# # Send ourselves a signal
# # Wreck XSTATE header
# # Got SIGSEGV
# ok 1 Back from the signal. Now schedule.
# ok 2 Back in the main thread.
# # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0
ok 41 selftests: x86: corrupt_xstate_header_64
---
| 30 +++++++++++--------
1 file changed, 18 insertions(+), 12 deletions(-)
--git a/tools/testing/selftests/x86/corrupt_xstate_header.c b/tools/testing/selftests/x86/corrupt_xstate_header.c
index cf9ce8fbb656c..119ff74763c6d 100644
--- a/tools/testing/selftests/x86/corrupt_xstate_header.c
+++ b/tools/testing/selftests/x86/corrupt_xstate_header.c
@@ -39,7 +39,7 @@ static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
sa.sa_flags = SA_SIGINFO | flags;
sigemptyset(&sa.sa_mask);
if (sigaction(sig, &sa, 0))
- err(1, "sigaction");
+ ksft_exit_fail_perror("sigaction");
}
static void sigusr1(int sig, siginfo_t *info, void *uc_void)
@@ -48,26 +48,29 @@ static void sigusr1(int sig, siginfo_t *info, void *uc_void)
uint8_t *fpstate = (uint8_t *)uc->uc_mcontext.fpregs;
uint64_t *xfeatures = (uint64_t *)(fpstate + 512);
- printf("\tWreck XSTATE header\n");
+ ksft_print_msg("Wreck XSTATE header\n");
/* Wreck the first reserved bytes in the header */
*(xfeatures + 2) = 0xfffffff;
}
static void sigsegv(int sig, siginfo_t *info, void *uc_void)
{
- printf("\tGot SIGSEGV\n");
+ ksft_print_msg("Got SIGSEGV\n");
}
int main(void)
{
cpu_set_t set;
+ ksft_print_header();
+ ksft_set_plan(2);
+
sethandler(SIGUSR1, sigusr1, 0);
sethandler(SIGSEGV, sigsegv, 0);
if (!xsave_enabled()) {
- printf("[SKIP] CR4.OSXSAVE disabled.\n");
- return 0;
+ ksft_print_msg("CR4.OSXSAVE disabled.\n");
+ return KSFT_SKIP;
}
CPU_ZERO(&set);
@@ -79,18 +82,21 @@ int main(void)
*/
sched_setaffinity(getpid(), sizeof(set), &set);
- printf("[RUN]\tSend ourselves a signal\n");
+ ksft_print_msg("Send ourselves a signal\n");
raise(SIGUSR1);
- printf("[OK]\tBack from the signal. Now schedule.\n");
+ ksft_test_result_pass("Back from the signal. Now schedule.\n");
+
pid_t child = fork();
- if (child < 0)
- err(1, "fork");
if (child == 0)
return 0;
- if (child)
+
+ if (child < 0) {
+ ksft_test_result_fail("fork: %s\n", strerror(errno));
+ } else if (child) {
waitpid(child, NULL, 0);
- printf("[OK]\tBack in the main thread.\n");
+ ksft_test_result_pass("Back in the main thread.\n");
+ }
/*
* We could try to confirm that extended state is still preserved
@@ -98,5 +104,5 @@ int main(void)
* a warning in the kernel logs.
*/
- return 0;
+ ksft_finished();
}
--
2.39.2
next prev parent reply other threads:[~2024-07-18 11:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 11:32 [PATCH v3 0/4] selftest: x86: improve tests Muhammad Usama Anjum
2024-07-18 11:32 ` [PATCH v3 1/4] selftests: x86: check_initial_reg_state: remove manual counting and increase maintainability Muhammad Usama Anjum
2024-07-18 15:48 ` Shuah Khan
2024-07-19 7:28 ` Muhammad Usama Anjum
2024-07-19 16:52 ` Shuah Khan
2024-07-18 11:32 ` Muhammad Usama Anjum [this message]
2024-07-18 11:32 ` [PATCH v3 3/4] selftests: x86: fsgsbase_restore: " Muhammad Usama Anjum
2024-07-18 11:32 ` [PATCH v3 4/4] selftests: x86: entry_from_vm86: " Muhammad Usama Anjum
2024-07-18 15:49 ` [PATCH v3 0/4] selftest: x86: improve tests Shuah Khan
-- strict thread matches above, loose matches on Subject: below --
2024-07-12 8:53 [PATCH v3 0/4] selftest: x86: remove manual counting and increase maintainability Muhammad Usama Anjum
2024-07-12 8:53 ` [PATCH v3 2/4] selftests: x86: corrupt_xstate_header: " Muhammad Usama Anjum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240718113222.867116-3-usama.anjum@collabora.com \
--to=usama.anjum@collabora.com \
--cc=binbin.wu@linux.intel.com \
--cc=chang.seok.bae@intel.com \
--cc=kernel@collabora.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®