diff --git a/tests/common.cpp b/tests/common.cpp index 03cec06..461f624 100644 --- a/tests/common.cpp +++ b/tests/common.cpp @@ -514,69 +514,6 @@ QString randomMessage(int words) return msg; } -/* - * Returns the average system load since last time this function was called (or - * since boot if this first time this function is called). The scale is [1, 0], - * where 1 is busy and 0 is idle system. In case of errors, -1 is returned. - */ -double getSystemLoad() -{ - // Parsing assumes that first line of /proc/stat looks something like this: - // cpu 110807 325 23491 425840 37435 1367 32 0 0 - - QFile file("/proc/stat"); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << Q_FUNC_INFO << "Failed to open /proc/stat"; - return -1; - } - - QTextStream in(&file); - QString line = in.readLine(); - file.close(); - - QStringList parts = line.split(" ", QString::SkipEmptyParts); - if (parts.size() < 10) { - qWarning() << Q_FUNC_INFO << "Invalid input from /proc/stat:" << line; - return -1; - } - if (parts.at(0) != QStringLiteral("cpu")) { - qWarning() << Q_FUNC_INFO << "Invalid input from /proc/stat:" << line; - return -1; - } - - int newIdleTicks = parts.at(4).toInt(); - int newAllTicks = 0; - for (int i = 1; i < parts.count(); i++) { - newAllTicks += parts.at(i).toInt(); - } - - quint64 idleTickDelta = newIdleTicks - idleTicks; - quint64 allTickDelta = newAllTicks - allTicks; - idleTicks = newIdleTicks; - allTicks = newAllTicks; - - return 1.0 - ((double)idleTickDelta / allTickDelta); -} - -/* - * Wait in semi-busy loop until system load drops below IDLE_TRESHOLD - */ -void waitForIdle(int pollInterval) { - double load = 1.0; - QDateTime startTime = QDateTime::currentDateTime(); - getSystemLoad(); - while (load > IDLE_TRESHOLD) { - qDebug() << Q_FUNC_INFO << "Waiting system to calm down. Wait time:" - << startTime.secsTo(QDateTime::currentDateTime()) << "seconds. Load:" - << load * 100 << "\%"; - QTest::qWait(pollInterval); - load = getSystemLoad(); - } - qDebug() << Q_FUNC_INFO << "Done. Wait time:" - << startTime.secsTo(QDateTime::currentDateTime()) << "seconds. Load:" - << load * 100 << "\%"; -} - bool waitSignal(QSignalSpy &spy, int msec) { if (!spy.isEmpty()) { @@ -593,17 +530,6 @@ bool waitSignal(QSignalSpy &spy, int msec) return !spy.isEmpty(); } -void waitWithDeletes(int msec) -{ - QTime timer; - timer.start(); - while (timer.elapsed() < msec) { - QCoreApplication::sendPostedEvents(); - QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QCoreApplication::processEvents(); - } -} - void summarizeResults(const QString &className, QList ×, QFile *logFile, int testSecs) { int sum = 0; diff --git a/tests/common.h b/tests/common.h index 4ffd707..40c92a9 100644 --- a/tests/common.h +++ b/tests/common.h @@ -58,12 +58,6 @@ const QString TEST_DATABASE_DIR = QStandardPaths::writableLocation(QStandardPath const QString ACCOUNT1 = "/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0"; const QString ACCOUNT2 = "/org/freedesktop/Telepathy/Account/gabble/jabber/dut2_40localhost0"; -/* The default load polling interval when waiting system to become idle */ -const int IDLE_POLL_INTERVAL = 500; - -/* System is considered idle when system load drops below this value */ -const double IDLE_TRESHOLD = 0.07; // 7% (system often sits at 5-6%) - const int WAIT_SIGNAL_TIMEOUT = 5000; /* Duration of phone calls added with addTestEvent */ @@ -98,11 +92,7 @@ void cleanupTestEvents(); bool compareEvents(Event &e1, Event &e2); void deleteAll(); QString randomMessage(int words); -double getSystemLoad(); -void waitForIdle(int pollInterval = IDLE_POLL_INTERVAL); bool waitSignal(QSignalSpy &spy, int msec = WAIT_SIGNAL_TIMEOUT); -// wait and allow deferred deletes to be processed (http://bugreports.qt.nokia.com/browse/QTBUG-12575) -void waitWithDeletes(int msec = WAIT_SIGNAL_TIMEOUT); void summarizeResults(const QString &className, QList ×, QFile *logFile, int testSecs); #endif diff --git a/tests/mem_eventmodel/mem_eventmodel.cpp b/tests/mem_eventmodel/mem_eventmodel.cpp index 074f5e3..ec53979 100644 --- a/tests/mem_eventmodel/mem_eventmodel.cpp +++ b/tests/mem_eventmodel/mem_eventmodel.cpp @@ -21,6 +21,7 @@ ******************************************************************************/ #include +#include #include #include #include "eventmodel.h" @@ -38,6 +39,18 @@ Group group; #define MALLINFO_DUMP(s) {struct mallinfo m = mallinfo();qDebug() << "MALLINFO" << (s) << m.arena << m.uordblks << m.fordblks;} +static void waitWithDeletes(int msec) +{ + QTime timer; + timer.start(); + while (timer.elapsed() < msec) { + QCoreApplication::sendPostedEvents(); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + } +} + + void MemEventModelTest::initTestCase() { initTestDatabase(); diff --git a/tests/perf_callmodel/callmodelperftest.cpp b/tests/perf_callmodel/callmodelperftest.cpp index 94ba663..6959714 100644 --- a/tests/perf_callmodel/callmodelperftest.cpp +++ b/tests/perf_callmodel/callmodelperftest.cpp @@ -201,8 +201,6 @@ void CallModelPerfTest::getEvents() fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve); fetchModel.setFilter(CallModel::SortByContact); - waitForIdle(); - QTime time; time.start(); diff --git a/tests/perf_conversationmodel/conversationmodelperftest.cpp b/tests/perf_conversationmodel/conversationmodelperftest.cpp index 3e18958..8d651df 100644 --- a/tests/perf_conversationmodel/conversationmodelperftest.cpp +++ b/tests/perf_conversationmodel/conversationmodelperftest.cpp @@ -228,8 +228,6 @@ void ConversationModelPerfTest::getEvents() fetchModel.setChunkSize(limit); } - waitForIdle(); - QTime time; time.start(); bool result = fetchModel.getEvents(groupIds); diff --git a/tests/perf_groupmodel/groupmodelperftest.cpp b/tests/perf_groupmodel/groupmodelperftest.cpp index e93c0bf..bd34a84 100644 --- a/tests/perf_groupmodel/groupmodelperftest.cpp +++ b/tests/perf_groupmodel/groupmodelperftest.cpp @@ -214,8 +214,6 @@ void GroupModelPerfTest::getGroups() fetchModel.setManager(&manager); - waitForIdle(); - QTime time; time.start(); bool result = fetchModel.getGroups(); diff --git a/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp b/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp index 9a1c52d..a8a6ade 100644 --- a/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp +++ b/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp @@ -203,8 +203,6 @@ void RecentContactsModelPerfTest::getEvents() if (limit) fetchModel.setLimit(limit); - waitForIdle(); - QTime time; time.start(); diff --git a/tests/profile_callmodel/callmodelprofiletest.cpp b/tests/profile_callmodel/callmodelprofiletest.cpp index 70a54db..4f005f5 100644 --- a/tests/profile_callmodel/callmodelprofiletest.cpp +++ b/tests/profile_callmodel/callmodelprofiletest.cpp @@ -161,8 +161,6 @@ void CallModelProfileTest::execute() fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve); fetchModel.setFilter(CallModel::SortByContact); - waitForIdle(); - QTime time; time.start(); diff --git a/tests/profile_conversationmodel/conversationmodelprofiletest.cpp b/tests/profile_conversationmodel/conversationmodelprofiletest.cpp index f4d57fa..6330ede 100644 --- a/tests/profile_conversationmodel/conversationmodelprofiletest.cpp +++ b/tests/profile_conversationmodel/conversationmodelprofiletest.cpp @@ -184,8 +184,6 @@ void ConversationModelProfileTest::execute() fetchModel.setChunkSize(limit); } - waitForIdle(); - QTime time; time.start(); bool result = fetchModel.getEvents(); diff --git a/tests/profile_groupmodel/groupmodelprofiletest.cpp b/tests/profile_groupmodel/groupmodelprofiletest.cpp index 955757e..93fb90e 100644 --- a/tests/profile_groupmodel/groupmodelprofiletest.cpp +++ b/tests/profile_groupmodel/groupmodelprofiletest.cpp @@ -169,8 +169,6 @@ void GroupModelProfileTest::execute() fetchModel.setManager(&manager); - waitForIdle(); - QTime time; time.start(); diff --git a/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp b/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp index 42aa2de..9c8da0f 100644 --- a/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp +++ b/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp @@ -173,8 +173,6 @@ void RecentContactsModelProfileTest::execute() RecentContactsModel fetchModel; fetchModel.setLimit(limit); - waitForIdle(); - QTime time; time.start();