Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kselftest/arm64: Convert za-fork to use kselftest.h

Now that kselftest.h can be used with nolibc convert the za-fork test to
use it. We do still have to open code ksft_print_msg() but that's not the
end of the world. Some of the advantage comes from using printf() which we
could have been using already.

This does change the output when tests are skipped, bringing it in line
with the standard kselftest output by removing the test name - we move
from

ok 0 skipped

to

ok 1 # SKIP fork_test

The old output was not following KTAP format for skips, and the
numbering was not standard or consistent with the reported plan.

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Mark Brown and committed by
Shuah Khan
266679ff 9e38be73

+17 -73
+1 -1
tools/testing/selftests/arm64/fp/Makefile
··· 38 38 $(OUTPUT)/vlset: vlset.c 39 39 $(OUTPUT)/za-fork: za-fork.c $(OUTPUT)/za-fork-asm.o 40 40 $(CC) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ 41 - -include ../../../../include/nolibc/nolibc.h \ 41 + -include ../../../../include/nolibc/nolibc.h -I../..\ 42 42 -static -ffreestanding -Wall $^ -o $@ 43 43 $(OUTPUT)/za-ptrace: za-ptrace.c 44 44 $(OUTPUT)/za-test: za-test.S $(OUTPUT)/asm-utils.o
+16 -72
tools/testing/selftests/arm64/fp/za-fork.c
··· 9 9 #include <linux/sched.h> 10 10 #include <linux/wait.h> 11 11 12 + #include "kselftest.h" 13 + 12 14 #define EXPECTED_TESTS 1 13 - 14 - static void putstr(const char *str) 15 - { 16 - write(1, str, strlen(str)); 17 - } 18 - 19 - static void putnum(unsigned int num) 20 - { 21 - char c; 22 - 23 - if (num / 10) 24 - putnum(num / 10); 25 - 26 - c = '0' + (num % 10); 27 - write(1, &c, 1); 28 - } 29 - 30 - static int tests_run; 31 - static int tests_passed; 32 - static int tests_failed; 33 - static int tests_skipped; 34 - 35 - static void print_summary(void) 36 - { 37 - if (tests_passed + tests_failed + tests_skipped != EXPECTED_TESTS) 38 - putstr("# UNEXPECTED TEST COUNT: "); 39 - 40 - putstr("# Totals: pass:"); 41 - putnum(tests_passed); 42 - putstr(" fail:"); 43 - putnum(tests_failed); 44 - putstr(" xfail:0 xpass:0 skip:"); 45 - putnum(tests_skipped); 46 - putstr(" error:0\n"); 47 - } 48 15 49 16 int fork_test(void); 50 17 int verify_fork(void); ··· 30 63 if (newpid == 0) { 31 64 /* In child */ 32 65 if (!verify_fork()) { 33 - putstr("# ZA state invalid in child\n"); 66 + ksft_print_msg("ZA state invalid in child\n"); 34 67 exit(0); 35 68 } else { 36 69 exit(1); 37 70 } 38 71 } 39 72 if (newpid < 0) { 40 - putstr("# fork() failed: -"); 41 - putnum(-newpid); 42 - putstr("\n"); 73 + ksft_print_msg("fork() failed: %d\n", newpid); 74 + 43 75 return 0; 44 76 } 45 77 46 78 parent_result = verify_fork(); 47 79 if (!parent_result) 48 - putstr("# ZA state invalid in parent\n"); 80 + ksft_print_msg("ZA state invalid in parent\n"); 49 81 50 82 for (;;) { 51 83 waiting = waitpid(newpid, &child_status, 0); ··· 52 86 if (waiting < 0) { 53 87 if (errno == EINTR) 54 88 continue; 55 - putstr("# waitpid() failed: "); 56 - putnum(errno); 57 - putstr("\n"); 89 + ksft_print_msg("waitpid() failed: %d\n", errno); 58 90 return 0; 59 91 } 60 92 if (waiting != newpid) { 61 - putstr("# waitpid() returned wrong PID\n"); 93 + ksft_print_msg("waitpid() returned wrong PID\n"); 62 94 return 0; 63 95 } 64 96 65 97 if (!WIFEXITED(child_status)) { 66 - putstr("# child did not exit\n"); 98 + ksft_print_msg("child did not exit\n"); 67 99 return 0; 68 100 } 69 101 ··· 69 105 } 70 106 } 71 107 72 - #define run_test(name) \ 73 - if (name()) { \ 74 - tests_passed++; \ 75 - } else { \ 76 - tests_failed++; \ 77 - putstr("not "); \ 78 - } \ 79 - putstr("ok "); \ 80 - putnum(++tests_run); \ 81 - putstr(" " #name "\n"); 82 - 83 108 int main(int argc, char **argv) 84 109 { 85 110 int ret, i; 86 111 87 - putstr("TAP version 13\n"); 88 - putstr("1.."); 89 - putnum(EXPECTED_TESTS); 90 - putstr("\n"); 112 + ksft_print_header(); 113 + ksft_set_plan(EXPECTED_TESTS); 91 114 92 - putstr("# PID: "); 93 - putnum(getpid()); 94 - putstr("\n"); 115 + ksft_print_msg("PID: %d\n", getpid()); 95 116 96 117 /* 97 118 * This test is run with nolibc which doesn't support hwcap and ··· 85 136 */ 86 137 ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0); 87 138 if (ret >= 0) { 88 - run_test(fork_test); 139 + ksft_test_result(fork_test(), "fork_test"); 89 140 90 141 } else { 91 - putstr("# SME support not present\n"); 92 - 142 + ksft_print_msg("SME not supported\n"); 93 143 for (i = 0; i < EXPECTED_TESTS; i++) { 94 - putstr("ok "); 95 - putnum(i); 96 - putstr(" skipped\n"); 144 + ksft_test_result_skip("fork_test\n"); 97 145 } 98 - 99 - tests_skipped += EXPECTED_TESTS; 100 146 } 101 147 102 - print_summary(); 148 + ksft_finished(); 103 149 104 150 return 0; 105 151 }