From 40b2d3673b29081bdbffb036d1069058804edf28 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 20 Nov 2022 15:04:44 +0800 Subject: [PATCH 1/8] test: python asan --- tests/parallel_test/cases.task | 6 +++--- tests/pytest/util/log.py | 2 +- tests/system-test/test.sh | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index a43859ebfa..e1b7f9cb32 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -278,7 +278,7 @@ ,,y,script,./test.sh -f tsim/stable/values.sim ,,y,script,./test.sh -f tsim/stable/vnode3.sim ,,y,script,./test.sh -f tsim/stable/metrics_idx.sim -,,n,script,./test.sh -f tsim/sma/drop_sma.sim +,,y,script,./test.sh -f tsim/sma/drop_sma.sim ,,y,script,./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim ,,y,script,./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim ,,y,script,./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim @@ -438,11 +438,11 @@ ,,,system-test,python3 ./test.py -f 1-insert/database_pre_suf.py ,,,system-test,python3 ./test.py -f 1-insert/InsertFuturets.py ,,,system-test,python3 ./test.py -f 0-others/show.py -,,,system-test,python3 ./test.py -f 2-query/abs.py +,,,system-test,./test.sh python3 ./test.py -f 2-query/abs.py ,,,system-test,python3 ./test.py -f 2-query/abs.py -R ,,,system-test,python3 ./test.py -f 2-query/and_or_for_byte.py ,,,system-test,python3 ./test.py -f 2-query/and_or_for_byte.py -R -,,,system-test,python3 ./test.py -f 2-query/apercentile.py +,,,system-test,./test.sh python3 ./test.py -f 2-query/apercentile.py ,,,system-test,python3 ./test.py -f 2-query/apercentile.py -R ,,,system-test,python3 ./test.py -f 2-query/arccos.py ,,,system-test,python3 ./test.py -f 2-query/arccos.py -R diff --git a/tests/pytest/util/log.py b/tests/pytest/util/log.py index a132178308..000c907ea4 100644 --- a/tests/pytest/util/log.py +++ b/tests/pytest/util/log.py @@ -33,7 +33,7 @@ class TDLog: print("\033[1;36m%s %s\033[0m" % (datetime.datetime.now(), err)) def success(self, info): - print("\033[1;32m%s %s\033[0m" % (datetime.datetime.now(), info)) + printf("\033[1;32m%s %s\033[0m" % (datetime.datetime.now(), info)) def notice(self, err): print("\033[1;33m%s %s\033[0m" % (datetime.datetime.now(), err)) diff --git a/tests/system-test/test.sh b/tests/system-test/test.sh index 2a3187e641..bba6552fab 100755 --- a/tests/system-test/test.sh +++ b/tests/system-test/test.sh @@ -68,15 +68,16 @@ ulimit -c unlimited #sudo sysctl -w kernel.core_pattern=$TOP_DIR/core.%p.%e echo "ExcuteCmd:" $* -echo "AsanDir:" $ASAN_DIR/psim.asan +echo "AsanDir:" $ASAN_DIR/psim.info export LD_PRELOAD=libasan.so.5 -$* -a 2> $ASAN_DIR/psim.asan +$* -a 2> $ASAN_DIR/psim.info + result=$? echo "Execute result:" $result if [ $result -eq 0 ]; then - $CODE_DIR/sh/checkAsan.sh + $TOP_DIR/tests/script/sh/checkAsan.sh else exit 1 fi From ed7eb1cbf101f35b47eb139a6ae64fce44e0b078 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 20 Nov 2022 16:47:10 +0800 Subject: [PATCH 2/8] test: python asan --- tests/system-test/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/test.sh b/tests/system-test/test.sh index bba6552fab..c6238d37d0 100755 --- a/tests/system-test/test.sh +++ b/tests/system-test/test.sh @@ -45,7 +45,7 @@ declare -x SIM_DIR=$TOP_DIR/sim PROGRAM=$BUILD_DIR/build/bin/tsim PRG_DIR=$SIM_DIR/tsim ASAN_DIR=$SIM_DIR/asan -SYSTEM_TEST_DIR=$TOP_DIR/tests/system-test +SYSTEM_TEST_DIR=$CODE_DIR/tests/system-test chmod -R 777 $PRG_DIR echo "------------------------------------------------------------------------" @@ -77,7 +77,7 @@ result=$? echo "Execute result:" $result if [ $result -eq 0 ]; then - $TOP_DIR/tests/script/sh/checkAsan.sh + $CODE_DIR/tests/script/sh/checkAsan.sh else exit 1 fi From 4dc1b33414e918b90bc68f7b96228e129b088e30 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 20 Nov 2022 17:29:16 +0800 Subject: [PATCH 3/8] test: python asan --- tests/script/sh/checkAsan.sh | 1 + tests/script/sh/exec.sh | 1 + tests/script/sh/stop_dnodes.sh | 2 +- tests/system-test/test.py | 2 +- tests/system-test/test.sh | 28 +++++++++++++++++++--------- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/tests/script/sh/checkAsan.sh b/tests/script/sh/checkAsan.sh index 0ce74a989e..8e5738e911 100755 --- a/tests/script/sh/checkAsan.sh +++ b/tests/script/sh/checkAsan.sh @@ -3,6 +3,7 @@ set +e #set -x +export LD_PRELOAD= SCRIPT_DIR=`dirname $0` cd $SCRIPT_DIR/../ SCRIPT_DIR=`pwd` diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 5ef4cca741..ad671631a9 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -11,6 +11,7 @@ set +e #set -x +export LD_PRELOAD= UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index 38667d9b3f..34777ccb59 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -3,10 +3,10 @@ set +e #set -x +export LD_PRELOAD= UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` -export LD_PRELOAD= PID=`ps -ef|grep /usr/bin/taosd | grep -v grep | awk '{print $2}'` if [ -n "$PID" ]; then echo systemctl stop taosd diff --git a/tests/system-test/test.py b/tests/system-test/test.py index 712b9689ba..cf9aba123c 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -555,5 +555,5 @@ if __name__ == "__main__": conn.close() if asan: tdDnodes.StopAllSigint() - tdLog.info("address sanitizer mode finished") + tdLog.info("Address sanitizer mode finished") sys.exit(0) diff --git a/tests/system-test/test.sh b/tests/system-test/test.sh index c6238d37d0..6fbc9961d6 100755 --- a/tests/system-test/test.sh +++ b/tests/system-test/test.sh @@ -45,13 +45,11 @@ declare -x SIM_DIR=$TOP_DIR/sim PROGRAM=$BUILD_DIR/build/bin/tsim PRG_DIR=$SIM_DIR/tsim ASAN_DIR=$SIM_DIR/asan -SYSTEM_TEST_DIR=$CODE_DIR/tests/system-test chmod -R 777 $PRG_DIR echo "------------------------------------------------------------------------" echo "Start TDengine Testing Case ..." echo "BUILD_DIR: $BUILD_DIR" -echo "SYSTEM_TEST_DIR : $SYSTEM_TEST_DIR" echo "SIM_DIR : $SIM_DIR" echo "CODE_DIR : $CODE_DIR" echo "ASAN_DIR : $ASAN_DIR" @@ -61,24 +59,36 @@ rm -rf $SIM_DIR/* mkdir -p $PRG_DIR mkdir -p $ASAN_DIR -cd $SYSTEM_TEST_DIR +cd $CODE_DIR ulimit -n 600000 ulimit -c unlimited #sudo sysctl -w kernel.core_pattern=$TOP_DIR/core.%p.%e echo "ExcuteCmd:" $* -echo "AsanDir:" $ASAN_DIR/psim.info +AsanFile=$ASAN_DIR/psim.asan +echo "AsanFile:" $AsanFile export LD_PRELOAD=libasan.so.5 -$* -a 2> $ASAN_DIR/psim.info +$* -a 2> $AsanFile -result=$? -echo "Execute result:" $result +export LD_PRELOAD= +AsanFileLen=`cat $AsanFile | wc -l` +while [ $AsanFileLen -lt 10 ] +do + sleep 1 + `cat $AsanFile | wc -l` +done +echo "AsanFileLen:" $AsanFileLen -if [ $result -eq 0 ]; then - $CODE_DIR/tests/script/sh/checkAsan.sh +AsanFileSuccessLen=`grep -w successfully $AsanFile | wc -l` +echo "AsanFileSuccessLen:" $AsanFileSuccessLen + +if [ $AsanFileSuccessLen -gt 0 ]; then + echo "Execute script successfully and check asan" + $CODE_DIR/../script/sh/checkAsan.sh else + echo "Execute script failure" exit 1 fi From 15c0bb944613f249ba2911218718ae04acd96187 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 20 Nov 2022 21:26:54 +0800 Subject: [PATCH 4/8] test: python asan --- tests/pytest/util/dnodes.py | 15 ++++++++++++--- tests/script/sh/checkAsan.sh | 2 +- tests/script/sh/exec.sh | 2 +- tests/script/sh/sigint_stop_dnodes.sh | 2 +- tests/script/sh/stop_dnodes.sh | 2 +- tests/system-test/{test.sh => pytest.sh} | 3 ++- 6 files changed, 18 insertions(+), 8 deletions(-) rename tests/system-test/{test.sh => pytest.sh} (98%) diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index edb3d761cb..22e6127973 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -162,7 +162,11 @@ class TDDnode: def setAsan(self, value): self.asan = value if value: - self.execPath = os.path.abspath(self.path + "/tests/script/sh/exec.sh") + selfPath = os.path.dirname(os.path.realpath(__file__)) + if ("community" in selfPath): + self.execPath = os.path.abspath(self.path + "/community/tests/script/sh/exec.sh") + else: + self.execPath = os.path.abspath(self.path + "/tests/script/sh/exec.sh") def getDataSize(self): totalSize = 0 @@ -670,8 +674,13 @@ class TDDnodes: def setAsan(self, value): self.asan = value if value: - self.stopDnodesPath = os.path.abspath(self.path + "/tests/script/sh/stop_dnodes.sh") - self.stopDnodesSigintPath = os.path.abspath(self.path + "/tests/script/sh/sigint_stop_dnodes.sh") + selfPath = os.path.dirname(os.path.realpath(__file__)) + if ("community" in selfPath): + self.stopDnodesPath = os.path.abspath(self.path + "/community/tests/script/sh/stop_dnodes.sh") + self.stopDnodesSigintPath = os.path.abspath(self.path + "/community/tests/script/sh/sigint_stop_dnodes.sh") + else: + self.stopDnodesPath = os.path.abspath(self.path + "/tests/script/sh/stop_dnodes.sh") + self.stopDnodesSigintPath = os.path.abspath(self.path + "/tests/script/sh/sigint_stop_dnodes.sh") tdLog.info("run in address sanitizer mode") def setKillValgrind(self, value): diff --git a/tests/script/sh/checkAsan.sh b/tests/script/sh/checkAsan.sh index 8e5738e911..5dfb19e0ae 100755 --- a/tests/script/sh/checkAsan.sh +++ b/tests/script/sh/checkAsan.sh @@ -3,7 +3,7 @@ set +e #set -x -export LD_PRELOAD= +unset LD_PRELOAD SCRIPT_DIR=`dirname $0` cd $SCRIPT_DIR/../ SCRIPT_DIR=`pwd` diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index ad671631a9..c8cb121b8a 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -11,7 +11,7 @@ set +e #set -x -export LD_PRELOAD= +unset LD_PRELOAD UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` diff --git a/tests/script/sh/sigint_stop_dnodes.sh b/tests/script/sh/sigint_stop_dnodes.sh index 12b58225de..a398e00772 100755 --- a/tests/script/sh/sigint_stop_dnodes.sh +++ b/tests/script/sh/sigint_stop_dnodes.sh @@ -3,7 +3,7 @@ set +e #set -x -export LD_PRELOAD= +unset LD_PRELOAD UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index 34777ccb59..ce2d7144f9 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -3,7 +3,7 @@ set +e #set -x -export LD_PRELOAD= +unset LD_PRELOAD UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` diff --git a/tests/system-test/test.sh b/tests/system-test/pytest.sh similarity index 98% rename from tests/system-test/test.sh rename to tests/system-test/pytest.sh index 6fbc9961d6..f6d081da2a 100755 --- a/tests/system-test/test.sh +++ b/tests/system-test/pytest.sh @@ -69,10 +69,11 @@ echo "ExcuteCmd:" $* AsanFile=$ASAN_DIR/psim.asan echo "AsanFile:" $AsanFile +unset LD_PRELOAD export LD_PRELOAD=libasan.so.5 $* -a 2> $AsanFile -export LD_PRELOAD= +unset LD_PRELOAD AsanFileLen=`cat $AsanFile | wc -l` while [ $AsanFileLen -lt 10 ] do From c8f6235027c9651208c4537b6d62d2b56f5185d5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 20 Nov 2022 22:09:48 +0800 Subject: [PATCH 5/8] test: python asan --- tests/parallel_test/cases.task | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index e1b7f9cb32..12e0a9c89d 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -438,11 +438,11 @@ ,,,system-test,python3 ./test.py -f 1-insert/database_pre_suf.py ,,,system-test,python3 ./test.py -f 1-insert/InsertFuturets.py ,,,system-test,python3 ./test.py -f 0-others/show.py -,,,system-test,./test.sh python3 ./test.py -f 2-query/abs.py +,,,system-test,./pytest.sh python3 ./test.py -f 2-query/abs.py ,,,system-test,python3 ./test.py -f 2-query/abs.py -R ,,,system-test,python3 ./test.py -f 2-query/and_or_for_byte.py ,,,system-test,python3 ./test.py -f 2-query/and_or_for_byte.py -R -,,,system-test,./test.sh python3 ./test.py -f 2-query/apercentile.py +,,,system-test,./pytest.sh python3 ./test.py -f 2-query/apercentile.py ,,,system-test,python3 ./test.py -f 2-query/apercentile.py -R ,,,system-test,python3 ./test.py -f 2-query/arccos.py ,,,system-test,python3 ./test.py -f 2-query/arccos.py -R From d17dd17be49a811cbafaf2d0fbb479a9111aad28 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 20 Nov 2022 23:14:33 +0800 Subject: [PATCH 6/8] test: preload libasan --- tests/system-test/pytest.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/system-test/pytest.sh b/tests/system-test/pytest.sh index f6d081da2a..d5ae59b4fe 100755 --- a/tests/system-test/pytest.sh +++ b/tests/system-test/pytest.sh @@ -70,7 +70,14 @@ AsanFile=$ASAN_DIR/psim.asan echo "AsanFile:" $AsanFile unset LD_PRELOAD -export LD_PRELOAD=libasan.so.5 +#export LD_PRELOAD=libasan.so.5 +#echo "export1:" $? +export LD_PRELOAD=`gcc -print-file-name=libasan.so` +echo "export2:" $? + +echo "export4:" "$BUILD_DIR/build/bin/taos" +ldd $BUILD_DIR/build/bin/taos + $* -a 2> $AsanFile unset LD_PRELOAD From ee9f5740cfb0ed0ba830564c3b496b7d4bf184fe Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 21 Nov 2022 08:52:32 +0800 Subject: [PATCH 7/8] test: check asan errors --- tests/parallel_test/cases.task | 2 +- tests/script/sh/checkAsan.sh | 7 ++++++- tests/system-test/2-query/abs.py | 2 ++ tests/system-test/pytest.sh | 8 ++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 12e0a9c89d..a9a02d8380 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -278,7 +278,7 @@ ,,y,script,./test.sh -f tsim/stable/values.sim ,,y,script,./test.sh -f tsim/stable/vnode3.sim ,,y,script,./test.sh -f tsim/stable/metrics_idx.sim -,,y,script,./test.sh -f tsim/sma/drop_sma.sim +,,n,script,./test.sh -f tsim/sma/drop_sma.sim ,,y,script,./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim ,,y,script,./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim ,,y,script,./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim diff --git a/tests/script/sh/checkAsan.sh b/tests/script/sh/checkAsan.sh index 5dfb19e0ae..c53fde1171 100755 --- a/tests/script/sh/checkAsan.sh +++ b/tests/script/sh/checkAsan.sh @@ -22,19 +22,24 @@ error_num=`cat ${LOG_DIR}/*.asan | grep "ERROR" | wc -l` memory_leak=`cat ${LOG_DIR}/*.asan | grep "Direct leak" | wc -l` indirect_leak=`cat ${LOG_DIR}/*.asan | grep "Indirect leak" | wc -l` runtime_error=`cat ${LOG_DIR}/*.asan | grep "runtime error" | grep -v "trees.c:873" | wc -l` +python_error=`cat ${LOG_DIR}/*.info | grep "stack" | wc -l` echo -e "\033[44;32;1m"asan error_num: $error_num"\033[0m" echo -e "\033[44;32;1m"asan memory_leak: $memory_leak"\033[0m" echo -e "\033[44;32;1m"asan indirect_leak: $indirect_leak"\033[0m" echo -e "\033[44;32;1m"asan runtime error: $runtime_error"\033[0m" +echo -e "\033[44;32;1m"asan python error: $python_error"\033[0m" -let "errors=$error_num+$memory_leak+$indirect_leak+$runtime_error" +let "errors=$error_num+$memory_leak+$indirect_leak+$runtime_error+$python_error" if [ $errors -eq 0 ]; then echo -e "\033[44;32;1m"no asan errors"\033[0m" exit 0 else echo -e "\033[44;31;1m"asan total errors: $errors"\033[0m" + if [ $python_error -ne 0 ]; then + cat ${LOG_DIR}/*.info + fi cat ${LOG_DIR}/*.asan exit 1 fi \ No newline at end of file diff --git a/tests/system-test/2-query/abs.py b/tests/system-test/2-query/abs.py index d7478a55a8..dcd9e6d620 100644 --- a/tests/system-test/2-query/abs.py +++ b/tests/system-test/2-query/abs.py @@ -487,6 +487,8 @@ class TDTestCase: self.check_result_auto( f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from {dbname}.sub1_bound;", f"select abs(c1) from {dbname}.sub1_bound") + tdSql.query(f"select t1 xxx") + # check basic elem for table per row tdSql.query( f"select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from {dbname}.sub1_bound ") diff --git a/tests/system-test/pytest.sh b/tests/system-test/pytest.sh index d5ae59b4fe..3f03058342 100755 --- a/tests/system-test/pytest.sh +++ b/tests/system-test/pytest.sh @@ -66,17 +66,13 @@ ulimit -c unlimited #sudo sysctl -w kernel.core_pattern=$TOP_DIR/core.%p.%e echo "ExcuteCmd:" $* -AsanFile=$ASAN_DIR/psim.asan +AsanFile=$ASAN_DIR/psim.info echo "AsanFile:" $AsanFile unset LD_PRELOAD #export LD_PRELOAD=libasan.so.5 -#echo "export1:" $? export LD_PRELOAD=`gcc -print-file-name=libasan.so` -echo "export2:" $? - -echo "export4:" "$BUILD_DIR/build/bin/taos" -ldd $BUILD_DIR/build/bin/taos +echo "Preload AsanSo:" $? $* -a 2> $AsanFile From c454f849b21f238af3fe3cb7dcb3fcb476d1d9cc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 21 Nov 2022 09:45:38 +0800 Subject: [PATCH 8/8] test: adjust python asan script --- tests/script/sh/checkAsan.sh | 2 +- tests/system-test/2-query/abs.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/script/sh/checkAsan.sh b/tests/script/sh/checkAsan.sh index c53fde1171..8759db8722 100755 --- a/tests/script/sh/checkAsan.sh +++ b/tests/script/sh/checkAsan.sh @@ -22,7 +22,7 @@ error_num=`cat ${LOG_DIR}/*.asan | grep "ERROR" | wc -l` memory_leak=`cat ${LOG_DIR}/*.asan | grep "Direct leak" | wc -l` indirect_leak=`cat ${LOG_DIR}/*.asan | grep "Indirect leak" | wc -l` runtime_error=`cat ${LOG_DIR}/*.asan | grep "runtime error" | grep -v "trees.c:873" | wc -l` -python_error=`cat ${LOG_DIR}/*.info | grep "stack" | wc -l` +python_error=`cat ${LOG_DIR}/*.info | grep -w "stack" | wc -l` echo -e "\033[44;32;1m"asan error_num: $error_num"\033[0m" echo -e "\033[44;32;1m"asan memory_leak: $memory_leak"\033[0m" diff --git a/tests/system-test/2-query/abs.py b/tests/system-test/2-query/abs.py index dcd9e6d620..d7478a55a8 100644 --- a/tests/system-test/2-query/abs.py +++ b/tests/system-test/2-query/abs.py @@ -487,8 +487,6 @@ class TDTestCase: self.check_result_auto( f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from {dbname}.sub1_bound;", f"select abs(c1) from {dbname}.sub1_bound") - tdSql.query(f"select t1 xxx") - # check basic elem for table per row tdSql.query( f"select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from {dbname}.sub1_bound ")