1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <gnu/lib-names.h>
5 #include <ldsodefs.h>
6 
7 
8 static int
do_test(void)9 do_test (void)
10 {
11   int result = 0;
12 
13   for (int i = 1; i <= 10; ++i)
14     {
15       void *h[DL_NNS - 1];
16       char used[DL_NNS];
17 
18       printf ("round %d\n", i);
19 
20       memset (used, '\0', sizeof (used));
21       used[LM_ID_BASE] = 1;
22 
23       for (int j = 0; j < DL_NNS - 1; ++j)
24 	{
25 	  h[j] = dlmopen (LM_ID_NEWLM, "$ORIGIN/tst-dlmopen1mod.so",
26 			  RTLD_LAZY);
27 	  if (h[j] == NULL)
28 	    {
29 	      printf ("round %d, namespace %d: load failed: %s\n",
30 		      i, j, dlerror ());
31 	      return 1;
32 	    }
33 	  Lmid_t ns;
34 	  if (dlinfo (h[j], RTLD_DI_LMID, &ns) != 0)
35 	    {
36 	      printf ("round %d, namespace %d: dlinfo failed: %s\n",
37 		      i, j, dlerror ());
38 	      return 1;
39 	    }
40 	  if (ns < 0 || ns >= DL_NNS)
41 	    {
42 	      printf ("round %d, namespace %d: invalid namespace %ld",
43 		      i, j, (long int) ns);
44 	      result = 1;
45 	    }
46 	  else if (used[ns] != 0)
47 	    {
48 	      printf ("\
49 round %d, namespace %d: duplicate allocate of namespace %ld",
50 		      i, j, (long int) ns);
51 	      result = 1;
52 	    }
53 	  else
54 	    used[ns] = 1;
55 	}
56 
57       for (int j = 0; j < DL_NNS - 1; ++j)
58 	if (dlclose (h[j]) != 0)
59 	  {
60 	    printf ("round %d, namespace %d: close failed: %s\n",
61 		    i, j, dlerror ());
62 	    return 1;
63 	  }
64     }
65 
66   return result;
67 }
68 
69 #include <support/test-driver.c>
70