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

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

Version: ~ [ linux-5.5 ] ~ [ linux-5.4.15 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.98 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.167 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.211 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.211 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ 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 /*
  2  * Ptrace test for VMX/VSX registers
  3  *
  4  * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
  5  *
  6  * This program is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU General Public License
  8  * as published by the Free Software Foundation; either version
  9  * 2 of the License, or (at your option) any later version.
 10  */
 11 #include "ptrace.h"
 12 #include "ptrace-vsx.h"
 13 
 14 /* Tracer and Tracee Shared Data */
 15 int shm_id;
 16 int *cptr, *pptr;
 17 
 18 unsigned long fp_load[VEC_MAX];
 19 unsigned long fp_load_new[VEC_MAX];
 20 unsigned long fp_store[VEC_MAX];
 21 
 22 void vsx(void)
 23 {
 24         int ret;
 25 
 26         cptr = (int *)shmat(shm_id, NULL, 0);
 27         loadvsx(fp_load, 0);
 28         cptr[1] = 1;
 29 
 30         while (!cptr[0])
 31                 asm volatile("" : : : "memory");
 32         shmdt((void *) cptr);
 33 
 34         storevsx(fp_store, 0);
 35         ret = compare_vsx_vmx(fp_store, fp_load_new);
 36         if (ret)
 37                 exit(1);
 38         exit(0);
 39 }
 40 
 41 int trace_vsx(pid_t child)
 42 {
 43         unsigned long vsx[VSX_MAX];
 44         unsigned long vmx[VMX_MAX + 2][2];
 45 
 46         FAIL_IF(start_trace(child));
 47         FAIL_IF(show_vsx(child, vsx));
 48         FAIL_IF(validate_vsx(vsx, fp_load));
 49         FAIL_IF(show_vmx(child, vmx));
 50         FAIL_IF(validate_vmx(vmx, fp_load));
 51 
 52         memset(vsx, 0, sizeof(vsx));
 53         memset(vmx, 0, sizeof(vmx));
 54         load_vsx_vmx(fp_load_new, vsx, vmx);
 55 
 56         FAIL_IF(write_vsx(child, vsx));
 57         FAIL_IF(write_vmx(child, vmx));
 58         FAIL_IF(stop_trace(child));
 59 
 60         return TEST_PASS;
 61 }
 62 
 63 int ptrace_vsx(void)
 64 {
 65         pid_t pid;
 66         int ret, status, i;
 67 
 68         shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
 69 
 70         for (i = 0; i < VEC_MAX; i++)
 71                 fp_load[i] = i + rand();
 72 
 73         for (i = 0; i < VEC_MAX; i++)
 74                 fp_load_new[i] = i + 2 * rand();
 75 
 76         pid = fork();
 77         if (pid < 0) {
 78                 perror("fork() failed");
 79                 return TEST_FAIL;
 80         }
 81 
 82         if (pid == 0)
 83                 vsx();
 84 
 85         if (pid) {
 86                 pptr = (int *)shmat(shm_id, NULL, 0);
 87                 while (!pptr[1])
 88                         asm volatile("" : : : "memory");
 89 
 90                 ret = trace_vsx(pid);
 91                 if (ret) {
 92                         kill(pid, SIGTERM);
 93                         shmdt((void *)pptr);
 94                         shmctl(shm_id, IPC_RMID, NULL);
 95                         return TEST_FAIL;
 96                 }
 97 
 98                 pptr[0] = 1;
 99                 shmdt((void *)pptr);
100 
101                 ret = wait(&status);
102                 shmctl(shm_id, IPC_RMID, NULL);
103                 if (ret != pid) {
104                         printf("Child's exit status not captured\n");
105                         return TEST_FAIL;
106                 }
107 
108                 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
109                         TEST_PASS;
110         }
111         return TEST_PASS;
112 }
113 
114 int main(int argc, char *argv[])
115 {
116         return test_harness(ptrace_vsx, "ptrace_vsx");
117 }
118 

~ [ 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