From e58623bcc0efccb1770c8e5d614722be46fedabe Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 22 Dec 2016 11:46:40 -0800 Subject: [PATCH] Working on test/trace script interface --- .../src/scripting/TestScriptingInterface.cpp | 78 ++++++++++++++++++- .../src/scripting/TestScriptingInterface.h | 20 ++++- libraries/networking/src/ResourceCache.cpp | 9 +++ libraries/networking/src/ResourceCache.h | 3 + .../oculus/src/OculusBaseDisplayPlugin.cpp | 1 - plugins/oculus/src/OculusDisplayPlugin.cpp | 1 - tests/render-perf/src/main.cpp | 3 + 7 files changed, 109 insertions(+), 6 deletions(-) diff --git a/interface/src/scripting/TestScriptingInterface.cpp b/interface/src/scripting/TestScriptingInterface.cpp index 1e1a4d8d0c..8bc601ec83 100644 --- a/interface/src/scripting/TestScriptingInterface.cpp +++ b/interface/src/scripting/TestScriptingInterface.cpp @@ -5,15 +5,17 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - - #include "TestScriptingInterface.h" #include #include +#include #include #include +#include + +#include "Application.h" TestScriptingInterface* TestScriptingInterface::getInstance() { static TestScriptingInterface sharedInstance; @@ -25,12 +27,51 @@ void TestScriptingInterface::quit() { } void TestScriptingInterface::waitForTextureIdle() { + waitForCondition(0, []()->bool { + return (0 == gpu::Context::getTextureGPUTransferCount()); + }); } void TestScriptingInterface::waitForDownloadIdle() { + waitForCondition(0, []()->bool { + return (0 == ResourceCache::getLoadingRequestCount()) && (0 == ResourceCache::getPendingRequestCount()); + }); +} + +void TestScriptingInterface::waitForProcessingIdle() { + auto statTracker = DependencyManager::get(); + waitForCondition(0, [statTracker]()->bool { + return (0 == statTracker->getStat("Processing").toInt() && 0 == statTracker->getStat("PendingProcessing").toInt()); + }); } void TestScriptingInterface::waitIdle() { + // Initial wait for some incoming work + QThread::sleep(1); + waitForDownloadIdle(); + waitForProcessingIdle(); + waitForTextureIdle(); +} + +bool TestScriptingInterface::loadTestScene(QString scene) { + // FIXME implement + // qApp->postLambdaEvent([isClient] { + // auto tree = qApp->getEntityClipboard(); + // tree->setIsClient(isClient); + // }); + /* + Test.setClientTree(false); + Resources.overrideUrlPrefix("atp:/", TEST_BINARY_ROOT + scene + ".atp/"); + if (!Clipboard.importEntities(TEST_SCENES_ROOT + scene + ".json")) { + return false; + } + var position = { x: 0, y: 0, z: 0 }; + var pastedEntityIDs = Clipboard.pasteEntities(position); + for (var id in pastedEntityIDs) { + print("QQQ ID imported " + id); + } + */ + return false; } bool TestScriptingInterface::startTracing(QString logrules) { @@ -55,4 +96,35 @@ bool TestScriptingInterface::stopTracing(QString filename) { tracer->stopTracing(); tracer->serialize(filename); return true; -} \ No newline at end of file +} + +void TestScriptingInterface::clear() { + qApp->postLambdaEvent([] { + qApp->getEntities()->clear(); + }); +} + +bool TestScriptingInterface::waitForConnection(qint64 maxWaitMs) { + // Wait for any previous connection to die + QThread::sleep(1); + return waitForCondition(maxWaitMs, []()->bool { + return DependencyManager::get()->getDomainHandler().isConnected(); + }); +} + +void TestScriptingInterface::wait(int milliseconds) { + QThread::msleep(milliseconds); +} + +bool TestScriptingInterface::waitForCondition(qint64 maxWaitMs, std::function condition) { + QElapsedTimer elapsed; + elapsed.start(); + while (!condition()) { + if (maxWaitMs > 0 && elapsed.elapsed() > maxWaitMs) { + return false; + } + QThread::msleep(1); + } + return condition(); +} + diff --git a/interface/src/scripting/TestScriptingInterface.h b/interface/src/scripting/TestScriptingInterface.h index 0c6ab6baaa..6307289ac2 100644 --- a/interface/src/scripting/TestScriptingInterface.h +++ b/interface/src/scripting/TestScriptingInterface.h @@ -10,6 +10,7 @@ #ifndef hifi_TestScriptingInterface_h #define hifi_TestScriptingInterface_h +#include #include class TestScriptingInterface : public QObject { @@ -34,10 +35,24 @@ public slots: void waitForDownloadIdle(); /**jsdoc - * Waits for all pending downloads and texture transfers to be complete + * Waits for all file parsing operations to be complete + */ + void waitForProcessingIdle(); + + /**jsdoc + * Waits for all pending downloads, parsing and texture transfers to be complete */ void waitIdle(); + + bool waitForConnection(qint64 maxWaitMs = 10000); + + void wait(int milliseconds); + + bool loadTestScene(QString sceneFile); + + void clear(); + /**jsdoc * Start recording Chrome compatible tracing events * logRules can be used to specify a set of logging category rules to limit what gets captured @@ -49,6 +64,9 @@ public slots: * Using a filename with a .gz extension will automatically compress the output file */ bool stopTracing(QString filename); + +private: + bool waitForCondition(qint64 maxWaitMs, std::function condition); }; #endif // hifi_TestScriptingInterface_h diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 677be8ecf5..d95c6f140f 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -71,6 +71,11 @@ QList> ResourceCacheSharedItems::getLoadingRequests() { return result; } +uint32_t ResourceCacheSharedItems::getLoadingRequestsCount() const { + Lock lock(_mutex); + return _loadingRequests.size(); +} + void ResourceCacheSharedItems::removeRequest(QWeakPointer resource) { Lock lock(_mutex); @@ -463,6 +468,10 @@ int ResourceCache::getPendingRequestCount() { return DependencyManager::get()->getPendingRequestsCount(); } +int ResourceCache::getLoadingRequestCount() { + return DependencyManager::get()->getLoadingRequestsCount(); +} + bool ResourceCache::attemptRequest(QSharedPointer resource) { Q_ASSERT(!resource.isNull()); auto sharedItems = DependencyManager::get(); diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 4231785616..03d37bc9ac 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -73,6 +73,7 @@ public: uint32_t getPendingRequestsCount() const; QList> getLoadingRequests(); QSharedPointer getHighestPendingRequest(); + uint32_t getLoadingRequestsCount() const; private: ResourceCacheSharedItems() = default; @@ -241,6 +242,8 @@ public: static int getPendingRequestCount(); + static int getLoadingRequestCount(); + ResourceCache(QObject* parent = nullptr); virtual ~ResourceCache(); diff --git a/plugins/oculus/src/OculusBaseDisplayPlugin.cpp b/plugins/oculus/src/OculusBaseDisplayPlugin.cpp index 5db5840f43..26906ef2fb 100644 --- a/plugins/oculus/src/OculusBaseDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusBaseDisplayPlugin.cpp @@ -137,5 +137,4 @@ void OculusBaseDisplayPlugin::updatePresentPose() { } OculusBaseDisplayPlugin::~OculusBaseDisplayPlugin() { - qDebug() << "Destroying OculusBaseDisplayPlugin"; } diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index 2e9f74a0e5..88ca02edc2 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -183,5 +183,4 @@ QString OculusDisplayPlugin::getPreferredAudioOutDevice() const { } OculusDisplayPlugin::~OculusDisplayPlugin() { - qDebug() << "Destroying OculusDisplayPlugin"; } diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index bd731564e7..31bb13f4d0 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -475,6 +476,8 @@ public: DependencyManager::registerInheritance(); DependencyManager::registerInheritance(); DependencyManager::registerInheritance(); + DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(NodeType::Agent); DependencyManager::set();