Make QTRY_IMPL() exit its loop if the test fails

Some tests, particularly the asynchronous ones that depend on the
QTRY_*() macros, have call-backs in which a test can fail, but the
macro used to test for failure only returns from the call-back, so the
test doesn't know to fail.

Make sure the QTRY_*() macro gives up if that happens, so that the
test function at least gets control back and can notice that it's
failed. Even if they don't check, they'll fail sooner, where they
might otherwise have been stuck in a loop that would never exit until
the watchdog timer shoots the test down (and Coin ends up with a
debugger back-trace and no output from later tests).

Change-Id: I622a53117de5e97d23dd22e04e5cd20361a54651
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Edward Welbourne 2020-09-08 12:10:27 +02:00
parent e926e68f50
commit 6b43b665a8

View File

@ -129,7 +129,7 @@ do {\
#endif // !QT_NO_EXCEPTIONS #endif // !QT_NO_EXCEPTIONS
// NB: not do {...} while (0) wrapped, as qt_test_i is accessed after it
#define QTRY_LOOP_IMPL(expr, timeoutValue, step) \ #define QTRY_LOOP_IMPL(expr, timeoutValue, step) \
if (!(expr)) { \ if (!(expr)) { \
QTest::qWait(0); \ QTest::qWait(0); \
@ -154,8 +154,8 @@ do {\
#define QTRY_IMPL(expr, timeout)\ #define QTRY_IMPL(expr, timeout)\
const int qt_test_step = timeout < 350 ? timeout / 7 + 1 : 50; \ const int qt_test_step = timeout < 350 ? timeout / 7 + 1 : 50; \
const int qt_test_timeoutValue = timeout; \ const int qt_test_timeoutValue = timeout; \
{ QTRY_LOOP_IMPL((expr), qt_test_timeoutValue, qt_test_step); } \ { QTRY_LOOP_IMPL(QTest::currentTestFailed() || (expr), qt_test_timeoutValue, qt_test_step); } \
QTRY_TIMEOUT_DEBUG_IMPL((expr), qt_test_timeoutValue, qt_test_step)\ QTRY_TIMEOUT_DEBUG_IMPL(QTest::currentTestFailed() || (expr), qt_test_timeoutValue, qt_test_step)
// Will try to wait for the expression to become true while allowing event processing // Will try to wait for the expression to become true while allowing event processing
#define QTRY_VERIFY_WITH_TIMEOUT(expr, timeout) \ #define QTRY_VERIFY_WITH_TIMEOUT(expr, timeout) \