0001
0002
0003
0004
0005
0006
0007 #include "ptrace.h"
0008 #include "ptrace-vsx.h"
0009
0010
0011 int shm_id;
0012 int *cptr, *pptr;
0013
0014 unsigned long fp_load[VEC_MAX];
0015 unsigned long fp_load_new[VEC_MAX];
0016 unsigned long fp_store[VEC_MAX];
0017
0018 void vsx(void)
0019 {
0020 int ret;
0021
0022 cptr = (int *)shmat(shm_id, NULL, 0);
0023 loadvsx(fp_load, 0);
0024 cptr[1] = 1;
0025
0026 while (!cptr[0])
0027 asm volatile("" : : : "memory");
0028 shmdt((void *) cptr);
0029
0030 storevsx(fp_store, 0);
0031 ret = compare_vsx_vmx(fp_store, fp_load_new);
0032 if (ret)
0033 exit(1);
0034 exit(0);
0035 }
0036
0037 int trace_vsx(pid_t child)
0038 {
0039 unsigned long vsx[VSX_MAX];
0040 unsigned long vmx[VMX_MAX + 2][2];
0041
0042 FAIL_IF(start_trace(child));
0043 FAIL_IF(show_vsx(child, vsx));
0044 FAIL_IF(validate_vsx(vsx, fp_load));
0045 FAIL_IF(show_vmx(child, vmx));
0046 FAIL_IF(validate_vmx(vmx, fp_load));
0047
0048 memset(vsx, 0, sizeof(vsx));
0049 memset(vmx, 0, sizeof(vmx));
0050 load_vsx_vmx(fp_load_new, vsx, vmx);
0051
0052 FAIL_IF(write_vsx(child, vsx));
0053 FAIL_IF(write_vmx(child, vmx));
0054 FAIL_IF(stop_trace(child));
0055
0056 return TEST_PASS;
0057 }
0058
0059 int ptrace_vsx(void)
0060 {
0061 pid_t pid;
0062 int ret, status, i;
0063
0064 SKIP_IF(!have_hwcap(PPC_FEATURE_HAS_VSX));
0065
0066 shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
0067
0068 for (i = 0; i < VEC_MAX; i++)
0069 fp_load[i] = i + rand();
0070
0071 for (i = 0; i < VEC_MAX; i++)
0072 fp_load_new[i] = i + 2 * rand();
0073
0074 pid = fork();
0075 if (pid < 0) {
0076 perror("fork() failed");
0077 return TEST_FAIL;
0078 }
0079
0080 if (pid == 0)
0081 vsx();
0082
0083 if (pid) {
0084 pptr = (int *)shmat(shm_id, NULL, 0);
0085 while (!pptr[1])
0086 asm volatile("" : : : "memory");
0087
0088 ret = trace_vsx(pid);
0089 if (ret) {
0090 kill(pid, SIGTERM);
0091 shmdt((void *)pptr);
0092 shmctl(shm_id, IPC_RMID, NULL);
0093 return TEST_FAIL;
0094 }
0095
0096 pptr[0] = 1;
0097 shmdt((void *)pptr);
0098
0099 ret = wait(&status);
0100 shmctl(shm_id, IPC_RMID, NULL);
0101 if (ret != pid) {
0102 printf("Child's exit status not captured\n");
0103 return TEST_FAIL;
0104 }
0105
0106 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
0107 TEST_PASS;
0108 }
0109 return TEST_PASS;
0110 }
0111
0112 int main(int argc, char *argv[])
0113 {
0114 return test_harness(ptrace_vsx, "ptrace_vsx");
0115 }