Back to index

glibc  2.9
tst-typesizes.c
Go to the documentation of this file.
00001 /* Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdio.h>
00021 #include <pthreadP.h>
00022 #include <semaphore.h>
00023 
00024 static const struct
00025 {
00026   const char *name;
00027   size_t expected;
00028   size_t is;
00029 } types[] =
00030   {
00031 #define T(t, c) \
00032     { #t, c, sizeof (t) }
00033     T (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T),
00034     T (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T),
00035     T (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T),
00036     T (pthread_cond_t, __SIZEOF_PTHREAD_COND_T),
00037     T (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T),
00038     T (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T),
00039     T (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T),
00040     T (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T),
00041     T (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T)
00042   };
00043 
00044 static int
00045 do_test (void)
00046 {
00047   int result = 0;
00048 
00049 #define TEST_TYPE(name) \
00050   printf ("%s: ", #name);                                            \
00051   if (sizeof (name) != sizeof (((name *) 0)->__size))                       \
00052     {                                                                \
00053       printf ("expected %zu, is %zu\n",                                     \
00054              sizeof (((name *) 0)->__size), sizeof (name));                 \
00055       result = 1;                                                    \
00056     }                                                                \
00057   else                                                               \
00058     puts ("OK")
00059 
00060   TEST_TYPE (pthread_mutex_t);
00061   TEST_TYPE (pthread_cond_t);
00062   TEST_TYPE (pthread_rwlock_t);
00063 
00064 #define TEST_TYPE2(name, internal)                                   \
00065   printf ("%s: ", #name);                                            \
00066   if (sizeof (((name *) 0)->__size) < sizeof (internal))                    \
00067     {                                                                \
00068       printf ("expected %zu, is %zu\n",                                     \
00069              sizeof (((name *) 0)->__size), sizeof (internal));             \
00070       result = 1;                                                    \
00071     }                                                                \
00072   else                                                               \
00073     puts ("OK")
00074 
00075   TEST_TYPE2 (pthread_attr_t, struct pthread_attr);
00076   TEST_TYPE2 (pthread_mutexattr_t, struct pthread_mutexattr);
00077   TEST_TYPE2 (pthread_condattr_t, struct pthread_condattr);
00078   TEST_TYPE2 (pthread_rwlockattr_t, struct pthread_rwlockattr);
00079   TEST_TYPE2 (pthread_barrier_t, struct pthread_barrier);
00080   TEST_TYPE2 (pthread_barrierattr_t, struct pthread_barrierattr);
00081   TEST_TYPE2 (sem_t, struct new_sem);
00082   TEST_TYPE2 (sem_t, struct old_sem);
00083 
00084   for (size_t i = 0; i < sizeof (types) / sizeof (types[0]); ++i)
00085     if (types[i].expected != types[i].is)
00086       {
00087        printf ("%s: expected %zu, is %zu\n",
00088               types[i].name, types[i].expected, types[i].is);
00089        result = 1;
00090       }
00091 
00092   return result;
00093 }
00094 
00095 #define TEST_FUNCTION do_test ()
00096 #include "../test-skeleton.c"