exception2.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * File: exception2.c
  3. *
  4. *
  5. * --------------------------------------------------------------------------
  6. *
  7. * Pthreads-win32 - POSIX Threads Library for Win32
  8. * Copyright(C) 1998 John E. Bossom
  9. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  10. *
  11. * Contact Email: [email protected]
  12. *
  13. * The current list of contributors is contained
  14. * in the file CONTRIBUTORS included with the source
  15. * code distribution. The list can also be seen at the
  16. * following World Wide Web location:
  17. * http://sources.redhat.com/pthreads-win32/contributors.html
  18. *
  19. * This library is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU Lesser General Public
  21. * License as published by the Free Software Foundation; either
  22. * version 2 of the License, or (at your option) any later version.
  23. *
  24. * This library is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. * Lesser General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Lesser General Public
  30. * License along with this library in the file COPYING.LIB;
  31. * if not, write to the Free Software Foundation, Inc.,
  32. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  33. *
  34. * --------------------------------------------------------------------------
  35. *
  36. * Test Synopsis: Test passing of exceptions out of thread scope.
  37. *
  38. * Test Method (Validation or Falsification):
  39. * -
  40. *
  41. * Requirements Tested:
  42. * -
  43. *
  44. * Features Tested:
  45. * -
  46. *
  47. * Cases Tested:
  48. * -
  49. *
  50. * Description:
  51. * -
  52. *
  53. * Environment:
  54. * -
  55. *
  56. * Input:
  57. * - None.
  58. *
  59. * Output:
  60. * - File name, Line number, and failed expression on failure.
  61. * - No output on success.
  62. *
  63. * Assumptions:
  64. * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
  65. * pthread_testcancel, pthread_cancel
  66. *
  67. * Pass Criteria:
  68. * - Process returns zero exit status.
  69. *
  70. * Fail Criteria:
  71. * - Process returns non-zero exit status.
  72. */
  73. #if defined(_MSC_VER) || defined(__cplusplus)
  74. #if defined(_MSC_VER) && defined(__cplusplus)
  75. #include <eh.h>
  76. #elif defined(__cplusplus)
  77. #include <exception>
  78. #endif
  79. #ifdef __GNUC__
  80. #include <stdlib.h>
  81. #endif
  82. #include "test.h"
  83. /*
  84. * Create NUMTHREADS threads in addition to the Main thread.
  85. */
  86. enum {
  87. NUMTHREADS = 1
  88. };
  89. void *
  90. exceptionedThread(void * arg)
  91. {
  92. int dummy = 0x1;
  93. #if defined(_MSC_VER) && !defined(__cplusplus)
  94. RaiseException(dummy, 0, 0, NULL);
  95. #elif defined(__cplusplus)
  96. throw dummy;
  97. #endif
  98. return (void *) 100;
  99. }
  100. int
  101. main(int argc, char* argv[])
  102. {
  103. int i;
  104. pthread_t mt;
  105. pthread_t et[NUMTHREADS];
  106. if (argc <= 1)
  107. {
  108. int result;
  109. printf("You should see an \"abnormal termination\" message\n");
  110. fflush(stdout);
  111. result = system("exception2.exe die");
  112. exit(0);
  113. }
  114. assert((mt = pthread_self()).p != NULL);
  115. for (i = 0; i < NUMTHREADS; i++)
  116. {
  117. assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0);
  118. }
  119. Sleep(1000);
  120. /*
  121. * Success.
  122. */
  123. return 0;
  124. }
  125. #else /* defined(_MSC_VER) || defined(__cplusplus) */
  126. #include <stdio.h>
  127. int
  128. main()
  129. {
  130. fprintf(stderr, "Test N/A for this compiler environment.\n");
  131. return 0;
  132. }
  133. #endif /* defined(_MSC_VER) || defined(__cplusplus) */