tst_qmetatype: factor the most expensive test into its own TU

The PRINT_2ARD_TEMPLATE macro expansion alone is responsible for about
50% of the compile time and RAM requirements of tst_qmetatype.cpp. By
factoring it into its own TU, we reduce the maximum memory load on my
machine from 4.0GiB to 2.5GiB, provided we don't parallelize the
build, then we take 0.5GiB more.

This is a quick-fix for the QNX build problems currently plaguing the
CI. Going forward, we should probably have a better solution, whatever
that may be.

Task-number: QTQAINFRA-4669
Change-Id: I2732b4c25b369b15cce1c7afe222d041ecb6795a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Marc Mutz 2021-11-25 10:35:33 +01:00
parent 70e765b1c5
commit f898128ee2
4 changed files with 127 additions and 81 deletions

View File

@ -10,6 +10,7 @@ list(APPEND test_data "./typeFlags.bin")
qt_internal_add_test(tst_qmetatype
SOURCES
tst_qmetatype.h tst_qmetatype.cpp tst_qmetatype2.cpp
tst_qmetatype3.cpp
DEFINES
QT_DISABLE_DEPRECATED_BEFORE=0
INCLUDE_DIRECTORIES

View File

@ -1545,30 +1545,7 @@ public:
typedef MyObject* MyObjectPtr;
Q_DECLARE_METATYPE(MyObjectPtr)
#if !defined(TST_QMETATYPE_BROKEN_COMPILER)
static QByteArray createTypeName(const char *begin, const char *va)
{
QByteArray tn(begin);
const QList<QByteArray> args = QByteArray(va).split(',');
tn += args.first().trimmed();
if (args.size() > 1) {
QList<QByteArray>::const_iterator it = args.constBegin() + 1;
const QList<QByteArray>::const_iterator end = args.constEnd();
for (; it != end; ++it) {
tn += ",";
tn += it->trimmed();
}
}
if (tn.endsWith('>'))
tn += ' ';
tn += '>';
return tn;
}
#endif
Q_DECLARE_METATYPE(const void*)
void tst_QMetaType::automaticTemplateRegistration()
void tst_QMetaType::automaticTemplateRegistration_1()
{
#define TEST_SEQUENTIAL_CONTAINER(CONTAINER, VALUE_TYPE) \
{ \
@ -1745,60 +1722,7 @@ void tst_QMetaType::automaticTemplateRegistration()
#if !defined(TST_QMETATYPE_BROKEN_COMPILER)
#define FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \
F(bool) \
F(int) \
F(qulonglong) \
F(double) \
F(short) \
F(char) \
F(ulong) \
F(uchar) \
F(float) \
F(QObject*) \
F(QString) \
F(CustomMovable)
#define FOR_EACH_STATIC_PRIMITIVE_TYPE2(F, SecondaryRealName) \
F(uint, SecondaryRealName) \
F(qlonglong, SecondaryRealName) \
F(char, SecondaryRealName) \
F(uchar, SecondaryRealName) \
F(QObject*, SecondaryRealName)
#define CREATE_AND_VERIFY_CONTAINER(CONTAINER, ...) \
{ \
CONTAINER< __VA_ARGS__ > t; \
const QVariant v = QVariant::fromValue(t); \
QByteArray tn = createTypeName(#CONTAINER "<", #__VA_ARGS__); \
const int expectedType = ::qMetaTypeId<CONTAINER< __VA_ARGS__ > >(); \
const int type = QMetaType::type(tn); \
QCOMPARE(type, expectedType); \
QCOMPARE((QMetaType::fromType<CONTAINER< __VA_ARGS__ >>().id()), expectedType); \
}
#define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \
F(QList, TYPE) \
F(QQueue, TYPE) \
F(QStack, TYPE) \
F(QSet, TYPE)
#define PRINT_1ARG_TEMPLATE(RealName) \
FOR_EACH_1ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName)
#define FOR_EACH_2ARG_TEMPLATE_TYPE(F, RealName1, RealName2) \
F(QHash, RealName1, RealName2) \
F(QMap, RealName1, RealName2) \
F(std::pair, RealName1, RealName2)
#define PRINT_2ARG_TEMPLATE_INTERNAL(RealName1, RealName2) \
FOR_EACH_2ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName1, RealName2)
#define PRINT_2ARG_TEMPLATE(RealName) \
FOR_EACH_STATIC_PRIMITIVE_TYPE2(PRINT_2ARG_TEMPLATE_INTERNAL, RealName)
#define REGISTER_TYPEDEF(TYPE, ARG1, ARG2) \
qRegisterMetaType<TYPE <ARG1, ARG2>>(#TYPE "<" #ARG1 "," #ARG2 ">");
REGISTER_TYPEDEF(QHash, int, uint)
REGISTER_TYPEDEF(QMap, int, uint)
@ -1807,9 +1731,6 @@ void tst_QMetaType::automaticTemplateRegistration()
FOR_EACH_STATIC_PRIMITIVE_TYPE(
PRINT_1ARG_TEMPLATE
)
FOR_EACH_STATIC_PRIMITIVE_TYPE(
PRINT_2ARG_TEMPLATE
)
CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QList<QVariant>>>>)
CREATE_AND_VERIFY_CONTAINER(QList, void*)

View File

@ -119,7 +119,10 @@ private slots:
void isRegisteredStaticLess_data();
void isRegisteredStaticLess();
void isEnum();
void automaticTemplateRegistration();
void automaticTemplateRegistration_1();
#ifndef TST_QMETATYPE_BROKEN_COMPILER
void automaticTemplateRegistration_2(); // defined in tst_qmetatype3.cpp
#endif
void saveAndLoadBuiltin_data();
void saveAndLoadBuiltin();
void saveAndLoadCustom();
@ -244,3 +247,81 @@ QT_END_NAMESPACE
#endif
Q_DECLARE_METATYPE(CustomMovable);
#define FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \
F(bool) \
F(int) \
F(qulonglong) \
F(double) \
F(short) \
F(char) \
F(ulong) \
F(uchar) \
F(float) \
F(QObject*) \
F(QString) \
F(CustomMovable)
#define FOR_EACH_STATIC_PRIMITIVE_TYPE2(F, SecondaryRealName) \
F(uint, SecondaryRealName) \
F(qlonglong, SecondaryRealName) \
F(char, SecondaryRealName) \
F(uchar, SecondaryRealName) \
F(QObject*, SecondaryRealName)
#define CREATE_AND_VERIFY_CONTAINER(CONTAINER, ...) \
{ \
CONTAINER< __VA_ARGS__ > t; \
const QVariant v = QVariant::fromValue(t); \
QByteArray tn = createTypeName(#CONTAINER "<", #__VA_ARGS__); \
const int expectedType = ::qMetaTypeId<CONTAINER< __VA_ARGS__ > >(); \
const int type = QMetaType::type(tn); \
QCOMPARE(type, expectedType); \
QCOMPARE((QMetaType::fromType<CONTAINER< __VA_ARGS__ >>().id()), expectedType); \
}
#define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \
F(QList, TYPE) \
F(QQueue, TYPE) \
F(QStack, TYPE) \
F(QSet, TYPE)
#define PRINT_1ARG_TEMPLATE(RealName) \
FOR_EACH_1ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName)
#define FOR_EACH_2ARG_TEMPLATE_TYPE(F, RealName1, RealName2) \
F(QHash, RealName1, RealName2) \
F(QMap, RealName1, RealName2) \
F(std::pair, RealName1, RealName2)
#define PRINT_2ARG_TEMPLATE_INTERNAL(RealName1, RealName2) \
FOR_EACH_2ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName1, RealName2)
#define PRINT_2ARG_TEMPLATE(RealName) \
FOR_EACH_STATIC_PRIMITIVE_TYPE2(PRINT_2ARG_TEMPLATE_INTERNAL, RealName)
#define REGISTER_TYPEDEF(TYPE, ARG1, ARG2) \
qRegisterMetaType<TYPE <ARG1, ARG2>>(#TYPE "<" #ARG1 "," #ARG2 ">");
#if !defined(TST_QMETATYPE_BROKEN_COMPILER)
static inline QByteArray createTypeName(const char *begin, const char *va)
{
QByteArray tn(begin);
const QList<QByteArray> args = QByteArray(va).split(',');
tn += args.first().trimmed();
if (args.size() > 1) {
QList<QByteArray>::const_iterator it = args.constBegin() + 1;
const QList<QByteArray>::const_iterator end = args.constEnd();
for (; it != end; ++it) {
tn += ",";
tn += it->trimmed();
}
}
if (tn.endsWith('>'))
tn += ' ';
tn += '>';
return tn;
}
#endif
Q_DECLARE_METATYPE(const void*)

View File

@ -0,0 +1,43 @@
/****************************************************************************
**
** Copyright (C) 2021 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 "tst_qmetatype.h"
#include <QtCore/private/qmetaobjectbuilder_p.h>
#if !defined(TST_QMETATYPE_BROKEN_COMPILER)
void tst_QMetaType::automaticTemplateRegistration_2()
{
FOR_EACH_STATIC_PRIMITIVE_TYPE(
PRINT_2ARG_TEMPLATE
)
}
#endif // !defined(TST_QMETATYPE_BROKEN_COMPILER)