Skip to content

Commit 827bc96

Browse files
committed
tarantool: support code coverage
Follows up tarantool/tarantool#11250 Follows up #14656
1 parent 2182961 commit 827bc96

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

infra/base-images/base-runner/coverage

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,30 @@ function run_fuzz_target {
122122
# Extract fuzztest binary name from fuzztest wrapper script.
123123
target=(${target//@/ }[0])
124124
fi
125-
profraw_update.py $OUT/$target -i $profraw_file_mask
125+
# XXX: readelf: Error: Not an ELF file - it has the wrong magic
126+
# bytes at the start.
127+
grep -q "luarocks" "$target"
128+
is_lua=$?
129+
if [[ "$is_lua" -ne 0 ]]; then
130+
profraw_update.py $OUT/$target -i $profraw_file_mask
131+
fi
126132
llvm-profdata merge -j=1 -sparse $profraw_file_mask -o $profdata_file
127133

128134
# Delete unnecessary and (potentially) large .profraw files.
129135
rm $profraw_file_mask
130136

131-
shared_libraries=$(coverage_helper shared_libs -build-dir=$OUT -object=$target)
137+
# `coverage_helper shared_libraries` raise an exception because
138+
# it runs `ldd` on a test wrapper and `ldd` returns a non-zero
139+
# exit code.
140+
test_dir=$(dirname $(realpath "$target"))
141+
if [[ "$is_lua" -ne 0 ]]; then
142+
shared_libraries=$(coverage_helper shared_libs -build-dir=$OUT -object=$objects)
143+
else
144+
shared_libraries=$(find $test_dir -name "*.so" ! -name 'luzer_impl.so' ! -name 'libfuzzer_with_ubsan.so' ! -name 'libcustom_mutator.so' ! -name 'libfuzzer_with_asan.so' -type f -print | tr "\n" " ")
145+
fi
132146

133-
llvm-cov export -summary-only -instr-profile=$profdata_file -object=$target \
147+
# Lua runtime must have name `lua`.
148+
llvm-cov export -summary-only -instr-profile=$profdata_file -object=$test_dir/lua \
134149
$shared_libraries $LLVM_COV_COMMON_ARGS > $FUZZER_STATS_DIR/$target.json
135150

136151
# If grep returned zero an error was matched.
@@ -624,7 +639,17 @@ else
624639

625640
# TODO(mmoroz): add script from Chromium for rendering directory view reports.
626641
# The first path in $objects does not have -object= prefix (llvm-cov format).
627-
shared_libraries=$(coverage_helper shared_libs -build-dir=$OUT -object=$objects)
642+
# `coverage_helper shared_libraries` raise an exception because
643+
# it runs `ldd` on a test wrapper and `ldd` returns a non-zero
644+
# exit code.
645+
grep -q "luarocks" "$target"
646+
is_lua=$?
647+
if [[ "$is_lua" -ne 0 ]]; then
648+
shared_libraries=$(coverage_helper shared_libs -build-dir=$OUT -object=$objects)
649+
else
650+
test_dir=$(dirname $(realpath "$target"))
651+
shared_libraries=$(find $test_dir -name "*.so" ! -name 'luzer_impl.so' ! -name 'libfuzzer_with_ubsan.so' ! -name 'libcustom_mutator.so' ! -name 'libfuzzer_with_asan.so' -type f -print | tr "\n" " ")
652+
fi
628653
objects="$objects $shared_libraries"
629654

630655
generate_html $PROFILE_FILE "$shared_libraries" "$objects" "$REPORT_ROOT_DIR"

projects/tarantool/build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fi
4848
: ${LDFLAGS:="${CXXFLAGS}"} # to make sure we link with sanitizer runtime
4949

5050
FUZZER_ARGS=""
51-
if [[ "$FUZZING_ENGINE" == libfuzzer ]]; then
51+
if [[ "$FUZZING_ENGINE" == libfuzzer && "$SANITIZER" != "coverage" ]]; then
5252
FUZZER_ARGS="-DENABLE_LIBFUZZER_STATIC_LINKAGE=ON"
5353
fi
5454

@@ -132,8 +132,9 @@ fi
132132
# see FUZZING_ENGINE environment variable.
133133
cmake --build build --target tarantool --parallel --verbose
134134

135-
LUA_RUNTIME_NAME=tarantool
136-
TARANTOOL_PATH=build/src/$LUA_RUNTIME_NAME
135+
# XXX: Code coverage scripts relies on that.
136+
LUA_RUNTIME_NAME=lua
137+
TARANTOOL_PATH=build/src/tarantool
137138
LUA_MODULES_DIR=lua_modules
138139

139140
apt install -y luarocks liblua5.1-0 liblua5.1-0-dev liblua5.1-0-dbg lua5.1

0 commit comments

Comments
 (0)