From 019598f57e892feacfb43b1095b3ccf5cec4d4ee Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 15 Jan 2014 12:30:36 +0100 Subject: Make sure that profiling can only be started if debugging is enabled. Enabling the profiler doesn't make much sense if there is no debug service as the messages can't be sent anywhere then. Furthermore, the profiler instance is only properly initialized if debugging is enabled and thus enabling profiling without debugging being enabled can cause problems. Change-Id: I784a110126d45a9a2bc9d9e14d9a22e2980c3a42 Reviewed-by: Kai Koehne --- .../qqmlprofilerservice/data/controlFromJS.qml | 68 ++++++++++++++++++++++ .../qqmlprofilerservice/qqmlprofilerservice.pro | 3 +- .../tst_qqmlprofilerservice.cpp | 19 ++++++ tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp | 4 +- 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml (limited to 'tests') diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml b/tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml new file mode 100644 index 0000000000..7bcabc33ac --- /dev/null +++ b/tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + Timer { + running: true + interval: 1 + onTriggered: { + console.profile(); + stopTimer.start(); + } + } + + Timer { + id: stopTimer + interval: 1000 + onTriggered: { + console.profileEnd(); + endTimer.start(); + } + } + + Timer { + id: endTimer + interval: 1000 + onTriggered: Qt.quit(); + } +} diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro b/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro index b2b325dc72..a83927e720 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro +++ b/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro @@ -14,4 +14,5 @@ QT += core qml testlib gui-private DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 OTHER_FILES += \ - data/pixmapCacheTest.qml + data/pixmapCacheTest.qml \ + data/controlFromJS.qml diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index 929b079a51..acbc62807b 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -180,6 +180,7 @@ private slots: void pixmapCacheData(); void scenegraphData(); void profileOnExit(); + void controlFromJS(); }; void QQmlProfilerClient::messageReceived(const QByteArray &message) @@ -494,6 +495,24 @@ void tst_QQmlProfilerService::profileOnExit() QCOMPARE(m_client->traceMessages.last().detailType, (int)QQmlProfilerClient::EndTrace); } +void tst_QQmlProfilerService::controlFromJS() +{ + connect(true, "controlFromJS.qml"); + QVERIFY(m_client); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + + m_client->setTraceState(false); + QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); + + // must start with "StartTrace" + QCOMPARE(m_client->traceMessages.first().messageType, (int)QQmlProfilerClient::Event); + QCOMPARE(m_client->traceMessages.first().detailType, (int)QQmlProfilerClient::StartTrace); + + // must end with "EndTrace" + QCOMPARE(m_client->traceMessages.last().messageType, (int)QQmlProfilerClient::Event); + QCOMPARE(m_client->traceMessages.last().detailType, (int)QQmlProfilerClient::EndTrace); +} + QTEST_MAIN(tst_QQmlProfilerService) #include "tst_qqmlprofilerservice.moc" diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp index e6f31dcb83..a37d705284 100644 --- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp +++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp @@ -115,8 +115,8 @@ void tst_qqmlconsole::profiling() QUrl testUrl = testFileUrl("profiling.qml"); // profiling() - QTest::ignoreMessage(QtDebugMsg, "Profiling started."); - QTest::ignoreMessage(QtDebugMsg, "Profiling ended."); + QTest::ignoreMessage(QtWarningMsg, "Cannot start profiling because debug service is disabled. Start with -qmljsdebugger=port:XXXXX."); + QTest::ignoreMessage(QtWarningMsg, "Profiling was not started."); QQmlComponent component(&engine, testUrl); QObject *object = component.create(); -- cgit v1.2.3