From 2e9fc0d3f06c41f0a3d6c68d321ea56a761b25bf Mon Sep 17 00:00:00 2001
From: Liang Qi <liang.qi@qt.io>
Date: Tue, 26 Apr 2016 09:31:39 +0200
Subject: [PATCH] testlib: added env QTEST_FUNCTION_TIMEOUT for single test
 function timeout

This is a regression with 5.5, it causes some customer test functions
crash. d3d10cf2 introduced the 5 minutes timeout. The timeout could be
changed after this.

Task-number: QTBUG-52402
Change-Id: I8940bbde5004b4d888732b551274f079ddf20563
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
---
 src/testlib/qtestcase.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 46430133719..6e30a5d429b 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1455,6 +1455,7 @@ namespace QTest
     static int keyDelay = -1;
     static int mouseDelay = -1;
     static int eventDelay = -1;
+    static int timeout = -1;
     static bool noCrashHandler = false;
 
 /*! \internal
@@ -1506,6 +1507,18 @@ int Q_TESTLIB_EXPORT defaultKeyDelay()
     return keyDelay;
 }
 
+static int defaultTimeout()
+{
+    if (timeout == -1) {
+        bool ok = false;
+        timeout = qEnvironmentVariableIntValue("QTEST_FUNCTION_TIMEOUT", &ok);
+
+        if (!ok || timeout <= 0)
+            timeout = 5*60*1000;
+    }
+    return timeout;
+}
+
 static bool isValidSlot(const QMetaMethod &sl)
 {
     if (sl.access() != QMetaMethod::Private || sl.parameterCount() != 0
@@ -2119,7 +2132,7 @@ public:
 
     void beginTest() {
         QMutexLocker locker(&mutex);
-        timeout.store(5*60*1000);
+        timeout.store(defaultTimeout());
         waitCondition.wakeAll();
     }
 
-- 
GitLab