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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ 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 // 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         SKIP_IF_MSG(!have_hwcap(PPC_FEATURE_HAS_VSX), "Don't have VSX");
 65 
 66         shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
 67 
 68         for (i = 0; i < VEC_MAX; i++)
 69                 fp_load[i] = i + rand();
 70 
 71         for (i = 0; i < VEC_MAX; i++)
 72                 fp_load_new[i] = i + 2 * rand();
 73 
 74         pid = fork();
 75         if (pid < 0) {
 76                 perror("fork() failed");
 77                 return TEST_FAIL;
 78         }
 79 
 80         if (pid == 0)
 81                 vsx();
 82 
 83         if (pid) {
 84                 pptr = (int *)shmat(shm_id, NULL, 0);
 85                 while (!pptr[1])
 86                         asm volatile("" : : : "memory");
 87 
 88                 ret = trace_vsx(pid);
 89                 if (ret) {
 90                         kill(pid, SIGTERM);
 91                         shmdt((void *)pptr);
 92                         shmctl(shm_id, IPC_RMID, NULL);
 93                         return TEST_FAIL;
 94                 }
 95 
 96                 pptr[0] = 1;
 97                 shmdt((void *)pptr);
 98 
 99                 ret = wait(&status);
100                 shmctl(shm_id, IPC_RMID, NULL);
101                 if (ret != pid) {
102                         printf("Child's exit status not captured\n");
103                         return TEST_FAIL;
104                 }
105 
106                 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
107                         TEST_PASS;
108         }
109         return TEST_PASS;
110 }
111 
112 int main(int argc, char *argv[])
113 {
114         return test_harness(ptrace_vsx, "ptrace_vsx");
115 }
116 

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

sflogo.php