tst-basic4.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <sys/wait.h>
  22. #include "../test-skeleton.h"
  23. #ifdef __ARCH_USE_MMU__
  24. static void
  25. final_test (void)
  26. {
  27. puts ("final_test has been called");
  28. #define THE_SIGNAL SIGUSR1
  29. kill (getpid (), SIGUSR1);
  30. }
  31. static void *
  32. tf (void *a)
  33. {
  34. pid_t pid = fork ();
  35. if (pid == -1)
  36. {
  37. puts ("fork failed");
  38. exit (1);
  39. }
  40. if (pid == 0)
  41. {
  42. atexit (final_test);
  43. pthread_exit (NULL);
  44. }
  45. int r;
  46. int e = TEMP_FAILURE_RETRY (waitpid (pid, &r, 0));
  47. if (e != pid)
  48. {
  49. puts ("waitpid failed");
  50. exit (1);
  51. }
  52. if (! WIFSIGNALED (r))
  53. {
  54. puts ("child not signled");
  55. exit (1);
  56. }
  57. if (WTERMSIG (r) != THE_SIGNAL)
  58. {
  59. puts ("child's termination signal wrong");
  60. exit (1);
  61. }
  62. return NULL;
  63. }
  64. int
  65. do_test (void)
  66. {
  67. pthread_t th;
  68. if (pthread_create (&th, NULL, tf, NULL) != 0)
  69. {
  70. puts ("create failed");
  71. _exit (1);
  72. }
  73. if (pthread_join (th, NULL) != 0)
  74. {
  75. puts ("join failed");
  76. exit (1);
  77. }
  78. return 0;
  79. }
  80. #define TEST_FUNCTION do_test ()
  81. #include "../test-skeleton.c"
  82. #else
  83. int main(void)
  84. {
  85. printf("Skipping test on non-mmu host!\n");
  86. return 23;
  87. }
  88. #endif