93 lines · c
1// SPDX-License-Identifier: GPL-2.0-or-later2/*3 * Copyright 2015, Cyril Bur, IBM Corp.4 *5 * This test attempts to see if the VMX registers change across a syscall (fork).6 */7 8#include <altivec.h>9#include <stdio.h>10#include <unistd.h>11#include <sys/syscall.h>12#include <sys/time.h>13#include <stdlib.h>14#include <sys/types.h>15#include <sys/wait.h>16#include "utils.h"17 18vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},19 {13,14,15,16},{17,18,19,20},{21,22,23,24},20 {25,26,27,28},{29,30,31,32},{33,34,35,36},21 {37,38,39,40},{41,42,43,44},{45,46,47,48}};22 23extern int test_vmx(vector int *varray, pid_t *pid);24 25int vmx_syscall(void)26{27 pid_t fork_pid;28 int i;29 int ret;30 int child_ret;31 for (i = 0; i < 1000; i++) {32 /* test_vmx will fork() */33 ret = test_vmx(varray, &fork_pid);34 if (fork_pid == -1)35 return -1;36 if (fork_pid == 0)37 exit(ret);38 waitpid(fork_pid, &child_ret, 0);39 if (ret || child_ret)40 return 1;41 }42 43 return 0;44}45 46int test_vmx_syscall(void)47{48 /*49 * Setup an environment with much context switching50 */51 pid_t pid2;52 pid_t pid;53 int ret;54 int child_ret;55 56 // vcmpequd used in vmx_asm.S is v2.0757 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));58 59 pid = fork();60 FAIL_IF(pid == -1);61 62 pid2 = fork();63 ret = vmx_syscall();64 /* Can't FAIL_IF(pid2 == -1); because we've already forked */65 if (pid2 == -1) {66 /*67 * Couldn't fork, ensure child_ret is set and is a fail68 */69 ret = child_ret = 1;70 } else {71 if (pid2)72 waitpid(pid2, &child_ret, 0);73 else74 exit(ret);75 }76 77 ret |= child_ret;78 79 if (pid)80 waitpid(pid, &child_ret, 0);81 else82 exit(ret);83 84 FAIL_IF(ret || child_ret);85 return 0;86}87 88int main(int argc, char *argv[])89{90 return test_harness(test_vmx_syscall, "vmx_syscall");91 92}93