mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
selftests/mm: protection_keys: use kselftest framework
Convert protection_keys test to use kselftest framework for reporting and tracking successful and failing runs. Adjust dprintf0() printouts to use "#" in the beginning of the line for TAP compatibility. Link: https://lore.kernel.org/20260511162840.375890-18-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Tested-by: Luiz Capitulino <luizcap@redhat.com> Tested-by: Sarthak Sharma <sarthak.sharma@arm.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Donet Tom <donettom@linux.ibm.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Leon Romanovsky <leon@kernel.org> Cc: Liam Howlett <liam@infradead.org> Cc: Li Wang <li.wang@linux.dev> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Nico Pache <npache@redhat.com> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
a932f05e2e
commit
04d0c0092b
|
|
@ -71,13 +71,14 @@ static inline void sigsafe_printf(const char *format, ...)
|
|||
extern void abort_hooks(void);
|
||||
#define pkey_assert(condition) do { \
|
||||
if (!(condition)) { \
|
||||
dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \
|
||||
__FILE__, __LINE__, \
|
||||
test_nr, iteration_nr); \
|
||||
dprintf0("errno at assert: %d", errno); \
|
||||
abort_hooks(); \
|
||||
exit(__LINE__); \
|
||||
} \
|
||||
dprintf0("# assert() at %s::%d test_nr: %d iteration: %d\n", \
|
||||
__FILE__, __LINE__, \
|
||||
test_nr, iteration_nr); \
|
||||
dprintf0("# errno at assert: %d\n", errno); \
|
||||
abort_hooks(); \
|
||||
ksft_exit_fail_msg("test %d (iteration %d)\n", \
|
||||
test_nr, iteration_nr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define barrier() __asm__ __volatile__("": : :"memory")
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ static void tracing_off(void)
|
|||
|
||||
void abort_hooks(void)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "running %s()...\n", __func__);
|
||||
tracing_off();
|
||||
#ifdef SLEEP_ON_ABORT
|
||||
|
|
@ -370,8 +371,8 @@ static void signal_handler(int signum, siginfo_t *si, void *vucontext)
|
|||
if ((si->si_code == SEGV_MAPERR) ||
|
||||
(si->si_code == SEGV_ACCERR) ||
|
||||
(si->si_code == SEGV_BNDERR)) {
|
||||
printf("non-PK si_code, exiting...\n");
|
||||
exit(4);
|
||||
dprintf0("# non-PK si_code: %d, exiting...\n", si->si_code);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
si_pkey_ptr = siginfo_get_pkey_ptr(si);
|
||||
|
|
@ -719,7 +720,7 @@ static void setup_hugetlbfs(void)
|
|||
long hpagesz_mb;
|
||||
|
||||
if (geteuid() != 0) {
|
||||
fprintf(stderr, "WARNING: not run as root, can not do hugetlb test\n");
|
||||
ksft_print_msg("WARNING: not run as root, can not do hugetlb test\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -855,7 +856,7 @@ void expected_pkey_fault(int pkey)
|
|||
|
||||
#define do_not_expect_pkey_fault(msg) do { \
|
||||
if (last_pkey_faults != pkey_faults) \
|
||||
dprintf0("unexpected PKey fault: %s\n", msg); \
|
||||
dprintf0("# unexpected PKey fault: %s\n", msg); \
|
||||
pkey_assert(last_pkey_faults == pkey_faults); \
|
||||
} while (0)
|
||||
|
||||
|
|
@ -1753,7 +1754,7 @@ static void run_tests_once(void)
|
|||
tracing_off();
|
||||
close_test_fds();
|
||||
|
||||
printf("test %s PASSED (iteration %d)\n", pkey_tests[test_nr].name, iteration_nr);
|
||||
ksft_test_result_pass("test %s (iteration %d)\n", pkey_tests[test_nr].name, iteration_nr);
|
||||
dprintf1("======================\n\n");
|
||||
}
|
||||
iteration_nr++;
|
||||
|
|
@ -1773,27 +1774,30 @@ int main(void)
|
|||
|
||||
setup_handlers();
|
||||
|
||||
printf("has pkeys: %d\n", pkeys_supported);
|
||||
ksft_print_header();
|
||||
|
||||
if (!pkeys_supported) {
|
||||
int size = PAGE_SIZE;
|
||||
int *ptr;
|
||||
|
||||
printf("running PKEY tests for unsupported CPU/OS\n");
|
||||
ksft_set_plan(1);
|
||||
ksft_print_msg("running PKEY tests for unsupported CPU/OS\n");
|
||||
|
||||
ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
assert(ptr != (void *)-1);
|
||||
test_mprotect_pkey_on_unsupported_cpu(ptr, 1);
|
||||
exit(0);
|
||||
ksft_test_result_pass("pkey on unsupported CPU/OS\n");
|
||||
ksft_finished();
|
||||
}
|
||||
|
||||
ksft_set_plan(ARRAY_SIZE(pkey_tests) * nr_iterations);
|
||||
|
||||
pkey_setup_shadow();
|
||||
printf("startup pkey_reg: %016llx\n", read_pkey_reg());
|
||||
ksft_print_msg("startup pkey_reg: %016llx\n", read_pkey_reg());
|
||||
setup_hugetlbfs();
|
||||
|
||||
while (nr_iterations-- > 0)
|
||||
run_tests_once();
|
||||
|
||||
printf("done (all tests OK)\n");
|
||||
return 0;
|
||||
ksft_finished();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user