#!/bin/bash # Local example $./run.unittest.sh :0 5.12.5 /media/sf_VMSHARE function readTestsList() { TESTS_LIST=() input=$WORKING_DIR/scripts/build/tst_names.lst while read -r line do if [ "$line" != "" ]; then TESTS_LIST+=($line) fi done < "$input" } function getSupportFunctions() { if [[ ! -d "supportscript" ]] then git clone ssh://git@dvm-linux02:7999/bl/supportscript.git fi source ./supportscript/supportscript.sh } function setup_Script_Environment() { getSupportFunctions # --- keep Test Folder folder PWD=$(pwd) WORKING_DIR=$PWD # --- keep Local Project Folder LOCAL_PROJECT_DIR=$HOME/Projects # --- setup local or server Environment DISPLAY_NO=:10.0 QT_VER="" DENALI_SQUISH=denaliSquish if [ ! -z "$RUN_FOR_LOCAL" ];then #is local DISPLAY_NO=:0 QT_VER="5.12.5" SERVER_DIR="/media/sf_VMSHARE" #Setting up Display number if [ ! -z "$1" ]; then DISPLAY_NO=$1 fi #setup Qt dir version if [ ! -z "$2" ]; then QT_VER=$2 fi #Setting up server folder if [ ! -z "$1" ]; then SERVER_DIR=$3 fi fi # --- setup common SQUISH_SERVER_PORT=4322 QT_DIR="/opt/Qt$QT_VER/5.12.5/gcc_64" SQUISH_DIR="/opt/squishqt" COCO_DIR="/opt/SquishCoco" setBuildVariables ${buildSpecs[@]} REPORT_DIR=$(getRemoteCopyAddress "DEN_UI") STATUS_REPORT=$(createStatusReport "application" $REPORT_DIR) getCommitHashes $STATUS_REPORT "ui" BUID_DIR=build BUILD_PATH=$WORKING_DIR/$BUID_DIR REPORT=Report LOG=Logs REPORT_PATH=$WORKING_DIR/$REPORT LOG_PATH=$REPORT_PATH/$LOG UNITTEST_RESULT=0 } function setup_System_Environment() { export PATH=$PATH:$QT_DIR/bin/:$QT_DIR/lib export PATH=$COCO_DIR/wrapper/bin/:$COCO_DIR/bin/:$PATH export LD_LIBRARY_PATH=$QT_DIR/lib export DISPLAY=$DISPLAY_NO } function make_Directories() { echo " ------------------------------ Create the Report output/log folder" mkdir -p $LOG_PATH echo " ------------------------------ Create the UnitTest results folder" mkdir -p $REPORT_PATH/UnitTest echo " ------------------------------ Build Application " mkdir $BUILD_PATH cd $BUILD_PATH } function clone_Repositories() { cd $WORKING_DIR echo " ------------------------------ Clone Denali " if [ -z "$RUN_FOR_LOCAL" ]; then git clone ssh://git@dvm-linux02:7999/bl/setupscript.git ./setupscript/projectsetup.sh "ui" else cp -r $LOCAL_PROJECT_DIR/application application cp -r $LOCAL_PROJECT_DIR/common common fi echo " ------------------------------ Clone the Test Suites" if [ -z "$RUN_FOR_LOCAL" ]; then git clone ssh://git@dvm-linux02:7999/ui/testsuites.git testsuites else cp -r $LOCAL_PROJECT_DIR/testsuites testsuites fi cd testsuites/tools ./setup_env.sh # Updated paths.ini sudo python3 update_paths.py --squishqt $SQUISH_DIR } function build_WithCoverage() { # ------------------------------ run qmake $QT_DIR/bin/qmake \ $WORKING_DIR/application/denali.pro \ -spec linux-g++ \ CONFIG+=qtquickcompiler \ CONFIG+="$1" \ CONFIG+=CodeCoverage \ TARGET="$1" # ------------------------------ run make /usr/bin/make \ LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4 \ 2> $LOG_PATH/build_for_"$1".err \ | tee $LOG_PATH/build_for_"$1".log # ------------------------------ clear for next build /usr/bin/make clean } function run_QtTest() { # ------------------------------ build_WithCoverage build_WithCoverage "$1" # ------------------------------ run the test ./"$1" -o -,txt \ 2> $LOG_PATH/QtTest_"$1".err \ | tee $LOG_PATH/QtTest_"$1".log # ------------------------------ check result UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) } function start_SquishServer() { echo " ------------------------------ Starting the Squish Server" $SQUISH_DIR/bin/squishserver \ --config addAUT $DENALI_SQUISH \ $WORKING_DIR/$BUID_DIR/ \ 2> $LOG_PATH/squishqtserver.err \ | tee $LOG_PATH/squishqtserver.log $SQUISH_DIR/bin/squishserver \ 1>> $LOG_PATH/squishqtserver.log \ 2>> $LOG_PATH/squishqtserver.err & # has to be & } function stop_SquishServer() { echo " ------------------------------ Stoping the Squish Server" $SQUISH_DIR/bin/squishserver --stop } function start_SquishRunner() { echo " ------------------------------ Starting tests" $SQUISH_DIR/bin/squishrunner \ --testsuite testsuites \ --exitCodeOnFail 10000 \ --reportgen html,$REPORT_PATH/UnitTest \ 2> $LOG_PATH/squishqtrunner.err \ | tee $LOG_PATH/squishqtrunner.log UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) } function run_SquishQt() { cd $BUILD_PATH # ------------------------------ cocoInstrumentation build_WithCoverage $DENALI_SQUISH cd $WORKING_DIR start_SquishRunner } function run_Tests() { for test in ${TESTS_LIST[@]};do run_QtTest $test done copy_TestsResults start_SquishServer run_SquishQt stop_SquishServer } function check_TestResults() { failedUnitTests=() targetedCoverage=100 cd $REPORT_DIR cd Coverage/index_html # In the index.html, get the Coverage section (exact pattern) # Parse everything that is from .*prg0 to the tag # In the parsed section, get everything from .*prg2"> to % percentage=$(cat index.html | awk '/\yCoverage\y/' | sed -e 's/.*prg0//' -e 's/<\/PRE>.*//' | \ sed -e 's/.*prg2">//' -e 's/%.*//' | grep -o -E '[0-9]+([.][0-9]+)') # Remove the floating point of the number percentage=${percentage%.*} echo "Code Coverage is $percentage%" # Check if the coverage percentage is less than 100% if [[ $percentage -lt $targetedCoverage ]] then echo "Coverage test failed!" echo "Coverage Test, Failed, $percentage%" >> $STATUS_REPORT else echo "Coverage test passed!" echo "Coverage Test, Passed, $percentage%" >> $STATUS_REPORT fi echo "" >> $STATUS_REPORT cd $REPORT_DIR cd UnitTest # In the unit test folder, get the all the .log files logFiles=$(find . -type f -iname "*.log") for file in ${logFiles[@]} do # Inside each log file, find the exact pattern of Totals # Find the commas and print the 4th one which is the number of failed cases failures=$(cat $file | awk '/\yTotals\y/' | awk '/,/ {print $4}' | grep -o -E '[0-9]+') skipped=$(cat $file | awk '/\yTotals\y/' | awk '/,/ {print $6}' | grep -o -E '[0-9]+') blackListed=$(cat $file | awk '/\yTotals\y/' | awk '/,/ {print $6}' | grep -o -E '[0-9]+') # Remove ./ from the file name file=${file##*/} echo "$file has $failures failed cases" # Check if the number of failures is greater than 0 if [[ $failures -gt 0 ]] then failedUnitTests+=("$file,Failed_Cases,$failures") fi # Check if the number of skipped tests is greater than 0 if [[ $skipped -gt 0 ]] then failedUnitTests+=("$file,Skipped_Cases,$skipped") fi # Check if the number of blacklisted tests is greater than 0 if [[ $blackListed -gt 0 ]] then failedUnitTests+=("$file,BlackListed_Cases,$blackListed") fi done # If the list is not empty, the test has failed if [[ ! -z ${failedUnitTests[@]} ]] then echo "Unit Test, Failed" >> $STATUS_REPORT for test in ${failedUnitTests[@]} do echo $test >> $STATUS_REPORT done else echo "Unit Test, Passed" >> $STATUS_REPORT fi # Go to data folder cd data # Check for ERROR in the results-v1.js file. # NOTE: ERROR must be all upper case, it is case sensitive local unitTestCoverage=$(cat results-v1.js | grep "ERROR") # If there are any errors, Check for the word PASS # NOTE: PASS is upper case. If there is an ERROR, there should not be a PASS if [[ ! -z $unitTestCoverage ]] then local unitTestCoveragePct=$(echo $unitTestCoverage | grep "PASS") if [[ -z $unitTestCoveragePct ]] then echo "Unit Test Coverage, Failed" >> $STATUS_REPORT fi else echo "Unit Test Coverage, Passed" >> $STATUS_REPORT fi echo "" >> $STATUS_REPORT } function copy_TestsResults() { cp $LOG_PATH/QtTest*.log $REPORT_PATH/UnitTest/ } function mergeCoverages() { echo " ------------------------------ Merging the excecution report databases" local csmes="" for test in ${TESTS_LIST[@]};do csmes+=$BUILD_PATH/$test.csmes" " done cmmerge -o $BUID_DIR/denali.csmes \ $BUILD_PATH/$DENALI_SQUISH.csmes\ $csmes \ 2> $LOG_PATH/cmmerge.err \ | tee $LOG_PATH/cmmerge.log } function importCoverage() { echo " ------------------------------ Importing the excecution report into the coverage database" local csexe="" for test in ${TESTS_LIST[@]};do cmcsexeimport \ -m $BUILD_PATH/denali.csmes \ -t $test \ -e $BUILD_PATH/$test.csexe \ 2> $LOG_PATH/cmcsexeimport_$test.err \ | tee $LOG_PATH/cmcsexeimport_$test.log done cmcsexeimport \ -m $BUILD_PATH/denali.csmes \ -t Squish \ -e $BUILD_PATH/$DENALI_SQUISH.csexe \ 2> $LOG_PATH/cmcsexeimport_squish.err \ | tee $LOG_PATH/cmcsexeimport_squish.log } function reportCoverage() { echo " ------------------------------ Generating the coverage report" cmreport \ --csmes=$BUILD_PATH/denali.csmes \ --html=$REPORT_PATH/Coverage/index \ 2> $LOG_PATH/cmreport.err \ | tee $LOG_PATH/cmreport.log } function copy_TestsResults_IntoServer() { echo " ------------------------------ Copy the reports to server" cp -rd $REPORT_PATH/* $REPORT_DIR sync;sync;sync; } function main() { setup_Script_Environment setup_System_Environment # has to be after setup_Script_Environment ran clone_Repositories make_Directories readTestsList run_Tests mergeCoverages importCoverage reportCoverage } main copy_TestsResults_IntoServer check_TestResults