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 FPU registers change across a syscall (fork).
0006  */
0007 
0008 #include <stdio.h>
0009 #include <unistd.h>
0010 #include <sys/syscall.h>
0011 #include <sys/time.h>
0012 #include <sys/types.h>
0013 #include <sys/wait.h>
0014 #include <stdlib.h>
0015 
0016 #include "utils.h"
0017 
0018 extern int test_fpu(double *darray, pid_t *pid);
0019 
0020 double darray[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
0021              1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0,
0022              2.1};
0023 
0024 int syscall_fpu(void)
0025 {
0026     pid_t fork_pid;
0027     int i;
0028     int ret;
0029     int child_ret;
0030     for (i = 0; i < 1000; i++) {
0031         /* test_fpu will fork() */
0032         ret = test_fpu(darray, &fork_pid);
0033         if (fork_pid == -1)
0034             return -1;
0035         if (fork_pid == 0)
0036             exit(ret);
0037         waitpid(fork_pid, &child_ret, 0);
0038         if (ret || child_ret)
0039             return 1;
0040     }
0041 
0042     return 0;
0043 }
0044 
0045 int test_syscall_fpu(void)
0046 {
0047     /*
0048      * Setup an environment with much context switching
0049      */
0050     pid_t pid2;
0051     pid_t pid = fork();
0052     int ret;
0053     int child_ret;
0054     FAIL_IF(pid == -1);
0055 
0056     pid2 = fork();
0057     /* Can't FAIL_IF(pid2 == -1); because already forked once */
0058     if (pid2 == -1) {
0059         /*
0060          * Couldn't fork, ensure test is a fail
0061          */
0062         child_ret = ret = 1;
0063     } else {
0064         ret = syscall_fpu();
0065         if (pid2)
0066             waitpid(pid2, &child_ret, 0);
0067         else
0068             exit(ret);
0069     }
0070 
0071     ret |= child_ret;
0072 
0073     if (pid)
0074         waitpid(pid, &child_ret, 0);
0075     else
0076         exit(ret);
0077 
0078     FAIL_IF(ret || child_ret);
0079     return 0;
0080 }
0081 
0082 int main(int argc, char *argv[])
0083 {
0084     return test_harness(test_syscall_fpu, "syscall_fpu");
0085 
0086 }