Skip to content

Commit 945eb97

Browse files
author
Dmitri Naumov
committed
Merge branch 'test-shared-lib-loading' into 'master'
Work around library loading issues and test shared lib loading See merge request ogs/ogs!5384
2 parents 550b360 + 20b0bc5 commit 945eb97

File tree

8 files changed

+113
-7
lines changed

8 files changed

+113
-7
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,11 @@ if(OGS_BUILD_WHEEL)
287287
message(FATAL_ERROR "Binary list comparison failed. Please update binaries_list in provide_ogs_cli_tools_via_wheel.py!")
288288
endif()
289289
endif()
290+
291+
if(TARGET ogs_test_dlopen)
292+
# Has to come last in this top-level CMakeLists.txt to add tests for all shared libraries.
293+
# We pass ${Python_LIBRARIES} as additional lib(s) to load, because many OGS libs
294+
# (e.g. each process, because of a cyclic dependency between the generic process lib and (Python) BCs)
295+
# depend on them and they are not explicitly linked against.
296+
for_each_subdir("${PROJECT_SOURCE_DIR}" add_dlopen_tests ${Python_LIBRARIES})
297+
endif()

ProcessLib/ProcessVariable.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ ProcessVariable::ProcessVariable(
213213

214214
ProcessVariable::ProcessVariable(ProcessVariable&&) = default;
215215

216-
std::string const& ProcessVariable::getName() const
217-
{
218-
return _name;
219-
}
220-
221216
MeshLib::Mesh const& ProcessVariable::getMesh() const
222217
{
223218
return _mesh;

ProcessLib/ProcessVariable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ProcessVariable
7272

7373
ProcessVariable(ProcessVariable&&);
7474

75-
std::string const& getName() const;
75+
std::string const& getName() const { return _name; }
7676

7777
/// Returns a mesh on which the process variable is defined.
7878
MeshLib::Mesh const& getMesh() const;

Tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,5 @@ endif()
198198
# cmake-format: on
199199

200200
unset(CMAKE_FOLDER)
201+
202+
add_subdirectory(Dlopen)

Tests/Dlopen/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
if(LINUX)
2+
add_executable(ogs_test_dlopen dlopen.cpp)
3+
4+
# Adds ogs_test_dlopen tests for each shared library in the passed dir.
5+
# Any surplus arguments (${ARGN}) are added as commandline arguments to the test command.
6+
function(add_dlopen_tests dir)
7+
get_directory_property(_targets DIRECTORY "${dir}" BUILDSYSTEM_TARGETS)
8+
9+
foreach(target IN LISTS _targets)
10+
get_target_property(_type ${target} TYPE)
11+
if(_type STREQUAL "SHARED_LIBRARY")
12+
add_test(
13+
NAME "dlopen_${target}"
14+
COMMAND $<TARGET_FILE:ogs_test_dlopen> ${ARGN} $<TARGET_FILE:${target}>)
15+
set_tests_properties("dlopen_${target}" PROPERTIES DEPENDS ogs_test_dlopen)
16+
endif()
17+
endforeach()
18+
endfunction()
19+
20+
# Invokes the passed callback for each subdirectory of the passed directory (and for dir itself).
21+
# Only subdirectories of the ${PROJECT_SOURCE_DIR} are considered.
22+
# Any surplus arguments (${ARGN}) are passed on to the callback.
23+
function(for_each_subdir dir callback)
24+
if(COMMAND ${callback})
25+
cmake_language(CALL "${callback}" "${dir}" ${ARGN})
26+
else()
27+
message(FATAL_ERROR "Callback ${callback} is not a valid function")
28+
endif()
29+
30+
get_directory_property(_subdirs DIRECTORY "${dir}" SUBDIRECTORIES)
31+
32+
foreach(subdir IN LISTS _subdirs)
33+
string(FIND "${subdir}" "${PROJECT_SOURCE_DIR}" _index)
34+
if(NOT _index EQUAL 0)
35+
continue()
36+
endif()
37+
38+
for_each_subdir("${subdir}" "${callback}" ${ARGN})
39+
endforeach()
40+
endfunction()
41+
endif()

Tests/Dlopen/dlopen.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* \file
3+
* \copyright
4+
* Copyright (c) 2012-2025, OpenGeoSys Community (http://www.opengeosys.org)
5+
* Distributed under a Modified BSD License.
6+
* See accompanying file LICENSE.txt or
7+
* http://www.opengeosys.org/project/license
8+
*
9+
*/
10+
11+
#include <dlfcn.h>
12+
13+
#include <cassert>
14+
#include <iostream>
15+
16+
void* load(char const* lib)
17+
{
18+
void* handle = dlopen(lib, RTLD_NOW | RTLD_GLOBAL);
19+
20+
if (!handle)
21+
{
22+
std::cerr << dlerror() << '\n';
23+
std::exit(EXIT_FAILURE);
24+
}
25+
26+
dlerror(); /* Clear any existing error */
27+
28+
return handle;
29+
}
30+
31+
int main(int argc, char** argv)
32+
{
33+
if (argc < 2)
34+
{
35+
std::cerr << "you invoked this command without arguments\n";
36+
std::exit(EXIT_FAILURE);
37+
}
38+
39+
for (int i = 1; i < argc; ++i)
40+
{
41+
void* handle = load(argv[i]);
42+
std::cout << "lib address of " << argv[i] << " is: " << handle
43+
<< std::endl;
44+
}
45+
}

scripts/ci/extends/test-artifacts.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
when: always
44
paths:
55
- build/*/logs
6+
- build/*/Testing/Temporary/LastTestsFailed*.log
67
- build/*/Tests/ctest-junit.xml
78
- build/*/Tests/testrunner.xml
89
- build/*/make.txt

scripts/ci/jobs/package.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,26 @@ aggregate ctest logs:
7070
tags: [envinf, shell]
7171
script:
7272
- |
73+
out_root=build/log_summary
7374
python -m venv .venv_custom_job
7475
. .venv_custom_job/bin/activate
7576
pip install pandas
7677
mkdir -p build/log_summary
7778
set -x
78-
Applications/Python/ogs/dev/ogs_log_summary.py --snippet-out --out build/log_summary/ -v build/*/logs &>build/log_summary/ogs_log_summary.txt
79+
Applications/Python/ogs/dev/ogs_log_summary.py --snippet-out --out "$out_root" -v build/*/logs &>"$out_root/ogs_log_summary.txt"
80+
#
81+
# summarize failed ctests
82+
#
83+
function exists() {
84+
[ -e "$1" ]
85+
}
86+
if exists build/*/Testing/Temporary/LastTestsFailed*.log
87+
then
88+
out_dir="$out_root/Testing/Temporary"
89+
mkdir -p "$out_dir"
90+
echo "### Failed ctests from all jobs (and number of jobs where they failed):"
91+
cut -d':' -f2- build/*/Testing/Temporary/LastTestsFailed*.log | sort | uniq -c | tee "$out_dir/LastTestsFailed.log"
92+
fi
7993
rules:
8094
- when: always
8195
artifacts:

0 commit comments

Comments
 (0)