tst-tsd1.c 2.7 KB

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