fpu_syscall.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 FPU registers change across a syscall (fork).
  10. */
  11. #include <stdio.h>
  12. #include <unistd.h>
  13. #include <sys/syscall.h>
  14. #include <sys/time.h>
  15. #include <sys/types.h>
  16. #include <sys/wait.h>
  17. #include <stdlib.h>
  18. #include "utils.h"
  19. extern int test_fpu(double *darray, pid_t *pid);
  20. double darray[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
  21. 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0,
  22. 2.1};
  23. int syscall_fpu(void)
  24. {
  25. pid_t fork_pid;
  26. int i;
  27. int ret;
  28. int child_ret;
  29. for (i = 0; i < 1000; i++) {
  30. /* test_fpu will fork() */
  31. ret = test_fpu(darray, &fork_pid);
  32. if (fork_pid == -1)
  33. return -1;
  34. if (fork_pid == 0)
  35. exit(ret);
  36. waitpid(fork_pid, &child_ret, 0);
  37. if (ret || child_ret)
  38. return 1;
  39. }
  40. return 0;
  41. }
  42. int test_syscall_fpu(void)
  43. {
  44. /*
  45. * Setup an environment with much context switching
  46. */
  47. pid_t pid2;
  48. pid_t pid = fork();
  49. int ret;
  50. int child_ret;
  51. FAIL_IF(pid == -1);
  52. pid2 = fork();
  53. /* Can't FAIL_IF(pid2 == -1); because already forked once */
  54. if (pid2 == -1) {
  55. /*
  56. * Couldn't fork, ensure test is a fail
  57. */
  58. child_ret = ret = 1;
  59. } else {
  60. ret = syscall_fpu();
  61. if (pid2)
  62. waitpid(pid2, &child_ret, 0);
  63. else
  64. exit(ret);
  65. }
  66. ret |= child_ret;
  67. if (pid)
  68. waitpid(pid, &child_ret, 0);
  69. else
  70. exit(ret);
  71. FAIL_IF(ret || child_ret);
  72. return 0;
  73. }
  74. int main(int argc, char *argv[])
  75. {
  76. return test_harness(test_syscall_fpu, "syscall_fpu");
  77. }