summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2013-10-16 10:49:42 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-13 10:02:10 +0100
commit43f9bb9a800b7081a48aaa0817f9ce0d453732b9 (patch)
treeee799b5c06c598633a9d0433e6cef8d4a86aeee6 /src/testlib
parent019588f30792132d9eca5dab11278547b287804e (diff)
Extend QTRY_COMPARE and QTRY_VERIFY macros
We need to fix CI, one of the most common complains is that CI machines are overloaded and some tests simply timeouts. This patch extends QTRY* macros to gather statistics. Each time a QTRY* macro is used it is waiting for the expression to be true by certain time (by default 5 sec) Next, if it failed, it waits twice as much to prove that the expression is not affected by CI machine slowness, then fails anyway. Before the next major release, we should decide if this functionality should be included, as it changes behavior slightly. The following task should be kept open until the decision has been made: Task-number: QTBUG-36036 Change-Id: I7ab5070cb7eb7d96a7289dd7b2bebf91d93090e5 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.h42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index f95a155ed9..05da33c400 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -129,34 +129,44 @@ do {\
#endif // !QT_NO_EXCEPTIONS
-// Will try to wait for the expression to become true while allowing event processing
-#define QTRY_VERIFY_WITH_TIMEOUT(__expr, __timeout) \
-do { \
- const int __step = 50; \
- const int __timeoutValue = __timeout; \
+#define QTRY_LOOP_IMPL(__expr, __timeoutValue, __step) \
if (!(__expr)) { \
QTest::qWait(0); \
} \
- for (int __i = 0; __i < __timeoutValue && !(__expr); __i+=__step) { \
+ int __i = 0; \
+ for (; __i < __timeoutValue && !(__expr); __i += __step) { \
QTest::qWait(__step); \
- } \
+ }
+
+#define QTRY_TIMEOUT_DEBUG_IMPL(__expr, __timeoutValue, __step)\
+ if (!(__expr)) { \
+ QTRY_LOOP_IMPL(__expr, (2 * __timeoutValue), __step);\
+ if (__expr) { \
+ QString msg = QString::fromUtf8("QTestLib: This test case check (\"%1\") failed because the requested timeout (%2 ms) was too short, %3 ms would have been sufficient this time."); \
+ msg = msg.arg(QString::fromUtf8(#__expr)).arg(__timeoutValue).arg(__timeoutValue + __i); \
+ QFAIL(qPrintable(msg)); \
+ } \
+ }
+
+#define QTRY_IMPL(__expr, __timeout)\
+ const int __step = 50; \
+ const int __timeoutValue = __timeout; \
+ QTRY_LOOP_IMPL(__expr, __timeoutValue, __step); \
+ QTRY_TIMEOUT_DEBUG_IMPL(__expr, __timeoutValue, __step)\
+
+// Will try to wait for the expression to become true while allowing event processing
+#define QTRY_VERIFY_WITH_TIMEOUT(__expr, __timeout) \
+do { \
+ QTRY_IMPL(__expr, __timeout);\
QVERIFY(__expr); \
} while (0)
#define QTRY_VERIFY(__expr) QTRY_VERIFY_WITH_TIMEOUT(__expr, 5000)
// Will try to wait for the comparison to become successful while allowing event processing
-
#define QTRY_COMPARE_WITH_TIMEOUT(__expr, __expected, __timeout) \
do { \
- const int __step = 50; \
- const int __timeoutValue = __timeout; \
- if ((__expr) != (__expected)) { \
- QTest::qWait(0); \
- } \
- for (int __i = 0; __i < __timeoutValue && ((__expr) != (__expected)); __i+=__step) { \
- QTest::qWait(__step); \
- } \
+ QTRY_IMPL(((__expr) == (__expected)), __timeout);\
QCOMPARE(__expr, __expected); \
} while (0)