diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-03-26 13:42:08 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-03-27 13:52:52 +0000 |
commit | 2f0d959bfb324b7e7f0c79b26819700e66b4c44a (patch) | |
tree | d03265799e7abb459cd4d6226beaa8ff2d1cd085 /tests/auto | |
parent | fe4aaf9cc11467aa5cab0d9d1d2706b283719b0a (diff) |
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 <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 68 | ||||
-rw-r--r-- | tests/auto/qml/qml.pro | 1 | ||||
-rw-r--r-- | tests/auto/qml/qv4assembler/qv4assembler.pro | 7 | ||||
-rw-r--r-- | tests/auto/qml/qv4assembler/tst_qv4assembler.cpp | 91 |
4 files changed, 99 insertions, 68 deletions
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<QByteArray> functions; - while (!file.atEnd()) { - const QByteArray contents = file.readLine(); - QVERIFY(contents.endsWith('\n')); - QList<QByteArray> 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 <QtTest/QtTest> +#include <QtCore/qprocess.h> +#include <QtCore/qtemporaryfile.h> + +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<QByteArray> functions; + while (!file.atEnd()) { + const QByteArray contents = file.readLine(); + QVERIFY(contents.endsWith('\n')); + QList<QByteArray> 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" + |