ptrace-vsx.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /* Tracer and Tracee Shared Data */
  14. int shm_id;
  15. int *cptr, *pptr;
  16. unsigned long fp_load[VEC_MAX];
  17. unsigned long fp_load_new[VEC_MAX];
  18. unsigned long fp_store[VEC_MAX];
  19. void vsx(void)
  20. {
  21. int ret;
  22. cptr = (int *)shmat(shm_id, NULL, 0);
  23. loadvsx(fp_load, 0);
  24. cptr[1] = 1;
  25. while (!cptr[0])
  26. asm volatile("" : : : "memory");
  27. shmdt((void *) cptr);
  28. storevsx(fp_store, 0);
  29. ret = compare_vsx_vmx(fp_store, fp_load_new);
  30. if (ret)
  31. exit(1);
  32. exit(0);
  33. }
  34. int trace_vsx(pid_t child)
  35. {
  36. unsigned long vsx[VSX_MAX];
  37. unsigned long vmx[VMX_MAX + 2][2];
  38. FAIL_IF(start_trace(child));
  39. FAIL_IF(show_vsx(child, vsx));
  40. FAIL_IF(validate_vsx(vsx, fp_load));
  41. FAIL_IF(show_vmx(child, vmx));
  42. FAIL_IF(validate_vmx(vmx, fp_load));
  43. memset(vsx, 0, sizeof(vsx));
  44. memset(vmx, 0, sizeof(vmx));
  45. load_vsx_vmx(fp_load_new, vsx, vmx);
  46. FAIL_IF(write_vsx(child, vsx));
  47. FAIL_IF(write_vmx(child, vmx));
  48. FAIL_IF(stop_trace(child));
  49. return TEST_PASS;
  50. }
  51. int ptrace_vsx(void)
  52. {
  53. pid_t pid;
  54. int ret, status, i;
  55. shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
  56. for (i = 0; i < VEC_MAX; i++)
  57. fp_load[i] = i + rand();
  58. for (i = 0; i < VEC_MAX; i++)
  59. fp_load_new[i] = i + 2 * rand();
  60. pid = fork();
  61. if (pid < 0) {
  62. perror("fork() failed");
  63. return TEST_FAIL;
  64. }
  65. if (pid == 0)
  66. vsx();
  67. if (pid) {
  68. pptr = (int *)shmat(shm_id, NULL, 0);
  69. while (!pptr[1])
  70. asm volatile("" : : : "memory");
  71. ret = trace_vsx(pid);
  72. if (ret) {
  73. kill(pid, SIGTERM);
  74. shmdt((void *)pptr);
  75. shmctl(shm_id, IPC_RMID, NULL);
  76. return TEST_FAIL;
  77. }
  78. pptr[0] = 1;
  79. shmdt((void *)pptr);
  80. ret = wait(&status);
  81. shmctl(shm_id, IPC_RMID, NULL);
  82. if (ret != pid) {
  83. printf("Child's exit status not captured\n");
  84. return TEST_FAIL;
  85. }
  86. return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
  87. TEST_PASS;
  88. }
  89. return TEST_PASS;
  90. }
  91. int main(int argc, char *argv[])
  92. {
  93. return test_harness(ptrace_vsx, "ptrace_vsx");
  94. }