| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> | 
 | 2 | #include <pthread.h> | 
 | 3 | #include <stdio.h> | 
 | 4 | #include <stdlib.h> | 
 | 5 | #include <string.h> | 
 | 6 | #include <gnu/lib-names.h> | 
 | 7 |  | 
 | 8 | static void * | 
 | 9 | tf (void *arg) | 
 | 10 | { | 
 | 11 |   void *h = dlopen (LIBM_SO, RTLD_LAZY); | 
 | 12 |   if (h == NULL) | 
 | 13 |     { | 
 | 14 |       printf ("dlopen failed: %s\n", dlerror ()); | 
 | 15 |       exit (1); | 
 | 16 |     } | 
 | 17 |   if (dlsym (h, "sin") == NULL) | 
 | 18 |     { | 
 | 19 |       printf ("dlsym failed: %s\n", dlerror ()); | 
 | 20 |       exit (1); | 
 | 21 |     } | 
 | 22 |   if (dlclose (h) != 0) | 
 | 23 |     { | 
 | 24 |       printf ("dlclose failed: %s\n", dlerror ()); | 
 | 25 |       exit (1); | 
 | 26 |     } | 
 | 27 |   return NULL; | 
 | 28 | } | 
 | 29 |  | 
 | 30 |  | 
 | 31 | static int | 
 | 32 | do_test (void) | 
 | 33 | { | 
 | 34 | #define N 10 | 
 | 35 |   pthread_t th[N]; | 
 | 36 |   for (int i = 0; i < N; ++i) | 
 | 37 |     { | 
 | 38 |       int e = pthread_create (&th[i], NULL, tf, NULL); | 
 | 39 |       if (e != 0) | 
 | 40 | 	{ | 
 | 41 | 	  printf ("pthread_create failed with %d (%s)\n", e, strerror (e)); | 
 | 42 | 	  return 1; | 
 | 43 | 	} | 
 | 44 |     } | 
 | 45 |   for (int i = 0; i < N; ++i) | 
 | 46 |     { | 
 | 47 |       void *res; | 
 | 48 |       int e = pthread_join (th[i], &res); | 
 | 49 |       if (e != 0 || res != NULL) | 
 | 50 | 	{ | 
 | 51 | 	  puts ("thread failed"); | 
 | 52 | 	  return 1; | 
 | 53 | 	} | 
 | 54 |     } | 
 | 55 |   return 0; | 
 | 56 | } | 
 | 57 |  | 
 | 58 | #define TEST_FUNCTION do_test () | 
 | 59 | #include "../test-skeleton.c" |