Merge pull request #13154 from NissimHadar/perfTest_1

Added method to test namespace to save JSON object to a file.
This commit is contained in:
John Conklin II 2018-05-15 10:30:34 -07:00 committed by GitHub
commit 574a52fdbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 15 deletions

View file

@ -735,9 +735,9 @@ extern InputPluginList getInputPlugins();
extern void saveInputPluginSettings(const InputPluginList& plugins);
// Parameters used for running tests from teh command line
const QString TEST_SCRIPT_COMMAND { "--testScript" };
const QString TEST_QUIT_WHEN_FINISHED_OPTION { "quitWhenFinished" };
const QString TEST_SNAPSHOT_LOCATION_COMMAND { "--testSnapshotLocation" };
const QString TEST_SCRIPT_COMMAND{ "--testScript" };
const QString TEST_QUIT_WHEN_FINISHED_OPTION{ "quitWhenFinished" };
const QString TEST_RESULTS_LOCATION_COMMAND{ "--testResultsLocation" };
bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
const char** constArgv = const_cast<const char**>(argv);
@ -1015,22 +1015,25 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
// If the URL scheme is http(s) or ftp, then use as is, else - treat it as a local file
// This is done so as not break previous command line scripts
if (testScriptPath.left(URL_SCHEME_HTTP.length()) == URL_SCHEME_HTTP || testScriptPath.left(URL_SCHEME_FTP.length()) == URL_SCHEME_FTP) {
if (testScriptPath.left(URL_SCHEME_HTTP.length()) == URL_SCHEME_HTTP ||
testScriptPath.left(URL_SCHEME_FTP.length()) == URL_SCHEME_FTP) {
setProperty(hifi::properties::TEST, QUrl::fromUserInput(testScriptPath));
} else if (QFileInfo(testScriptPath).exists()) {
setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath));
}
// quite when finished parameter must directly follow the test script
// quite when finished parameter must directly follow the test script
if ((i + 2) < args.size() && args.at(i + 2) == TEST_QUIT_WHEN_FINISHED_OPTION) {
quitWhenFinished = true;
}
} else if (args.at(i) == TEST_SNAPSHOT_LOCATION_COMMAND) {
} else if (args.at(i) == TEST_RESULTS_LOCATION_COMMAND) {
// Set test snapshot location only if it is a writeable directory
QString pathname(args.at(i + 1));
QFileInfo fileInfo(pathname);
QString path(args.at(i + 1));
QFileInfo fileInfo(path);
if (fileInfo.isDir() && fileInfo.isWritable()) {
testSnapshotLocation = pathname;
TestScriptingInterface::getInstance()->setTestResultsLocation(path);
}
}
}
@ -7588,7 +7591,9 @@ void Application::loadAvatarBrowser() const {
void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRatio, const QString& filename) {
postLambdaEvent([notify, includeAnimated, aspectRatio, filename, this] {
// Get a screenshot and save it
QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio), filename, testSnapshotLocation);
QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio), filename,
TestScriptingInterface::getInstance()->getTestResultsLocation());
// If we're not doing an animated snapshot as well...
if (!includeAnimated) {
// Tell the dependency manager that the capture of the still snapshot has taken place.
@ -7602,7 +7607,9 @@ void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRa
void Application::takeSecondaryCameraSnapshot(const QString& filename) {
postLambdaEvent([filename, this] {
QString snapshotPath = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getSecondaryCameraScreenshot(), filename, testSnapshotLocation);
QString snapshotPath = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getSecondaryCameraScreenshot(), filename,
TestScriptingInterface::getInstance()->getTestResultsLocation());
emit DependencyManager::get<WindowScriptingInterface>()->stillSnapshotTaken(snapshotPath, true);
});
}

View file

@ -419,7 +419,6 @@ public slots:
void updateVerboseLogging();
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
private slots:
void onDesktopRootItemCreated(QQuickItem* qmlContext);
void onDesktopRootContextCreated(QQmlContext* qmlContext);
@ -753,7 +752,6 @@ private:
std::atomic<bool> _pendingIdleEvent { true };
std::atomic<bool> _pendingRenderEvent { true };
QString testSnapshotLocation;
bool quitWhenFinished { false };
};
#endif // hifi_Application_h

View file

@ -160,3 +160,29 @@ void TestScriptingInterface::clearCaches() {
qApp->reloadResourceCaches();
}
// Writes a JSON object from javascript to a file
void TestScriptingInterface::saveObject(QVariant variant, const QString& filename) {
if (_testResultsLocation.isNull()) {
return;
}
QJsonDocument jsonDocument;
jsonDocument = QJsonDocument::fromVariant(variant);
if (jsonDocument.isNull()) {
return;
}
QByteArray jsonData = jsonDocument.toJson();
// Append trailing slash if needed
if (_testResultsLocation.right(1) != "/") {
_testResultsLocation += "/";
}
QString filepath = QDir::cleanPath(_testResultsLocation + filename);
QFile file(filepath);
file.open(QFile::WriteOnly);
file.write(jsonData);
file.close();
}

View file

@ -18,6 +18,10 @@ class QScriptValue;
class TestScriptingInterface : public QObject {
Q_OBJECT
public:
void setTestResultsLocation(const QString path) { _testResultsLocation = path; }
const QString& getTestResultsLocation() { return _testResultsLocation; };
public slots:
static TestScriptingInterface* getInstance();
@ -46,7 +50,6 @@ public slots:
*/
void waitIdle();
bool waitForConnection(qint64 maxWaitMs = 10000);
void wait(int milliseconds);
@ -83,8 +86,14 @@ public slots:
*/
void clearCaches();
/**jsdoc
* Save a JSON object to a file in the test results location
*/
void saveObject(QVariant v, const QString& filename);
private:
bool waitForCondition(qint64 maxWaitMs, std::function<bool()> condition);
QString _testResultsLocation;
};
#endif // hifi_TestScriptingInterface_h
#endif // hifi_TestScriptingInterface_h