Skip to content

Commit 4676e57

Browse files
committed
tarantool: support luzer-based testing
sudo python infra/helper.py build_fuzzers tarantool sudo python infra/helper.py check_build tarantool decimal_new_test sudo python infra/helper.py run_fuzzer tarantool decimal_new_test Depends on google#13929 Depends on ligurio/lunapark#163 Depends on ligurio/luzer#73 Depends on ligurio/luzer#76 Depends on tarantool/tarantool#12097
1 parent 27fa1e9 commit 4676e57

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
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: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ fi
4848
: ${LDFLAGS:="${CXXFLAGS}"} # to make sure we link with sanitizer runtime
4949

5050
cmake_args=(
51-
# Specific to Tarantool
51+
# Specific to Tarantool.
52+
# Tarantool executable binary is needed for running Lua tests,
53+
# it should not have any dependencies.
54+
-DBUILD_STATIC=ON
55+
# XXX: Sysprof requires ENABLE_BACKTRACE=ON.
5256
-DENABLE_BACKTRACE=OFF
5357
-DENABLE_FUZZER=ON
5458
-DOSS_FUZZ=ON
@@ -82,18 +86,22 @@ cmake_args=(
8286

8387
# To deal with a host filesystem from inside of container.
8488
git config --global --add safe.directory '*'
89+
git pull --rebase
90+
91+
# Required by luzer and tarantool.
92+
export OSS_FUZZ=1
8593

8694
# Build the project and fuzzers.
8795
[[ -e build ]] && rm -rf build
8896
cmake "${cmake_args[@]}" -S . -B build
89-
cmake --build build --target fuzzers --parallel --verbose
97+
cmake --build build --target fuzzers --target tarantool --parallel --verbose
9098

9199
# Archive and copy to $OUT seed corpus if the build succeeded.
92100
# Postfix `_fuzzer` is used in Tarantool, postfix `_test` is
93-
# used in Lua C API tests [1].
101+
# used in additional tests [1].
94102
#
95103
# 1. https://github.com/ligurio/lunapark
96-
cp test/static/*.dict test/static/*.options $OUT/
104+
# cp test/static/*.dict test/static/*.options $OUT/
97105
for f in $(find build/test/fuzz/ \( -name '*_fuzzer' -o -name '*_test' \) -type f);
98106
do
99107
name=$(basename $f);
@@ -105,3 +113,31 @@ do
105113
zip --quiet -j $OUT/"$name"_seed_corpus.zip $corpus_dir/*
106114
fi
107115
done
116+
117+
# Finish execution if libFuzzer is not used, because luzer
118+
# is libFuzzer-based, UndefinedSanitizer is not supported.
119+
if [[ "$FUZZING_ENGINE" != libfuzzer ]] ||
120+
[[ "$SANITIZER" == "undefined" ]]; then
121+
exit
122+
fi
123+
124+
LUA_RUNTIME_NAME=tarantool
125+
TARANTOOL_PATH=build/src/$LUA_RUNTIME_NAME
126+
LUA_MODULES_DIR=lua_modules
127+
128+
apt install -y luarocks liblua5.1-0 liblua5.1-0-dev liblua5.1-0-dbg lua5.1
129+
130+
luarocks install --lua-version 5.1 --server=https://luarocks.org/dev --tree=$LUA_MODULES_DIR luzer
131+
132+
cp build/test/fuzz/lua-tests/src/tests/lapi/lib.lua "$OUT"
133+
# Copying luzer-based tests to build/luzer_tests.
134+
cmake --build build --parallel --verbose --target copy_tests
135+
# Generating test wrappers for luzer-based tests.
136+
for test_file in $(find build/luzer_tests -name "*.lua" -type f);
137+
do
138+
"$SRC/compile_lua_fuzzer" "$LUA_RUNTIME_NAME" $(basename "$test_file")
139+
cp "$test_file" "$OUT/"
140+
done
141+
142+
cp $TARANTOOL_PATH "$OUT/$LUA_RUNTIME_NAME"
143+
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 2025 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)