vcs之urg脚本详解

vcs中,可以使用urg命令生成覆盖率报告,其实urg命令本身是一个sh脚本,本文对该脚本进行分析。
vcs版本:2016.06

###############################################
# env check & setting about VCS_HOME
###############################################
#set mode flag linux -> 32, mode64 -> 64; filter "-mode64"
URG_MODE_FLAG=32
URG_MODE_STR=""
if [ `${ECHO} ${URG_ARGS} | ${EGREP} -c '(^| )\-mode64'` = 1 ]; then
    URG_MODE_FLAG=64;
    URG_MODE_STR="-mode64"
elif [ `${ECHO} ${URG_ARGS} | ${EGREP} -c '(^| )\-full64'` = 1 ]; then
    URG_MODE_FLAG=64;
    URG_MODE_STR="-full64"
fi

分析:选择32位还是64位程序运行,默认32位。

# check whether the given vdb directories contain .mode64 file
isAutoAppendFull64=0;
if [ "${URG_MODE_STR}"x = "x" ]; then
    isDir=0;
    for arg in ${URG_ARGS_ARRAY}; do
        if [ `${ECHO} $arg | ${EGREP} -c '^-dir$'` = 1 ]; then
            isDir=1;
        elif [ `${ECHO} $arg | ${EGREP} -c '^-'` = 1 ]; then
            isDir=0;
        else
            if [ $isDir = 1 ]; then
                if [ -f $arg"/.mode64" ]; then
                    # if any vdb directory contains .mode64 file
                    if [ `${VCS_HOME}/bin/vcs -location -full64 | ${EGREP} -c '^Error-\[CF_SIM_KRNL64\]'` = 0 ]; then
                        # if vcs version is 64bit, add -full64 by default
                        URG_MODE_FLAG=64;
                        URG_MODE_STR="-full64"
                        isAutoAppendFull64=1;
                        if [ ` env | ${EGREP} -c '^VCS_RUNNING_REGRESSION'` = 0 ]; then
                            ${ECHO}
                            ${ECHO} "INFO : The directory  '$arg' passed to the URG command line is generated from a 64-bit simulation kernel. Hence, '-full64' is automatically added to the URG command line and URG would generate the reports with Full64 VCS installation."
                            ${ECHO}
                        fi
                    else
                        if [ ` env | ${EGREP} -c '^VCS_RUNNING_REGRESSION'` = 0 ]; then
                            ${ECHO}
                            ${ECHO} "INFO : The directory '$arg' passed to the URG command line is generated from a 64-bit simulation kernel. Hence, it is advised to install Full64 VCS, pass '-full64' to the URG command line and generate the reports. Currently, URG would generate the reports with 32-bit VCS installation."
                            ${ECHO}
                        fi
                    fi
                    break;
                fi
            fi
        fi
    done
fi

分析:vcs会读取你的-dir参数,然后判断vdb目录下是否存在.mode64文件。如果存在且你的vcs支持64bit,它会自己给你加上-full64参数,并将标记isAutoAppendFull64置1,如果你的vcs不支持64bit,那么它就会提醒你安装64bit的版本。

# set correct home(BASE_STRING), reuse vcs script, do not re-check in urg script
if [ "X$VCS_HOME" != "X" ]; then
    BASE_STRING=`${VCS_HOME}/bin/vcs -location ${URG_MODE_STR}`
elif [ "X$PIONEER_HOME" != "X" ]; then
    VCS_HOME=${PIONEER_HOME}
    export VCS_HOME
    BASE_STRING=`${PIONEER_HOME}/bin/vcs -location ${URG_MODE_STR}`
else
    ${ECHO} " Please make sure VCS_HOME is set correctly and continue.. ";
    exit 1;
fi
if [ `${ECHO} ${BASE_STRING} | ${EGREP} -c '(^| )Error\-'` = 1 ]; then #VCSMSG_EXCLUDE
    ${ECHO} "$BASE_STRING"
    ${ECHO} " Please make sure VCS_HOME is set correctly and continue.. ";
    exit 1;
fi

分析:没啥好说的,重新设置vcs命令路径(可以将32bit的vcs改成64bit的)。

# use vcs error message report
if [ -f ${BASE_STRING}/bin/vcsMsgReport ]; then #VCSMSG_EXCLUDE
    ERR_MSG_REPORT=${BASE_STRING}/bin/vcsMsgReport; #VCSMSG_EXCLUDE
else
    ${ECHO} " ERROR : Cannot find 'vcsMsgReport' script in $BASE_STRING/bin " ; #VCSMSG_EXCLUDE
    ${ECHO} " Please make sure VCS_HOME is set correctly and continue.. ";
    exit 1;
fi

分析:该脚本会调用vcsMsgReport脚本,所以要确认下vcsMsgReport是否存在。

# no longer support 64_32 mode
if [ "$URG_MODE_FLAG"x = "64_32x" ]; then
    $ERR_MSG_REPORT "URG-S-MNS"
    exit 1;
fi

分析:不再支持64_32x模式,这TM是个什么模式。

###############################################
# env check & setting about URG
###############################################
# check for bin directory
binpath="${BASE_STRING}/${BIN}";
if [ ! -d ${BASE_STRING}/${BIN} ]; then
    $ERR_MSG_REPORT "URG-S-DE" "$binpath"
    exit 1
fi

# check for urg1
CMD="${binpath}";
if [ ! -f ${BASE_STRING}/${BIN}/urg1 ]; then
    $ERR_MSG_REPORT "URG-NF" "urg1" "VCS installation"
    exit 1;
elif [ ! -x ${BASE_STRING}/${BIN}/urg1 ]; then
    $ERR_MSG_REPORT "URG-PERM" "urg1" "$CMD"
fi

分析:检查bin目录和urg1(实际使用到的urg)是否存在。

PrintID() 
{
	m=`uname -n`;
	if [ "$URG_ARCH" = "AIX" ]; then
		o=`uname -s -v`.$URG_RNAME;
	else
		o=`uname -s -r`;
	fi
	echo "machine name = $m "
	echo "machine os = $o "
	exec ${binpath}/urg1 -ID
	
	exit 0;
}

分析:打印主机的信息。

Run() 
{
    # if it contains -parallel , swtich to hierarchicalMerge 
    if [ `${ECHO} ${URG_ARGS} | ${EGREP} -c -i '(^| )\-parallel($| )'` = 1  ]; then
        PARALLEL_MODE=1;
    else
        if [ `${ECHO} ${URG_ARGS} | ${EGREP} -c -i '(^| )\-readucis($| )'` = 1  ]; then
            $ERR_MSG_REPORT URG-CVOP -readucis
        else
            exec $URG_DIAGTOOL $CMD/urg1 $URG_ARGS
        fi
    fi 
}

分析:如果urg参数含有-parallel(并行merge覆盖率)时,将标志PARALLEL_MODE置位。如果出现-readucis参数,报错。猜测这是urg早期的一个参数,现在不再支持。如果不进行并行merge,那么直接调用urg1命令,urg1的参数和urg是一样的,但是urg1不是脚本,而是一个可执行文件。

EXEC()
{
    #Invoking actual executable .. with all the options supplied.

    #set LD_LIBRARY_PATH
    if [ -x ${BASE_STRING}/lib ]; then
#        ${ECHO} "$BASE_STRING/lib"
	case $URG_ARCH in
	        HP-UX)
    		SHLIB_PATH=$BASE_STRING/lib:$SHLIB_PATH
	    	export SHLIB_PATH
    		;;
	        AIX)
    		LIBPATH=$BASE_STRING/lib:$LIBPATH
	    	export LIBPATH
    		;;
	        *)
    		LD_LIBRARY_PATH=$BASE_STRING/lib:$LD_LIBRARY_PATH
	    	export LD_LIBRARY_PATH
    		;;
    	esac
    fi

    #Run urg -id, then exit    
    if [ `${ECHO} ${URG_ARGS} | ${EGREP} -c -i '(^| )\-id'` = 1 ]; then
        URG_ARGS=`echo ${URG_ARGS} | sed -e 's/\-[Ii][Dd]//g'`;
        PrintID;
        exit 1;
    fi

    #Run normal case
    Run
}

分析:设置LD_LIBRARY_PATH。如果命令中含有-id,执行PrintID子程序。

EXEC

分析:主程序

if [ $PARALLEL_MODE = 1 ]; then
#
# Note we get hierarchicalMerge from the same directory as the urg script,
# NOT from the '$CMD' directory
#
    hierMergeDir=`dirname ${0}`
    hierMergeCMD="$hierMergeDir/hierarchicalMerge"

    if [ -x $hierMergeCMD ]; then
          perlVersion=`perl -v | sed -n '/[p|P]erl\ 4/'p | wc -l`
          if [ $perlVersion = 1 ]; then
	  	$ERR_MSG_REPORT "URG-S-PVE"
		exit 1;
          else
              if [ $isAutoAppendFull64 = 1 ]; then
                  exec $hierMergeCMD "$@" "-full64"
              else
                  exec $hierMergeCMD "$@"
              fi
          fi
    else
          if [ -f $hierMergeCMD ]; then
	  	$ERR_MSG_REPORT "URG-PERM" "hierarchicalMerge" "$hierMergeCMD"
          else
	  	$ERR_MSG_REPORT "URG-NF" "hierarchicalMerge" "$hierMergeCMD"
          fi

	  exit 1;
    fi

fi 

分析:按照这种写法风格,很明显-parallel参数在vcs早期的版本是不支持的,是后来才加上去的。主要还是调用hierarchicalMerge脚本来进行覆盖率并行merge。而且,还要求perl的版本不能是perl 4。并行merge的脚本参数和urg参数是一致的。

# Normal exit
exit 0;

分析:正常退出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值