test: add checks for void function invocations to the CI pipeline

This commit is contained in:
chenhaoran 2024-09-26 17:39:49 +08:00
parent 2f3fe7ba42
commit f0dee9d2f0
3 changed files with 121 additions and 2 deletions

64
tests/ci/check_void.sh Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
# usage: check_void.sh -c func.txt <file or directory>
# Example: check_void.sh -c func.txt -f TDengine/source
# Example: check_void.sh -c func.txt -f TDengine/source/util/src/ttimer.c
while getopts "c:f:h" arg
do
case "$arg" in
c)
func_list_file=$OPTARG
;;
f)
source_file=$OPTARG
;;
h)
echo "Usage: -c [function list file] "
echo " -f [source file or directory] "
echo " -h help"
exit 0
;;
*)
echo "Invalid option: -$OPTARG"
exit 1
;;
esac
done
# echo "funclist list configuration file: $func_list_file"
if [ ! -e "$func_list_file" ] || [ ! -r "$func_list_file" ]
then
echo "$func_list_file doesn't exist or is not readable"
fi
# cat $func_list_file
grep_string=""
separator="\|"
while read -r line
do
# echo "current function: $line"
tmp="$grep_string"
grep_string="$tmp$line$separator"
# echo "grep_string: $grep_string"
done < $func_list_file
# echo "${grep_string:1:-2}"
# echo "We are going to check (void) function invocation in $*"
grep -Rn "${grep_string:1:-2}" $source_file |grep -v "test" > ./check_void_result.txt
if [ -s ./check_void_result.txt ]
then
failed_number=$(cat ./check_void_result.txt|wc -l )
echo "Found $failed_number (void) function invocation in $source_file:"
cat ./check_void_result.txt
exit 1
else
echo "No (void) function invocation in $source_file"
exit 0
fi

View File

@ -31,7 +31,6 @@ fi
# enterprise edition # enterprise edition
INTERNAL_REPDIR=$WORKDIR/TDinternal INTERNAL_REPDIR=$WORKDIR/TDinternal
REPDIR_DEBUG=$WORKDIR/debugNoSan/
REP_MOUNT_PARAM="$INTERNAL_REPDIR:/home/TDinternal" REP_MOUNT_PARAM="$INTERNAL_REPDIR:/home/TDinternal"
@ -46,7 +45,7 @@ docker run \
--rm --ulimit core=-1 taos_test:v1.0 python3 $check_assert_scripts --rm --ulimit core=-1 taos_test:v1.0 python3 $check_assert_scripts
EOF EOF
docker run \ docker run \
-v $REP_MOUNT_PARAM \ -v "$REP_MOUNT_PARAM" \
--rm --ulimit core=-1 taos_test:v1.0 python3 $check_assert_scripts --rm --ulimit core=-1 taos_test:v1.0 python3 $check_assert_scripts
ret=$? ret=$?

View File

@ -0,0 +1,56 @@
#!/bin/bash
function usage() {
echo "$0"
echo -e "\t -d work dir"
echo -e "\t -h help"
}
while getopts "d:h" opt; do
case $opt in
d)
WORKDIR=$OPTARG
;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG"
usage
exit 0
;;
esac
done
if [ -z "$WORKDIR" ]; then
usage
exit 1
fi
# enterprise edition
INTERNAL_REPDIR=$WORKDIR/TDinternal
REP_MOUNT_PARAM="$INTERNAL_REPDIR:/home/TDinternal"
CONTAINER_TESTDIR=/home/TDinternal/community
check_assert_scripts="$CONTAINER_TESTDIR/tests/ci/check_void.sh "
func_list_file="$CONTAINER_TESTDIR/tests/ci/func.txt"
source_file_path="$CONTAINER_TESTDIR/source/"
ulimit -c unlimited
cat << EOF
docker run \
-v $REP_MOUNT_PARAM \
--rm --ulimit core=-1 taos_test:v1.0 "$check_assert_scripts" -c $func_list_file -f $source_file_path
EOF
docker run \
-v "$REP_MOUNT_PARAM" \
--rm --ulimit core=-1 taos_test:v1.0 "$check_assert_scripts" -c $func_list_file -f $source_file_path
ret=$?
exit $ret