summaryrefslogtreecommitdiff
path: root/elf/loadtest.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-01-16 17:09:04 +0000
committerUlrich Drepper <drepper@redhat.com>1999-01-16 17:09:04 +0000
commit482eec0d1188823ad93247f79bf965886e8bd4f7 (patch)
tree5a3157c41a1310f5440de77f841753a32bb1444d /elf/loadtest.c
parent37a87f834a459f6136ff44c7887b013d1ae0f6be (diff)
downloadglibc-482eec0d1188823ad93247f79bf965886e8bd4f7.tar.gz
Update.
1999-01-16 Ulrich Drepper <drepper@cygnus.com> * elf/Makefile (tests): Add loadtest. Add rules to generate test modules. * Makeconfig (+link): Add $(LDFLAGS-$(@F)) to command line. * elf/loadtest.c: New file. * elf/testobj1.c: New file. * elf/testobj2.c: New file. * elf/testobj3.c: New file. * elf/dl-close.c: Correct removing module from global list. * elf/dl-open.c: Add debugging code. * include/string.h: Add __rawmemchr prototype. * string/Makefile (routines): Add rawmemchr. * string/Versions [GLIBC_2.1]: Add __rawmemchr and rawmemchr. * string/string.h: Add prototype for rawmemchr. * string/bits/string2.h: Optimize strchr with rawmemchr. * sysdeps/generic/rawmemchr.c: New file. * sysdeps/i386/rawmemchr.c: New file. * sysdeps/i386/i486/bits/string.h: Add rawmemchr inline code. Optimize strchr with rawmemchr. * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define _LFS_LARGEFILE, _LFS64_LARGEFILE, and _LFS64_STDIO for Unix98. 1999-01-14 Andreas Jaeger <aj@arthur.rhein-neckar.de> * nis/nis_error.c (nis_errlist): Fix capitilasation.
Diffstat (limited to 'elf/loadtest.c')
-rw-r--r--elf/loadtest.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/elf/loadtest.c b/elf/loadtest.c
new file mode 100644
index 0000000000..209f420141
--- /dev/null
+++ b/elf/loadtest.c
@@ -0,0 +1,114 @@
+#include <assert.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+/* How many load/unload operations do we do. */
+#define TEST_ROUNDS 100
+
+
+static struct
+{
+ /* Name of the module. */
+ const char *name;
+ /* The handle. */
+ void *handle;
+} testobjs[] =
+{
+ { "testobj1.so", NULL },
+ { "testobj2.so", NULL },
+ { "testobj3.so", NULL },
+};
+#define NOBJS (sizeof (testobjs) / sizeof (testobjs[0]))
+
+
+static const struct
+{
+ /* Name of a function to call. */
+ const char *fname;
+ /* Index in status and handle array. */
+ int index;
+ /* Options while loading the module. */
+ int options;
+} tests[] =
+{
+ { "obj1func2", 0, RTLD_LAZY },
+ { "obj1func1", 0, RTLD_LAZY | RTLD_GLOBAL },
+ { "obj1func1", 0, RTLD_NOW, },
+ { "obj1func2", 0, RTLD_NOW | RTLD_GLOBAL },
+ { "obj2func2", 1, RTLD_LAZY },
+ { "obj2func1", 1, RTLD_LAZY | RTLD_GLOBAL, },
+ { "obj2func1", 1, RTLD_NOW, },
+ { "obj2func2", 1, RTLD_NOW | RTLD_GLOBAL },
+ { "obj3func2", 2, RTLD_LAZY },
+ { "obj3func1", 2, RTLD_LAZY | RTLD_GLOBAL },
+ { "obj3func1", 2, RTLD_NOW },
+ { "obj3func2", 2, RTLD_NOW | RTLD_GLOBAL },
+};
+#define NTESTS (sizeof (tests) / sizeof (tests[0]))
+
+
+int
+main (void)
+{
+ int count = TEST_ROUNDS;
+
+ /* Just a seed. */
+ srandom (TEST_ROUNDS);
+
+ while (count--)
+ {
+ int nr = random () % NTESTS;
+ int index = tests[nr].index;
+
+ printf ("%4d: %4d: ", count + 1, nr);
+ fflush (stdout);
+
+ if (testobjs[index].handle == NULL)
+ {
+ int (*fct) (int);
+
+ /* Load the object. */
+ testobjs[index].handle = dlopen (testobjs[index].name,
+ tests[nr].options);
+ if (testobjs[index].handle == NULL)
+ error (EXIT_FAILURE, 0, "cannot load `%s': %s",
+ testobjs[index].name, dlerror ());
+
+ /* Test the function call. */
+ fct = dlsym (testobjs[index].handle, tests[nr].fname);
+ if (fct == NULL)
+ error (EXIT_FAILURE, 0,
+ "cannot get function `%s' from shared object `%s': %s",
+ tests[nr].fname, testobjs[index].name, dlerror ());
+
+ fct (10);
+
+ printf ("successfully loaded `%s'\n", testobjs[index].name);
+ }
+ else
+ {
+ dlclose (testobjs[index].handle);
+ testobjs[index].handle = NULL;
+
+ printf ("successfully unloaded `%s'\n", testobjs[index].name);
+ }
+ }
+
+ /* Unload all loaded modules. */
+ for (count = 0; count < NOBJS; ++count)
+ if (testobjs[count].handle != NULL)
+ dlclose (testobjs[count].handle);
+
+ return 0;
+}
+
+
+int
+foo (int a)
+{
+ return a - 1;
+}