Merge tag 'xtensa-20180225' of git://github.com/jcmvbkbc/linux-xtensa
[cris-mirror.git] / tools / testing / selftests / powerpc / ptrace / ptrace-vsx.c
blob04084ee7d27b96f23668cffcf6d87e74049f5eeb
1 /*
2 * Ptrace test for VMX/VSX registers
4 * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
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.
11 #include "ptrace.h"
12 #include "ptrace-vsx.h"
14 /* Tracer and Tracee Shared Data */
15 int shm_id;
16 int *cptr, *pptr;
18 unsigned long fp_load[VEC_MAX];
19 unsigned long fp_load_new[VEC_MAX];
20 unsigned long fp_store[VEC_MAX];
22 void vsx(void)
24 int ret;
26 cptr = (int *)shmat(shm_id, NULL, 0);
27 loadvsx(fp_load, 0);
28 cptr[1] = 1;
30 while (!cptr[0])
31 asm volatile("" : : : "memory");
32 shmdt((void *) cptr);
34 storevsx(fp_store, 0);
35 ret = compare_vsx_vmx(fp_store, fp_load_new);
36 if (ret)
37 exit(1);
38 exit(0);
41 int trace_vsx(pid_t child)
43 unsigned long vsx[VSX_MAX];
44 unsigned long vmx[VMX_MAX + 2][2];
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));
52 memset(vsx, 0, sizeof(vsx));
53 memset(vmx, 0, sizeof(vmx));
54 load_vsx_vmx(fp_load_new, vsx, vmx);
56 FAIL_IF(write_vsx(child, vsx));
57 FAIL_IF(write_vmx(child, vmx));
58 FAIL_IF(stop_trace(child));
60 return TEST_PASS;
63 int ptrace_vsx(void)
65 pid_t pid;
66 int ret, status, i;
68 shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
70 for (i = 0; i < VEC_MAX; i++)
71 fp_load[i] = i + rand();
73 for (i = 0; i < VEC_MAX; i++)
74 fp_load_new[i] = i + 2 * rand();
76 pid = fork();
77 if (pid < 0) {
78 perror("fork() failed");
79 return TEST_FAIL;
82 if (pid == 0)
83 vsx();
85 if (pid) {
86 pptr = (int *)shmat(shm_id, NULL, 0);
87 while (!pptr[1])
88 asm volatile("" : : : "memory");
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;
98 pptr[0] = 1;
99 shmdt((void *)pptr);
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;
108 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
109 TEST_PASS;
111 return TEST_PASS;
114 int main(int argc, char *argv[])
116 return test_harness(ptrace_vsx, "ptrace_vsx");