History

Working on test/trace script interface

Brad Davis committed 9 years ago

Commit e58623b1 parent 08cfd8a7 files · +109 −6Browse files

Showing the changes to interface/src/scripting/TestScriptingInterface.cpp (1 of 7 files). Show all

Unified · Split

interface/src/scripting/TestScriptingInterface.cpp+75−3
@@ -5,15 +5,17 @@ · 4 unmodified lines
55 // Distributed under the Apache License, Version 2.0.
66 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
77 //
8−
9−
108 #include "TestScriptingInterface.h"
119
1210 #include <QtCore/QCoreApplication>
1311 #include <QtCore/QLoggingCategory>
12+#include <QtCore/QThread>
1413
1514 #include <DependencyManager.h>
1615 #include <Trace.h>
16+#include <StatTracker.h>
17+
18+#include "Application.h"
1719
1820 TestScriptingInterface* TestScriptingInterface::getInstance() {
1921 static TestScriptingInterface sharedInstance;
@@ -25,12 +27,51 @@ void TestScriptingInterface::quit() { · 5 unmodified lines
2527 }
2628
2729 void TestScriptingInterface::waitForTextureIdle() {
30+ waitForCondition(0, []()->bool {
31+ return (0 == gpu::Context::getTextureGPUTransferCount());
32+ });
2833 }
2934
3035 void TestScriptingInterface::waitForDownloadIdle() {
36+ waitForCondition(0, []()->bool {
37+ return (0 == ResourceCache::getLoadingRequestCount()) && (0 == ResourceCache::getPendingRequestCount());
38+ });
39+}
40+
41+void TestScriptingInterface::waitForProcessingIdle() {
42+ auto statTracker = DependencyManager::get<StatTracker>();
43+ waitForCondition(0, [statTracker]()->bool {
44+ return (0 == statTracker->getStat("Processing").toInt() && 0 == statTracker->getStat("PendingProcessing").toInt());
45+ });
3146 }
3247
3348 void TestScriptingInterface::waitIdle() {
49+ // Initial wait for some incoming work
50+ QThread::sleep(1);
51+ waitForDownloadIdle();
52+ waitForProcessingIdle();
53+ waitForTextureIdle();
54+}
55+
56+bool TestScriptingInterface::loadTestScene(QString scene) {
57+ // FIXME implement
58+ // qApp->postLambdaEvent([isClient] {
59+ // auto tree = qApp->getEntityClipboard();
60+ // tree->setIsClient(isClient);
61+ // });
62+ /*
63+ Test.setClientTree(false);
64+ Resources.overrideUrlPrefix("atp:/", TEST_BINARY_ROOT + scene + ".atp/");
65+ if (!Clipboard.importEntities(TEST_SCENES_ROOT + scene + ".json")) {
66+ return false;
67+ }
68+ var position = { x: 0, y: 0, z: 0 };
69+ var pastedEntityIDs = Clipboard.pasteEntities(position);
70+ for (var id in pastedEntityIDs) {
71+ print("QQQ ID imported " + id);
72+ }
73+ */
74+ return false;
3475 }
3576
3677 bool TestScriptingInterface::startTracing(QString logrules) {
@@ -55,4 +96,35 @@ bool TestScriptingInterface::stopTracing(QString filename) { · 18 unmodified lines
5596 tracer->stopTracing();
5697 tracer->serialize(filename);
5798 return true;
58−}
99+}
100+
101+void TestScriptingInterface::clear() {
102+ qApp->postLambdaEvent([] {
103+ qApp->getEntities()->clear();
104+ });
105+}
106+
107+bool TestScriptingInterface::waitForConnection(qint64 maxWaitMs) {
108+ // Wait for any previous connection to die
109+ QThread::sleep(1);
110+ return waitForCondition(maxWaitMs, []()->bool {
111+ return DependencyManager::get<NodeList>()->getDomainHandler().isConnected();
112+ });
113+}
114+
115+void TestScriptingInterface::wait(int milliseconds) {
116+ QThread::msleep(milliseconds);
117+}
118+
119+bool TestScriptingInterface::waitForCondition(qint64 maxWaitMs, std::function<bool()> condition) {
120+ QElapsedTimer elapsed;
121+ elapsed.start();
122+ while (!condition()) {
123+ if (maxWaitMs > 0 && elapsed.elapsed() > maxWaitMs) {
124+ return false;
125+ }
126+ QThread::msleep(1);
127+ }
128+ return condition();
129+}
130+