-
Tor Arne Vestbø authored
It's only supposed to be included by clients of the library, and confuses qmake's dependency resolution into thinking the header-only features such as qtestkeyboard.h and qtestmouse.h are dependencies of this source file. Change-Id: I5fe73b752c1c491ee0088bced77f997696d96c62 Reviewed-by:
Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by:
Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com> Reviewed-by:
Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
10bf53ae
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtTest module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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 http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtestblacklist_p.h"
#include "qtestresult_p.h"
#include <QtTest/qtestcase.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qfile.h>
#include <QtCore/qset.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qvariant.h>
#include <QtCore/QSysInfo>
#include <set>
QT_BEGIN_NAMESPACE
/*
The file format is simply a grouped listing of keywords
Ungrouped entries at the beginning apply to the whole testcase
Groups define testfunctions or specific test data to ignore.
After the groups come a list of entries (one per line) that define
for which platform/os combination to ignore the test result.
All keys in a single line have to match to blacklist the test.
mac
[testFunction]
linux
windows 64bit
[testfunction2:testData]
msvc
The known keys are listed below:
*/
static QSet<QByteArray> keywords()
{
// this list can be extended with new keywords as required
QSet<QByteArray> set = QSet<QByteArray>()
<< "*"
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
#ifdef Q_OS_LINUX
<< "linux"
#endif
#ifdef Q_OS_OSX
<< "osx"
#endif
#ifdef Q_OS_WIN
<< "windows"
#endif
#ifdef Q_OS_IOS
<< "ios"
#endif
#ifdef Q_OS_ANDROID
<< "android"
#endif
#ifdef Q_OS_QNX
<< "qnx"
#endif
#ifdef Q_OS_WINRT
<< "winrt"
#endif
#ifdef Q_OS_WINCE
<< "wince"
#endif
#if QT_POINTER_SIZE == 8
<< "64bit"
#else
<< "32bit"
#endif
#ifdef Q_CC_GNU
<< "gcc"
#endif
#ifdef Q_CC_CLANG
<< "clang"
#endif
#ifdef Q_CC_MSVC
<< "msvc"
#ifdef _MSC_VER
#if _MSC_VER == 1900
<< "msvc-2015"
#elif _MSC_VER == 1800
<< "msvc-2013"
#elif _MSC_VER == 1700
<< "msvc-2012"
#elif _MSC_VER == 1600
<< "msvc-2010"
#endif
#endif
#endif
#ifdef Q_AUTOTEST_EXPORT
<< "developer-build"
#endif
;
QCoreApplication *app = QCoreApplication::instance();
if (app) {
const QVariant platformName = app->property("platformName");
if (platformName.isValid())
set << platformName.toByteArray();
}
return set;
}
static bool checkCondition(const QByteArray &condition)
{
static QSet<QByteArray> matchedConditions = keywords();
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
QList<QByteArray> conds = condition.split(' ');
QByteArray distributionName = QSysInfo::productType().toLower().toUtf8();
QByteArray distributionRelease = QSysInfo::productVersion().toLower().toUtf8();
if (!distributionName.isEmpty()) {
if (matchedConditions.find(distributionName) == matchedConditions.end())
matchedConditions.insert(distributionName);
matchedConditions.insert(distributionName + "-" + distributionRelease);
}
for (int i = 0; i < conds.size(); ++i) {
QByteArray c = conds.at(i);
bool result = c.startsWith('!');
if (result)
c = c.mid(1);
result ^= matchedConditions.contains(c);
if (!result)
return false;
}
return true;
}
static bool ignoreAll = false;
static std::set<QByteArray> *ignoredTests = 0;
static std::set<QByteArray> *gpuFeatures = 0;
Q_TESTLIB_EXPORT std::set<QByteArray> *(*qgpu_features_ptr)(const QString &) = 0;
static bool isGPUTestBlacklisted(const char *slot, const char *data = 0)
{
const QByteArray disableKey = QByteArrayLiteral("disable_") + QByteArray(slot);
if (gpuFeatures->find(disableKey) != gpuFeatures->end()) {
QByteArray msg = QByteArrayLiteral("Skipped due to GPU blacklist: ") + disableKey;
if (data)
msg += ':' + QByteArray(data);
QTest::qSkip(msg.constData(), __FILE__, __LINE__);
return true;
}
return false;
}
namespace QTestPrivate {
void parseBlackList()
{
QString filename = QTest::qFindTestData(QStringLiteral("BLACKLIST"));
if (filename.isEmpty())
return;
QFile ignored(filename);
if (!ignored.open(QIODevice::ReadOnly))
return;
QByteArray function;
while (!ignored.atEnd()) {
QByteArray line = ignored.readLine().simplified();
if (line.isEmpty() || line.startsWith('#'))
continue;
if (line.startsWith('[')) {
function = line.mid(1, line.length() - 2);
continue;
}
bool condition = checkCondition(line);
if (condition) {
if (!function.size()) {
ignoreAll = true;
} else {
if (!ignoredTests)
ignoredTests = new std::set<QByteArray>;
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
ignoredTests->insert(function);
}
}
}
}
void parseGpuBlackList()
{
if (!qgpu_features_ptr)
return;
QString filename = QTest::qFindTestData(QStringLiteral("GPU_BLACKLIST"));
if (filename.isEmpty())
return;
if (!gpuFeatures)
gpuFeatures = qgpu_features_ptr(filename);
}
void checkBlackLists(const char *slot, const char *data)
{
bool ignore = ignoreAll;
if (!ignore && ignoredTests) {
QByteArray s = slot;
ignore = (ignoredTests->find(s) != ignoredTests->end());
if (!ignore && data) {
s += ':';
s += data;
ignore = (ignoredTests->find(s) != ignoredTests->end());
}
}
QTestResult::setBlacklistCurrentTest(ignore);
// Tests blacklisted in GPU_BLACKLIST are to be skipped. Just ignoring the result is
// not sufficient since these are expected to crash or behave in undefined ways.
if (!ignore && gpuFeatures) {
QByteArray s_gpu = slot;
ignore = isGPUTestBlacklisted(s_gpu, data);
if (!ignore && data) {
s_gpu += ':';
s_gpu += data;
isGPUTestBlacklisted(s_gpu);
}
}
}
}
QT_END_NAMESPACE