Search code examples
c++qtqt4.8qobjectqtestlib

QTEST_MAIN doesn't use provided Testclass


I want to do a performance test on threads and their interactions (e.g. shared data). To achieve this, I tried the Qt provided Tutorial for Benchmarks, which lead me to write the following code.

The Benchmark-Class:

class Bm : public QObject
{
     Q_OBJECT
private slots:
    void Benchmark_1()
    {
        bm_1 bm;
        QBENCHMARK
        {
            pool.start(&bm);         //pool is a QThreadpool
            pool.start(&bm);
            pool.waitForDone();
        }

    }
    void Benchmark_2()
    {
        bm_1 b_1; bm_2 b_2;
        QBENCHMARK
        {
            pool.start(&b_1);
            pool.start(&b_2);
            pool.waitForDone();
        }
    }
};

The class that contains the task for the thread:

class bm_1 : public QRunnable         //bm_2 looks just like bm_1
{
public:
    void test_1();
    void run()
    {
        test_1();
    }
};

The main-function gets replaced by a QTest-macro:

QTEST_MAIN(Bm)

QTEST_MAIN returns 0, which means, according to the Qt-documentation, there is nothing to be tested. If I now try to use the debugger, to get a glimp of what might go wrong, I get two startup-errors:

The Gdb-process was terminated(0)

and

During startup program exited with code 0xc0000138

What did I do wrong?

I need QTest (and not e.g. ellapsedTimer) to measure the performance without OS and adobe updater pollution. It's a company owned laptop. I checked my includes, and I even reinstalled Qt.


Solution

  • I found my wrong doing. The class that contained my benchmark was called Bm, the files it was implemented in were called benchmar.cppand benchmark.h. Changing the name of the class to benchmark resolved the problem.

    Why that is i have no clue and me reading the QObject 4.8 dokumentation didn't get me any further. Soo... one more quirk to live with.

    Whoohey!