From 0c69fff849b2c19c1d06ad769c3d979532728180 Mon Sep 17 00:00:00 2001 From: freemine Date: Fri, 27 Dec 2024 17:09:40 +0800 Subject: [PATCH 1/3] fix ps/grep/kill flaws found in test.script --- tests/script/sh/stop_dnodes.sh | 9 +++++---- tests/script/test.sh | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index 8923804547..6f647cd5c0 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -13,7 +13,7 @@ if [ -n "$PID" ]; then systemctl stop taosd fi -PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` +PID=`ps -C taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 taosd @@ -27,7 +27,7 @@ while [ -n "$PID" ]; do PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` done -PID=`ps -ef|grep -w taos | grep -v grep | grep -v taosanode|awk '{print $2}'` +PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 taos @@ -39,9 +39,10 @@ while [ -n "$PID" ]; do lsof -nti:6030 | xargs kill -9 fi PID=`ps -ef|grep -w taos | grep -v grep | awk '{print $2}'` + PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}'` done -PID=`ps -ef|grep -w tmq_sim | grep -v grep | awk '{print $2}'` +PID=`ps -C tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 tmq_sim @@ -53,4 +54,4 @@ while [ -n "$PID" ]; do lsof -nti:6030 | xargs kill -9 fi PID=`ps -ef|grep -w tmq_sim | grep -v grep | awk '{print $2}'` -done \ No newline at end of file +done diff --git a/tests/script/test.sh b/tests/script/test.sh index 26c01a6c09..b1588ac2e6 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -43,9 +43,9 @@ CODE_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CODE_DIR" == *"$IN_TDINTERNAL"* ]]; then - cd ../../.. + pushd ../../.. else - cd ../../ + pushd ../../ fi TOP_DIR=`pwd` @@ -119,6 +119,8 @@ ulimit -c unlimited #sudo sysctl -w kernel.core_pattern=$TOP_DIR/core.%p.%e +popd + if [ -n "$FILE_NAME" ]; then echo "------------------------------------------------------------------------" if [ $VALGRIND -eq 1 ]; then From 9c7278f6425f1c6e051187f0441970ebb2fcce09 Mon Sep 17 00:00:00 2001 From: freemine Date: Fri, 27 Dec 2024 17:21:25 +0800 Subject: [PATCH 2/3] typo correction, and add MacOSX support --- tests/script/sh/stop_dnodes.sh | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index 6f647cd5c0..354c423285 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -13,7 +13,11 @@ if [ -n "$PID" ]; then systemctl stop taosd fi -PID=`ps -C taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` +if [ "$OS_TYPE" != "Darwin" ]; then + PID=`ps -C taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` +else + PID=`ps a -c | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` +fi while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 taosd @@ -24,10 +28,18 @@ while [ -n "$PID" ]; do else lsof -nti:6030 | xargs kill -9 fi - PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` + if [ "$OS_TYPE" != "Darwin" ]; then + PID=`ps -C taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` + else + PID=`ps a -c | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` + fi done -PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` +if [ "$OS_TYPE" != "Darwin" ]; then + PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` +else + PID=`ps a -c | grep -w "[t]aos" | awk '{print $1}' | head -n 1` +fi while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 taos @@ -38,11 +50,18 @@ while [ -n "$PID" ]; do else lsof -nti:6030 | xargs kill -9 fi - PID=`ps -ef|grep -w taos | grep -v grep | awk '{print $2}'` - PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}'` + if [ "$OS_TYPE" != "Darwin" ]; then + PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` + else + PID=`ps a -c | grep -w "[t]aos" | awk '{print $1}' | head -n 1` + fi done -PID=`ps -C tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` +if [ "$OS_TYPE" != "Darwin" ]; then + PID=`ps -C tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` +else + PID=`ps a -c | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` +fi while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 tmq_sim @@ -53,5 +72,9 @@ while [ -n "$PID" ]; do else lsof -nti:6030 | xargs kill -9 fi - PID=`ps -ef|grep -w tmq_sim | grep -v grep | awk '{print $2}'` + if [ "$OS_TYPE" != "Darwin" ]; then + PID=`ps -C tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` + else + PID=`ps a -c | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` + fi done From 958cf30e259f4064f89e1e3a0feb998bb91d88f7 Mon Sep 17 00:00:00 2001 From: freemine Date: Sat, 4 Jan 2025 10:52:05 +0800 Subject: [PATCH 3/3] unify among LINUX and MacOSX --- tests/script/sh/stop_dnodes.sh | 44 +++++++++++----------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index 354c423285..96a1108893 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -7,17 +7,21 @@ unset LD_PRELOAD UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` +psby() { + if [ "$OS_TYPE" != "Darwin" ]; then + ps -C $1 + else + ps a -c + fi +} + PID=`ps -ef|grep /usr/bin/taosd | grep -v grep | awk '{print $2}'` if [ -n "$PID" ]; then echo systemctl stop taosd systemctl stop taosd fi -if [ "$OS_TYPE" != "Darwin" ]; then - PID=`ps -C taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` -else - PID=`ps a -c | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` -fi +PID=`psby taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 taosd @@ -28,18 +32,10 @@ while [ -n "$PID" ]; do else lsof -nti:6030 | xargs kill -9 fi - if [ "$OS_TYPE" != "Darwin" ]; then - PID=`ps -C taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` - else - PID=`ps a -c | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` - fi + PID=`psby taosd | grep -w "[t]aosd" | awk '{print $1}' | head -n 1` done -if [ "$OS_TYPE" != "Darwin" ]; then - PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` -else - PID=`ps a -c | grep -w "[t]aos" | awk '{print $1}' | head -n 1` -fi +PID=`psby taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 taos @@ -50,18 +46,10 @@ while [ -n "$PID" ]; do else lsof -nti:6030 | xargs kill -9 fi - if [ "$OS_TYPE" != "Darwin" ]; then - PID=`ps -C taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` - else - PID=`ps a -c | grep -w "[t]aos" | awk '{print $1}' | head -n 1` - fi + PID=`psby taos | grep -w "[t]aos" | awk '{print $1}' | head -n 1` done -if [ "$OS_TYPE" != "Darwin" ]; then - PID=`ps -C tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` -else - PID=`ps a -c | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` -fi +PID=`psby tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` while [ -n "$PID" ]; do echo kill -9 $PID #pkill -9 tmq_sim @@ -72,9 +60,5 @@ while [ -n "$PID" ]; do else lsof -nti:6030 | xargs kill -9 fi - if [ "$OS_TYPE" != "Darwin" ]; then - PID=`ps -C tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` - else - PID=`ps a -c | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` - fi + PID=`psby tmq_sim | grep -w "[t]mq_sim" | awk '{print $1}' | head -n 1` done