aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-03-16 17:27:38 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-03-19 07:25:24 +0000
commitd5c7229339a916b2f1f004ec4ea9de89995c003d (patch)
tree6994773be946a8f9a95c5f2cf6a1d40191955e1f /tests/auto/qml
parent61447075954aab99b3abc9c78294e5966ae3b6ce (diff)
Restore the QV4_WRITE_PERF_MAP feature
We want to be able to generate perf map files for JITed code. Task-number: QTBUG-67056 Change-Id: I56899e1dbf184083d94efe926d21fca4f9ea1e18 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 8f3011001b..8ffaa96569 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -202,6 +202,7 @@ private slots:
void malformedExpression();
void scriptScopes();
+ void perfMapFile();
signals:
void testSignal();
@@ -4130,6 +4131,73 @@ 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"