query fuzzer

This commit is contained in:
Alexander Kuzmenkov 2020-07-10 14:11:31 +03:00
parent 01b5c2663c
commit 0fe4c37033

View File

@ -1,14 +1,13 @@
#!/bin/bash
set -ex
set -eux
set -o pipefail
trap "exit" INT TERM
trap 'kill $(jobs -pr) ||:' EXIT
stage=${stage:-}
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Doesn't work for clone stage, but should work after that
repo_dir=${repo_dir:-$(readlink -f "$script_dir/../../..")}
echo "$script_dir"
repo_dir=ch
function clone
{
@ -42,12 +41,21 @@ function download
function configure
{
rm -rf db ||:
mkdir db ||:
cp -av "$repo_dir"/programs/server/config* db
cp -av "$repo_dir"/programs/server/user* db
cp -av "$repo_dir"/tests/config db/config.d
}
function watchdog
{
sleep 3600
echo "Fuzzing run has timed out"
killall -9 clickhouse clickhouse-server clickhouse-client
}
function fuzz
{
./clickhouse server --config-file db/config.xml -- --path db 2>&1 | tail -1000000 > server.log &
@ -55,10 +63,19 @@ function fuzz
kill -0 $server_pid
while ! ./clickhouse client --query "select 1" && kill -0 $server_pid ; do echo . ; sleep 1 ; done
./clickhouse client --query "select 1"
kill -0 $server_pid
echo Server started
for f in $(ls ch/tests/queries/0_stateless/*.sql | sort -R); do cat $f; echo ';'; done \
| ./clickhouse client --query-fuzzer-runs=10 2>&1 | tail -1000000 > fuzzer.log
fuzzer_exit_code=0
./clickhouse client --query-fuzzer-runs=10 \
< <(for f in $(ls ch/tests/queries/0_stateless/*.sql | sort -R); do cat "$f"; echo ';'; done) \
> >(tail -1000000 > fuzzer.log) \
2>&1 \
|| fuzzer_exit_code=$?
echo "Fuzzer exit code is $fuzzer_exit_code"
kill -9 $server_pid
return $fuzzer_exit_code
}
case "$stage" in
@ -66,9 +83,19 @@ case "$stage" in
;&
"clone")
time clone
export stage=download
time ch/docker/test/fuzzer/run-fuzzer.sh
;;
if [ -v FUZZ_LOCAL_SCRIPT ]
then
# just fall through
echo Using the testing script from docker container
:
else
# run the testing script from the repository
echo Using the testing script from the repository
export stage=download
time ch/docker/test/fuzzer/run-fuzzer.sh
exit $?
fi
;&
"download")
time download
;&
@ -76,9 +103,12 @@ case "$stage" in
time configure
;&
"fuzz")
time fuzz
;&
"report")
watchdog &
watchdog_pid=$!
fuzzer_exit_code=0
time fuzz || fuzzer_exit_code=$?
kill $watchdog_pid
exit $fuzzer_exit_code
;&
esac