#!/bin/bash # cmcsexeimport --csmes coco/tst_models/tst_models.csmes --title tst_models --csexe coco/tst_models/tst_models.csexe 2>coco/log/tst_models_cmcsexeimport.err | tee coco/tst_models/tst_models_cmcsexeimport.log # cmreport --csmes=tst_models/tst_models.csmes --html=Report/index 2>coco/log/tst_models_cmreport.err | tee coco/tst_models/tst_models_cmreport.log # SINGLE CASE EXEUTION WITH REPORT # └ β /opt/squish-for-qt-7.1-20230505-1514/bin/squishserver --config addAUT denaliSquish /home/denali/coco/build/denaliSquish/ # └ β /opt/squish-for-qt-7.1-20230505-1514/bin/squishserver & # └ β /opt/squish-for-qt-7.1-20230505-1514/bin/squishrunner --testsuite /home/denali/Projects/testsuites --testcase tst_service_screen --reportgen html,/home/denali/coco/report/squish ERR_TESTSUITE=10000 ERR_COCO_SERVER_CONNECTION=1001 ERR_CANBUS_SETUP=1002 JOBS=4 COCO_SERVER=192.168.10.41 QT_VER=5.15.10 QT_PATH="/opt/Qt$QT_VER/$QT_VER/gcc_64/bin" QT_TESTS_LIST_FILE=tst_names.lst #QT_TESTS_LIST_PATH=$HOME/Projects/scripts/local/ QT_TESTS_LIST_PATH=/home/ui-devtest-admin/wsUIdevtest/scripts/local/ APPLICATION_DIR=unittests TESTSUITE_DIR=testsuites WORKING_DIR=coco LOG_DIR=logs BUILD_DIR=build MERGE_DIR=merge REPORT_DIR=report DENALI_SQUISH=denaliSquish USB_DRIVE_PATH=$HOME/Desktop/usb-disk/ SD_CARD_PATH=$HOME/Desktop/sd-card/ #PROJECT_PATH=$HOME/Projects PROJECT_PATH=/home/ui-devtest-admin/wsUIdevtest WORKING_PATH=$HOME/coco REPORT_PATH=$WORKING_PATH/$REPORT_DIR LOG_PATH=$WORKING_PATH/$LOG_DIR BUILD_PATH=$WORKING_PATH/$BUILD_DIR MERGE_PATH=$WORKING_PATH/$MERGE_DIR AUT_PATH="$BUILD_PATH/$DENALI_SQUISH" APPLICATION_PATH=$PROJECT_PATH/$APPLICATION_DIR TESTSUITE_PATH=$PROJECT_PATH/$TESTSUITE_DIR VCAN_SCRIPT=$PROJECT_PATH/scripts/setupCAN/setupVCAN.sh SQUISH_SERVER=/opt/squish-for-qt-7.1-20230505-1514/bin/squishserver SQUISH_RUNNER=/opt/squish-for-qt-7.1-20230505-1514/bin/squishrunner REPORT_COCO=$REPORT_PATH/coco REPORT_SQUISH=$REPORT_PATH/squish REPORT_QTTEST=$REPORT_PATH/qttest TESTCASES_KEY="TEST_CASES=" TESTCASES_OPT="--testcase" #TESTCASES_LINE=$(grep "$TESTCASES_KEY" ~/Projects/testsuites/suite.conf) TESTCASES_LINE=$(grep "$TESTCASES_KEY" /home/ui-devtest-admin/wsUIdevtest/testsuites/suite.conf) TESTCASES_LIST=${TESTCASES_LINE:${#TESTCASES_KEY}:${#TESTCASES_LINE}} TESTCASES_ARGS="${TESTCASES_LIST// / $TESTCASES_OPT }" ##### ---------- HELPER ----------------------------------------------------------------------------------------------- function generate_alarm_mapping() { echo " ------------------------------ Generating the alarms mapping" # alarmMapping must run in the application folder. pushd $APPLICATION_PATH #./alarmMapping.sh ./alarmMapping_server.sh popd } ##### ---------- SERVER ----------------------------------------------------------------------------------------------- ##### ---------- SERVER COCO ------------------------------------------------------------------------------------------ function server_coco_check() { ping "$COCO_SERVER" -c 2 -W 1 if [ "$?" != "0" ]; then echo " ------------------------------ Coco Lic Server unreachable" exit $ERR_COCO_SERVER_CONNECTION fi } ##### ---------- SERVER SQUISH ---------------------------------------------------------------------------------------- function server_squish_start() { echo " ------------------------------ Starting the Squish Server" # configuring the server $SQUISH_SERVER \ --config addAUT $DENALI_SQUISH \ $AUT_PATH/ \ 2> $LOG_PATH/squishqtserver.err \ | tee $LOG_PATH/squishqtserver.log # running the server $SQUISH_SERVER & # must have '&' } function server_squish_run() { echo " ------------------------------ Starting tests $TESTSUITE_PATH" $SQUISH_RUNNER \ --testsuite $TESTSUITE_PATH \ --testcase $TESTCASES_ARGS \ --reportgen html,$REPORT_SQUISH \ 2> $LOG_PATH/squishqtrunner.err \ | tee $LOG_PATH/squishqtrunner.log } function server_squish_stop() { echo " ------------------------------ Stopping the Squish Server" $SQUISH_SERVER --stop } ##### ---------- INIT ------------------------------------------------------------------------------------------------- function cleanup_directories() { rm -frd $WORKING_PATH mkdir -p $WORKING_PATH mkdir -p $LOG_PATH mkdir -p $MERGE_PATH mkdir -p $REPORT_PATH mkdir -p $REPORT_COCO mkdir -p $REPORT_SQUISH mkdir -p $REPORT_QTTEST } ##### ---------- TESTS ------------------------------------------------------------------------------------------------ function tests_copy_list() { cp $QT_TESTS_LIST_PATH/$QT_TESTS_LIST_FILE $WORKING_PATH } function tests_read_list() { QT_TESTS_LIST=() echo " ------------------------------ Test List:" while read -r line do test=`echo $line | sed -e 's/^[[:space:]]*//' | sed -e '/^#/d'` if [ "$test" != "" ]; then QT_TESTS_LIST+=($test) echo " - $test" fi done < "$QT_TESTS_LIST_FILE" } function tests_setup() { if [ $($VCAN_SCRIPT) -eq 0 ];then echo " ------------------------------ Canbus setup failed" exit $ERR_CANBUS_SETUP fi } function tests_run_one() { test=$1 pushd $BUILD_PATH/$test if [ "$test" == "$DENALI_SQUISH" ]; then server_squish_start server_squish_run server_squish_stop else $BUILD_PATH/$test/$test \ 2> $LOG_PATH/$test.err \ | tee $REPORT_QTTEST/$test.report fi popd } function tests_run() { if [[ "$1" != "" ]]; then tests_run_one "$1" else for test in ${QT_TESTS_LIST[@]};do tests_run_one $test done fi } ##### ---------- COVERAGE --------------------------------------------------------------------------------------------- function coverage_build() { echo " ------------------------------ Run qmake" echo $(pwd) $QT_PATH/qmake \ $APPLICATION_PATH/denali.pro \ -spec linux-g++ \ CONFIG+="$1" \ CONFIG+=CodeCoverage \ TARGET="$BUILD_PATH/$1/$1" echo "Run make" echo "" > "$LOG_PATH/build_$1".err tail -f "$LOG_PATH/build_$1".err & /usr/bin/make \ LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j$JOBS \ 2>> "$LOG_PATH/build_$1".err \ | tee "$LOG_PATH/build_$1".log /usr/bin/make clean rm *.csmes echo " ------------------------------ Cleaned for next build" killall tail # better to get the process id to avoid killing user tail processes. } function coverage_merge() { echo " ------------------------------ Merging the excecution report databases" local csmes="" for test in ${QT_TESTS_LIST[@]};do csmes+="$BUILD_PATH/$test/$test.csmes " done cmmerge \ -o $MERGE_PATH/$MERGE_DIR.csmes \ $csmes \ 2> $LOG_PATH/$MERGE_DIR.err \ | tee $LOG_PATH/$MERGE_DIR.log } function coverage_import() { echo " ------------------------------ Importing the execution report into the coverage database" local csexe="" for test in ${QT_TESTS_LIST[@]};do echo $BUILD_PATH/$test/$test.csexe cmcsexeimport \ --csmes=$MERGE_PATH/$MERGE_DIR.csmes \ --title=$test \ --csexe=$BUILD_PATH/$test/$test.csexe \ 2> $LOG_PATH/import_$test.err \ | tee $LOG_PATH/import_$test.log done } function coverage_report() { REPORT_TYPE="html" REPORT_CMD="--html=$REPORT_COCO/index" if [[ "$1" == "csv" ]]; then REPORT_TYPE="csv" REPORT_FILE=report_out.csv REPORT_CMD="--csv-excel=$REPORT_FILE" fi echo " ------------------------------ Generating the coverage report <$REPORT_TYPE>" cmreport \ --coverage-mcdc \ --csmes=$MERGE_PATH/$MERGE_DIR.csmes \ $REPORT_CMD \ 2> $LOG_PATH/report.err \ | tee $LOG_PATH/report.log if [[ "$1" == "csv" ]]; then mv report_out.csv report/ fi echo " ------------------------------ Out file location : $(pwd)/$REPORT_COCO/$REPORT_FILE" } ##### ---------- MAIN ------------------------------------------------------------------------------------------------- server_coco_check if [ "$1" == "--build" ]; then if [[ "$2" == "" ]]; then cleanup_directories fi cd $WORKING_PATH tests_copy_list tests_read_list generate_alarm_mapping if [[ "$2" == "" ]]; then for test in ${QT_TESTS_LIST[@]};do echo "coverage build for the test $test" coverage_build $test done else echo "coverage build for the test $test" coverage_build "$2" fi fi if [ "$1" == "--run" ]; then cd $WORKING_PATH # tst_service screen needs the folders to be empty. rm -frd $USB_DRIVE_PATH rm -frd $SD_CARD_PATH tests_read_list tests_run $2 fi if [ "$1" == "--merge" ]; then cd $WORKING_PATH tests_read_list coverage_merge coverage_import fi if [ "$1" == "--report" ]; then cd $WORKING_PATH coverage_report "$2" fi if [ "$1" == "" ]; then echo "Usage:" echo "run.coco.sh [test name]" echo "--build build and instrment the application and tests from $APPLICATION_PATH" echo " [test name] Test name can be used to build only the selected test from the list." echo " If used the folder won't be cleaned/wiped." echo "--run run the tests" echo "--merge merge the test results" echo "--report create the execution report of the ran applicaiton" echo " report type html:default, csv" fi