source: rtems/testsuites/libtests/dl06/dl-load.c @ 86e79d7

5
Last change on this file since 86e79d7 was 86e79d7, checked in by Chris Johns <chrisj@…>, on 04/12/18 at 04:52:36

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

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>.  All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#include <stdio.h>
10
11#include <dlfcn.h>
12
13#include <rtems/rtl/rtl-trace.h>
14
15#include "dl-load.h"
16
17typedef int (*call_t)(int argc, const char* argv[]);
18
19static const char* call_args[] = { "1", "2", "3", "4" };
20
21static void* dl_load_obj(const char* name)
22{
23  void* handle;
24  int   unresolved;
25  char* message = "loaded";
26
27#if DL06_DEBUG_TRACING
28  rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL);
29#endif
30
31  printf("\nload: %s\n", name);
32
33  handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL);
34  if (!handle)
35  {
36    printf("dlopen failed: %s\n", dlerror());
37    return NULL;
38  }
39
40  if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0)
41    message = "dlinfo error checking unresolved status";
42  else if (unresolved)
43    message = "has unresolved externals";
44
45  printf ("handle: %p %s\n", handle, message);
46
47  return handle;
48}
49
50int dl_load_test(void)
51{
52  void*  r1;
53  call_t call;
54  int    call_ret;
55  int    ret;
56
57  r1 = dl_load_obj("/dl06.rap");
58  if (!r1)
59    return 1;
60
61#if 0
62  {
63    char* list[] = { "rtl", "list", NULL };
64    rtems_rtl_shell_command (2, list);
65    char* sym[] = { "rtl", "sym", NULL };
66    rtems_rtl_shell_command (2, sym);
67  }
68#endif
69
70  call = dlsym (r1, "rtems_main");
71  if (call == NULL)
72  {
73    printf("dlsym failed: symbol not found\n");
74    return 1;
75  }
76
77  call_ret = call (4, call_args);
78  if (call_ret != 4)
79  {
80    printf("dlsym call failed: ret value bad\n");
81    return 1;
82  }
83
84  ret = 0;
85
86  if (dlclose (r1) < 0)
87  {
88    printf("dlclose o1 failed: %s\n", dlerror());
89    ret = 1;
90  }
91
92  printf ("handle: %p closed\n", r1);
93
94  return ret;
95}
Note: See TracBrowser for help on using the repository browser.