Path: blob/master/tools/testing/selftests/arm64/fp/za-fork.c
26289 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2022 ARM Limited.3* Original author: Mark Brown <[email protected]>4*/56// SPDX-License-Identifier: GPL-2.0-only78#include <linux/sched.h>9#include <linux/wait.h>1011#include "kselftest.h"1213#define EXPECTED_TESTS 11415int fork_test(void);16int verify_fork(void);1718/*19* If we fork the value in the parent should be unchanged and the20* child should start with the same value. This is called from the21* fork_test() asm function.22*/23int fork_test_c(void)24{25pid_t newpid, waiting;26int child_status, parent_result;2728newpid = fork();29if (newpid == 0) {30/* In child */31if (!verify_fork()) {32ksft_print_msg("ZA state invalid in child\n");33exit(0);34} else {35exit(1);36}37}38if (newpid < 0) {39ksft_print_msg("fork() failed: %d\n", newpid);4041return 0;42}4344parent_result = verify_fork();45if (!parent_result)46ksft_print_msg("ZA state invalid in parent\n");4748for (;;) {49waiting = waitpid(newpid, &child_status, 0);5051if (waiting < 0) {52if (errno == EINTR)53continue;54ksft_print_msg("waitpid() failed: %d\n", errno);55return 0;56}57if (waiting != newpid) {58ksft_print_msg("waitpid() returned wrong PID\n");59return 0;60}6162if (!WIFEXITED(child_status)) {63ksft_print_msg("child did not exit\n");64return 0;65}6667return WEXITSTATUS(child_status) && parent_result;68}69}7071int main(int argc, char **argv)72{73int ret, i;7475ksft_print_header();76ksft_set_plan(EXPECTED_TESTS);7778ksft_print_msg("PID: %d\n", getpid());7980/*81* This test is run with nolibc which doesn't support hwcap and82* it's probably disproportionate to implement so instead check83* for the default vector length configuration in /proc.84*/85ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0);86if (ret >= 0) {87ksft_test_result(fork_test(), "fork_test\n");8889} else {90ksft_print_msg("SME not supported\n");91for (i = 0; i < EXPECTED_TESTS; i++) {92ksft_test_result_skip("fork_test\n");93}94}9596ksft_finished();9798return 0;99}100101102