9 /* How many load/unload operations do we do. */
10 #define TEST_ROUNDS 1000
15 /* Name of the module. */
21 { "testobj1.so", NULL
},
22 { "testobj2.so", NULL
},
23 { "testobj3.so", NULL
},
24 { "testobj4.so", NULL
},
25 { "testobj5.so", NULL
},
26 { "testobj6.so", NULL
},
28 #define NOBJS (sizeof (testobjs) / sizeof (testobjs[0]))
33 /* Name of a function to call. */
35 /* Index in status and handle array. */
37 /* Options while loading the module. */
41 { "obj1func2", 0, RTLD_LAZY
},
42 { "obj1func1", 0, RTLD_LAZY
| RTLD_GLOBAL
},
43 { "obj1func1", 0, RTLD_NOW
, },
44 { "obj1func2", 0, RTLD_NOW
| RTLD_GLOBAL
},
45 { "obj2func2", 1, RTLD_LAZY
},
46 { "obj2func1", 1, RTLD_LAZY
| RTLD_GLOBAL
, },
47 { "obj2func1", 1, RTLD_NOW
, },
48 { "obj2func2", 1, RTLD_NOW
| RTLD_GLOBAL
},
49 { "obj3func2", 2, RTLD_LAZY
},
50 { "obj3func1", 2, RTLD_LAZY
| RTLD_GLOBAL
},
51 { "obj3func1", 2, RTLD_NOW
},
52 { "obj3func2", 2, RTLD_NOW
| RTLD_GLOBAL
},
53 { "obj4func2", 3, RTLD_LAZY
},
54 { "obj4func1", 3, RTLD_LAZY
| RTLD_GLOBAL
},
55 { "obj4func1", 3, RTLD_NOW
},
56 { "obj4func2", 3, RTLD_NOW
| RTLD_GLOBAL
},
57 { "obj5func2", 4, RTLD_LAZY
},
58 { "obj5func1", 4, RTLD_LAZY
| RTLD_GLOBAL
},
59 { "obj5func1", 4, RTLD_NOW
},
60 { "obj5func2", 4, RTLD_NOW
| RTLD_GLOBAL
},
61 { "obj6func2", 5, RTLD_LAZY
},
62 { "obj6func1", 5, RTLD_LAZY
| RTLD_GLOBAL
},
63 { "obj6func1", 5, RTLD_NOW
},
64 { "obj6func2", 5, RTLD_NOW
| RTLD_GLOBAL
},
66 #define NTESTS (sizeof (tests) / sizeof (tests[0]))
72 int count
= TEST_ROUNDS
;
75 srandom (TEST_ROUNDS
);
79 int nr
= random () % NTESTS
;
80 int index
= tests
[nr
].index
;
82 printf ("%4d: %4d: ", count
+ 1, nr
);
85 if (testobjs
[index
].handle
== NULL
)
89 /* Load the object. */
90 testobjs
[index
].handle
= dlopen (testobjs
[index
].name
,
92 if (testobjs
[index
].handle
== NULL
)
93 error (EXIT_FAILURE
, 0, "cannot load `%s': %s",
94 testobjs
[index
].name
, dlerror ());
96 /* Test the function call. */
97 fct
= dlsym (testobjs
[index
].handle
, tests
[nr
].fname
);
99 error (EXIT_FAILURE
, 0,
100 "cannot get function `%s' from shared object `%s': %s",
101 tests
[nr
].fname
, testobjs
[index
].name
, dlerror ());
105 printf ("successfully loaded `%s'\n", testobjs
[index
].name
);
109 dlclose (testobjs
[index
].handle
);
110 testobjs
[index
].handle
= NULL
;
112 printf ("successfully unloaded `%s'\n", testobjs
[index
].name
);
116 /* Unload all loaded modules. */
117 for (count
= 0; count
< NOBJS
; ++count
)
118 if (testobjs
[count
].handle
!= NULL
)
119 dlclose (testobjs
[count
].handle
);