crash_gen.sh 3.2 KB
Newer Older
S
Steven Li 已提交
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash

# This is the script for us to try to cause the TDengine server or client to crash
#    
# PREPARATION
#
# 1. Build an compile the TDengine source code that comes with this script, in the same directory tree
# 2. Please follow the direction in our README.md, and build TDengine in the build/ directory
# 3. Adjust the configuration file if needed under build/test/cfg/taos.cfg
# 4. Run the TDengine server instance: cd build; ./build/bin/taosd -c test/cfg
# 5. Make sure you have a working Python3 environment: run /usr/bin/python3 --version, and you should get 3.6 or above
12
# 6. Make sure you have the proper Python packages: # sudo apt install python3-setuptools python3-pip python3-distutils
S
Steven Li 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#
# RUNNING THIS SCRIPT
# 
# This script assumes the source code directory is intact, and that the binaries has been built in the
# build/ directory, as such, will will load the Python libraries in the directory tree, and also load
# the TDengine client shared library (so) file, in the build/directory, as evidenced in the env
# variables below.
#
# Running the script is simple, no parameter is needed (for now, but will change in the future).
#
# Happy Crashing...


# Due to the heavy path name assumptions/usage, let us require that the user be in the current directory
EXEC_DIR=`dirname "$0"`
if [[ $EXEC_DIR != "." ]]
then
    echo "ERROR: Please execute `basename "$0"` in its own directory (for now anyway, pardon the dust)"
    exit -1
fi

S
Shuduo Sang 已提交
34 35 36 37
CURR_DIR=`pwd`
IN_TDINTERNAL="community"
if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
  TAOS_DIR=$CURR_DIR/../../..
L
liuyq-617 已提交
38 39
  TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
  LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib
S
Shuduo Sang 已提交
40 41
else
  TAOS_DIR=$CURR_DIR/../..
L
liuyq-617 已提交
42 43
  TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
  LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
S
Shuduo Sang 已提交
44 45
fi

46 47 48 49
# Now getting ready to execute Python
# The following is the default of our standard dev env (Ubuntu 20.04), modify/adjust at your own risk
PYTHON_EXEC=python3.8

S
Steven Li 已提交
50
# First we need to set up a path for Python to find our own TAOS modules, so that "import" can work.
51
export PYTHONPATH=$(pwd)/../../src/connector/python/linux/python3:$(pwd)
S
Steven Li 已提交
52 53

# Then let us set up the library path so that our compiled SO file can be loaded by Python
S
Shuduo Sang 已提交
54
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR
S
Steven Li 已提交
55

56
# Now we are all let, and let's see if we can find a crash. Note we pass all params
57
CRASH_GEN_EXEC=crash_gen_bootstrap.py
58 59 60
if [[ $1 == '--valgrind' ]]; then
  shift
  export PYTHONMALLOC=malloc
61 62
  VALGRIND_OUT=valgrind.out 
  VALGRIND_ERR=valgrind.err
63 64
  # How to generate valgrind suppression file: https://stackoverflow.com/questions/17159578/generating-suppressions-for-memory-leaks
  # valgrind --leak-check=full --gen-suppressions=all --log-fd=9 python3.8 ./crash_gen.py $@ 9>>memcheck.log
65
  echo Executing under VALGRIND, with STDOUT/ERR going to $VALGRIND_OUT and $VALGRIND_ERR, please watch them from a different terminal.
66 67 68
  valgrind  \
    --leak-check=yes \
    --suppressions=crash_gen/valgrind_taos.supp \
69
    $PYTHON_EXEC \
70
    $CRASH_GEN_EXEC $@ > $VALGRIND_OUT 2> $VALGRIND_ERR 
71 72 73 74 75
elif [[ $1 == '--helgrind' ]]; then
  shift
  valgrind  \
    --tool=helgrind \
    $PYTHON_EXEC \
76
    $CRASH_GEN_EXEC $@
77
else
78
  $PYTHON_EXEC $CRASH_GEN_EXEC $@
79 80
fi