~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/ptrace/ptrace-vsx.c

Version: ~ [ linux-5.13-rc7 ] ~ [ linux-5.12.12 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.45 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.127 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.195 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.237 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.273 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.273 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Ptrace test for VMX/VSX registers
  4  *
  5  * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
  6  */
  7 #include "ptrace.h"
  8 #include "ptrace-vsx.h"
  9 
 10 /* Tracer and Tracee Shared Data */
 11 int shm_id;
 12 int *cptr, *pptr;
 13 
 14 unsigned long fp_load[VEC_MAX];
 15 unsigned long fp_load_new[VEC_MAX];
 16 unsigned long fp_store[VEC_MAX];
 17 
 18 void vsx(void)
 19 {
 20         int ret;
 21 
 22         cptr = (int *)shmat(shm_id, NULL, 0);
 23         loadvsx(fp_load, 0);
 24         cptr[1] = 1;
 25 
 26         while (!cptr[0])
 27                 asm volatile("" : : : "memory");
 28         shmdt((void *) cptr);
 29 
 30         storevsx(fp_store, 0);
 31         ret = compare_vsx_vmx(fp_store, fp_load_new);
 32         if (ret)
 33                 exit(1);
 34         exit(0);
 35 }
 36 
 37 int trace_vsx(pid_t child)
 38 {
 39         unsigned long vsx[VSX_MAX];
 40         unsigned long vmx[VMX_MAX + 2][2];
 41 
 42         FAIL_IF(start_trace(child));
 43         FAIL_IF(show_vsx(child, vsx));
 44         FAIL_IF(validate_vsx(vsx, fp_load));
 45         FAIL_IF(show_vmx(child, vmx));
 46         FAIL_IF(validate_vmx(vmx, fp_load));
 47 
 48         memset(vsx, 0, sizeof(vsx));
 49         memset(vmx, 0, sizeof(vmx));
 50         load_vsx_vmx(fp_load_new, vsx, vmx);
 51 
 52         FAIL_IF(write_vsx(child, vsx));
 53         FAIL_IF(write_vmx(child, vmx));
 54         FAIL_IF(stop_trace(child));
 55 
 56         return TEST_PASS;
 57 }
 58 
 59 int ptrace_vsx(void)
 60 {
 61         pid_t pid;
 62         int ret, status, i;
 63 
 64         shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
 65 
 66         for (i = 0; i < VEC_MAX; i++)
 67                 fp_load[i] = i + rand();
 68 
 69         for (i = 0; i < VEC_MAX; i++)
 70                 fp_load_new[i] = i + 2 * rand();
 71 
 72         pid = fork();
 73         if (pid < 0) {
 74                 perror("fork() failed");
 75                 return TEST_FAIL;
 76         }
 77 
 78         if (pid == 0)
 79                 vsx();
 80 
 81         if (pid) {
 82                 pptr = (int *)shmat(shm_id, NULL, 0);
 83                 while (!pptr[1])
 84                         asm volatile("" : : : "memory");
 85 
 86                 ret = trace_vsx(pid);
 87                 if (ret) {
 88                         kill(pid, SIGTERM);
 89                         shmdt((void *)pptr);
 90                         shmctl(shm_id, IPC_RMID, NULL);
 91                         return TEST_FAIL;
 92                 }
 93 
 94                 pptr[0] = 1;
 95                 shmdt((void *)pptr);
 96 
 97                 ret = wait(&status);
 98                 shmctl(shm_id, IPC_RMID, NULL);
 99                 if (ret != pid) {
100                         printf("Child's exit status not captured\n");
101                         return TEST_FAIL;
102                 }
103 
104                 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
105                         TEST_PASS;
106         }
107         return TEST_PASS;
108 }
109 
110 int main(int argc, char *argv[])
111 {
112         return test_harness(ptrace_vsx, "ptrace_vsx");
113 }
114 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp