Skip to content

Commit 5c51219

Browse files
committed
Fixed use of mock binaries for Glibc hook unit tests under AddressSanitizer
1 parent e14c4aa commit 5c51219

8 files changed

+16
-24
lines changed

CI/utility_docker_functions.bash

+1-5
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,9 @@ sarus-utest() {
112112
echo "${FUNCNAME^^} with:"
113113
_print_parameters
114114

115-
if [ ${toolchain_file} = "gcc-asan.cmake" ]; then
116-
privileged_excludes="GlibcHook"
117-
fi
118-
119115
_run_cmd_in_container ${image_run} root \
120116
". /sarus-source/CI/utility_functions.bash && \
121-
run_unit_tests $(_build_dir_container) ${privileged_excludes}"
117+
run_unit_tests $(_build_dir_container)"
122118

123119
fail_on_error "${FUNCNAME}: failed"
124120
}

CI/utility_functions.bash

+2-6
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,16 @@ run_sarus_registry() {
178178
}
179179

180180
run_unit_tests() {
181-
local build_dir=$1; shift && privileged_excludes="$1"
181+
local build_dir=$1; shift || error "${FUNCNAME}: missing build_dir argument"
182182
cd ${build_dir}
183183

184-
if [ ! -z ${privileged_excludes} ]; then
185-
privileged_excludes=("--exclude-regex" "${privileged_excludes}")
186-
fi
187-
188184
# Note: use CI/LSan.supp to suppress errors about memory leaks in
189185
# Sarus dependencies, e.g. OpenSSL. Such leaks are out of our control.
190186

191187
sudo -u docker CTEST_OUTPUT_ON_FAILURE=1 ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=${build_dir}/../CI/LSan.supp ctest --exclude-regex AsRoot
192188
fail_on_error "Unit tests as normal user failed"
193189

194-
CTEST_OUTPUT_ON_FAILURE=1 ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=${build_dir}/../CI/LSan.supp ctest --tests-regex AsRoot "${privileged_excludes[@]}" # Add as many regex as you want with -R. Allow output with -VV.
190+
CTEST_OUTPUT_ON_FAILURE=1 ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=${build_dir}/../CI/LSan.supp ctest --tests-regex AsRoot # Add as many regex as you want with -R. Allow output with -VV.
195191
# TODO: allow args forwarding to cpputest so we can run specific testswithin the filtered file with -n for example.
196192
fail_on_error "Unit tests as root user failed"
197193

src/hooks/glibc/test/CMakeLists.txt

+1-9
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,4 @@ set(object_files_directory "${CMAKE_BINARY_DIR}/src/hooks/glibc/CMakeFiles/hooks
55

66
add_unit_test(hooks_glibc_GlibcHook_AsRoot test_GlibcHook.cpp "${link_libraries}")
77

8-
# Link statically only if address sanitizer is not enabled
9-
string(FIND ${CMAKE_CXX_FLAGS} "-fsanitize=address" POS_FOUND)
10-
if(POS_FOUND EQUAL -1)
11-
link_libraries("-static")
12-
endif()
13-
14-
add_executable(lddMockOlder "lddMockOlder.cpp")
15-
add_executable(lddMockEqual "lddMockEqual.cpp")
16-
add_executable(lddMockNewer "lddMockNewer.cpp")
8+
add_subdirectory(mocks)

src/hooks/glibc/test/Checker.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ class Checker {
9292
}
9393

9494
Checker& mockLddWithOlderVersion() {
95-
sarus::common::copyFile(boost::filesystem::current_path() / "lddMockOlder", rootfsDir / lddPath);
95+
sarus::common::copyFile(boost::filesystem::current_path() / "mocks/lddMockOlder", rootfsDir / lddPath);
9696
return *this;
9797
}
9898

9999
Checker& mockLddWithEqualVersion() {
100-
sarus::common::copyFile(boost::filesystem::current_path() / "lddMockEqual", rootfsDir / lddPath);
100+
sarus::common::copyFile(boost::filesystem::current_path() / "mocks/lddMockEqual", rootfsDir / lddPath);
101101
return *this;
102102
}
103103

104104
Checker& mockLddWithNewerVersion() {
105-
sarus::common::copyFile(boost::filesystem::current_path() / "lddMockNewer", rootfsDir / lddPath);
105+
sarus::common::copyFile(boost::filesystem::current_path() / "mocks/lddMockNewer", rootfsDir / lddPath);
106106
return *this;
107107
}
108108

@@ -130,7 +130,7 @@ class Checker {
130130
sarus::common::writeJSON(doc, bundleDir / "config.json");
131131
test_utility::ocihooks::writeContainerStateToStdin(bundleDir);
132132

133-
sarus::common::setEnvironmentVariable("LDD_PATH=" + (boost::filesystem::current_path() / "lddMockEqual").string());
133+
sarus::common::setEnvironmentVariable("LDD_PATH=" + (boost::filesystem::current_path() / "mocks/lddMockEqual").string());
134134
sarus::common::setEnvironmentVariable("LDCONFIG_PATH=ldconfig");
135135
sarus::common::setEnvironmentVariable("READELF_PATH=readelf");
136136
sarus::common::setEnvironmentVariable("GLIBC_LIBS="
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Disable sanitizing for static helper binaries mocking ldd
2+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize=all")
3+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=all")
4+
link_libraries("-static")
5+
6+
add_executable(lddMockOlder "lddMockOlder.cpp")
7+
add_executable(lddMockEqual "lddMockEqual.cpp")
8+
add_executable(lddMockNewer "lddMockNewer.cpp")

0 commit comments

Comments
 (0)