Working on test/trace script interface

This commit is contained in:
Brad Davis 2016-12-22 11:46:40 -08:00
parent 08cfd8a40e
commit e58623bcc0
7 changed files with 109 additions and 6 deletions

View file

@ -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 <QtCore/QCoreApplication>
#include <QtCore/QLoggingCategory>
#include <QtCore/QThread>
#include <DependencyManager.h>
#include <Trace.h>
#include <StatTracker.h>
#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<StatTracker>();
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;
}
}
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<NodeList>()->getDomainHandler().isConnected();
});
}
void TestScriptingInterface::wait(int milliseconds) {
QThread::msleep(milliseconds);
}
bool TestScriptingInterface::waitForCondition(qint64 maxWaitMs, std::function<bool()> condition) {
QElapsedTimer elapsed;
elapsed.start();
while (!condition()) {
if (maxWaitMs > 0 && elapsed.elapsed() > maxWaitMs) {
return false;
}
QThread::msleep(1);
}
return condition();
}

View file

@ -10,6 +10,7 @@
#ifndef hifi_TestScriptingInterface_h
#define hifi_TestScriptingInterface_h
#include <functional>
#include <QtCore/QObject>
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<bool()> condition);
};
#endif // hifi_TestScriptingInterface_h

View file

@ -71,6 +71,11 @@ QList<QSharedPointer<Resource>> ResourceCacheSharedItems::getLoadingRequests() {
return result;
}
uint32_t ResourceCacheSharedItems::getLoadingRequestsCount() const {
Lock lock(_mutex);
return _loadingRequests.size();
}
void ResourceCacheSharedItems::removeRequest(QWeakPointer<Resource> resource) {
Lock lock(_mutex);
@ -463,6 +468,10 @@ int ResourceCache::getPendingRequestCount() {
return DependencyManager::get<ResourceCacheSharedItems>()->getPendingRequestsCount();
}
int ResourceCache::getLoadingRequestCount() {
return DependencyManager::get<ResourceCacheSharedItems>()->getLoadingRequestsCount();
}
bool ResourceCache::attemptRequest(QSharedPointer<Resource> resource) {
Q_ASSERT(!resource.isNull());
auto sharedItems = DependencyManager::get<ResourceCacheSharedItems>();

View file

@ -73,6 +73,7 @@ public:
uint32_t getPendingRequestsCount() const;
QList<QSharedPointer<Resource>> getLoadingRequests();
QSharedPointer<Resource> 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();

View file

@ -137,5 +137,4 @@ void OculusBaseDisplayPlugin::updatePresentPose() {
}
OculusBaseDisplayPlugin::~OculusBaseDisplayPlugin() {
qDebug() << "Destroying OculusBaseDisplayPlugin";
}

View file

@ -183,5 +183,4 @@ QString OculusDisplayPlugin::getPreferredAudioOutDevice() const {
}
OculusDisplayPlugin::~OculusDisplayPlugin() {
qDebug() << "Destroying OculusDisplayPlugin";
}

View file

@ -38,6 +38,7 @@
#include <shared/NetworkUtils.h>
#include <shared/FileLogger.h>
#include <shared/FileUtils.h>
#include <StatTracker.h>
#include <LogHandler.h>
#include <AssetClient.h>
@ -475,6 +476,8 @@ public:
DependencyManager::registerInheritance<EntityActionFactoryInterface, TestActionFactory>();
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
DependencyManager::registerInheritance<SpatialParentFinder, ParentFinder>();
DependencyManager::set<tracing::Tracer>();
DependencyManager::set<StatTracker>();
DependencyManager::set<AddressManager>();
DependencyManager::set<NodeList>(NodeType::Agent);
DependencyManager::set<DeferredLightingEffect>();