Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright 2015, Cyril Bur, IBM Corp.
0004  *
0005  * This test attempts to see if the VMX registers change across a syscall (fork).
0006  */
0007 
0008 #include <altivec.h>
0009 #include <stdio.h>
0010 #include <unistd.h>
0011 #include <sys/syscall.h>
0012 #include <sys/time.h>
0013 #include <stdlib.h>
0014 #include <sys/types.h>
0015 #include <sys/wait.h>
0016 #include "utils.h"
0017 
0018 vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},
0019     {13,14,15,16},{17,18,19,20},{21,22,23,24},
0020     {25,26,27,28},{29,30,31,32},{33,34,35,36},
0021     {37,38,39,40},{41,42,43,44},{45,46,47,48}};
0022 
0023 extern int test_vmx(vector int *varray, pid_t *pid);
0024 
0025 int vmx_syscall(void)
0026 {
0027     pid_t fork_pid;
0028     int i;
0029     int ret;
0030     int child_ret;
0031     for (i = 0; i < 1000; i++) {
0032         /* test_vmx will fork() */
0033         ret = test_vmx(varray, &fork_pid);
0034         if (fork_pid == -1)
0035             return -1;
0036         if (fork_pid == 0)
0037             exit(ret);
0038         waitpid(fork_pid, &child_ret, 0);
0039         if (ret || child_ret)
0040             return 1;
0041     }
0042 
0043     return 0;
0044 }
0045 
0046 int test_vmx_syscall(void)
0047 {
0048     /*
0049      * Setup an environment with much context switching
0050      */
0051     pid_t pid2;
0052     pid_t pid;
0053     int ret;
0054     int child_ret;
0055 
0056     // vcmpequd used in vmx_asm.S is v2.07
0057     SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
0058 
0059     pid = fork();
0060     FAIL_IF(pid == -1);
0061 
0062     pid2 = fork();
0063     ret = vmx_syscall();
0064     /* Can't FAIL_IF(pid2 == -1); because we've already forked */
0065     if (pid2 == -1) {
0066         /*
0067          * Couldn't fork, ensure child_ret is set and is a fail
0068          */
0069         ret = child_ret = 1;
0070     } else {
0071         if (pid2)
0072             waitpid(pid2, &child_ret, 0);
0073         else
0074             exit(ret);
0075     }
0076 
0077     ret |= child_ret;
0078 
0079     if (pid)
0080         waitpid(pid, &child_ret, 0);
0081     else
0082         exit(ret);
0083 
0084     FAIL_IF(ret || child_ret);
0085     return 0;
0086 }
0087 
0088 int main(int argc, char *argv[])
0089 {
0090     return test_harness(test_vmx_syscall, "vmx_syscall");
0091 
0092 }