ptrace-vsx.c 2.1 KB

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