Index: build/tst_names.lst =================================================================== diff -u --- build/tst_names.lst (revision 0) +++ build/tst_names.lst (revision f50c927937dfdf781f4f47ad07c9eac540ff01dc) @@ -0,0 +1,5 @@ +tst_logging +tst_canbus +tst_utilities +tst_acknow + Index: build/unittest.sh =================================================================== diff -u -rfc2e596a6af398a6fba75e8a9c1c261b47ecb9a6 -rf50c927937dfdf781f4f47ad07c9eac540ff01dc --- build/unittest.sh (.../unittest.sh) (revision fc2e596a6af398a6fba75e8a9c1c261b47ecb9a6) +++ build/unittest.sh (.../unittest.sh) (revision f50c927937dfdf781f4f47ad07c9eac540ff01dc) @@ -1,150 +1,280 @@ #!/bin/bash # Local example $./run.unittest.sh :0 5.12.5 /media/sf_VMSHARE -echo " ------------------------------ Definitions " -DISPLAY_NO=:10.0 -QT_VER="" -SERVER_DIR="/media/BambooProjects" +function readTestsList() { + TESTS_LIST=() -DENALI_SQUISH=denaliSquish -DENALI_QTTEST=denaliTest + input=$WORKING_DIR/scripts/build/tst_names.lst -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 + while IFS= read -r line + do + if [ "$line" != "" ]; then + TESTS_LIST+=($line) + fi + done < "$input" +} + +function setup_Script_Environment() { + + # --- keep Test Folder folder + PWD=$(pwd) + WORKING_DIR=$PWD + + # --- keep Local Project Folder + LOCAL_PROJECT_DIR=$HOME/Project + + + # --- setup local or server Environment + DISPLAY_NO=:10.0 + QT_VER="" + SERVER_DIR="/media/BambooProjects" + + 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 Qt dir version - if [ ! -z "$2" ]; then - QT_VER=$2 + # --- 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" + + REMOTE_DIR="$SERVER_DIR/DEN_UI" + REPORT_DIR="$timeStamp-BuildNo-$buildNumber-$buildPlan" + + 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 + export SQUISH_GUI_COVERAGE=1 +} + +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/ui/application.git application + else + cp -r $LOCAL_PROJECT_DIR/application application fi - #Setting up server folder - if [ ! -z "$1" ]; then - SERVER_DIR=$3 + 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 -fi +} -SQUISH_SERVER_PORT=4322 -BUID_DIR=build -QT_DIR="/opt/Qt$QT_VER/5.12.5/gcc_64" -SQUISH_DIR="/opt/squishqt" -COCO_DIR="/opt/SquishCoco" -REMOTE_DIR="$SERVER_DIR/DEN_UI" -REPORT_DIR="$timeStamp-BuildNo-$buildNumber-$buildPlan" -REPORT=Report -LOG=Logs -UNITTEST_RESULT=0 +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" -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 -export SQUISH_GUI_COVERAGE=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 -echo " ------------------------------ Create the Report output/log folder" -mkdir -p $REPORT/$LOG + # ------------------------------ clear for next build + /usr/bin/make clean +} -echo " ------------------------------ Clone Denali " -if [ -z "$RUN_FOR_LOCAL" ]; then - git clone ssh://git@dvm-linux02:7999/ui/application.git -else - cp -r ../../Project/application application -fi +function run_QtTest() { + # ------------------------------ build_WithCoverage + build_WithCoverage "$1" -echo " ------------------------------ Clone the Test Suites" -if [ -z "$RUN_FOR_LOCAL" ]; then - git clone ssh://git@dvm-linux02:7999/ui/testsuites.git -else - cp -r ../../Project/testsuites testsuites -fi + # ------------------------------ run the test + ./"$1" -o -,txt \ + 2> $LOG_PATH/QtTest_"$1".err \ + | tee $LOG_PATH/QtTest_"$1".log -echo " ------------------------------ Build Application " -mkdir $BUID_DIR -cd $BUID_DIR + # ------------------------------ check result + UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) +} -if [ -z "$RUN_QTTEST" ]; then -echo " ------------------------------ QtTest : Configure The Project for Coverage" +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 -# Coco Build - Instrumentation -# logging test should be the first one otherwise other tests will add logs to the log file content and test will fail. -$QT_DIR/bin/qmake ../application/denali.pro -spec linux-g++ CONFIG+=qtquickcompiler CONFIG+=tst_logging CONFIG+=CodeCoverage TARGET=tst_logging_$DENALI_QTTEST -/usr/bin/make LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4 1>>../$REPORT/$LOG/build_for_QtTest.log 2>>../$REPORT/$LOG/build_for_QtTest.err -/usr/bin/make clean -./tst_logging_$DENALI_QTTEST -o -,txt 1>>../$REPORT/$LOG/QtTest.log 2>>../$REPORT/$LOG/QtTest.err -UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) + $SQUISH_DIR/bin/squishserver \ + 1>> $LOG_PATH/squishqtserver.log \ + 2>> $LOG_PATH/squishqtserver.err & # has to be & +} -$QT_DIR/bin/qmake ../application/denali.pro -spec linux-g++ CONFIG+=qtquickcompiler CONFIG+=tst_canbus CONFIG+=CodeCoverage TARGET=tst_canbus_$DENALI_QTTEST -/usr/bin/make LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4 1>>../$REPORT/$LOG/build_for_QtTest.log 2>>../$REPORT/$LOG/build_for_QtTest.err -/usr/bin/make clean -./tst_canbus_$DENALI_QTTEST -o -,txt 1>>../$REPORT/$LOG/QtTest.log 2>>../$REPORT/$LOG/QtTest.err -UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) +function stop_SquishServer() { + echo " ------------------------------ Stoping the Squish Server" + $SQUISH_DIR/bin/squishserver --stop +} -$QT_DIR/bin/qmake ../application/denali.pro -spec linux-g++ CONFIG+=qtquickcompiler CONFIG+=tst_utilities CONFIG+=CodeCoverage TARGET=tst_utilities_$DENALI_QTTEST -/usr/bin/make LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4 1>>../$REPORT/$LOG/build_for_QtTest.log 2>>../$REPORT/$LOG/build_for_QtTest.err -/usr/bin/make clean -./tst_utilities_$DENALI_QTTEST -o -,txt 1>>../$REPORT/$LOG/QtTest.log 2>>../$REPORT/$LOG/QtTest.err -UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) +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 -$QT_DIR/bin/qmake ../application/denali.pro -spec linux-g++ CONFIG+=qtquickcompiler CONFIG+=tst_acknow CONFIG+=CodeCoverage TARGET=tst_acknow_$DENALI_QTTEST -/usr/bin/make LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4 1>>../$REPORT/$LOG/build_for_QtTest.log 2>>../$REPORT/$LOG/build_for_QtTest.err -/usr/bin/make clean -./tst_acknow_$DENALI_QTTEST -o -,txt 1>>../$REPORT/$LOG/QtTest.log 2>>../$REPORT/$LOG/QtTest.err -UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) + UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) +} -fi +function run_SquishQt() { + cd $BUILD_PATH + # ------------------------------ cocoInstrumentation + build_WithCoverage $DENALI_SQUISH + cd $WORKING_DIR + start_SquishRunner +} -echo " ------------------------------ Squish : Configure The Project for Coverage" -# Coco Build - Instrumentation -$QT_DIR/bin/qmake ../application/denali.pro -spec linux-g++ CONFIG+=qtquickcompiler CONFIG+=CodeCoverage TARGET=$DENALI_SQUISH -/usr/bin/make LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4 1>../$REPORT/$LOG/build_for_SquishQt.log 2>../$REPORT/$LOG/build_for_SquishQt.err -/usr/bin/make clean +function run_Tests() { + for test in ${TESTS_LIST[@]};do + run_QtTest $test + done + copy_TestsResults -cd .. + start_SquishServer + run_SquishQt + stop_SquishServer -echo " ------------------------------ Starting the Squish Server" -$SQUISH_DIR/bin/squishserver --config addAUT $DENALI_SQUISH $(pwd)/$BUID_DIR/ 1>$REPORT/$LOG/squishqtserver.log 2>$REPORT/$LOG/squishqtserver.err -$SQUISH_DIR/bin/squishserver 1>>$REPORT/$LOG/squishqtserver.log 2>>$REPORT/$LOG/squishqtserver.err & +} -echo " ------------------------------ Starting tests" -$SQUISH_DIR/bin/squishrunner --testsuite testsuites --exitCodeOnFail 10000 --reportgen html,$REPORT/UnitTest 1>$REPORT/$LOG/squishqtrunner.log 2>$REPORT/$LOG/squishqtrunner.err -UNITTEST_RESULT=$((UNITTEST_RESULT+$?)) -cp $REPORT/$LOG/QtTest.log $REPORT/UnitTest/QtTest.txt +function check_TestResults() { + if [ -z "$StopOnUnitTestError" ]; then + exit $UNITTEST_RESULT + else + exit 0 + fi +} +function copy_TestsResults() { + cp $LOG_PATH/QtTest*.log $REPORT_PATH/UnitTest/ +} -echo " ------------------------------ Merging the excecution report databases" -cmmerge -o $BUID_DIR/denali.csmes \ - $BUID_DIR/$DENALI_SQUISH.csmes \ - $BUID_DIR/tst_canbus_$DENALI_QTTEST.csmes \ - $BUID_DIR/tst_logging_$DENALI_QTTEST.csmes \ - $BUID_DIR/tst_utilities_$DENALI_QTTEST.csmes \ - $BUID_DIR/tst_acknow_$DENALI_QTTEST.csmes \ - 1>$REPORT/$LOG/cmmerge.log - 2>$REPORT/$LOG/cmmerge.err -echo " ------------------------------ Importing the excecution report into the coverage database" -cmcsexeimport -m $BUID_DIR/denali.csmes -t QtTest -e $BUID_DIR/tst_canbus_$DENALI_QTTEST.csexe 1>$REPORT/$LOG/cmcsexeimport_qttest.log 2>$REPORT/$LOG/cmcsexeimport_qttest.err -cmcsexeimport -m $BUID_DIR/denali.csmes -t QtTest -e $BUID_DIR/tst_logging_$DENALI_QTTEST.csexe 1>$REPORT/$LOG/cmcsexeimport_qttest.log 2>$REPORT/$LOG/cmcsexeimport_qttest.err -cmcsexeimport -m $BUID_DIR/denali.csmes -t QtTest -e $BUID_DIR/tst_utilities_$DENALI_QTTEST.csexe 1>$REPORT/$LOG/cmcsexeimport_qttest.log 2>$REPORT/$LOG/cmcsexeimport_qttest.err -cmcsexeimport -m $BUID_DIR/denali.csmes -t QtTest -e $BUID_DIR/tst_acknow_$DENALI_QTTEST.csexe 1>$REPORT/$LOG/cmcsexeimport_qttest.log 2>$REPORT/$LOG/cmcsexeimport_qttest.err -cmcsexeimport -m $BUID_DIR/denali.csmes -t Squish -e $BUID_DIR/$DENALI_SQUISH.csexe 1>$REPORT/$LOG/cmcsexeimport_squish.log 2>$REPORT/$LOG/cmcsexeimport_squish.err +function mergeCoverages() { + echo " ------------------------------ Merging the excecution report databases" + local csmes="" + for test in ${TESTS_LIST[@]};do + csmes+=$BUILD_PATH/$test.csmes" " + done -echo " ------------------------------ Generating the coverage report" -cmreport --csmes=$BUID_DIR/denali.csmes --html=$REPORT/Coverage/index 1>$REPORT/$LOG/cmreport.log 2>$REPORT/$LOG/cmreport.err + cmmerge -o $BUID_DIR/denali.csmes \ + $BUILD_PATH/$DENALI_SQUISH.csmes\ + $csmes \ + 2> $LOG_PATH/cmmerge.err \ + | tee $LOG_PATH/cmmerge.log +} -echo " ------------------------------ Copy the reports to server" -mkdir -p $REMOTE_DIR/$REPORT_DIR -cp -rd Report/* $REMOTE_DIR/$REPORT_DIR -sync;sync;sync; +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 QtTest \ + -e $BUILD_PATH/$test.csexe \ + 2> $LOG_PATH/cmcsexeimport_qttest.err \ + | tee $LOG_PATH/cmcsexeimport_qttest.log + done -echo " ------------------------------ Stoping the Squish Server" -$SQUISH_DIR/bin/squishserver --stop -if [ -z "$StopOnUnitTestError" ]; then - exit $UNITTEST_RESULT -else - exit 0 -fi + 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" + mkdir -p $REMOTE_DIR/$REPORT_DIR + cp -rd $REPORT_PATH/* $REMOTE_DIR/$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 +