Commit 251c21d8 authored by pvuorela's avatar pvuorela

Merge branch 'remove_test_idle_check' into 'master'

Remove test idle check. Fixes JB#53609

See merge request !53
parents 91a353c0 1cd0e4e3
......@@ -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<int> &times, QFile *logFile, int testSecs)
{
int sum = 0;
......
......@@ -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<int> &times, QFile *logFile, int testSecs);
#endif
......@@ -21,6 +21,7 @@
******************************************************************************/
#include <QtTest/QtTest>
#include <QTime>
#include <time.h>
#include <malloc.h>
#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();
......
......@@ -201,8 +201,6 @@ void CallModelPerfTest::getEvents()
fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve);
fetchModel.setFilter(CallModel::SortByContact);
waitForIdle();
QTime time;
time.start();
......
......@@ -228,8 +228,6 @@ void ConversationModelPerfTest::getEvents()
fetchModel.setChunkSize(limit);
}
waitForIdle();
QTime time;
time.start();
bool result = fetchModel.getEvents(groupIds);
......
......@@ -214,8 +214,6 @@ void GroupModelPerfTest::getGroups()
fetchModel.setManager(&manager);
waitForIdle();
QTime time;
time.start();
bool result = fetchModel.getGroups();
......
......@@ -203,8 +203,6 @@ void RecentContactsModelPerfTest::getEvents()
if (limit)
fetchModel.setLimit(limit);
waitForIdle();
QTime time;
time.start();
......
......@@ -161,8 +161,6 @@ void CallModelProfileTest::execute()
fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve);
fetchModel.setFilter(CallModel::SortByContact);
waitForIdle();
QTime time;
time.start();
......
......@@ -184,8 +184,6 @@ void ConversationModelProfileTest::execute()
fetchModel.setChunkSize(limit);
}
waitForIdle();
QTime time;
time.start();
bool result = fetchModel.getEvents();
......
......@@ -169,8 +169,6 @@ void GroupModelProfileTest::execute()
fetchModel.setManager(&manager);
waitForIdle();
QTime time;
time.start();
......
......@@ -173,8 +173,6 @@ void RecentContactsModelProfileTest::execute()
RecentContactsModel fetchModel;
fetchModel.setLimit(limit);
waitForIdle();
QTime time;
time.start();
......
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