summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/dl01
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/libtests/dl01')
-rw-r--r--testsuites/libtests/dl01/Makefile.am43
-rw-r--r--testsuites/libtests/dl01/dl-load.c77
-rw-r--r--testsuites/libtests/dl01/dl-load.h14
-rw-r--r--testsuites/libtests/dl01/dl-o1.c31
-rw-r--r--testsuites/libtests/dl01/dl01.doc0
-rw-r--r--testsuites/libtests/dl01/dl01.scn0
-rw-r--r--testsuites/libtests/dl01/init.c84
7 files changed, 249 insertions, 0 deletions
diff --git a/testsuites/libtests/dl01/Makefile.am b/testsuites/libtests/dl01/Makefile.am
new file mode 100644
index 0000000000..df62d60df0
--- /dev/null
+++ b/testsuites/libtests/dl01/Makefile.am
@@ -0,0 +1,43 @@
+rtems_tests_PROGRAMS = dl01
+dl01_SOURCES = init.c dl-load.c dl-tar.c dl-tar.h
+
+BUILT_SOURCES = dl-tar.c dl-tar.h
+
+dist_rtems_tests_DATA = dl01.scn dl01.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 = $(dl01_OBJECTS)
+LINK_LIBS = $(dl01_LDLIBS)
+
+dl-o1.o: dl-o1.c
+
+dl.tar: dl-o1.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
+
+dl01.pre$(EXEEXT): $(dl01_OBJECTS) $(dl01_DEPENDENCIES)
+ @rm -f dl01.pre$(EXEEXT)
+ $(make-exe)
+
+dl-sym.o: dl01.pre$(EXEEXT)
+ rtems-syms -e -c "$(CFLAGS)" -o $@ $<
+
+dl01$(EXEEXT): $(dl01_OBJECTS) $(dl01_DEPENDENCIES) dl-sym.o
+ @rm -f dl01$(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/dl01/dl-load.c b/testsuites/libtests/dl01/dl-load.c
new file mode 100644
index 0000000000..cd63cc5953
--- /dev/null
+++ b/testsuites/libtests/dl01/dl-load.c
@@ -0,0 +1,77 @@
+/*
+ * 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, char* argv[]);
+
+
+static const char* call_1[] = { "Line 1", "Line 2" };
+static const char* call_2[] = { "Call 2, line 1",
+ "Call 2, line 2",
+ "Call 2, line 3" };
+
+int dl_load_test(void)
+{
+ void* handle;
+ call_t call;
+ int call_ret;
+ int unresolved;
+ char* message = "loaded";
+
+ printf("load: /dl-o1.o\n");
+
+ handle = dlopen ("/dl-o1.o", RTLD_NOW | RTLD_GLOBAL);
+ if (!handle)
+ {
+ printf("dlopen failed: %s\n", dlerror());
+ return 1;
+ }
+
+ 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);
+
+ call = dlsym (handle, "rtems_main");
+ if (call == NULL)
+ {
+ printf("dlsym failed: symbol not found\n");
+ return 1;
+ }
+
+ call_ret = call (2, call_1);
+ if (call_ret != 2)
+ {
+ printf("dlsym call failed: ret value bad\n");
+ return 1;
+ }
+
+ call_ret = call (3, call_2);
+ if (call_ret != 3)
+ {
+ printf("dlsym call failed: ret value bad\n");
+ return 1;
+ }
+
+ if (dlclose (handle) < 0)
+ {
+ printf("dlclose failed: %s\n", dlerror());
+ return 1;
+ }
+
+ printf ("handle: %p closed\n", handle);
+
+ return 0;
+}
diff --git a/testsuites/libtests/dl01/dl-load.h b/testsuites/libtests/dl01/dl-load.h
new file mode 100644
index 0000000000..3f3910a90d
--- /dev/null
+++ b/testsuites/libtests/dl01/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/dl01/dl-o1.c b/testsuites/libtests/dl01/dl-o1.c
new file mode 100644
index 0000000000..6e7bb8a07c
--- /dev/null
+++ b/testsuites/libtests/dl01/dl-o1.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 <stdlib.h>
+
+/**
+ * Hello World as a loadable module.
+ */
+
+#include <stdio.h>
+
+/*
+ * 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, char* argv[]);
+
+int rtems_main (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;
+}
diff --git a/testsuites/libtests/dl01/dl01.doc b/testsuites/libtests/dl01/dl01.doc
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuites/libtests/dl01/dl01.doc
diff --git a/testsuites/libtests/dl01/dl01.scn b/testsuites/libtests/dl01/dl01.scn
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuites/libtests/dl01/dl01.scn
diff --git a/testsuites/libtests/dl01/init.c b/testsuites/libtests/dl01/init.c
new file mode 100644
index 0000000000..d66750202e
--- /dev/null
+++ b/testsuites/libtests/dl01/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) Loader 1";
+
+/* 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>
+