How to build and test Qt applications instrumented by PureCov

Last edited on

Assuming that PureCov, Qt and Squish are installed on the system, here are step by step

instructions on how to prepare, build, instrument and test a simple Qt application with Squish on Unix:

  1. The example application we are going to use:
#include <qwidget.h>
#include <qapplication.h>
#include "qtbuiltinhook.h"

int main(int argc, char \*argv\[\])
{
   QApplication app(argc, argv);

   // added for testing
   Squish::installBuiltinHook();

   QWidget w;
   w.show();
   return app.exec();
}
main.cpp

Please refer to the Squish documentation on how to set up the built-in hook.

  1. Build and instrument the application with PureCov:
purecov g++ -g -o instrumented \
   -I/home/user/projects/squish/include \
   -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I. \
   -I/usr/lib64/qt4/include/QtCore \
   -I/usr/lib64/qt4/include/QtCore \
   -I/usr/lib64/qt4/include/QtGui \
   -I/usr/lib64/qt4/include/QtGui \
   -I/usr/lib64/qt4/include \
   -L/usr/lib64/qt4/lib64 \
   -lQtGui -lQtCore \
   main.cpp

This command will build and instrument a sample application called 'instrumented'.

Note the '-I/home/user/projects/squish/include' path that points to the directory where 'qtbuiltinhook.h' header file lives.

  1. Configure the squishserver to enforce the use of the built-in hook for the sample application.

Within the <squish_install>/bin directory invoke:

./squishserver --config usesBuiltinHook instrumented
  1. Start Squish IDE, create a test suite and test cases for the 'instrumented' AUT.

When you instrument an application and run it with Squish, PureCov report will contain the coverage information of Squish libraries too. In order to avoid this, you can configure PureCov to ignore these libraries and report only coverage for your AUT related stuff. To do this simply create a .purecov file in your home directory and use 'exclude' directive to ignore Squish libraries. For example:

exclude /home/user/squish-5.1-qt42x-linux64/lib*
.purecov

The wildcard indicates that all libraries will be ignored.

In some cases the AUT needs to be run in a specific environment that defines options for, for example, PureCov. In such cases you can use a shell scrips that will set up the environment variables and start the application. For example:

#!/bin/sh

Build_Version=2014.09-RTM
Build_Date=20140818
DataDir=$Build_Version/$Build_Date
CurrentTime=$RANDOM
LogFile="$RTM_PURECOV_DIR/$DataDir/logs/$CurrentTime.log"
CountsFile="$RTM_PURECOV_DIR/$DataDir/counts/Squish_$CurrentTime.pcv"
export PURECOVOPTIONS="-counts-file=$CountsFile -logfile=$LogFile $PURECOVOPTIONS"

/home/user/test/instrumented
run_app.sh

The script sets some environment variables and starts the instrumented application. In order to use this script as AUT in Squish it should be registered with squishserver in the same way, as we registered binary in point 3 above:

./squishserver --config usesBuiltinHook run_app.sh

And finally you need to set the run_app.sh as the AUT in the Squish test suite and start recording a test.