summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/dl06
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2018-04-12 14:52:36 +1000
committerChris Johns <chrisj@rtems.org>2018-04-12 17:54:59 +1000
commit86e79d795514424a4a69be0568bc2eeb802733b6 (patch)
tree104b9b331cc21ff80c424dcd4c19a224b2f0702c /testsuites/libtests/dl06
parenttools: Add a -N option to force a name on the array. (diff)
downloadrtems-86e79d795514424a4a69be0568bc2eeb802733b6.tar.bz2
testsuites/dl06: Add a test for RAP format.
This test loads a RAP format file that contains calls that are not in the kernel and linked from libm. It uses and test rtems-ld. Update #2769
Diffstat (limited to 'testsuites/libtests/dl06')
-rw-r--r--testsuites/libtests/dl06/dl-load.c95
-rw-r--r--testsuites/libtests/dl06/dl-load.h14
-rw-r--r--testsuites/libtests/dl06/dl06-o1.c53
-rw-r--r--testsuites/libtests/dl06/dl06-o2.c38
-rw-r--r--testsuites/libtests/dl06/dl06-o2.h16
-rw-r--r--testsuites/libtests/dl06/dl06.doc20
-rw-r--r--testsuites/libtests/dl06/dl06.scn24
-rw-r--r--testsuites/libtests/dl06/init.c89
8 files changed, 349 insertions, 0 deletions
diff --git a/testsuites/libtests/dl06/dl-load.c b/testsuites/libtests/dl06/dl-load.c
new file mode 100644
index 0000000000..d78e9d1ef8
--- /dev/null
+++ b/testsuites/libtests/dl06/dl-load.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <rtems/rtl/rtl-trace.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";
+
+#if DL06_DEBUG_TRACING
+ rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL);
+#endif
+
+ printf("\nload: %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* r1;
+ call_t call;
+ int call_ret;
+ int ret;
+
+ r1 = dl_load_obj("/dl06.rap");
+ if (!r1)
+ 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 (r1, "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 (r1) < 0)
+ {
+ printf("dlclose o1 failed: %s\n", dlerror());
+ ret = 1;
+ }
+
+ printf ("handle: %p closed\n", r1);
+
+ return ret;
+}
diff --git a/testsuites/libtests/dl06/dl-load.h b/testsuites/libtests/dl06/dl-load.h
new file mode 100644
index 0000000000..3f3910a90d
--- /dev/null
+++ b/testsuites/libtests/dl06/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/dl06/dl06-o1.c b/testsuites/libtests/dl06/dl06-o1.c
new file mode 100644
index 0000000000..d3c882ebfb
--- /dev/null
+++ b/testsuites/libtests/dl06/dl06-o1.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018 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 "dl06-o2.h"
+
+#include <dlfcn.h>
+#include <math.h>
+
+#include <rtems/test.h>
+
+#define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__);
+
+typedef void (*func1_t)(unsigned short s[7]);
+
+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;
+}
+
+/*
+ * 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;
+ double d;
+ unsigned short s[7] = { 12, 34, 56, 78, 90, 13, 57 };
+
+ printf("Loaded module: argc:%d [%s]\n", argc, __FILE__);
+
+ f1 = find_sym ("dl_o2_func1");
+ if (f1 == NULL)
+ return 0;
+
+ f1 (s);
+
+ d = dl_o2_func2 (7.1, 33.0);
+ d = dl_o2_func3 (0.778899);
+
+ return argc;
+}
diff --git a/testsuites/libtests/dl06/dl06-o2.c b/testsuites/libtests/dl06/dl06-o2.c
new file mode 100644
index 0000000000..7d6f6c8d57
--- /dev/null
+++ b/testsuites/libtests/dl06/dl06-o2.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 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 "dl06-o2.h"
+
+#include <stdlib.h>
+#include <math.h>
+
+#include <rtems/test.h>
+
+#define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__);
+
+/*
+ * Call function that are not part of the RTEMS kernel base image.
+ */
+
+void dl_o2_func1 (unsigned short s[7])
+{
+ printf("libm: lcong48\n")
+ lcong48 (s);
+}
+
+double dl_o2_func2 (double d1, double d2)
+{
+ printf("libm: atan2\n")
+ return atan2 (d1, d2);
+}
+
+double dl_o2_func3 (double d)
+{
+ printf("libm: tan\n")
+ return tan (d);
+}
diff --git a/testsuites/libtests/dl06/dl06-o2.h b/testsuites/libtests/dl06/dl06-o2.h
new file mode 100644
index 0000000000..12be7ee197
--- /dev/null
+++ b/testsuites/libtests/dl06/dl06-o2.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2018 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(DL06_02_H)
+#define DL06_02_H
+
+void dl_o2_func1 (unsigned short s[7]);
+double dl_o2_func2 (double d1, double d2);
+double dl_o2_func3 (double d);
+
+#endif
diff --git a/testsuites/libtests/dl06/dl06.doc b/testsuites/libtests/dl06/dl06.doc
new file mode 100644
index 0000000000..8487385b04
--- /dev/null
+++ b/testsuites/libtests/dl06/dl06.doc
@@ -0,0 +1,20 @@
+# Copyright (c) 2018 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: dl06
+
+directives:
+
+ n/a
+
+concepts:
+
++ Create a single RAP for file with 2 object files where one references
+ functions in libm that should never be part of the kernel base image.
++ Load the RAP image and executable the math library calls.
diff --git a/testsuites/libtests/dl06/dl06.scn b/testsuites/libtests/dl06/dl06.scn
new file mode 100644
index 0000000000..ea6bc5c1a9
--- /dev/null
+++ b/testsuites/libtests/dl06/dl06.scn
@@ -0,0 +1,24 @@
+*** BEGIN OF TEST libdl (RTL) 6 ***
+*** TEST VERSION: 5.0.0.af6168c6ef19b317c8724ca5950699414d15cf3c-modified
+*** TEST STATE: EXPECTED-PASS
+*** TEST BUILD: RTEMS_NETWORKING RTEMS_POSIX_API
+*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 4b3e0f8e3d6998b84a2503dd2e11578989b1672b, Newlib 3.0.0)
+
+load: /dl06.rap
+handle: 0x2041ee0 loaded
+Loaded module: argc:4 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl06/dl06-o1.c]
+libm: lcong48
+libm: atan2
+libm: tan
+handle: 0x2041ee0 closed
+
+*** END OF TEST libdl (RTL) 6 ***
+
+
+*** FATAL ***
+fatal source: 5 (RTEMS_FATAL_SOURCE_EXIT)
+fatal code: 0 (0x00000000)
+RTEMS version: 5.0.0.af6168c6ef19b317c8724ca5950699414d15cf3c-modified
+RTEMS tools: 7.3.0 20180125 (RTEMS 5, RSB 4b3e0f8e3d6998b84a2503dd2e11578989b1672b, Newlib 3.0.0)
+executing thread ID: 0x08a010001
+executing thread name: UI1
diff --git a/testsuites/libtests/dl06/init.c b/testsuites/libtests/dl06/init.c
new file mode 100644
index 0000000000..4c28c6a06a
--- /dev/null
+++ b/testsuites/libtests/dl06/init.c
@@ -0,0 +1,89 @@
+/*
+ * 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) 6";
+
+/* forward declarations to avoid warnings */
+static rtems_task Init(rtems_task_argument argument);
+
+#if DL06_PRE
+#include "dl06-pre-tar.h"
+#else
+#include "dl06-tar.h"
+#endif
+
+#define TARFILE_START dl06_tar
+#define TARFILE_SIZE dl06_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_SIMPLE_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_MAXIMUM_SEMAPHORES 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>