test:support TDengine/TDinternal

This commit is contained in:
happyguoxy 2025-01-03 17:05:19 +08:00
parent 78eeed3051
commit 26c1edd965
1 changed files with 147 additions and 77 deletions

View File

@ -13,16 +13,33 @@ function print_color() {
echo -e "${color}${message}${NC}"
}
# 初始化参数
TDENGINE_DIR="/root/TDinternal/community"
function printHelp() {
echo "Usage: $(basename $0) [options]"
echo
echo "Options:"
echo " -d [Project dir] Project directory (default: outermost project directory)"
echo " Options: "
echo " e.g., -d /root/TDengine or -d /root/TDinternal"
echo " -b [Build test branch] Build test branch (default: null)"
echo " Options: "
echo " e.g., -b main (pull main branch, build and install)"
echo " -s [Save cases log] Save cases log(default: notsave)"
echo " Options:"
echo " e.g., -c notsave : do not save the log "
echo " -c save : default save ci case log in Project dir/tests/ci_bak"
exit 0
}
# Initialization parameter
PROJECT_DIR=""
BRANCH=""
SAVE_LOG="notsave"
# 解析命令行参数
while getopts "hd:b:t:s:" arg; do
# Parse command line parameters
while getopts "hb:d:s:" arg; do
case $arg in
d)
TDENGINE_DIR=$OPTARG
PROJECT_DIR=$OPTARG
;;
b)
BRANCH=$OPTARG
@ -31,11 +48,7 @@ while getopts "hd:b:t:s:" arg; do
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
printHelp
;;
?)
echo "Usage: ./$(basename $0) -h"
@ -44,76 +57,142 @@ while getopts "hd:b:t:s:" arg; do
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
function get_DIR() {
today=`date +"%Y%m%d"`
if [ -z "$PROJECT_DIR" ]; then
CODE_DIR=$(dirname $0)
cd $CODE_DIR
CODE_DIR=$(pwd)
if [[ "$CODE_DIR" == *"/community/"* ]]; then
PROJECT_DIR=$(realpath ../..)
TDENGINE_DIR="$PROJECT_DIR"
BUILD_DIR="$PROJECT_DIR/debug"
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
BACKUP_DIR="$TDENGINE_DIR/tests/ci_bak"
mkdir -p "$BACKUP_DIR"
else
PROJECT_DIR=$(realpath ..)
TDENGINE_DIR="$PROJECT_DIR"
BUILD_DIR="$PROJECT_DIR/debug"
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
BACKUP_DIR="$TDENGINE_DIR/tests/ci_bak"
mkdir -p "$BACKUP_DIR"
fi
elif [[ "$PROJECT_DIR" == *"/TDinternal" ]]; then
TDENGINE_DIR="$PROJECT_DIR/community"
BUILD_DIR="$PROJECT_DIR/debug"
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
BACKUP_DIR="$TDENGINE_DIR/tests/ci_bak"
mkdir -p "$BACKUP_DIR"
elif [[ "$PROJECT_DIR" == *"/TDengine" ]]; then
TDENGINE_DIR="$PROJECT_DIR"
BUILD_DIR="$PROJECT_DIR/debug"
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
BACKUP_DIR="$TDENGINE_DIR/tests/ci_bak"
mkdir -p "$BACKUP_DIR"
fi
}
get_DIR
echo "PROJECT_DIR = $PROJECT_DIR"
echo "TDENGINE_DIR = $TDENGINE_DIR"
today=`date +"%Y%m%d"`
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 *
echo "BUILD_DIR = $BUILD_DIR"
echo "BACKUP_DIR = $BACKUP_DIR"
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
if [[ "$PROJECT_DIR" == *"/TDinternal" ]]; then
TDENGINE_DIR="$PROJECT_DIR/community"
# 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"
# pull tdinternal code
cd "$TDENGINE_DIR/../"
print_color "$GREEN" "Git pull TDinternal 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_HTTP=false -DBUILD_DEPENDENCY_TESTS=false -DBUILD_TOOLS=true -DBUILD_GEOS=true -DBUILD_TEST=true -DBUILD_CONTRIB=false ../ "
print_color "$GREEN" "$makecmd"
$makecmd
make -j 8 install
if [ "$LOCAL_COMMIT" == "$REMOTE_COMMIT" ]; then
print_color "$GREEN" "repo up-to-date"
else
print_color "$GREEN" "repo need to pull"
TDENGINE_DIR="$PROJECT_DIR"
# 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_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
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
# Check and get the branch name
if [ -n "$BRANCH" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "Build is required for this test"
@ -135,18 +214,11 @@ function runCasesOneByOne () {
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`
@ -168,8 +240,6 @@ function runCasesOneByOne () {
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`
@ -180,9 +250,9 @@ function runCasesOneByOne () {
}
function runUnitTest() {
print_color "$GREEN" "=== Run unit test case ==="
print_color "$GREEN" " $TDENGINE_DIR/../debug"
cd $TDENGINE_DIR/../debug
get_DIR
print_color "$GREEN" "cd $BUILD_DIR"
cd $BUILD_DIR
ctest -j12
print_color "$GREEN" "3.0 unit test done"
}
@ -280,7 +350,7 @@ function stopTaosadapter {
}
WORK_DIR=/root/
WORK_DIR=$TDENGINE_DIR
date >> $WORK_DIR/date.log
print_color "$GREEN" "Run all ci test cases" | tee -a $WORK_DIR/date.log