[PATCH] testsuite: Add libdl/dl05 weak symbol test.

Chris Johns chrisj at rtems.org
Thu Aug 25 07:02:42 UTC 2016


Requires rtems-tools to be updated.
---
 testsuites/libtests/Makefile.am      |  2 +-
 testsuites/libtests/configure.ac     |  1 +
 testsuites/libtests/dl05/Makefile.am | 49 +++++++++++++++++++++
 testsuites/libtests/dl05/dl-load.c   | 49 +++++++++++++++++++++
 testsuites/libtests/dl05/dl-load.h   | 14 ++++++
 testsuites/libtests/dl05/dl-o5.c     | 17 ++++++++
 testsuites/libtests/dl05/dl05.doc    | 25 +++++++++++
 testsuites/libtests/dl05/dl05.scn    |  9 ++++
 testsuites/libtests/dl05/init.c      | 82 ++++++++++++++++++++++++++++++++++++
 9 files changed, 247 insertions(+), 1 deletion(-)
 create mode 100644 testsuites/libtests/dl05/Makefile.am
 create mode 100644 testsuites/libtests/dl05/dl-load.c
 create mode 100644 testsuites/libtests/dl05/dl-load.h
 create mode 100644 testsuites/libtests/dl05/dl-o5.c
 create mode 100644 testsuites/libtests/dl05/dl05.doc
 create mode 100644 testsuites/libtests/dl05/dl05.scn
 create mode 100644 testsuites/libtests/dl05/init.c

diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index effed07..4925775 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -46,7 +46,7 @@ _SUBDIRS += syscall01
 endif
 
 if DLTESTS
-_SUBDIRS += dl01 dl02 dl03
+_SUBDIRS += dl01 dl02 dl03 dl05
 if HAS_CXX
 _SUBDIRS += dl04
 endif
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index 31afcae..9093cba 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -128,6 +128,7 @@ dl01/Makefile
 dl02/Makefile
 dl03/Makefile
 dl04/Makefile
+dl05/Makefile
 dumpbuf01/Makefile
 ftp01/Makefile
 gxx01/Makefile
diff --git a/testsuites/libtests/dl05/Makefile.am b/testsuites/libtests/dl05/Makefile.am
new file mode 100644
index 0000000..4aeea8a
--- /dev/null
+++ b/testsuites/libtests/dl05/Makefile.am
@@ -0,0 +1,49 @@
+rtems_tests_PROGRAMS = dl05
+dl05_SOURCES = init.c dl-load.c dl-tar.c dl-tar.h
+
+BUILT_SOURCES = dl-tar.c dl-tar.h
+
+dist_rtems_tests_DATA = dl05.scn dl05.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(dl05_OBJECTS)
+LINK_LIBS = $(dl05_LDLIBS)
+
+dl-o1.o: dl-o5.c
+
+dl.tar: dl-o5.o
+	@rm -f $@
+	$(PAX) -w -f $@ $<
+CLEANFILES += dl.tar
+
+dl-tar.c: dl.tar
+	$(BIN2C) -C $< $@
+CLEANFILES += dl-tar.c
+
+dl-tar.h: dl.tar
+	$(BIN2C) -H $< $@
+CLEANFILES += dl-tar.h
+
+dl05.pre$(EXEEXT): $(dl05_OBJECTS) $(dl05_DEPENDENCIES)
+	@rm -f dl05.pre$(EXEEXT)
+	$(make-exe)
+	rm -f dl05.pre.ralf
+
+dl05.pre: dl05.pre$(EXEEXT)
+	mv $< $@
+CLEANFILES += dl05.pre
+
+dl-sym.o: dl05.pre
+	rtems-syms -e -c "$(CFLAGS)" -o $@ $<
+
+dl05$(EXEEXT):  $(dl05_OBJECTS) $(dl05_DEPENDENCIES) dl-sym.o
+	@rm -f dl05$(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/dl05/dl-load.c b/testsuites/libtests/dl05/dl-load.c
new file mode 100644
index 0000000..3036a3a
--- /dev/null
+++ b/testsuites/libtests/dl05/dl-load.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj at 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 "tmacros.h"
+
+#include <stdio.h>
+
+#include <dlfcn.h>
+
+#include "dl-load.h"
+
+typedef int (*dl_call)(void);
+
+__attribute__((__weak__)) void base_func(const char *c);
+
+__attribute__((__weak__)) void base_func(const char *c)
+{
+  printf("base_func: %s", c);
+}
+
+int dl_load_test(void)
+{
+  void*   handle;
+  dl_call call;
+  int     call_ret;
+  int     unresolved;
+  char*   message = "loaded";
+
+  printf("load: /dl-o5.o\n");
+  rtems_test_assert((handle = dlopen ("/dl-o5.o", RTLD_NOW | RTLD_GLOBAL)) != 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);
+  rtems_test_assert(unresolved == 0);
+  base_func("Called from " __FILE__ ": working?\n");
+  rtems_test_assert((call = dlsym (handle, "lib_func")) != NULL);
+  rtems_test_assert((call_ret = call ()) == 0);
+  rtems_test_assert(dlclose (handle) == 0);
+  printf ("handle: %p closed\n", handle);
+
+  return 0;
+}
diff --git a/testsuites/libtests/dl05/dl-load.h b/testsuites/libtests/dl05/dl-load.h
new file mode 100644
index 0000000..3f3910a
--- /dev/null
+++ b/testsuites/libtests/dl05/dl-load.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2014 Chris Johns <chrisj at 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/dl05/dl-o5.c b/testsuites/libtests/dl05/dl-o5.c
new file mode 100644
index 0000000..019f771
--- /dev/null
+++ b/testsuites/libtests/dl05/dl-o5.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2016 Chris Johns <chrisj at 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.
+ */
+
+void base_func(const char *c);
+
+int lib_func(void);
+
+int lib_func(void)
+{
+  base_func("Called from " __FILE__ ": hello, it is working!\n");
+  return 0;
+}
diff --git a/testsuites/libtests/dl05/dl05.doc b/testsuites/libtests/dl05/dl05.doc
new file mode 100644
index 0000000..deff50b
--- /dev/null
+++ b/testsuites/libtests/dl05/dl05.doc
@@ -0,0 +1,25 @@
+# Copyright (c) 2016 Chris Johns <chrisj at 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: dl05
+
+directives:
+
+  dlopen
+  dlinfo
+  dlsym
+  dlclose
+
+concepts:
+
++ Load a single ELF object file.
++ Check there are no unreolved externals.
++ Locate the lib_func symbol.
++ Calls the function and have the function call the base kernel's weak symbol.
++ Unload the ELF file.
diff --git a/testsuites/libtests/dl05/dl05.scn b/testsuites/libtests/dl05/dl05.scn
new file mode 100644
index 0000000..f0f3c84
--- /dev/null
+++ b/testsuites/libtests/dl05/dl05.scn
@@ -0,0 +1,9 @@
+*** BEGIN OF TEST libdl (RTL) 5 ***
+load: /dl-o5.o
+handle: 0x112268 loaded
+base_func: Called from
+/opt/work/chris/rtems/kernel/rtems.master/c/src/../../testsuites/libtests/dl05/dl-load.c: working?
+base_func: Called from
+/opt/work/chris/rtems/kernel/rtems.master/c/src/../../testsuites/libtests/dl05/dl-o5.c: hello, it is working!
+handle: 0x112268 closed
+*** END OF TEST libdl (RTL) 5 ***
diff --git a/testsuites/libtests/dl05/init.c b/testsuites/libtests/dl05/init.c
new file mode 100644
index 0000000..f6e0c20
--- /dev/null
+++ b/testsuites/libtests/dl05/init.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2016 Chris Johns <chrisj at 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) 5";
+
+/* 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_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>
-- 
2.4.6



More information about the devel mailing list