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
5// Distributed under the Apache License, Version 2.0.5// Distributed under the Apache License, Version 2.0.
6// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html6// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7//7//
8
9
10#include "TestScriptingInterface.h"8#include "TestScriptingInterface.h"
11 9
12#include <QtCore/QCoreApplication>10#include <QtCore/QCoreApplication>
13#include <QtCore/QLoggingCategory>11#include <QtCore/QLoggingCategory>
12#include <QtCore/QThread>
14 13
15#include <DependencyManager.h>14#include <DependencyManager.h>
16#include <Trace.h>15#include <Trace.h>
16#include <StatTracker.h>
17
18#include "Application.h"
17 19
18TestScriptingInterface* TestScriptingInterface::getInstance() {20TestScriptingInterface* TestScriptingInterface::getInstance() {
19 static TestScriptingInterface sharedInstance;21 static TestScriptingInterface sharedInstance;
@@ -25,12 +27,51 @@ void TestScriptingInterface::quit() { · 5 unmodified lines
25}27}
26 28
27void TestScriptingInterface::waitForTextureIdle() {29void TestScriptingInterface::waitForTextureIdle() {
30 waitForCondition(0, []()->bool {
31 return (0 == gpu::Context::getTextureGPUTransferCount());
32 });
28}33}
29 34
30void TestScriptingInterface::waitForDownloadIdle() {35void TestScriptingInterface::waitForDownloadIdle() {
36 waitForCondition(0, []()->bool {
37 return (0 == ResourceCache::getLoadingRequestCount()) && (0 == ResourceCache::getPendingRequestCount());
38 });
39}
40
41void 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 });
31}46}
32 47
33void TestScriptingInterface::waitIdle() {48void TestScriptingInterface::waitIdle() {
49 // Initial wait for some incoming work
50 QThread::sleep(1);
51 waitForDownloadIdle();
52 waitForProcessingIdle();
53 waitForTextureIdle();
54}
55
56bool 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;
34}75}
35 76
36bool TestScriptingInterface::startTracing(QString logrules) {77bool TestScriptingInterface::startTracing(QString logrules) {
@@ -55,4 +96,35 @@ bool TestScriptingInterface::stopTracing(QString filename) { · 18 unmodified lines
55 tracer->stopTracing();96 tracer->stopTracing();
56 tracer->serialize(filename);97 tracer->serialize(filename);
57 return true;98 return true;
58}99}
100
101void TestScriptingInterface::clear() {
102 qApp->postLambdaEvent([] {
103 qApp->getEntities()->clear();
104 });
105}
106
107bool 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
115void TestScriptingInterface::wait(int milliseconds) {
116 QThread::msleep(milliseconds);
117}
118
119bool 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