Increase test coverage for the V4 memory manager

This commit adds a small test that exercises a number of code paths
inside qv4mm.cpp which are normally gated via environment variables.

Change-Id: Ibe959387a9b86ce68df258513446d2165fe06ee2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Frank Meerkoetter 2016-06-11 22:23:41 +02:00
parent f7e462ba15
commit e88500ff25
5 changed files with 77 additions and 6 deletions

View File

@ -79,9 +79,9 @@ static uint maxShiftValue()
static uint result = 0;
if (!result) {
result = 6;
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QV4_MM_MAXBLOCK_SHIFT"))) {
if (Q_UNLIKELY(qEnvironmentVariableIsSet(QV4_MM_MAXBLOCK_SHIFT))) {
bool ok;
const uint overrideValue = qgetenv("QV4_MM_MAXBLOCK_SHIFT").toUInt(&ok);
const uint overrideValue = qgetenv(QV4_MM_MAXBLOCK_SHIFT).toUInt(&ok);
if (ok && overrideValue <= 11 && overrideValue > 0)
result = overrideValue;
}
@ -94,9 +94,9 @@ static std::size_t maxChunkSizeValue()
static std::size_t result = 0;
if (!result) {
result = 32 * 1024;
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QV4_MM_MAX_CHUNK_SIZE"))) {
if (Q_UNLIKELY(qEnvironmentVariableIsSet(QV4_MM_MAX_CHUNK_SIZE))) {
bool ok;
const std::size_t overrideValue = qgetenv("QV4_MM_MAX_CHUNK_SIZE").toUInt(&ok);
const std::size_t overrideValue = qgetenv(QV4_MM_MAX_CHUNK_SIZE).toUInt(&ok);
if (ok)
result = overrideValue;
}
@ -170,7 +170,7 @@ struct MemoryManager::Data
, maxShift(maxShiftValue())
, gcBlocked(false)
, aggressiveGC(!qEnvironmentVariableIsEmpty("QV4_MM_AGGRESSIVE_GC"))
, gcStats(!qEnvironmentVariableIsEmpty("QV4_MM_STATS"))
, gcStats(!qEnvironmentVariableIsEmpty(QV4_MM_STATS))
{
memset(nonFullChunks, 0, sizeof(nonFullChunks));
memset(nChunks, 0, sizeof(nChunks));

View File

@ -59,6 +59,10 @@
//#define DETAILED_MM_STATS
#define QV4_MM_MAXBLOCK_SHIFT "QV4_MM_MAXBLOCK_SHIFT"
#define QV4_MM_MAX_CHUNK_SIZE "QV4_MM_MAX_CHUNK_SIZE"
#define QV4_MM_STATS "QV4_MM_STATS"
QT_BEGIN_NAMESPACE
namespace QV4 {

View File

@ -62,7 +62,8 @@ PRIVATETESTS += \
qqmltranslation \
qqmlimport \
qqmlobjectmodel \
qmldiskcache
qmldiskcache \
qv4mm
qtHaveModule(widgets) {
PUBLICTESTS += \

View File

@ -0,0 +1,8 @@
CONFIG += testcase
TARGET = tst_qv4mm
osx:CONFIG -= app_bundle
SOURCES += tst_qv4mm.cpp
QT += qml qml-private testlib

View File

@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2016 basysKom GmbH.
** 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 <qtest.h>
#include <QQmlEngine>
#include <private/qv4mm_p.h>
class tst_qv4mm : public QObject
{
Q_OBJECT
private slots:
void gcStats();
void tweaks();
};
void tst_qv4mm::gcStats()
{
qputenv(QV4_MM_STATS, "1");
QQmlEngine engine;
engine.collectGarbage();
}
void tst_qv4mm::tweaks()
{
qputenv(QV4_MM_MAXBLOCK_SHIFT, "5");
qputenv(QV4_MM_MAX_CHUNK_SIZE, "65536");
QQmlEngine engine;
}
QTEST_MAIN(tst_qv4mm)
#include "tst_qv4mm.moc"