summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-11-04 16:31:50 +1100
committerChris Johns <chrisj@rtems.org>2014-11-04 16:31:50 +1100
commit540b7b417867f7b26320539a1ef17d12760f4efc (patch)
tree1c93c3d4bce409b4f697743acefd24c40ccaf531
parentd52c9e4d71a6ea065de4d024336de10873eb01d3 (diff)
downloadrtems-540b7b417867f7b26320539a1ef17d12760f4efc.tar.bz2
libtests: Add libdl test dl02.
Loads 2 interdependent ELF object files.
-rw-r--r--testsuites/libtests/Makefile.am2
-rw-r--r--testsuites/libtests/configure.ac1
-rw-r--r--testsuites/libtests/dl02/Makefile.am45
-rw-r--r--testsuites/libtests/dl02/dl-load.c101
-rw-r--r--testsuites/libtests/dl02/dl-load.h14
-rw-r--r--testsuites/libtests/dl02/dl-o1.c68
-rw-r--r--testsuites/libtests/dl02/dl-o2.c31
-rw-r--r--testsuites/libtests/dl02/dl-o2.h18
-rw-r--r--testsuites/libtests/dl02/dl02.doc28
-rw-r--r--testsuites/libtests/dl02/dl02.scn22
-rw-r--r--testsuites/libtests/dl02/init.c84
11 files changed, 413 insertions, 1 deletions
diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index 179c123204..26e11c69f6 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -37,7 +37,7 @@ _SUBDIRS += syscall01
endif
if DLTESTS
-_SUBDIRS += dl01
+_SUBDIRS += dl01 dl02
endif
include $(top_srcdir)/../automake/test-subdirs.am
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index 9914a06dd2..392e2a9ec0 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -102,6 +102,7 @@ devfs04/Makefile
deviceio01/Makefile
devnullfatal01/Makefile
dl01/Makefile
+dl02/Makefile
dumpbuf01/Makefile
ftp01/Makefile
gxx01/Makefile
diff --git a/testsuites/libtests/dl02/Makefile.am b/testsuites/libtests/dl02/Makefile.am
new file mode 100644
index 0000000000..f43eee5119
--- /dev/null
+++ b/testsuites/libtests/dl02/Makefile.am
@@ -0,0 +1,45 @@
+rtems_tests_PROGRAMS = dl02
+dl02_SOURCES = init.c dl-load.c dl-tar.c dl-tar.h
+
+BUILT_SOURCES = dl-tar.c dl-tar.h
+
+dist_rtems_tests_DATA = dl02.scn dl02.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(dl02_OBJECTS)
+LINK_LIBS = $(dl02_LDLIBS)
+
+dl-o1.o: dl-o1.c
+
+dl-o2.o: dl-o2.c
+
+dl.tar: dl-o1.o dl-o2.o
+ @rm -f $@
+ $(PAX) -w -f $@ $^
+
+dl-tar.c: dl.tar
+ $(BIN2C) -C $< $@
+CLEANFILES += dl-tar.c
+
+dl-tar.h: dl.tar
+ $(BIN2C) -H $< $@
+CLEANFILES += dl-tar.h
+
+dl02.pre$(EXEEXT): $(dl02_OBJECTS) $(dl02_DEPENDENCIES)
+ @rm -f dl02.pre$(EXEEXT)
+ $(make-exe)
+
+dl-sym.o: dl02.pre$(EXEEXT)
+ rtems-syms -e -c "$(CFLAGS)" -o $@ $<
+
+dl02$(EXEEXT): $(dl02_OBJECTS) $(dl02_DEPENDENCIES) dl-sym.o
+ @rm -f dl02$(EXEEXT)
+ $(LINK.c) $(CPU_CFLAGS) $(AM_CFLAGS) $(AM_LDFLAGS) \
+ -o $(basename $@)$(EXEEXT) $(LINK_OBJS) dl-sym.o $(LINK_LIBS)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/dl02/dl-load.c b/testsuites/libtests/dl02/dl-load.c
new file mode 100644
index 0000000000..5bb40dccba
--- /dev/null
+++ b/testsuites/libtests/dl02/dl-load.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <stdio.h>
+
+#include <dlfcn.h>
+
+#include "dl-load.h"
+
+typedef int (*call_t)(int argc, const char* argv[]);
+
+static const char* call_args[] = { "1", "2", "3", "4" };
+
+static void* dl_load_obj(const char* name)
+{
+ void* handle;
+ int unresolved;
+ char* message = "loaded";
+
+ printf("load: %s\n", name);
+
+ handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL);
+ if (!handle)
+ {
+ printf("dlopen failed: %s\n", dlerror());
+ return NULL;
+ }
+
+ if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0)
+ message = "dlinfo error checking unresolved status";
+ else if (unresolved)
+ message = "has unresolved externals";
+
+ printf ("handle: %p %s\n", handle, message);
+
+ return handle;
+}
+
+int dl_load_test(void)
+{
+ void* o1;
+ void* o2;
+ call_t call;
+ int call_ret;
+ int ret;
+
+ o1 = dl_load_obj("/dl-o1.o");
+ if (!o1)
+ return 1;
+ o2 = dl_load_obj("/dl-o2.o");
+ if (!o1)
+ return 1;
+
+#if 0
+ {
+ char* list[] = { "rtl", "list", NULL };
+ rtems_rtl_shell_command (2, list);
+ char* sym[] = { "rtl", "sym", NULL };
+ rtems_rtl_shell_command (2, sym);
+ }
+#endif
+
+ call = dlsym (o1, "rtems_main");
+ if (call == NULL)
+ {
+ printf("dlsym failed: symbol not found\n");
+ return 1;
+ }
+
+ call_ret = call (4, call_args);
+ if (call_ret != 4)
+ {
+ printf("dlsym call failed: ret value bad\n");
+ return 1;
+ }
+
+ ret = 0;
+
+ if (dlclose (o1) < 0)
+ {
+ printf("dlclose o1 failed: %s\n", dlerror());
+ ret = 1;
+ }
+
+ printf ("handle: %p closed\n", o1);
+
+ if (dlclose (o2) < 0)
+ {
+ printf("dlclose o1 failed: %s\n", dlerror());
+ ret = 1;
+ }
+
+ printf ("handle: %p closed\n", o2);
+
+ return ret;
+}
diff --git a/testsuites/libtests/dl02/dl-load.h b/testsuites/libtests/dl02/dl-load.h
new file mode 100644
index 0000000000..3f3910a90d
--- /dev/null
+++ b/testsuites/libtests/dl02/dl-load.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if !defined(_DL_LOAD_H_)
+#define _DL_LOAD_H_
+
+int dl_load_test(void);
+
+#endif
diff --git a/testsuites/libtests/dl02/dl-o1.c b/testsuites/libtests/dl02/dl-o1.c
new file mode 100644
index 0000000000..ff5a853c33
--- /dev/null
+++ b/testsuites/libtests/dl02/dl-o1.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <dlfcn.h>
+
+#include "dl-o2.h"
+
+typedef int (*func1_t)(int argc, const char* argv[]);
+
+static void* find_sym(const char* name)
+{
+ void* sym = dlsym(RTLD_DEFAULT, name);
+ if (sym == NULL)
+ printf("dlsym failed: not found: %s\n", name);
+ return sym;
+}
+
+static int dl_o1_callback(const char* message, int count)
+{
+ printf("dl_o1_callback: %s\n", message);
+ return count + 1;
+}
+
+/*
+ * Yes a decl in the source. This is a modules main and I could not find which
+ * header main is defined in.
+ */
+int rtems_main (int argc, const char* argv[]);
+
+int rtems_main (int argc, const char* argv[])
+{
+ func1_t f1;
+ int arg;
+ int ret;
+
+ printf("Loaded module: argc:%d [%s]\n", argc, __FILE__);
+ for (arg = 0; arg < argc; ++arg)
+ printf(" %d: %s\n", arg, argv[arg]);
+
+ f1 = find_sym ("dl_o2_func1");
+ if (f1 == NULL)
+ return 0;
+
+ if (f1 (argc, argv) != argc)
+ {
+ printf("rtems_main: dl_o2_func1 returned bad value\n");
+ return 0;
+ }
+
+ if (dl_o2_func2 (7.1, 33.0) != (7.1 * 33.0))
+ {
+ printf("rtems_main: dl_o2_func1 returned bad value\n");
+ return 0;
+ }
+
+ ret = dl_o2_func3 (dl_o1_callback, 1);
+ printf ("rtems_main: callback count: %d\n", ret);
+
+ return argc;
+}
diff --git a/testsuites/libtests/dl02/dl-o2.c b/testsuites/libtests/dl02/dl-o2.c
new file mode 100644
index 0000000000..43a337a1c0
--- /dev/null
+++ b/testsuites/libtests/dl02/dl-o2.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <stdio.h>
+
+#include "dl-o2.h"
+
+int dl_o2_func1 (int argc, char* argv[])
+{
+ int arg;
+ printf("Loaded module: argc:%d [%s]\n", argc, __FILE__);
+ for (arg = 0; arg < argc; ++arg)
+ printf(" %d: %s\n", arg, argv[arg]);
+ return argc;
+}
+
+double dl_o2_func2 (double d1, double d2)
+{
+ return d1 * d2;
+}
+
+int dl_o2_func3 (dl_o2_call_t callback, int count)
+{
+ return callback ("string in dl_o2", count + 1);
+}
+
diff --git a/testsuites/libtests/dl02/dl-o2.h b/testsuites/libtests/dl02/dl-o2.h
new file mode 100644
index 0000000000..43dbd39b9d
--- /dev/null
+++ b/testsuites/libtests/dl02/dl-o2.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if !defined(DL02_H)
+#define DL02_H
+
+typedef int (*dl_o2_call_t)(const char* message, int count);
+
+int dl_o2_func1 (int argc, char* argv[]);
+double dl_o2_func2 (double d1, double d2);
+int dl_o2_func3 (dl_o2_call_t callback, int count);
+
+#endif
diff --git a/testsuites/libtests/dl02/dl02.doc b/testsuites/libtests/dl02/dl02.doc
new file mode 100644
index 0000000000..4a325de9cc
--- /dev/null
+++ b/testsuites/libtests/dl02/dl02.doc
@@ -0,0 +1,28 @@
+# Copyright (c) 2014 Chris Johns <chrisj@rtems.org>
+#
+# The license and distribution terms for this file may be
+# found in the file LICENSE in this distribution or at
+# http://www.rtems.org/license/LICENSE.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: dl02
+
+directives:
+
+ dlopen
+ dlinfo
+ dlsym
+ dlclose
+
+concepts:
+
++ Load 2 interdependent ELF object files.
++ Check there are no unreolved externals. There should be unresolved
+ externals after the first lond and none after the second load.
++ Locate the rtems_main symbol in dl-o1.
++ Call the rtems_main sym and have that function call the second object.
+ Call the second download with a callback handler to a symbol in the first
+ object file.
++ Unload the ELF files.
diff --git a/testsuites/libtests/dl02/dl02.scn b/testsuites/libtests/dl02/dl02.scn
new file mode 100644
index 0000000000..f1b4489a5f
--- /dev/null
+++ b/testsuites/libtests/dl02/dl02.scn
@@ -0,0 +1,22 @@
+*** BEGIN OF TEST libdl (RTL) 2 ***
+load: /dl-o1.o
+handle: 0x2150d0 has unresolved externals
+load: /dl-o2.o
+handle: 0x215838 loaded
+Loaded module: argc:4
+[../../../../../../../../rtems.master/c/src/../../testsuites/libtests/dl02/dl-o1.c]
+ 0: 1
+ 1: 2
+ 2: 3
+ 3: 4
+Loaded module: argc:4
+[../../../../../../../../rtems.master/c/src/../../testsuites/libtests/dl02/dl-o2.c]
+ 0: 1
+ 1: 2
+ 2: 3
+ 3: 4
+dl_o1_callback: string in dl_o2
+rtems_main: callback count: 3
+handle: 0x2150d0 closed
+handle: 0x215838 closed
+*** END OF TEST libdl (RTL) 2 ***
diff --git a/testsuites/libtests/dl02/init.c b/testsuites/libtests/dl02/init.c
new file mode 100644
index 0000000000..bcb76c4e01
--- /dev/null
+++ b/testsuites/libtests/dl02/init.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include "tmacros.h"
+
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include <rtems/rtl/rtl.h>
+#include <rtems/untar.h>
+
+#include "dl-load.h"
+
+const char rtems_test_name[] = "libdl (RTL) 2";
+
+/* forward declarations to avoid warnings */
+static rtems_task Init(rtems_task_argument argument);
+
+#include "dl-tar.h"
+
+#define TARFILE_START dl_tar
+#define TARFILE_SIZE dl_tar_size
+
+static int test(void)
+{
+ int ret;
+ ret = dl_load_test();
+ if (ret)
+ rtems_test_exit(ret);
+ return 0;
+}
+
+static void Init(rtems_task_argument arg)
+{
+ int te;
+
+ TEST_BEGIN();
+
+ te = Untar_FromMemory((void *)TARFILE_START, (size_t)TARFILE_SIZE);
+ if (te != 0)
+ {
+ printf("untar failed: %d\n", te);
+ rtems_test_exit(1);
+ exit (1);
+ }
+
+ test();
+
+ TEST_END();
+
+ rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (8U * 1024U)
+
+#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+