Improve reliability of tst_qqmlcomponent::onDestructionLookup auto test on Windows
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 12 Aug 2013 09:55:53 +0000 (11:55 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 12 Aug 2013 11:29:27 +0000 (13:29 +0200)
The test relies on exact garbage collection, which we can't offer anymore.
But we can use the same tricks as in qqmlecmascript to improve the changes
of a successful collect significantly.

Change-Id: I7b3d7eca7a9bdb551a01a5a3da80549196c45f23
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
tests/auto/qml/qqmlcomponent/data/onDestructionLookup.qml
tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp

index a62d81c..4ca6b68 100644 (file)
@@ -25,6 +25,5 @@ Item {
 
     Component.onCompleted: {
         createObject()
-        gc()
     }
 }
index 9eeff66..408baef 100644 (file)
@@ -96,6 +96,23 @@ public slots:
     }
 };
 
+// The JavaScriptCore GC marks the C stack. To try to ensure that there is
+// no JSObject* left in stack memory by the compiler, we call this function
+// to zap some bytes of memory before calling collectGarbage().
+static void zapSomeStack()
+{
+    char *buf = (char*)alloca(4096);
+    memset(buf, 0, 4096);
+}
+
+static void gc(QQmlEngine &engine)
+{
+    zapSomeStack();
+    engine.collectGarbage();
+    QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+    QCoreApplication::processEvents();
+}
+
 class tst_qqmlcomponent : public QQmlDataTest
 {
     Q_OBJECT
@@ -377,6 +394,7 @@ void tst_qqmlcomponent::onDestructionLookup()
     QQmlEngine engine;
     QQmlComponent component(&engine, testFileUrl("onDestructionLookup.qml"));
     QScopedPointer<QObject> object(component.create());
+    gc(engine);
     QVERIFY(object != 0);
     QVERIFY(object->property("success").toBool());
 }