elf: Do not duplicate the GLIBC_TUNABLES string
[platform/upstream/glibc.git] / elf / loadtest.c
index 4a3c4c0..b5eab5e 100644 (file)
@@ -5,6 +5,7 @@
 #include <mcheck.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 
 /* How many load/unload operations do we do.  */
@@ -69,12 +70,18 @@ static const struct
 
 #include <include/link.h>
 
-#define OUT \
-  for (map = _r_debug.r_map; map != NULL; map = map->l_next)                 \
-    if (map->l_type == lt_loaded)                                            \
-      printf ("name = \"%s\", opencount = %d\n",                             \
-             map->l_name, (int) map->l_opencount);                           \
-  fflush (stdout)
+#define MAPS ((struct link_map *) _r_debug.r_map)
+
+#define OUT                                                    \
+  do                                                           \
+    {                                                          \
+      for (map = MAPS; map != NULL; map = map->l_next)         \
+       if (map->l_type == lt_loaded)                           \
+         printf ("name = \"%s\", direct_opencount = %d\n",     \
+                 map->l_name, (int) map->l_direct_opencount);  \
+      fflush (stdout);                                         \
+    }                                                          \
+  while (0)
 
 
 int
@@ -83,17 +90,23 @@ main (int argc, char *argv[])
   int debug = argc > 1 && argv[1][0] != '\0';
   int count = TEST_ROUNDS;
   int result = 0;
+  struct link_map *map;
 
   mtrace ();
 
   /* Just a seed.  */
   srandom (TEST_ROUNDS);
 
+  if (debug)
+    {
+      puts ("in the beginning");
+      OUT;
+    }
+
   while (count--)
     {
       int nr = random () % NTESTS;
       int index = tests[nr].index;
-      struct link_map *map;
 
       printf ("%4d: %4d: ", count + 1, nr);
       fflush (stdout);
@@ -133,6 +146,23 @@ main (int argc, char *argv[])
                    testobjs[index].name, testobjs[index].handle);
 
          testobjs[index].handle = NULL;
+
+         if (testobjs[0].handle == NULL
+             && testobjs[1].handle == NULL
+             && testobjs[5].handle == NULL)
+           {
+             /* In this case none of the objects above should be
+                present.  */
+             for (map = MAPS; map != NULL; map = map->l_next)
+               if (map->l_type == lt_loaded
+                   && (strstr (map->l_name, testobjs[0].name) != NULL
+                       || strstr (map->l_name, testobjs[1].name) != NULL
+                       || strstr (map->l_name, testobjs[5].name) != NULL))
+                 {
+                   printf ("`%s' is still loaded\n", map->l_name);
+                   result = 1;
+                 }
+           }
        }
 
       if (debug)
@@ -140,22 +170,35 @@ main (int argc, char *argv[])
     }
 
   /* Unload all loaded modules.  */
-  for (count = 0; count < NOBJS; ++count)
+  for (count = 0; count < (int) NOBJS; ++count)
     if (testobjs[count].handle != NULL)
-{        printf ("\nclose: %s: l_initfini = %p, l_versions = %p\n",
-                 testobjs[count].name,
-                 ((struct link_map*)testobjs[count].handle)->l_initfini,
-                 ((struct link_map*)testobjs[count].handle)->l_versions);
-      if (dlclose (testobjs[count].handle) != 0)
-       {
-         printf ("failed to close %s\n", testobjs[count].name);
-         result = 1;
-}      }
+      {
+       printf ("\nclose: %s: l_initfini = %p, l_versions = %p\n",
+               testobjs[count].name,
+               ((struct link_map *) testobjs[count].handle)->l_initfini,
+               ((struct link_map *) testobjs[count].handle)->l_versions);
+
+       if (dlclose (testobjs[count].handle) != 0)
+         {
+           printf ("failed to close %s\n", testobjs[count].name);
+           result = 1;
+         }
+      }
+
+  /* Check whether all files are unloaded.  */
+  for (map = MAPS; map != NULL; map = map->l_next)
+    if (map->l_type == lt_loaded)
+      {
+       printf ("name = \"%s\", direct_opencount = %d\n",
+               map->l_name, (int) map->l_direct_opencount);
+       result = 1;
+      }
 
   return result;
 }
 
 
+extern int foo (int a);
 int
 foo (int a)
 {