coverage.sh 2.4 KB
Newer Older
Z
zhenxiang.li 已提交
1 2
#!/bin/bash

3 4
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/milvus/lib

Z
zhenxiang.li 已提交
5 6 7 8 9 10 11 12 13 14 15
LCOV_CMD="lcov"
LCOV_GEN_CMD="genhtml"

FILE_INFO_BASE="base.info"
FILE_INFO_MILVUS="server.info"
FILE_INFO_OUTPUT="output.info"
FILE_INFO_OUTPUT_NEW="output_new.info"
DIR_LCOV_OUTPUT="lcov_out"

DIR_GCNO="cmake_build"
DIR_UNITTEST="milvus/bin"
Z
update  
zhiru 已提交
16
 
Z
update  
zhiru 已提交
17 18 19 20 21
MYSQL_USER_NAME=root
MYSQL_PASSWORD=Fantast1c
MYSQL_HOST='192.168.1.194'
MYSQL_PORT='3306'

Z
update  
zhiru 已提交
22
MYSQL_DB_NAME=milvus_`date +%s%N`
Z
update  
zhiru 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35

function mysql_exc()
{
    cmd=$1
    mysql -h${MYSQL_HOST} -u${MYSQL_USER_NAME} -p${MYSQL_PASSWORD} -e "${cmd}"
    if [ $? -ne 0 ]; then
        echo "mysql $cmd run failed"
    fi
}

mysql_exc "CREATE DATABASE IF NOT EXISTS ${MYSQL_DB_NAME};"
mysql_exc "GRANT ALL PRIVILEGES ON ${MYSQL_DB_NAME}.* TO '${MYSQL_USER_NAME}'@'%';"
mysql_exc "FLUSH PRIVILEGES;"
Z
update  
zhiru 已提交
36
mysql_exc "USE ${MYSQL_DB_NAME};"
Z
zhenxiang.li 已提交
37

Z
update  
zhiru 已提交
38 39 40 41 42
MYSQL_USER_NAME=root
MYSQL_PASSWORD=Fantast1c
MYSQL_HOST='192.168.1.194'
MYSQL_PORT='3306'

Z
update  
zhiru 已提交
43
MYSQL_DB_NAME=milvus_`date +%s%N`
Z
update  
zhiru 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56

function mysql_exc()
{
    cmd=$1
    mysql -h${MYSQL_HOST} -u${MYSQL_USER_NAME} -p${MYSQL_PASSWORD} -e "${cmd}"
    if [ $? -ne 0 ]; then
        echo "mysql $cmd run failed"
    fi
}

mysql_exc "CREATE DATABASE IF NOT EXISTS ${MYSQL_DB_NAME};"
mysql_exc "GRANT ALL PRIVILEGES ON ${MYSQL_DB_NAME}.* TO '${MYSQL_USER_NAME}'@'%';"
mysql_exc "FLUSH PRIVILEGES;"
Z
update  
zhiru 已提交
57
mysql_exc "USE ${MYSQL_DB_NAME};"
Z
update  
zhiru 已提交
58

Z
zhenxiang.li 已提交
59 60 61 62 63 64 65 66
# get baseline
${LCOV_CMD} -c -i -d ${DIR_GCNO} -o "${FILE_INFO_BASE}"
if [ $? -ne 0 ]; then
    echo "gen baseline coverage run failed"
    exit -1
fi

for test in `ls ${DIR_UNITTEST}`; do
Z
update  
zhiru 已提交
67
    echo $test
Z
update  
zhiru 已提交
68 69 70
    case ${test} in
        db_test)
            # set run args for db_test
Z
update  
zhiru 已提交
71
            args="mysql://${MYSQL_USER_NAME}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DB_NAME}"
Z
update  
zhiru 已提交
72
            ;;
Z
zhenxiang.li 已提交
73
        *_test)
Z
update  
zhiru 已提交
74
            args=""
Z
update  
zhiru 已提交
75
            ;;
Z
zhenxiang.li 已提交
76
    esac
Z
update  
zhiru 已提交
77 78 79 80 81
    # run unittest
    ./${DIR_UNITTEST}/${test} "${args}"
    if [ $? -ne 0 ]; then
        echo ${DIR_UNITTEST}/${test} "run failed"
    fi
Z
zhenxiang.li 已提交
82 83
done

Z
update  
zhiru 已提交
84 85
mysql_exc "DROP DATABASE IF EXISTS ${MYSQL_DB_NAME};"

Z
zhenxiang.li 已提交
86
# gen test converage
87
${LCOV_CMD} -d ${DIR_GCNO} -o "${FILE_INFO_MILVUS}" -c
Z
zhenxiang.li 已提交
88 89 90 91 92 93 94 95 96 97
# merge coverage
${LCOV_CMD} -a ${FILE_INFO_BASE} -a ${FILE_INFO_MILVUS} -o "${FILE_INFO_OUTPUT}"

# remove third party from tracefiles
${LCOV_CMD} -r "${FILE_INFO_OUTPUT}" -o "${FILE_INFO_OUTPUT_NEW}" \
    "/usr/*" \
    "*/boost/*" \
    "*/cmake_build/*_ep-prefix/*" \

# gen html report
Z
update  
zhiru 已提交
98
${LCOV_GEN_CMD} "${FILE_INFO_OUTPUT_NEW}" --output-directory ${DIR_LCOV_OUTPUT}/