vmx_syscall.c 1.8 KB

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