1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QFileInfo>
#include <QJSEngine>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLibraryInfo>
#include <QProcess>
#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtTest/QtTest>
#include "test262runner.h"
#include "private/qqmlbuiltinfunctions_p.h"
#include "private/qv4arraybuffer_p.h"
#include "private/qv4globalobject_p.h"
#include "private/qv4script_p.h"
#include <stdio.h>
class tst_EcmaScriptTests : public QQmlDataTest
{
Q_OBJECT
public:
tst_EcmaScriptTests()
: QQmlDataTest(QT_QMLTEST_DATADIR, FailOnWarningsPolicy::DoNotFailOnWarnings, "test262")
{
if (!qEnvironmentVariableIsEmpty("QTEST_FUNCTION_TIMEOUT"))
return;
#ifdef Q_OS_ANDROID
qputenv("QTEST_FUNCTION_TIMEOUT", "1800000"); // 30 minutes for android
#else
qputenv("QTEST_FUNCTION_TIMEOUT", "900000"); // 15 minutes for everything else
#endif
}
private slots:
void initTestCase() final;
void cleanupTestCase();
void runInterpreted();
void runJitted();
private:
static QLoggingCategory::CategoryFilter priorFilter;
static void filterCategories(QLoggingCategory *category);
};
QLoggingCategory::CategoryFilter tst_EcmaScriptTests::priorFilter = nullptr;
static inline bool isNoise(QByteArrayView name)
{
#ifdef QT_V4_WANT_ES262_WARNINGS
return false;
#else
const QByteArrayView noisy("qt.qml.usedbeforedeclared");
return name.startsWith(noisy) && (name.size() <= noisy.size() || name[noisy.size()] == '.');
#endif
}
void tst_EcmaScriptTests::filterCategories(QLoggingCategory *category)
{
if (priorFilter)
priorFilter(category);
if (isNoise(category->categoryName())) {
category->setEnabled(QtDebugMsg, false);
category->setEnabled(QtWarningMsg, false);
}
}
void tst_EcmaScriptTests::initTestCase()
{
QQmlDataTest::initTestCase();
/* Suppress lcQmlCompiler's "qt.qml.usedbeforedeclared" warnings; we aren't in a
position to fix test262's many warnings and they flood messages so we
didn't get to see actual failures unless we passed -maxwarnings with a
huge value on the command-line (resulting in huge log output).
*/
priorFilter = QLoggingCategory::installFilter(filterCategories);
}
void tst_EcmaScriptTests::cleanupTestCase()
{
QLoggingCategory::installFilter(priorFilter);
}
void tst_EcmaScriptTests::runInterpreted()
{
Test262Runner runner(QString(), dataDirectory(), directory() + QStringLiteral("/TestExpectations"));
runner.setFlags(Test262Runner::ForceBytecode
| Test262Runner::WithTestExpectations
| Test262Runner::Parallel
| Test262Runner::Verbose);
bool result = runner.run();
QVERIFY(result);
}
void tst_EcmaScriptTests::runJitted()
{
Test262Runner runner(QString(), dataDirectory(), directory() + QStringLiteral("/TestExpectations"));
runner.setFlags(Test262Runner::ForceJIT
| Test262Runner::WithTestExpectations
| Test262Runner::Parallel
| Test262Runner::Verbose);
bool result = runner.run();
QVERIFY(result);
}
//// v RUNNER PROCESS MODE v ////
void readInput(bool &done, QString &mode, QString &testData, QString &testCasePath,
QString &harnessForModules, bool &runAsModule)
{
QTextStream in(stdin);
QString input;
while (input.isEmpty())
input = in.readLine();
QJsonDocument json = QJsonDocument::fromJson(input.toUtf8());
done = json["done"].toBool(false);
mode = json["mode"].toString();
testData = json["testData"].toString();
testCasePath = json["testCasePath"].toString();
harnessForModules = json["harnessForModules"].toString();
runAsModule = json["runAsModule"].toBool(false);
}
void printResult(QV4::ExecutionEngine &vm, const QString &mode)
{
QJsonObject result;
result.insert("mode", mode);
if (vm.hasException) {
QV4::Scope scope(&vm);
QV4::ScopedValue val(scope, vm.catchException());
result.insert("resultState", int(TestCase::State::Fails));
result.insert("resultErrorMessage", val->toQString());
} else {
result.insert("resultState", int(TestCase::State::Passes));
}
QTextStream(stdout) << QJsonDocument(result).toJson(QJsonDocument::Compact) << "\r\n";
}
void doRunnerProcess()
{
bool done = false;
QString mode;
QString testData;
QString testCasePath;
QString harnessForModules;
bool runAsModule = false;
while (!done) {
QV4::ExecutionEngine vm;
readInput(done, mode, testData, testCasePath, harnessForModules, runAsModule);
if (done)
break;
Test262Runner::executeTest(vm, testData, testCasePath, harnessForModules, runAsModule);
printResult(vm, mode);
}
}
//// ^ RUNNER PROCESS MODE ^ ////
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
if (qEnvironmentVariableIntValue("runnerProcess") == 1) {
doRunnerProcess();
} else {
tst_EcmaScriptTests tc;
QTEST_SET_MAIN_SOURCE_PATH
return QTest::qExec(&tc, argc, argv);
}
}
#include "tst_ecmascripttests.moc"
|