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

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

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ 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 | 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