Merge pull request #29273 from taosdata/cover/3.0

merge: from cover/3.0 to 3.0 branch
This commit is contained in:
Shengliang Guan 2024-12-23 11:37:44 +08:00 committed by GitHub
commit eafbc5e97d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 259 additions and 45 deletions

View File

@ -385,6 +385,7 @@ Core dir: {core_dir}
send_msg(notification_robot_url, get_msg(text))
else:
send_msg(alert_robot_url, get_msg(text))
send_msg(notification_robot_url, get_msg(text))
#send_msg(get_msg(text))
except Exception as e:

View File

@ -419,6 +419,7 @@ Core dir: {core_dir}
send_msg(notification_robot_url, get_msg(text))
else:
send_msg(alert_robot_url, get_msg(text))
send_msg(notification_robot_url, get_msg(text))
#send_msg(get_msg(text))
except Exception as e:

View File

@ -407,6 +407,7 @@ Core dir: {core_dir}
send_msg(notification_robot_url, get_msg(text))
else:
send_msg(alert_robot_url, get_msg(text))
send_msg(notification_robot_url, get_msg(text))
#send_msg(get_msg(text))
except Exception as e:

View File

@ -7,12 +7,120 @@ GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
TDENGINE_DIR=/root/TDinternal/community
function print_color() {
local color="$1"
local message="$2"
echo -e "${color}${message}${NC}"
}
# 初始化参数
TDENGINE_DIR="/root/TDinternal/community"
BRANCH=""
SAVE_LOG="notsave"
# 解析命令行参数
while getopts "hd:b:t:s:" arg; do
case $arg in
d)
TDENGINE_DIR=$OPTARG
;;
b)
BRANCH=$OPTARG
;;
s)
SAVE_LOG=$OPTARG
;;
h)
echo "Usage: $(basename $0) -d [TDengine_dir] -b [branch] -s [save ci case log]"
echo " -d [TDengine_dir] [default /root/TDinternal/community] "
echo " -b [branch] [default local branch] "
echo " -s [save/notsave] [default save ci case log in TDengine_dir/tests/ci_bak] "
exit 0
;;
?)
echo "Usage: ./$(basename $0) -h"
exit 1
;;
esac
done
# 检查是否提供了命令名称
if [ -z "$TDENGINE_DIR" ]; then
echo "Error: TDengine dir is required."
echo "Usage: $(basename $0) -d [TDengine_dir] -b [branch] -s [save ci case log] "
echo " -d [TDengine_dir] [default /root/TDinternal/community] "
echo " -b [branch] [default local branch] "
echo " -s [save/notsave] [default save ci case log in TDengine_dir/tests/ci_bak] "
exit 1
fi
#echo "TDENGINE_DIR = $TDENGINE_DIR"
echo "TDENGINE_DIR = $TDENGINE_DIR"
today=`date +"%Y%m%d"`
TDENGINE_ALLCI_REPORT=$TDENGINE_DIR/tests/all-ci-report-$today.log
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
BACKUP_DIR="$TDENGINE_DIR/tests/ci_bak"
mkdir -p "$BACKUP_DIR"
#cd $BACKUP_DIR && rm -rf *
function buildTDengine() {
print_color "$GREEN" "TDengine build start"
# pull parent code
cd "$TDENGINE_DIR/../"
print_color "$GREEN" "git pull parent code..."
git remote prune origin > /dev/null
git remote update > /dev/null
# pull tdengine code
cd $TDENGINE_DIR
print_color "$GREEN" "git pull tdengine code..."
git remote prune origin > /dev/null
git remote update > /dev/null
REMOTE_COMMIT=`git rev-parse --short remotes/origin/$branch`
LOCAL_COMMIT=`git rev-parse --short @`
print_color "$GREEN" " LOCAL: $LOCAL_COMMIT"
print_color "$GREEN" "REMOTE: $REMOTE_COMMIT"
if [ "$LOCAL_COMMIT" == "$REMOTE_COMMIT" ]; then
print_color "$GREEN" "repo up-to-date"
else
print_color "$GREEN" "repo need to pull"
fi
git reset --hard
git checkout -- .
git checkout $branch
git checkout -- .
git clean -f
git pull
[ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug
cd $TDENGINE_DIR/debug
print_color "$GREEN" "rebuild.."
LOCAL_COMMIT=`git rev-parse --short @`
rm -rf *
makecmd="cmake -DBUILD_TEST=false -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=0 -DBUILD_TOOLS=true -DBUILD_GEOS=true -DBUILD_TEST=true -DBUILD_CONTRIB=false ../../"
print_color "$GREEN" "$makecmd"
$makecmd
make -j 8 install
print_color "$GREEN" "TDengine build end"
}
# 检查并获取分支名称
if [ -n "$BRANCH" ]; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "Build is required for this test"
buildTDengine
else
print_color "$GREEN" "Build is not required for this test"
fi
function runCasesOneByOne () {
@ -20,23 +128,50 @@ function runCasesOneByOne () {
if [[ "$line" != "#"* ]]; then
cmd=`echo $line | cut -d',' -f 5`
if [[ "$2" == "sim" ]] && [[ $line == *"script"* ]]; then
echo $cmd
case=`echo $cmd | cut -d' ' -f 3`
case_file=`echo $case | tr -d ' /' `
start_time=`date +%s`
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > /dev/null 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT \
|| echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
# # 记录日志和备份
# mkdir -p "$BACKUP_DIR/$case_file"
# tar --exclude='*.sock*' -czf "$BACKUP_DIR/$case_file/sim.tar.gz" -C "$TDENGINE_DIR/.." sim
# mv "$TDENGINE_DIR/tests/$case_file.log" "$BACKUP_DIR/$case_file"
if [ "$SAVE_LOG" == "save" ]; then
mkdir -p "$BACKUP_DIR/$case_file"
tar --exclude='*.sock*' -czf "$BACKUP_DIR/$case_file/sim.tar.gz" -C "$TDENGINE_DIR/.." sim
mv "$TDENGINE_DIR/tests/$case_file.log" "$BACKUP_DIR/$case_file"
else
echo "This case not save log!"
fi
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
elif [[ "$line" == *"$2"* ]]; then
echo $cmd
if [[ "$cmd" == *"pytest.sh"* ]]; then
cmd=`echo $cmd | cut -d' ' -f 2-20`
fi
case=`echo $cmd | cut -d' ' -f 4-20`
case_file=`echo $case | tr -d ' /' `
start_time=`date +%s`
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > /dev/null 2>&1 && \
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
if [ "$SAVE_LOG" == "save" ]; then
mkdir -p "$BACKUP_DIR/$case_file"
tar --exclude='*.sock*' -czf "$BACKUP_DIR/$case_file/sim.tar.gz" -C "$TDENGINE_DIR/.." sim
mv "$TDENGINE_DIR/tests/$case_file.log" "$BACKUP_DIR/$case_file"
else
echo "This case not save log!"
fi
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
fi
@ -45,62 +180,62 @@ function runCasesOneByOne () {
}
function runUnitTest() {
echo "=== Run unit test case ==="
echo " $TDENGINE_DIR/debug"
cd $TDENGINE_DIR/debug
print_color "$GREEN" "=== Run unit test case ==="
print_color "$GREEN" " $TDENGINE_DIR/../debug"
cd $TDENGINE_DIR/../debug
ctest -j12
echo "3.0 unit test done"
print_color "$GREEN" "3.0 unit test done"
}
function runSimCases() {
echo "=== Run sim cases ==="
print_color "$GREEN" "=== Run sim cases ==="
cd $TDENGINE_DIR/tests/script
runCasesOneByOne $TDENGINE_DIR/tests/parallel_test/cases-test.task sim
runCasesOneByOne $TDENGINE_DIR/tests/parallel_test/cases.task sim
totalSuccess=`grep 'sim success' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalSuccess" -gt "0" ]; then
echo "### Total $totalSuccess SIM test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
print_color "$GREEN" "### Total $totalSuccess SIM test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
totalFailed=`grep 'sim failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalFailed" -ne "0" ]; then
echo "### Total $totalFailed SIM test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
print_color "$RED" "### Total $totalFailed SIM test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
}
function runPythonCases() {
echo "=== Run python cases ==="
print_color "$GREEN" "=== Run python cases ==="
cd $TDENGINE_DIR/tests/parallel_test
sed -i '/compatibility.py/d' cases-test.task
sed -i '/compatibility.py/d' cases.task
# army
cd $TDENGINE_DIR/tests/army
runCasesOneByOne ../parallel_test/cases-test.task army
runCasesOneByOne ../parallel_test/cases.task army
# system-test
cd $TDENGINE_DIR/tests/system-test
runCasesOneByOne ../parallel_test/cases-test.task system-test
runCasesOneByOne ../parallel_test/cases.task system-test
# develop-test
cd $TDENGINE_DIR/tests/develop-test
runCasesOneByOne ../parallel_test/cases-test.task develop-test
runCasesOneByOne ../parallel_test/cases.task develop-test
totalSuccess=`grep 'py success' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalSuccess" -gt "0" ]; then
echo "### Total $totalSuccess python test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
print_color "$GREEN" "### Total $totalSuccess python test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
totalFailed=`grep 'py failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalFailed" -ne "0" ]; then
echo "### Total $totalFailed python test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
print_color "$RED" "### Total $totalFailed python test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
}
function runTest() {
echo "run Test"
print_color "$GREEN" "run Test"
cd $TDENGINE_DIR
[ -d sim ] && rm -rf sim
@ -119,7 +254,7 @@ function runTest() {
}
function stopTaosd {
echo "Stop taosd start"
print_color "$GREEN" "Stop taosd start"
systemctl stop taosd
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
@ -128,11 +263,11 @@ function stopTaosd {
sleep 1
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
done
echo "Stop tasod end"
print_color "$GREEN" "Stop tasod end"
}
function stopTaosadapter {
echo "Stop taosadapter"
print_color "$GREEN" "Stop taosadapter"
systemctl stop taosadapter.service
PID=`ps -ef|grep -w taosadapter | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
@ -141,18 +276,18 @@ function stopTaosadapter {
sleep 1
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
done
echo "Stop tasoadapter end"
print_color "$GREEN" "Stop tasoadapter end"
}
WORK_DIR=/root/
date >> $WORK_DIR/date.log
echo "Run ALL CI Test Cases" | tee -a $WORK_DIR/date.log
print_color "$GREEN" "Run all ci test cases" | tee -a $WORK_DIR/date.log
stopTaosd
runTest
date >> $WORK_DIR/date.log
echo "End of CI Test Cases" | tee -a $WORK_DIR/date.log
print_color "$GREEN" "End of ci test cases" | tee -a $WORK_DIR/date.log

View File

@ -17,9 +17,10 @@ function print_color() {
TDENGINE_DIR="/root/TDinternal/community"
BRANCH=""
TDENGINE_GCDA_DIR="/root/TDinternal/community/debug/"
LCOV_DIR="/usr/local/bin"
# Parse command line parameters
while getopts "hd:b:f:c:u:i:" arg; do
while getopts "hd:b:f:c:u:i:l:" arg; do
case $arg in
d)
TDENGINE_DIR=$OPTARG
@ -39,14 +40,18 @@ while getopts "hd:b:f:c:u:i:" arg; do
i)
BRANCH_BUILD=$OPTARG
;;
l)
LCOV_DIR=$OPTARG
;;
h)
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case]"
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] -l [Lcov dir]"
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
echo " -c [Test single case/all cases] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
echo " -l [Lcov bin dir] [default /usr/local/bin; eg: '/root/TDinternal/community/tests/lcov-1.14/bin' ] "
exit 0
;;
?)
@ -59,13 +64,14 @@ done
# Check if the command name is provided
if [ -z "$TDENGINE_DIR" ]; then
echo "Error: TDengine dir is required."
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] "
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] -l [Lcov dir] "
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
echo " -c [Test casingle case/all casesse] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
echo " -l [Lcov bin dir] [default /usr/local/bin; eg: '/root/TDinternal/community/tests/lcov-1.14/bin' ] "
exit 1
fi
@ -299,11 +305,18 @@ function lcovFunc {
print_color "$GREEN" "Test gcda file dir is default: /root/TDinternal/community/debug"
fi
if [ -n "$LCOV_DIR" ]; then
LCOV_DIR="$LCOV_DIR"
print_color "$GREEN" "Lcov bin dir: $LCOV_DIR "
else
print_color "$GREEN" "Lcov bin dir is default"
fi
# collect data
lcov -d "$TDENGINE_GCDA_DIR" -capture --rc lcov_branch_coverage=1 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info
$LCOV_DIR/lcov -d "$TDENGINE_GCDA_DIR" -capture --rc lcov_branch_coverage=1 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info
# remove exclude paths
lcov --remove coverage.info \
$LCOV_DIR/lcov --remove coverage.info \
'*/contrib/*' '*/test/*' '*/packaging/*' '*/taos-tools/*' '*/taosadapter/*' '*/TSZ/*' \
'*/AccessBridgeCalls.c' '*/ttszip.c' '*/dataInserter.c' '*/tlinearhash.c' '*/tsimplehash.c' '*/tsdbDiskData.c' '/*/enterprise/*' '*/docs/*' '*/sim/*'\
'*/texpr.c' '*/runUdf.c' '*/schDbg.c' '*/syncIO.c' '*/tdbOs.c' '*/pushServer.c' '*/osLz4.c'\
@ -316,7 +329,7 @@ function lcovFunc {
# generate result
echo "generate result"
lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT
$LCOV_DIR/lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT
}
@ -373,8 +386,14 @@ if [ ! -f "$COVERAGE_INFO" ]; then
exit 1
fi
if [ -n "$LCOV_DIR" ]; then
LCOV_DIR="$LCOV_DIR"
print_color "$GREEN" "Lcov bin dir: $LCOV_DIR "
else
print_color "$GREEN" "Lcov bin dir is default"
fi
# Generate local HTML reports
genhtml "$COVERAGE_INFO" --branch-coverage --function-coverage --output-directory "$OUTPUT_DIR"
$LCOV_DIR/genhtml "$COVERAGE_INFO" --branch-coverage --function-coverage --output-directory "$OUTPUT_DIR"
# Check whether the report was generated successfully
if [ $? -eq 0 ]; then

57
tests/setup-lcov.sh Normal file
View File

@ -0,0 +1,57 @@
#!/usr/bin/env bash
function usage() {
echo "Usage: $0 -v <version>"
echo "Example: $0 -v 1.14"
}
function download_lcov() {
local version=$1
local url="https://github.com/linux-test-project/lcov/releases/download/v${version}/lcov-${version}.tar.gz"
echo "Downloading lcov version ${version} from ${url}..."
curl -LO ${url}
tar -xzf lcov-${version}.tar.gz
echo "lcov version ${version} downloaded and extracted."
}
function install_lcov() {
echo -e "\nInstalling..."
local version=$1
cd lcov-${version}
sudo make uninstall && sudo make install
cd ..
echo "lcov version ${version} installed."
}
function verify_lcov() {
echo -e "\nVerify installation..."
lcov --version
}
function main() {
if [[ "$#" -ne 2 ]]; then
usage
exit 1
fi
while getopts "v:h" opt; do
case ${opt} in
v)
version=${OPTARG}
download_lcov ${version}
install_lcov ${version}
verify_lcov
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
}
main "$@"