From 37c5df162ccfcf18ffc8a3931cfb23dc800c4965 Mon Sep 17 00:00:00 2001 From: Martin Kampas Date: Mon, 14 Oct 2013 11:48:24 +0200 Subject: [PATCH] ut_rndssucli: run own (sandboxed) `ssud' instance Otherwise existing (not-sandboxed) `ssud' instance is talked to and system configuration is destroyed during test execution. --- tests/ut_rndssucli/rndssuclitest.cpp | 30 ++++++++++++++++++++++++++++ tests/ut_rndssucli/rndssuclitest.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/tests/ut_rndssucli/rndssuclitest.cpp b/tests/ut_rndssucli/rndssuclitest.cpp index 6ac423f..7966c91 100644 --- a/tests/ut_rndssucli/rndssuclitest.cpp +++ b/tests/ut_rndssucli/rndssuclitest.cpp @@ -26,9 +26,39 @@ void RndSsuCliTest::init(){ QFAIL("Failed to activate sandbox"); } setenv("LD_PRELOAD", qPrintable(QString("%1/libsandboxhook.so").arg(TESTS_PATH)), 1); + + m_bus = new QProcess(this); + m_bus->start("dbus-daemon", + Args() << "--session" << "--nofork" << "--nopidfile" << "--print-address"); + if (!m_bus->waitForReadyRead()){ + QFAIL("Failed to run sandboxed D-Bus instance"); + } + const QByteArray busAddress = m_bus->readAllStandardOutput(); + setenv("DBUS_SESSION_BUS_ADDRESS", busAddress.constData(), 1); + setenv("DBUS_SYSTEM_BUS_ADDRESS", busAddress.constData(), 1); + + m_ssud = new QProcess(this); + m_ssud->start("ssud"); + if (!m_ssud->waitForStarted()){ + QFAIL("Failed to run sandboxed ssud instance"); + } } void RndSsuCliTest::cleanup(){ + if (m_ssud->state() != QProcess::Running){ + QFAIL("Sandboxed ssud instance exited unexpectedly"); + } + delete m_ssud; + m_ssud = 0; + + if (m_bus->state() != QProcess::Running){ + QFAIL("Sandboxed D-Bus instance exited unexpectedly"); + } + unsetenv("DBUS_SESSION_BUS_ADDRESS"); + unsetenv("DBUS_SYSTEM_BUS_ADDRESS"); + delete m_bus; + m_bus = 0; + delete m_sandbox; m_sandbox = 0; } diff --git a/tests/ut_rndssucli/rndssuclitest.h b/tests/ut_rndssucli/rndssuclitest.h index aee55f4..ece6ff9 100644 --- a/tests/ut_rndssucli/rndssuclitest.h +++ b/tests/ut_rndssucli/rndssuclitest.h @@ -10,6 +10,8 @@ #include +class QProcess; + class Sandbox; class RndSsuCliTest: public QObject { @@ -28,6 +30,8 @@ class RndSsuCliTest: public QObject { private: Sandbox *m_sandbox; + QProcess *m_bus; + QProcess *m_ssud; }; #endif