Qt Autotest Environment: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Convert ExpressionEngine links)
(Add link to "Common problems" section in "Writing Unit Tests".)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 


[[Category:Developing_Qt::Guidelines]]
[[Category:Developing_Qt::Guidelines]]
[toc align_right="yes" depth="3"]


= Qt Autotest Environment =


== Introduction ==
== Introduction ==
Line 16: Line 14:
=== Qt build ===
=== Qt build ===


Qt autotests require that Qt be built for testing itself. This will make some additional symbols be exported and some additional code be built to support it. To enable such a build, when you configure Qt, remember to pass the option <code>-developer-build</code>:
Qt autotests require that Qt be built for testing itself. This will make some additional symbols be exported and some additional code be built to support it. To enable such a build, when you configure Qt, remember to pass the option '''-developer-build''':


<code>
<code>
Line 24: Line 22:
The main changes to the Qt build are:
The main changes to the Qt build are:


* <code>QT_INTERNAL_BUILD</code> is set, so code can #ifdef to determine whether to enable the additional code
* '''QT_INTERNAL_BUILD''' is set, so code can #ifdef to determine whether to enable the additional code
* <code>Q_AUTOTEST_EXPORT</code> is defined to exporting the symbols
* '''Q_AUTOTEST_EXPORT''' is defined to exporting the symbols
 
Note also that Qt tests have only been tested with a non-installing Qt (the <code>-prefix $PWD</code> option above). The test project files override the <code>make install</code> target, so they are not installable. And Qt doesn't work at all if it's not at its installation path.


h3. Shadow builds
Note also that Qt tests have only been tested with a non-installing Qt (the '''-prefix $PWD''' option above). The test project files override the '''make install''' target, so they are not installable. And Qt doesn't work at all if it's not at its installation path.


=== Shadow builds ===
Don't use shadow builds.
Don't use shadow builds.


Some tests assume that their source and build directory are the same directory in order to find testdata.
Some tests assume that their source and build directory are the same directory in order to find testdata.


Reference: [http://qt.gitorious.org/qt/qt/blobs/d6127efabb74e2004608f53d0be3b7c4a6df768d/tests/auto/qsslkey/tst_qsslkey.cpp#line107 qsslkey uses QCoreApplication::applicationDirPath() to look for testdata which lives in the source tree]
Reference: [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/qsslkey/tst_qsslkey.cpp#line107 qsslkey uses QCoreApplication::applicationDirPath() to look for testdata which lives in the source tree]
 
h3. Working directory


=== Working directory ===
When the test is invoked, the working directory must be the directory containing the test's source (and binary, due to "no shadow builds" rule).
When the test is invoked, the working directory must be the directory containing the test's source (and binary, due to "no shadow builds" rule).


For tests with multiple subdirectories, use the top level directory for that test (e.g. for the qprocess test, run from <code>tests/auto/qprocess</code>, even though the .pro file for the test is at <code>tests/auto/qprocess/test</code>).
For tests with multiple subdirectories, use the top level directory for that test (e.g. for the qprocess test, run from '''tests/auto/qprocess''', even though the .pro file for the test is at '''tests/auto/qprocess/test''').


Some tests read testdata from files found relative to the current working directory.
Some tests read testdata from files found relative to the current working directory.


Reference: "qscriptv8testsuite finds testdata relative to QDir(".[http://qt.gitorious.org/qt/qt/blobs/d6127efabb74e2004608f53d0be3b7c4a6df768d/tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp#line196 )]
Reference: [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp qscriptv8testsuite finds testdata relative to QDir]


h3. Environment variables
=== Environment variables ===
QTDIR: path to Qt build directory. [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/bic/tst_bic.cpp bic reads headers from $QTDIR/include]


QTDIR: path to Qt build directory. [http://qt.gitorious.org/qt/qt/blobs/d6127efabb74e2004608f53d0be3b7c4a6df768d/tests/auto/bic/tst_bic.cpp#line223 bic reads headers from $QTDIR/include]
QTSRCDIR: path to Qt source directory (same as QTDIR due to no shadow builds rule). Strictly speaking, does not seem required, as all tests which use this fall back on QTDIR, which is correct anyway due to "no shadow builds" rule. [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp xmlpatternsxqts adds $QTSRCDIR/include to INCLUDEPATH]


QTSRCDIR: path to Qt source directory (same as QTDIR due to no shadow builds rule). Strictly speaking, does not seem required, as all tests which use this fall back on QTDIR, which is correct anyway due to "no shadow builds" rule. [http://qt.gitorious.org/qt/qt/blobs/d6127efabb74e2004608f53d0be3b7c4a6df768d/tests/auto/xmlpatternsxqts/test/test.pro#line14 xmlpatternsxqts adds $QTSRCDIR/include to INCLUDEPATH]
PATH: must include bin directory for the tested Qt, '''in front of any bin directory from other Qt versions'''. [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/rcc/tst_rcc.cpp rcc assumes <nowiki><code></nowiki> rcc' is in PATH]
 
PATH: must include bin directory for the tested Qt, '''in front of any bin directory from other Qt versions'''. [http://qt.gitorious.org/qt/qt/blobs/d6127efabb74e2004608f53d0be3b7c4a6df768d/tests/auto/rcc/tst_rcc.cpp#line129 rcc assumes <code>rcc' is in PATH]
 
h3. Network tests


=== Network tests ===
In /etc/hosts (Unix) or windir32\drivers\etc\hosts (Windows), set up some hostnames to point to a server running particular test services.
In /etc/hosts (Unix) or windir32\drivers\etc\hosts (Windows), set up some hostnames to point to a server running particular test services.


The hostnames to be set up are:
The hostnames to be set up are:


<code>qt-test-server</code> and <code>qt-test-server.qt-test-net</code>- [http://qt.gitorious.org/qt/qt/blobs/d6127efabb74e2004608f53d0be3b7c4a6df768d/tests/auto/network-settings.h#line48 network-settings.h]
'''qt-test-server''' and '''qt-test-server.qt-test-net'''- [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/network-settings.h network-settings.h]


<code>qt-test-server.troll.no</code> - [http://qt.gitorious.org/qt/qt/blobs/ba5fb9f05c891feac8ab69006189de1aaafebc18/tests/auto/q3socket/tst_qsocket.cpp#line127 q3socket]
'''qt-test-server.troll.no''' - [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/q3socket/tst_qsocket.cpp q3socket]


The network test server can be set up by following the <code>qtqa/sysadmin.git</code> repository on gitorious; see [http://gitorious.org/qtqa/sysadmin/blobs/master/README.network_test_server.txt instructions here]
The network test server can be set up by following the '''qtqa/sysadmin.git''' repository on gitorious; see [http://code.qt.io/cgit/qtqa/sysadmin.git/tree/README.network_test_server.txt instructions here]


=== DBus tests ===
=== DBus tests ===


The DBus tests require a dbus session bus to be running.
The DBus tests require a dbus session bus to be running.
=== Common problems with test machine setup ===
Please see [https://wiki.qt.io/Writing_Unit_Tests#Common_problems_with_test_machine_setup here] for problems that can appear when running the auto tests.

Revision as of 12:33, 7 March 2017


Introduction

Many Qt autotests require some environment setup to work correctly. This page is an attempt to document precisely what this environment is.

Note that this is "best-effort" documentation. It should not be interpreted as coding standards for autotests, in fact quite the opposite - many of the requirements here are due to a lack of coding standards. Some of these environmental requirements can be considered problems with the autotests which should be fixed.

The information may become outdated as autotests change. The current version of this page was written for Qt 4.5 and 4.6.

Qt build

Qt autotests require that Qt be built for testing itself. This will make some additional symbols be exported and some additional code be built to support it. To enable such a build, when you configure Qt, remember to pass the option -developer-build:

 ./configure -developer-build -prefix $PWD

The main changes to the Qt build are:

  • QT_INTERNAL_BUILD is set, so code can #ifdef to determine whether to enable the additional code
  • Q_AUTOTEST_EXPORT is defined to exporting the symbols

Note also that Qt tests have only been tested with a non-installing Qt (the -prefix $PWD option above). The test project files override the make install target, so they are not installable. And Qt doesn't work at all if it's not at its installation path.

Shadow builds

Don't use shadow builds.

Some tests assume that their source and build directory are the same directory in order to find testdata.

Reference: qsslkey uses QCoreApplication::applicationDirPath() to look for testdata which lives in the source tree

Working directory

When the test is invoked, the working directory must be the directory containing the test's source (and binary, due to "no shadow builds" rule).

For tests with multiple subdirectories, use the top level directory for that test (e.g. for the qprocess test, run from tests/auto/qprocess, even though the .pro file for the test is at tests/auto/qprocess/test).

Some tests read testdata from files found relative to the current working directory.

Reference: qscriptv8testsuite finds testdata relative to QDir

Environment variables

QTDIR: path to Qt build directory. bic reads headers from $QTDIR/include

QTSRCDIR: path to Qt source directory (same as QTDIR due to no shadow builds rule). Strictly speaking, does not seem required, as all tests which use this fall back on QTDIR, which is correct anyway due to "no shadow builds" rule. xmlpatternsxqts adds $QTSRCDIR/include to INCLUDEPATH

PATH: must include bin directory for the tested Qt, in front of any bin directory from other Qt versions. rcc assumes <code> rcc' is in PATH

Network tests

In /etc/hosts (Unix) or windir32\drivers\etc\hosts (Windows), set up some hostnames to point to a server running particular test services.

The hostnames to be set up are:

qt-test-server and qt-test-server.qt-test-net- network-settings.h

qt-test-server.troll.no - q3socket

The network test server can be set up by following the qtqa/sysadmin.git repository on gitorious; see instructions here

DBus tests

The DBus tests require a dbus session bus to be running.

Common problems with test machine setup

Please see here for problems that can appear when running the auto tests.