tst-typesizes.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
  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 <stdio.h>
  16. #include <pthread.h>
  17. #include <semaphore.h>
  18. static const struct
  19. {
  20. const char *name;
  21. size_t expected;
  22. size_t is;
  23. } types[] =
  24. {
  25. #define T(t, c) \
  26. { #t, c, sizeof (t) }
  27. T (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T),
  28. T (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T),
  29. T (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T),
  30. T (pthread_cond_t, __SIZEOF_PTHREAD_COND_T),
  31. T (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T),
  32. T (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T),
  33. T (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T),
  34. T (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T),
  35. T (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T)
  36. };
  37. static int
  38. do_test (void)
  39. {
  40. int result = 0;
  41. #define TEST_TYPE(name) \
  42. printf ("%s: ", #name); \
  43. if (sizeof (name) != sizeof (((name *) 0)->__size)) \
  44. { \
  45. printf ("expected %zu, is %zu\n", \
  46. sizeof (((name *) 0)->__size), sizeof (name)); \
  47. result = 1; \
  48. } \
  49. else \
  50. puts ("OK")
  51. TEST_TYPE (pthread_mutex_t);
  52. TEST_TYPE (pthread_cond_t);
  53. TEST_TYPE (pthread_rwlock_t);
  54. #define TEST_TYPE2(name, internal) \
  55. printf ("%s: ", #name); \
  56. if (sizeof (((name *) 0)->__size) < sizeof (internal)) \
  57. { \
  58. printf ("expected %zu, is %zu\n", \
  59. sizeof (((name *) 0)->__size), sizeof (internal)); \
  60. result = 1; \
  61. } \
  62. else \
  63. puts ("OK")
  64. TEST_TYPE2 (pthread_attr_t, struct pthread_attr);
  65. TEST_TYPE2 (pthread_mutexattr_t, struct pthread_mutexattr);
  66. TEST_TYPE2 (pthread_condattr_t, struct pthread_condattr);
  67. TEST_TYPE2 (pthread_rwlockattr_t, struct pthread_rwlockattr);
  68. TEST_TYPE2 (pthread_barrier_t, struct pthread_barrier);
  69. TEST_TYPE2 (pthread_barrierattr_t, struct pthread_barrierattr);
  70. TEST_TYPE2 (sem_t, struct new_sem);
  71. TEST_TYPE2 (sem_t, struct old_sem);
  72. for (size_t i = 0; i < sizeof (types) / sizeof (types[0]); ++i)
  73. if (types[i].expected != types[i].is)
  74. {
  75. printf ("%s: expected %zu, is %zu\n",
  76. types[i].name, types[i].expected, types[i].is);
  77. result = 1;
  78. }
  79. return result;
  80. }
  81. #define TEST_FUNCTION do_test ()
  82. #include "../test-skeleton.c"