Skip to content

Commit 1058303

Browse files
committed
tarantool: support code coverage
1 parent e292c9f commit 1058303

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

infra/base-images/base-runner/coverage

Lines changed: 30 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.
@@ -406,6 +421,7 @@ function generate_html {
406421

407422
llvm-cov export -summary-only $llvm_cov_args > $summary_file
408423

424+
# support Lua
409425
coverage_helper -v post_process -src-root-dir=/ -summary-file=$summary_file \
410426
-output-dir=$output_dir $PATH_EQUIVALENCE_ARGS
411427
}
@@ -624,7 +640,17 @@ else
624640

625641
# TODO(mmoroz): add script from Chromium for rendering directory view reports.
626642
# 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)
643+
# `coverage_helper shared_libraries` raise an exception because
644+
# it runs `ldd` on a test wrapper and `ldd` returns a non-zero
645+
# exit code.
646+
grep -q "luarocks" "$target"
647+
is_lua=$?
648+
if [[ "$is_lua" -ne 0 ]]; then
649+
shared_libraries=$(coverage_helper shared_libs -build-dir=$OUT -object=$objects)
650+
else
651+
test_dir=$(dirname $(realpath "$target"))
652+
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" " ")
653+
fi
628654
objects="$objects $shared_libraries"
629655

630656
generate_html $PROFILE_FILE "$shared_libraries" "$objects" "$REPORT_ROOT_DIR"

projects/tarantool/build.sh

Lines changed: 5 additions & 7 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

@@ -119,11 +119,8 @@ done
119119
# is libFuzzer-based.
120120
# UndefinedBehaviorSanitizer is not supported,
121121
# see https://github.com/tarantool/tarantool/issues/12216.
122-
# Code coverage is not supported,
123-
# see https://github.com/google/oss-fuzz/issues/14859.
124122
if [[ "$FUZZING_ENGINE" != libfuzzer ]] ||
125-
[[ "$SANITIZER" == "undefined" ]] ||
126-
[[ "$SANITIZER" == "coverage" ]]; then
123+
[[ "$SANITIZER" == "undefined" ]]; then
127124
exit
128125
fi
129126

@@ -135,8 +132,9 @@ fi
135132
# see FUZZING_ENGINE environment variable.
136133
cmake --build build --target tarantool --parallel --verbose
137134

138-
LUA_RUNTIME_NAME=tarantool
139-
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
140138
LUA_MODULES_DIR=lua_modules
141139

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

0 commit comments

Comments
 (0)