9 /* How many load/unload operations do we do. */
10 #define TEST_ROUNDS 100
15 /* Name of the module. */
21 { "testobj1.so", NULL },
22 { "testobj2.so", NULL },
23 { "testobj3.so", NULL },
25 #define NOBJS (sizeof (testobjs) / sizeof (testobjs[0]))
30 /* Name of a function to call. */
32 /* Index in status and handle array. */
34 /* Options while loading the module. */
38 { "obj1func2", 0, RTLD_LAZY },
39 { "obj1func1", 0, RTLD_LAZY | RTLD_GLOBAL },
40 { "obj1func1", 0, RTLD_NOW, },
41 { "obj1func2", 0, RTLD_NOW | RTLD_GLOBAL },
42 { "obj2func2", 1, RTLD_LAZY },
43 { "obj2func1", 1, RTLD_LAZY | RTLD_GLOBAL, },
44 { "obj2func1", 1, RTLD_NOW, },
45 { "obj2func2", 1, RTLD_NOW | RTLD_GLOBAL },
46 { "obj3func2", 2, RTLD_LAZY },
47 { "obj3func1", 2, RTLD_LAZY | RTLD_GLOBAL },
48 { "obj3func1", 2, RTLD_NOW },
49 { "obj3func2", 2, RTLD_NOW | RTLD_GLOBAL },
51 #define NTESTS (sizeof (tests) / sizeof (tests[0]))
57 int count = TEST_ROUNDS;
60 srandom (TEST_ROUNDS);
64 int nr = random () % NTESTS;
65 int index = tests[nr].index;
67 printf ("%4d: %4d: ", count + 1, nr);
70 if (testobjs[index].handle == NULL)
74 /* Load the object. */
75 testobjs[index].handle = dlopen (testobjs[index].name,
77 if (testobjs[index].handle == NULL)
78 error (EXIT_FAILURE, 0, "cannot load `%s': %s",
79 testobjs[index].name, dlerror ());
81 /* Test the function call. */
82 fct = dlsym (testobjs[index].handle, tests[nr].fname);
84 error (EXIT_FAILURE, 0,
85 "cannot get function `%s' from shared object `%s': %s",
86 tests[nr].fname, testobjs[index].name, dlerror ());
90 printf ("successfully loaded `%s'\n", testobjs[index].name);
94 dlclose (testobjs[index].handle);
95 testobjs[index].handle = NULL;
97 printf ("successfully unloaded `%s'\n", testobjs[index].name);
101 /* Unload all loaded modules. */
102 for (count = 0; count < NOBJS; ++count)
103 if (testobjs[count].handle != NULL)
104 dlclose (testobjs[count].handle);