Testing the Psi world
During a couple of past days I’ve been actively working on creating a small sets of helper scripts and files to aid creation of unit tests. In theory, they should help us to fight bugs aggressively and to help valgrindizing individual bits of code, which means fewer bugs and better performance.
But how to actually use it? The rest of the post will serve as the first bits on topic and as a reminder to myself. Be careful, it contains some techie stuff.
There was some background thinking, and we assumed that the best structure of directories would be like this: each directory with some C++ code in it would contain subdirectory named unittest, and there would be a base test directory, named unittest too, and it contains some helper scripts and files.

In order to run all available tests simple make check should be enough, and you’ll instantly see if something gone wrong.
There’s also a make valgrind target in order to run valgrind on test subjects (also as an added bonus, you could make valgrind even the Psi itself, and it would use the usual suppression file, and other useful tracing options). And if you get too many errors (and leaks, which sadly happen quite frequently with X11), make valgrind_supp to the rescue! It will generate suppressions that you can put into psi/unittest/valgrind.supp for later reuse.
In my grand plan all code (even Iris) should be tested, but as I’m probably the only one who’ll be working on it, it won’t happen very soon.
But if someone occasionally volunteer into writing some tests, here’s a small overview of the process:
- Create unittest directory somewhere, and add relative path to it into psi/unittest/tests.txt, then run psi/unittest/update.rb script to update helper files (I hate duplicating efforts).
Create a qmake project file in that directory, which should follow this template:
# unittest helpers TARGET = testname CONFIG += unittest # this way you'll save a bunch lines of code TESTBASEDIR = ../../unittest # relative path to the base 'psi/unittest' directory include($$TESTBASEDIR/unittest.pri) # test suite's source SOURCES += testname.cppCreate a .cpp source file, according to the QTestLib Tutorial, and you’re set.
- Now just run make check to compile and run the test. Simple.