Skip to content

Commit 7e7f8be

Browse files
committed
tarantool: support luzer-based testing
Depends on google#13929 Depends on ligurio/luzer#73 Depends on ligurio/luzer#74 Depends on ligurio/luzer#76 Depends on ligurio/luzer#78 Depends on ligurio/lunapark#163 Depends on tarantool/tarantool#12097
1 parent 940c160 commit 7e7f8be

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

projects/tarantool/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ RUN rm -rf test/static
3030
RUN git clone https://github.com/ligurio/tarantool-corpus test/static
3131

3232
COPY build.sh $SRC/
33+
COPY compile_lua_fuzzer $SRC/

projects/tarantool/build.sh

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,25 @@ fi
4747
: ${LD:="${CXX}"}
4848
: ${LDFLAGS:="${CXXFLAGS}"} # to make sure we link with sanitizer runtime
4949

50+
FUZZER_ARGS=""
51+
if [[ "$FUZZING_ENGINE" == libfuzzer ]]; then
52+
FUZZER_ARGS="-DENABLE_LIBFUZZER_STATIC_LINKAGE=ON"
53+
fi
54+
5055
cmake_args=(
5156
# Specific to Tarantool
52-
-DENABLE_BACKTRACE=OFF
57+
# Tarantool executable binary is needed for running Lua tests,
58+
# it should not have any dependencies.
59+
-DBUILD_STATIC=ON
60+
-DENABLE_BACKTRACE=ON
5361
-DENABLE_FUZZER=ON
5462
-DOSS_FUZZ=ON
5563
-DLUA_USE_APICHECK=ON
5664
-DLUA_USE_ASSERT=ON
5765
-DLUAJIT_USE_SYSMALLOC=ON
5866
-DLUAJIT_ENABLE_GC64=ON
5967
$SANITIZERS_ARGS
68+
$FUZZER_ARGS
6069

6170
-DCMAKE_BUILD_TYPE=Debug
6271

@@ -76,7 +85,7 @@ cmake_args=(
7685

7786
# Dependencies
7887
-DENABLE_BUNDLED_ICU=ON
79-
-DENABLE_BUNDLED_LIBUNWIND=OFF
88+
-DENABLE_BUNDLED_LIBUNWIND=ON
8089
-DENABLE_BUNDLED_ZSTD=OFF
8190
)
8291

@@ -90,7 +99,7 @@ cmake --build build --target fuzzers --parallel --verbose
9099

91100
# Archive and copy to $OUT seed corpus if the build succeeded.
92101
# Postfix `_fuzzer` is used in Tarantool, postfix `_test` is
93-
# used in Lua C API tests [1].
102+
# used in additional tests [1].
94103
#
95104
# 1. https://github.com/ligurio/lunapark
96105
cp test/static/*.dict test/static/*.options $OUT/
@@ -105,3 +114,45 @@ do
105114
zip --quiet -j $OUT/"$name"_seed_corpus.zip $corpus_dir/*
106115
fi
107116
done
117+
118+
# Finish execution if libFuzzer is not used, because luzer
119+
# is libFuzzer-based.
120+
# UndefinedBehaviorSanitizer is not supported,
121+
# see https://github.com/tarantool/tarantool/issues/12216.
122+
if [[ "$FUZZING_ENGINE" != libfuzzer ]] ||
123+
[[ "$SANITIZER" == "undefined" ]]; then
124+
exit
125+
fi
126+
127+
# Tarantool binary is required for running luzer-based tests.
128+
# Beware, tarantool binary is linked with libFuzzer statically
129+
# when CMake options ENABLE_LIBFUZZER_STATIC_LINKAGE and
130+
# ENABLE_FUZZER are passed, the linkage can fail
131+
# when other fuzzing engine is used due to symbols conflict,
132+
# see FUZZING_ENGINE environment variable.
133+
cmake --build build --target tarantool --parallel --verbose
134+
135+
LUA_RUNTIME_NAME=tarantool
136+
TARANTOOL_PATH=build/src/$LUA_RUNTIME_NAME
137+
LUA_MODULES_DIR=lua_modules
138+
139+
apt install -y luarocks liblua5.1-0 liblua5.1-0-dev liblua5.1-0-dbg lua5.1
140+
141+
# Required by luzer installed using luarocks.
142+
export OSS_FUZZ=1
143+
luarocks install --lua-version 5.1 --server=https://luarocks.org/dev --tree=$LUA_MODULES_DIR luzer
144+
unset OSS_FUZZ
145+
146+
cp build/test/fuzz/lua-tests/src/tests/lapi/lib.lua "$OUT"
147+
LUZER_TEST_DIR="build/luzer_tests"
148+
# Copying luzer-based tests to a $LUZER_TEST_DIR.
149+
cmake --build build --parallel --verbose --target copy_tests
150+
# Generating test wrappers for luzer-based tests.
151+
for test_file in $(find $LUZER_TEST_DIR -name "*.lua" -type f);
152+
do
153+
"$SRC/compile_lua_fuzzer" "$LUA_RUNTIME_NAME" $(basename "$test_file")
154+
cp "$test_file" "$OUT/"
155+
done
156+
157+
cp $TARANTOOL_PATH "$OUT/$LUA_RUNTIME_NAME"
158+
cp -R $LUA_MODULES_DIR "$OUT/"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash -eu
2+
# Copyright 2026 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
################################################################################
17+
18+
# The Lua runtime name.
19+
lua_runtime=$1
20+
# Path to the fuzz target source file relative to the project's root.
21+
fuzz_target=$2
22+
23+
fuzzer_basename=$(basename -s .lua "$fuzz_target")
24+
25+
# Create an execution wrapper that executes luzer with the correct
26+
# arguments.
27+
echo "#!/bin/bash
28+
29+
# LLVMFuzzerTestOneInput so that the wrapper script is recognized
30+
# as a fuzz target for 'check_build'.
31+
project_dir=\$(dirname \"\$0\")
32+
eval \$(luarocks --lua-version 5.1 --tree lua_modules path)
33+
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$project_dir/llvm-symbolizer:detect_leaks=0 \
34+
\$project_dir/$lua_runtime \$project_dir/$fuzz_target \$@" > "$OUT/$fuzzer_basename"
35+
36+
chmod +x "$OUT/$fuzzer_basename"

0 commit comments

Comments
 (0)