From 2f0d959bfb324b7e7f0c79b26819700e66b4c44a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 26 Mar 2018 13:42:08 +0200 Subject: Use a separate process for testing perf.map file The environment change was too fragile. If the JIT ran before the relevant test function was executed, it would set the doProfile flag to false, and never re-evaluate the environment variable. The qmljs binary is only available for private tests, and the test didn't quite fit into qjsengine anyway. Therefore a new test for the QV4Assembler class that genertes the map files is added. Change-Id: Ice0c18daaee9f0f4f0f15eba0261bcc01aa4b105 Reviewed-by: Simon Hausmann --- tests/auto/qml/qjsengine/tst_qjsengine.cpp | 68 ------------------ tests/auto/qml/qml.pro | 1 + tests/auto/qml/qv4assembler/qv4assembler.pro | 7 ++ tests/auto/qml/qv4assembler/tst_qv4assembler.cpp | 91 ++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 68 deletions(-) create mode 100644 tests/auto/qml/qv4assembler/qv4assembler.pro create mode 100644 tests/auto/qml/qv4assembler/tst_qv4assembler.cpp (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 8a017fd573..0455895c14 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -203,7 +203,6 @@ private slots: void malformedExpression(); void scriptScopes(); - void perfMapFile(); signals: void testSignal(); @@ -4145,73 +4144,6 @@ void tst_QJSEngine::scriptScopes() QCOMPARE(use.toInt(), 42); } -static const char *perfMapKey = "QV4_PROFILE_WRITE_PERF_MAP"; -static const char *jitCallKey = "QV4_JIT_CALL_THRESHOLD"; - -struct EnvironmentModifier { - const bool hasPerfMap = false; - const bool hasJitCall = false; - const QByteArray perfMap; - const QByteArray jitCall; - - EnvironmentModifier() : - hasPerfMap(qEnvironmentVariableIsSet(perfMapKey)), - hasJitCall(qEnvironmentVariableIsSet(jitCallKey)), - perfMap(qgetenv(perfMapKey)), - jitCall(qgetenv(jitCallKey)) - { - qputenv(perfMapKey, "1"); - qputenv(jitCallKey, "0"); - } - - ~EnvironmentModifier() - { - if (hasPerfMap) - qputenv(perfMapKey, perfMap); - else - qunsetenv(perfMapKey); - - if (hasJitCall) - qputenv(jitCallKey, jitCall); - else - qunsetenv(jitCallKey); - } -}; - -void tst_QJSEngine::perfMapFile() -{ -#if !defined(Q_OS_LINUX) - QSKIP("perf map files are only generated on linux"); -#else - EnvironmentModifier modifier; - Q_UNUSED(modifier); - QJSEngine engine; - QJSValue def = engine.evaluate("'use strict'; function foo() { return 42 }"); - QVERIFY(!def.isError()); - QJSValue use = engine.evaluate("'use strict'; foo()"); - QVERIFY(use.isNumber()); - QFile file(QString::fromLatin1("/tmp/perf-%1.map").arg(QCoreApplication::applicationPid())); - QVERIFY(file.exists()); - QVERIFY(file.open(QIODevice::ReadOnly)); - QList functions; - while (!file.atEnd()) { - const QByteArray contents = file.readLine(); - QVERIFY(contents.endsWith('\n')); - QList fields = contents.split(' '); - QCOMPARE(fields.length(), 3); - bool ok = false; - const qulonglong address = fields[0].toULongLong(&ok, 16); - QVERIFY(ok); - QVERIFY(address > 0); - const ulong size = fields[1].toULong(&ok, 16); - QVERIFY(ok); - QVERIFY(size > 0); - functions.append(fields[2]); - } - QVERIFY(functions.contains("foo\n")); -#endif -} - QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index 9557393a2e..3433b56864 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -69,6 +69,7 @@ PRIVATETESTS += \ qqmltranslation \ qqmlimport \ qqmlobjectmodel \ + qv4assembler \ qv4mm \ ecmascripttests \ bindingdependencyapi diff --git a/tests/auto/qml/qv4assembler/qv4assembler.pro b/tests/auto/qml/qv4assembler/qv4assembler.pro new file mode 100644 index 0000000000..afd7586ac7 --- /dev/null +++ b/tests/auto/qml/qv4assembler/qv4assembler.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TARGET = tst_qv4assembler +macos:CONFIG -= app_bundle + +SOURCES += tst_qv4assembler.cpp + +QT += qml-private testlib diff --git a/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp b/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp new file mode 100644 index 0000000000..9bd1afa256 --- /dev/null +++ b/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_QV4Assembler : public QObject +{ + Q_OBJECT + +private slots: + void perfMapFile(); +}; + +void tst_QV4Assembler::perfMapFile() +{ +#if !defined(Q_OS_LINUX) + QSKIP("perf map files are only generated on linux"); +#else + const QString qmljs = QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmljs"; + QProcess process; + + QTemporaryFile infile; + QVERIFY(infile.open()); + infile.write("'use strict'; function foo() { return 42 }; foo();"); + infile.close(); + + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + environment.insert("QV4_PROFILE_WRITE_PERF_MAP", "1"); + environment.insert("QV4_JIT_CALL_THRESHOLD", "0"); + + process.setProcessEnvironment(environment); + process.start(qmljs, QStringList({infile.fileName()})); + QVERIFY(process.waitForStarted()); + const qint64 pid = process.processId(); + QVERIFY(pid != 0); + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitCode(), 0); + + QFile file(QString::fromLatin1("/tmp/perf-%1.map").arg(pid)); + QVERIFY(file.exists()); + QVERIFY(file.open(QIODevice::ReadOnly)); + QList functions; + while (!file.atEnd()) { + const QByteArray contents = file.readLine(); + QVERIFY(contents.endsWith('\n')); + QList fields = contents.split(' '); + QCOMPARE(fields.length(), 3); + bool ok = false; + const qulonglong address = fields[0].toULongLong(&ok, 16); + QVERIFY(ok); + QVERIFY(address > 0); + const ulong size = fields[1].toULong(&ok, 16); + QVERIFY(ok); + QVERIFY(size > 0); + functions.append(fields[2]); + } + QVERIFY(functions.contains("foo\n")); +#endif +} + +QTEST_MAIN(tst_QV4Assembler) + +#include "tst_qv4assembler.moc" + -- cgit v1.2.3