Commit 18f70493 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Create a logging category for the akonaditest helper

parent bf0b6140
......@@ -8,11 +8,13 @@ set(akonaditest_SRCS
testrunner.cpp
)
ecm_qt_declare_logging_category(akonaditest_SRCS HEADER akonaditest_debug.h IDENTIFIER AKONADITEST_LOG CATEGORY_NAME org.kde.pim.akonaditest)
add_executable(akonaditest ${akonaditest_SRCS})
target_link_libraries(akonaditest
KF5::AkonadiPrivate
KF5::AkonadiCore
KF5::AkonadiCore
KF5::I18n
KF5::ConfigCore
Qt5::Xml
......
......@@ -16,8 +16,7 @@
*/
#include "config.h" //krazy:exclude=includes
#include <QDebug>
#include "akonaditest_debug.h"
#include <QDir>
#include <QPair>
......@@ -51,11 +50,11 @@ void Config::readConfiguration(const QString &configfile)
QFile file(configfile);
if (!file.open(QIODevice::ReadOnly)) {
qFatal("error reading file: %s", qPrintable(configfile));
qFatal("Error reading file %s: %s", qPrintable(configfile), qUtf8Printable(file.errorString()));
}
mBasePath = QFileInfo(configfile).absolutePath() + QLatin1Char('/');
qDebug() << "Base path" << mBasePath;
qCDebug(AKONADITEST_LOG) << "Base path" << mBasePath;
QXmlStreamReader reader(&file);
while (!reader.atEnd()) {
......@@ -81,7 +80,7 @@ void Config::readConfiguration(const QString &configfile)
const auto attrs = reader.attributes();
const auto name = attrs.value(QLatin1String("name"));
if (name.isEmpty()) {
qWarning() << "Given envvar with no name.";
qCWarning(AKONADITEST_LOG) << "Given envvar with no name.";
} else {
mEnvVars[name.toString()] = reader.readElementText();
}
......
......@@ -20,10 +20,10 @@
#include "setup.h"
#include "shellscript.h"
#include "testrunner.h"
#include "akonaditest_debug.h"
#include <KAboutData>
#include <QDebug>
#include <KLocalizedString>
#include <signal.h>
......@@ -36,7 +36,7 @@ static TestRunner *runner = nullptr;
void sigHandler(int signal)
{
qDebug() << "Received signal" << signal;
qCCritical(AKONADITEST_LOG, "Received signal %d", signal);
static int sigCounter = 0;
if (sigCounter == 0) { // try clean shutdown
if (runner) {
......@@ -114,7 +114,7 @@ int main(int argc, char **argv)
if (!setup->startAkonadiDaemon()) {
delete setup;
qCritical("Failed to start Akonadi server!");
qCCritical(AKONADITEST_LOG, "Failed to start Akonadi server!");
return 1;
}
......
......@@ -18,6 +18,7 @@
#include "setup.h"
#include "config.h" //krazy:exclude=includes
#include "akonaditest_debug.h"
#include <agentinstance.h>
#include <agentinstancecreatejob.h>
......@@ -26,7 +27,6 @@
#include <KConfig>
#include <kconfiggroup.h>
#include <QDebug>
#include <KProcess>
#include <QCoreApplication>
......@@ -50,7 +50,7 @@ bool SetupTest::startAkonadiDaemon()
{ QStringLiteral("--instance"), instanceId() });
mAkonadiDaemonProcess->start();
const bool started = mAkonadiDaemonProcess->waitForStarted(5000);
qDebug() << "Started akonadi daemon with pid:" << mAkonadiDaemonProcess->pid();
qCInfo(AKONADITEST_LOG) << "Started akonadi daemon with pid:" << mAkonadiDaemonProcess->pid();
return started;
}
......@@ -63,7 +63,7 @@ void SetupTest::stopAkonadiDaemon()
mAkonadiDaemonProcess->terminate();
const bool finished = mAkonadiDaemonProcess->waitForFinished(5000);
if (!finished) {
qDebug() << "Problem finishing process.";
qCDebug(AKONADITEST_LOG) << "Problem finishing process.";
}
mAkonadiDaemonProcess->close();
mAkonadiDaemonProcess->deleteLater();
......@@ -79,7 +79,7 @@ void SetupTest::setupAgents()
Config *config = Config::instance();
const auto agents = config->agents();
for (const auto agent : agents) {
qDebug() << "Creating agent" << agent.first << "...";
qCDebug(AKONADITEST_LOG) << "Creating agent" << agent.first << "...";
++mSetupJobCount;
Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob(agent.first, this);
job->setProperty("sync", agent.second);
......@@ -94,7 +94,7 @@ void SetupTest::setupAgents()
void SetupTest::agentCreationResult(KJob *job)
{
qDebug() << "Agent created";
qCDebug(AKONADITEST_LOG) << "Agent created";
--mSetupJobCount;
if (job->error()) {
qCritical() << job->errorString();
......@@ -104,7 +104,7 @@ void SetupTest::agentCreationResult(KJob *job)
const bool needsSync = job->property("sync").toBool();
if (needsSync) {
++mSetupJobCount;
qDebug() << "Scheduling Agent sync";
qCDebug(AKONADITEST_LOG) << "Scheduling Agent sync";
Akonadi::ResourceSynchronizationJob *sync = new Akonadi::ResourceSynchronizationJob(
qobject_cast<Akonadi::AgentInstanceCreateJob *>(job)->instance(), this);
connect(sync, &Akonadi::ResourceSynchronizationJob::result, this, &SetupTest::synchronizationResult);
......@@ -118,7 +118,7 @@ void SetupTest::agentCreationResult(KJob *job)
void SetupTest::synchronizationResult(KJob *job)
{
qDebug() << "Sync done";
qCDebug(AKONADITEST_LOG) << "Sync done";
--mSetupJobCount;
if (job->error()) {
qCritical() << job->errorString();
......@@ -141,7 +141,7 @@ void SetupTest::serverStateChanged(Akonadi::ServerManager::State state)
void SetupTest::copyXdgDirectory(const QString &src, const QString &dst)
{
qDebug() << "Copying" << src << "to" << dst;
qCDebug(AKONADITEST_LOG) << "Copying" << src << "to" << dst;
const QDir srcDir(src);
const auto entries = srcDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
for (const auto &fi : entries) {
......@@ -164,12 +164,12 @@ void SetupTest::copyXdgDirectory(const QString &src, const QString &dst)
const QString baseName = fi.fileName().left(fi.fileName().size() - 2);
const QString dstPath = dst + QLatin1Char('/') + Akonadi::ServerManager::addNamespace(baseName) + QStringLiteral("rc");
if (!QFile::copy(fi.absoluteFilePath(), dstPath)) {
qWarning() << "Failed to copy" << fi.absoluteFilePath() << "to" << dstPath;
qCWarning(AKONADITEST_LOG) << "Failed to copy" << fi.absoluteFilePath() << "to" << dstPath;
}
} else {
const QString dstPath = dst + QLatin1Char('/') + fi.fileName();
if (!QFile::copy(fi.absoluteFilePath(), dstPath)) {
qWarning() << "Failed to copy" << fi.absoluteFilePath() << "to" << dstPath;
qCWarning(AKONADITEST_LOG) << "Failed to copy" << fi.absoluteFilePath() << "to" << dstPath;
}
}
}
......@@ -187,7 +187,7 @@ void SetupTest::copyDirectory(const QString &src, const QString &dst)
copyDirectory(fi.absoluteFilePath(), dstPath);
} else {
if (!QFile::copy(fi.absoluteFilePath(), dstPath)) {
qWarning() << "Failed to copy" << fi.absoluteFilePath() << "to" << dstPath;
qCWarning(AKONADITEST_LOG) << "Failed to copy" << fi.absoluteFilePath() << "to" << dstPath;
}
}
}
......@@ -195,7 +195,7 @@ void SetupTest::copyDirectory(const QString &src, const QString &dst)
void SetupTest::createTempEnvironment()
{
qDebug() << "Creating test environment in" << basePath();
qCDebug(AKONADITEST_LOG) << "Creating test environment in" << basePath();
const Config *config = Config::instance();
#ifdef Q_OS_WIN
......@@ -250,7 +250,7 @@ void SetupTest::writeAkonadiserverrc(const QString &path)
} else if (Config::instance()->dbBackend() == QLatin1String("pgsql")) {
backend = QStringLiteral("QPSQL");
} else {
qCritical("Invalid backend name %s", qPrintable(backend));
qCCritical(AKONADITEST_LOG, "Invalid backend name %s", qPrintable(backend));
return;
}
......@@ -264,7 +264,7 @@ void SetupTest::writeAkonadiserverrc(const QString &path)
settings.beginGroup(QStringLiteral("Debug"));
settings.setValue(QStringLiteral("Tracer"), QStringLiteral("null"));
settings.endGroup();
qDebug() << "Written akonadiserverrc to" << settings.fileName();
qCDebug(AKONADITEST_LOG) << "Written akonadiserverrc to" << settings.fileName();
}
void SetupTest::cleanTempEnvironment()
......@@ -304,7 +304,7 @@ SetupTest::SetupTest()
QHashIterator<QString, QString> iter(Config::instance()->envVars());
while (iter.hasNext()) {
iter.next();
qDebug() << "Setting environment variable" << iter.key() << "=" << iter.value();
qCDebug(AKONADITEST_LOG) << "Setting environment variable" << iter.key() << "=" << iter.value();
setEnvironmentVariable(iter.key().toLocal8Bit(), iter.value());
}
......@@ -336,7 +336,7 @@ void SetupTest::shutdown()
case Akonadi::ServerManager::Running:
case Akonadi::ServerManager::Starting:
case Akonadi::ServerManager::Upgrading:
qDebug() << "Shutting down Akonadi control...";
qCInfo(AKONADITEST_LOG) << "Shutting down Akonadi control...";
Akonadi::ServerManager::self()->stop();
// safety timeout
QTimer::singleShot(30 * 1000, this, &SetupTest::shutdownHarder);
......@@ -354,7 +354,7 @@ void SetupTest::shutdown()
void SetupTest::shutdownHarder()
{
qDebug();
qCDebug(AKONADITEST_LOG) << "Forcing akonaditest shutdown";
mShuttingDown = false;
stopAkonadiDaemon();
QCoreApplication::instance()->exit(mExitCode);
......@@ -362,12 +362,12 @@ void SetupTest::shutdownHarder()
void SetupTest::restartAkonadiServer()
{
qDebug();
qCDebug(AKONADITEST_LOG) << "Restarting Akonadi";
disconnect(mAkonadiDaemonProcess, SIGNAL(finished(int)), this, nullptr);
Akonadi::ServerManager::self()->stop();
const bool shutdownResult = mAkonadiDaemonProcess->waitForFinished();
if (!shutdownResult) {
qWarning() << "Akonadi control did not shut down in time, killing it.";
qCWarning(AKONADITEST_LOG) << "Akonadi control did not shut down in time, killing it.";
mAkonadiDaemonProcess->kill();
}
// we don't use Control::start() since we want to be able to kill
......@@ -408,7 +408,7 @@ QString SetupTest::basePath() const
void SetupTest::slotAkonadiDaemonProcessFinished(int exitCode)
{
if (mTrackAkonadiProcess || exitCode != EXIT_SUCCESS) {
qWarning() << "Akonadi server process was terminated externally!";
qCWarning(AKONADITEST_LOG) << "Akonadi server process was terminated externally!";
Q_EMIT serverExited(exitCode);
}
mAkonadiDaemonProcess = nullptr;
......@@ -431,7 +431,7 @@ void SetupTest::setupInstanceId()
bool SetupTest::isSetupDone() const
{
qDebug() << "isSetupDone:" << mSetupJobCount << mExitCode;
qCDebug(AKONADITEST_LOG) << "isSetupDone:" << mSetupJobCount << mExitCode;
return mSetupJobCount == 0 && mExitCode == 0;
}
......@@ -447,7 +447,7 @@ void SetupTest::setEnvironmentVariable(const QByteArray &name, const QString &va
qputenv(name.constData(), value.toLatin1());
}
QVector< SetupTest::EnvVar > SetupTest::environmentVariables() const
QVector<SetupTest::EnvVar> SetupTest::environmentVariables() const
{
return mEnvVars;
}
......@@ -16,10 +16,9 @@
*/
#include "shellscript.h"
#include "akonaditest_debug.h"
#include "config.h" //krazy:exclude=includes
#include <QDebug>
#include <QCoreApplication>
#include <QFile>
#include <QHashIterator>
......@@ -81,7 +80,7 @@ void ShellScript::writeShutdownFunction()
void ShellScript::makeShellScript(const QString &fileName)
{
qDebug() << fileName;
qCDebug(AKONADITEST_LOG) << "Writing environment shell script to" << fileName;
QFile file(fileName); //can user define the file name/location?
if (file.open(QIODevice::WriteOnly)) {
......
......@@ -16,8 +16,8 @@
*/
#include "testrunner.h"
#include "akonaditest_debug.h"
#include <QDebug>
#include <KProcess>
......@@ -36,7 +36,7 @@ int TestRunner::exitCode() const
void TestRunner::run()
{
qDebug() << mArguments;
qCDebug(AKONADITEST_LOG) << "Starting test" << mArguments;
mProcess = new KProcess(this);
mProcess->setProgram(mArguments);
connect(mProcess, QOverload<int>::of(&KProcess::finished), this, &TestRunner::processFinished);
......@@ -45,7 +45,7 @@ void TestRunner::run()
// environment setup seems to have been done by setuptest globally already
mProcess->start();
if (!mProcess->waitForStarted()) {
qWarning() << mArguments << "failed to start!";
qCWarning(AKONADITEST_LOG) << mArguments << "failed to start!";
mExitCode = 255;
Q_EMIT finished();
}
......@@ -63,14 +63,14 @@ void TestRunner::processFinished(int exitCode)
// is called after a process has finished.
if (mExitCode == 0) {
mExitCode = exitCode;
qDebug() << exitCode;
qCInfo(AKONADITEST_LOG) << "Test finished with exist code" << exitCode;
}
Q_EMIT finished();
}
void TestRunner::processError(QProcess::ProcessError error)
{
qWarning() << mArguments << "exited with an error:" << error;
qCWarning(AKONADITEST_LOG) << mArguments << "exited with an error:" << error;
mExitCode = 255;
Q_EMIT finished();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment