testsuites/libtest: Add DL incremental link test

This commit adds a test to validate the incremental linking
functionality in RTL. The test is related to issue #3740.
This commit is contained in:
Ranulfo Raphael
2024-06-13 08:34:48 -03:00
committed by Amar Takhar
parent dff15a820f
commit 78afce5bf2
10 changed files with 472 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ actions:
- dl09
- dl10
- dl11
- dl12
build-type: option
copyrights:
- Copyright (C) 2020 embedded brains GmbH & Co. KG

View File

@@ -0,0 +1,46 @@
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
build-type: script
cflags: []
copyrights:
- Copyright (C) 2024 Ranulfo Raphael
cppflags: []
do-build: |
path = "testsuites/libtests/dl12/"
objs = []
objs.append(self.cc(bld, bic, path + "dl12-o1.c"))
objs.append(self.cc(bld, bic, path + "dl12-o2.c"))
def ld(self, bld, bic, flags, source, target):
bld(rule="${LD} " + flags + " ${SRC} -o ${TGT}",
source=source,
target=target)
return target
objs = [ld(self, bld, bic, '-r', objs, path + "dl12-inc.o")]
tar = path + "dl12.tar"
self.tar(bld, objs, [path], tar)
tar_c, tar_h = self.bin2c(bld, tar)
objs = []
objs.append(self.cc(bld, bic, tar_c))
objs.append(self.cc(bld, bic, path + "init.c", deps=[tar_h], cppflags=bld.env.TEST_DL12_CPPFLAGS))
objs.append(self.cc(bld, bic, path + "dl-load.c"))
dl12_pre = path + "dl12.pre"
self.link_cc(bld, bic, objs, dl12_pre)
dl12_sym_o = path + "dl12-sym.o"
objs.append(dl12_sym_o)
self.rtems_syms(bld, dl12_pre, dl12_sym_o)
self.link_cc(bld, bic, objs, "testsuites/libtests/dl12.exe")
do-configure: null
enabled-by:
- and:
- not: TEST_DL12_EXCLUDE
- BUILD_LIBDL
includes:
- testsuites/libtests/dl12
ldflags: []
links: []
prepare-build: null
prepare-configure: null
stlib: []
target: testsuites/libtests/dl12.exe
type: build
use-after: []
use-before: []

View File

@@ -110,6 +110,8 @@ links:
uid: dl10
- role: build-dependency
uid: dl11
- role: build-dependency
uid: dl12
- role: build-dependency
uid: dumpbuf01
- role: build-dependency

View File

@@ -0,0 +1,139 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2014 Chris Johns <chrisj at rtems.org>. All rights reserved.
* Copyright (c) 2019 On-Line Applications Research
* Copyright (c) 2024 Ranulfo Raphael
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <dlfcn.h>
#include "dl-load.h"
#include <rtems/rtl/rtl-shell.h>
#include <rtems/rtl/rtl-trace.h>
#define TEST_TRACE 0
#if TEST_TRACE
#define DL_DEBUG_TRACE (RTEMS_RTL_TRACE_ALL & ~RTEMS_RTL_TRACE_ALLOCATOR)
#define DL_RTL_CMDS 1
#else
#define DL_DEBUG_TRACE 0
#define DL_RTL_CMDS 0
#endif
typedef const void *(*call_t)(void);
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* handle;
call_t call;
const void* dl_o1_str_addr;
const void* dl_o2_str_addr;
#if DL_DEBUG_TRACE
rtems_rtl_trace_set_mask (DL_DEBUG_TRACE);
#endif
handle = dl_load_obj("/dl12-inc.o");
if (!handle)
return 1;
#if DL_RTL_CMDS
{
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 (handle, "dl_o1_func");
if (call == NULL)
{
printf("dlsym failed: symbol not found\n");
return 1;
}
printf("\nAbout to call dl_o1_func at address %p\n", call);
dl_o1_str_addr = call ();
printf("\ndl_o1_func string literal address: %p\n", dl_o1_str_addr);
call = dlsym (handle, "dl_o2_func");
if (call == NULL)
{
printf("dlsym failed: symbol not found\n");
return 1;
}
printf("\nAbout to call dl_o2_func at address %p\n", call);
dl_o2_str_addr = call ();
printf("\ndl_o2_func string literal address: %p\n", dl_o2_str_addr);
if (dl_o1_str_addr == dl_o2_str_addr) {
printf("\nTwo symbols from different object files have the same address!\n");
return 1;
}
if (dlclose (handle) < 0)
{
printf("dlclose obj failed: %s\n", dlerror());
return 1;
}
printf ("\nhandle: %p closed\n", handle);
return 0;
}

View File

@@ -0,0 +1,33 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2014 Chris Johns <chrisj at rtems.org>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_DL_LOAD_H_)
#define _DL_LOAD_H_
int dl_load_test(void);
#endif

View File

@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2014 Chris Johns <chrisj at rtems.org>. All rights reserved.
* Copyright (c) 2019 On-Line Applications Research
* Copyright (c) 2024 Ranulfo Raphael
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <rtems/test-printer.h>
#define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__);
const void *dl_o1_func (void);
const void *dl_o1_func (void)
{
const char *str = "string_from_dl_o1_func";
printf(str);
return str;
}

View File

@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2014 Chris Johns <chrisj at rtems.org>. All rights reserved.
* Copyright (c) 2019 On-Line Applications Research
* Copyright (c) 2024 Ranulfo Raphael
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <rtems/test-printer.h>
#define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__);
const void *dl_o2_func (void);
const void *dl_o2_func (void)
{
const char *str = "string_from_dl_o2_func";
printf(str);
return str;
}

View File

@@ -0,0 +1,47 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2024 Ranulfo Raphael
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
This file describes the directives and concepts tested by this test set.
test set name: dl12
directives:
dlopen
dlinfo
dlsym
dlclose
concepts:
+ Load an incrementally linked object.
+ Check there are no unresolved externals.
+ Locate the dl_o1_func symbol.
Call the dl_o1_func sym and store the returned address.
Locate the dl_o2_func symbol.
Call the dl_o2_func sym and store the returned address.
Compare the returned values. The addresses must not be the same.
+ Unload the object.

View File

@@ -0,0 +1,15 @@
*** BEGIN OF TEST libdl (RTL) 12 ***
load: /dl12-inc.o
handle: 0x4003d8d0 loaded
About to call dl_o1_func at address 0x4003df80
string_from_dl_o1_func
dl_o1_func string literal address: 0x4003df40
About to call dl_o2_func at address 0x4003dfa4
string_from_dl_o2_func
dl_o2_func string literal address: 0x4003df58
handle: 0x4003d8d0 closed
*** END OF TEST libdl (RTL) 12 ***

View File

@@ -0,0 +1,103 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2014 Chris Johns <chrisj at rtems.org>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#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/imfs.h>
#include "dl-load.h"
const char rtems_test_name[] = "libdl (RTL) 12";
/* forward declarations to avoid warnings */
static rtems_task Init(rtems_task_argument argument);
#include "dl12-tar.h"
#define TARFILE_START dl12_tar
#define TARFILE_SIZE dl12_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 = rtems_tarfs_load("/", (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_MAXIMUM_FILE_DESCRIPTORS 4
#define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_MAXIMUM_SEMAPHORES 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT_TASK_STACK_SIZE (CONFIGURE_MINIMUM_TASK_STACK_SIZE + (4U * 1024U))
#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
#define CONFIGURE_INIT
#include <rtems/confdefs.h>