tst-tsd1.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright (C) 2002 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 <pthread.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. static int
  19. do_test (void)
  20. {
  21. pthread_key_t key1;
  22. pthread_key_t key2;
  23. void *value;
  24. int result = 0;
  25. int err;
  26. err = pthread_key_create (&key1, NULL);
  27. if (err != 0)
  28. {
  29. printf ("1st key_create failed: %s\n", strerror (err));
  30. return 1;
  31. }
  32. /* Initial value must be NULL. */
  33. value = pthread_getspecific (key1);
  34. if (value != NULL)
  35. {
  36. puts ("1st getspecific != NULL");
  37. result = 1;
  38. }
  39. err = pthread_setspecific (key1, (void *) -2l);
  40. if (err != 0)
  41. {
  42. printf ("1st setspecific failed: %s\n", strerror (err));
  43. return 1;
  44. }
  45. value = pthread_getspecific (key1);
  46. if (value == NULL)
  47. {
  48. puts ("2nd getspecific == NULL\n");
  49. result = 1;
  50. }
  51. else if (value != (void *) -2l)
  52. {
  53. puts ("2nd getspecific != -2l\n");
  54. result = 1;
  55. }
  56. err = pthread_setspecific (key1, (void *) -3l);
  57. if (err != 0)
  58. {
  59. printf ("2nd setspecific failed: %s\n", strerror (err));
  60. return 1;
  61. }
  62. value = pthread_getspecific (key1);
  63. if (value == NULL)
  64. {
  65. puts ("3rd getspecific == NULL\n");
  66. result = 1;
  67. }
  68. else if (value != (void *) -3l)
  69. {
  70. puts ("3rd getspecific != -2l\n");
  71. result = 1;
  72. }
  73. err = pthread_key_delete (key1);
  74. if (err != 0)
  75. {
  76. printf ("key_delete failed: %s\n", strerror (err));
  77. result = 1;
  78. }
  79. err = pthread_key_create (&key2, NULL);
  80. if (err != 0)
  81. {
  82. printf ("2nd key_create failed: %s\n", strerror (err));
  83. return 1;
  84. }
  85. if (key1 != key2)
  86. puts ("key1 != key2; no more tests performed");
  87. else
  88. {
  89. value = pthread_getspecific (key2);
  90. if (value != NULL)
  91. {
  92. puts ("4th getspecific != NULL");
  93. result = 1;
  94. }
  95. }
  96. return result;
  97. }
  98. #define TEST_FUNCTION do_test ()
  99. #include "../test-skeleton.c"