vmx_syscall.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2015, Cyril Bur, IBM Corp.
  4. *
  5. * This test attempts to see if the VMX registers change across a syscall (fork).
  6. */
  7. #include <altivec.h>
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <sys/syscall.h>
  11. #include <sys/time.h>
  12. #include <stdlib.h>
  13. #include <sys/types.h>
  14. #include <sys/wait.h>
  15. #include "utils.h"
  16. vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12},
  17. {13,14,15,16},{17,18,19,20},{21,22,23,24},
  18. {25,26,27,28},{29,30,31,32},{33,34,35,36},
  19. {37,38,39,40},{41,42,43,44},{45,46,47,48}};
  20. extern int test_vmx(vector int *varray, pid_t *pid);
  21. int vmx_syscall(void)
  22. {
  23. pid_t fork_pid;
  24. int i;
  25. int ret;
  26. int child_ret;
  27. for (i = 0; i < 1000; i++) {
  28. /* test_vmx will fork() */
  29. ret = test_vmx(varray, &fork_pid);
  30. if (fork_pid == -1)
  31. return -1;
  32. if (fork_pid == 0)
  33. exit(ret);
  34. waitpid(fork_pid, &child_ret, 0);
  35. if (ret || child_ret)
  36. return 1;
  37. }
  38. return 0;
  39. }
  40. int test_vmx_syscall(void)
  41. {
  42. /*
  43. * Setup an environment with much context switching
  44. */
  45. pid_t pid2;
  46. pid_t pid;
  47. int ret;
  48. int child_ret;
  49. // vcmpequd used in vmx_asm.S is v2.07
  50. SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
  51. pid = fork();
  52. FAIL_IF(pid == -1);
  53. pid2 = fork();
  54. ret = vmx_syscall();
  55. /* Can't FAIL_IF(pid2 == -1); because we've already forked */
  56. if (pid2 == -1) {
  57. /*
  58. * Couldn't fork, ensure child_ret is set and is a fail
  59. */
  60. ret = child_ret = 1;
  61. } else {
  62. if (pid2)
  63. waitpid(pid2, &child_ret, 0);
  64. else
  65. exit(ret);
  66. }
  67. ret |= child_ret;
  68. if (pid)
  69. waitpid(pid, &child_ret, 0);
  70. else
  71. exit(ret);
  72. FAIL_IF(ret || child_ret);
  73. return 0;
  74. }
  75. int main(int argc, char *argv[])
  76. {
  77. return test_harness(test_vmx_syscall, "vmx_syscall");
  78. }