1 /**************************************************************************
3 ** This file is part of Qt Creator Analyzer Tools
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Author: Frank Osterfeld, KDAB (frank.osterfeld@kdab.com)
9 ** Contact: Nokia Corporation (qt-info@nokia.com)
13 ** Licensees holding valid Qt Commercial licenses may use this file in
14 ** accordance with the Qt Commercial License Agreement provided with the
15 ** Software or, alternatively, in accordance with the terms contained in
16 ** a written agreement between you and Nokia.
18 ** GNU Lesser General Public License Usage
20 ** Alternatively, this file may be used under the terms of the GNU Lesser
21 ** General Public License version 2.1 as published by the Free Software
22 ** Foundation and appearing in the file LICENSE.LGPL included in the
23 ** packaging of this file. Please review the following information to
24 ** ensure the GNU Lesser General Public License version 2.1 requirements
25 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
27 ** If you are unsure which license is appropriate for your use, please
28 ** contact the sales department at http://qt.nokia.com/contact.
30 **************************************************************************/
35 #include <QtCore/QObject>
36 #include <QtCore/QPair>
37 #include <QtCore/QStringList>
38 #include <QtCore/QVector>
39 #include <QtCore/QDebug>
41 #include <valgrind/xmlprotocol/error.h>
42 #include <valgrind/xmlprotocol/status.h>
43 #include <valgrind/xmlprotocol/threadedparser.h>
44 #include <valgrind/xmlprotocol/parser.h>
45 #include <valgrind/memcheck/memcheckrunner.h>
53 void dumpError(const Valgrind::XmlProtocol::Error &e);
55 class Recorder : public QObject
59 explicit Recorder(Valgrind::XmlProtocol::Parser *parser, QObject *parent = 0)
62 connect(parser, SIGNAL(error(Valgrind::XmlProtocol::Error)),
63 this, SLOT(error(Valgrind::XmlProtocol::Error)));
64 connect(parser, SIGNAL(errorCount(qint64, qint64)),
65 this, SLOT(errorCount(qint64, qint64)));
66 connect(parser, SIGNAL(suppressionCount(QString, qint64)),
67 this, SLOT(suppressionCount(QString, qint64)));
70 QList<Valgrind::XmlProtocol::Error> errors;
71 QVector<QPair<qint64,qint64> > errorcounts;
72 QVector<QPair<QString,qint64> > suppcounts;
75 void error(const Valgrind::XmlProtocol::Error &err)
80 void errorCount(qint64 uniq, qint64 count)
82 errorcounts.push_back(qMakePair(uniq, count));
85 void suppressionCount(const QString &name, qint64 count)
87 suppcounts.push_back(qMakePair(name, count));
92 class RunnerDumper : public QObject
97 explicit RunnerDumper(Valgrind::Memcheck::MemcheckRunner *runner, Valgrind::XmlProtocol::ThreadedParser *parser)
99 , m_errorReceived(false)
101 connect(parser, SIGNAL(error(Valgrind::XmlProtocol::Error)),
102 this, SLOT(error(Valgrind::XmlProtocol::Error)));
103 connect(parser, SIGNAL(internalError(QString)),
104 this, SLOT(internalError(QString)));
105 connect(parser, SIGNAL(status(Valgrind::XmlProtocol::Status)),
106 this, SLOT(status(Valgrind::XmlProtocol::Status)));
107 connect(runner, SIGNAL(standardErrorReceived(QByteArray)),
108 this, SLOT(standardErrorReceived(QByteArray)));
109 connect(runner, SIGNAL(standardOutputReceived(QByteArray)),
110 this, SLOT(standardOutputReceived(QByteArray)));
111 connect(runner, SIGNAL(logMessageReceived(QByteArray)),
112 this, SLOT(logMessageReceived(QByteArray)));
113 connect(runner, SIGNAL(processErrorReceived(QString, QProcess::ProcessError)),
114 this, SLOT(processErrorReceived(QString)));
118 void error(const Valgrind::XmlProtocol::Error &e)
120 qDebug() << "error received";
123 void internalError(const QString& error)
125 qDebug() << "internal error received:" << error;
127 void standardErrorReceived(const QByteArray &err)
130 // qDebug() << "STDERR received:" << err; // this can be a lot of text
132 void standardOutputReceived(const QByteArray &out)
134 qDebug() << "STDOUT received:" << out;
136 void status(const Valgrind::XmlProtocol::Status &status)
138 qDebug() << "status received:" << status.state() << status.time();
140 void logMessageReceived(const QByteArray &log)
142 qDebug() << "log message received:" << log;
144 void processErrorReceived(const QString &s)
147 // qDebug() << "error received:" << s; // this can be a lot of text
148 m_errorReceived = true;
152 bool m_errorReceived;
156 class ParserTests : public QObject
164 void testMemcheckSample1();
165 void testMemcheckSample2();
166 void testMemcheckSample3();
167 void testMemcheckCharm();
168 void testHelgrindSample1();
170 void testValgrindCrash();
171 void testValgrindGarbage();
173 void testParserStop();
174 void testRealValgrind();
175 void testValgrindStartError_data();
176 void testValgrindStartError();
179 void initTest(const QLatin1String &testfile, const QStringList &otherArgs = QStringList());
181 QTcpServer *m_server;
183 QTcpSocket *m_socket;
186 #endif // PARSERTESTS_H