Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'remove_test_idle_check' into 'master'
Remove test idle check. Fixes JB#53609

See merge request mer-core/libcommhistory!53
  • Loading branch information
pvuorela committed Mar 24, 2021
2 parents 91a353c + 1cd0e4e commit 251c21d
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 100 deletions.
74 changes: 0 additions & 74 deletions tests/common.cpp
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions tests/common.h
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions tests/mem_eventmodel/mem_eventmodel.cpp
Expand Up @@ -21,6 +21,7 @@
******************************************************************************/

#include <QtTest/QtTest>
#include <QTime>
#include <time.h>
#include <malloc.h>
#include "eventmodel.h"
Expand All @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions tests/perf_callmodel/callmodelperftest.cpp
Expand Up @@ -201,8 +201,6 @@ void CallModelPerfTest::getEvents()
fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve);
fetchModel.setFilter(CallModel::SortByContact);

waitForIdle();

QTime time;
time.start();

Expand Down
2 changes: 0 additions & 2 deletions tests/perf_conversationmodel/conversationmodelperftest.cpp
Expand Up @@ -228,8 +228,6 @@ void ConversationModelPerfTest::getEvents()
fetchModel.setChunkSize(limit);
}

waitForIdle();

QTime time;
time.start();
bool result = fetchModel.getEvents(groupIds);
Expand Down
2 changes: 0 additions & 2 deletions tests/perf_groupmodel/groupmodelperftest.cpp
Expand Up @@ -214,8 +214,6 @@ void GroupModelPerfTest::getGroups()

fetchModel.setManager(&manager);

waitForIdle();

QTime time;
time.start();
bool result = fetchModel.getGroups();
Expand Down
Expand Up @@ -203,8 +203,6 @@ void RecentContactsModelPerfTest::getEvents()
if (limit)
fetchModel.setLimit(limit);

waitForIdle();

QTime time;
time.start();

Expand Down
2 changes: 0 additions & 2 deletions tests/profile_callmodel/callmodelprofiletest.cpp
Expand Up @@ -161,8 +161,6 @@ void CallModelProfileTest::execute()
fetchModel.setResolveContacts(resolve ? EventModel::ResolveImmediately : EventModel::DoNotResolve);
fetchModel.setFilter(CallModel::SortByContact);

waitForIdle();

QTime time;
time.start();

Expand Down
Expand Up @@ -184,8 +184,6 @@ void ConversationModelProfileTest::execute()
fetchModel.setChunkSize(limit);
}

waitForIdle();

QTime time;
time.start();
bool result = fetchModel.getEvents();
Expand Down
2 changes: 0 additions & 2 deletions tests/profile_groupmodel/groupmodelprofiletest.cpp
Expand Up @@ -169,8 +169,6 @@ void GroupModelProfileTest::execute()

fetchModel.setManager(&manager);

waitForIdle();

QTime time;
time.start();

Expand Down
Expand Up @@ -173,8 +173,6 @@ void RecentContactsModelProfileTest::execute()
RecentContactsModel fetchModel;
fetchModel.setLimit(limit);

waitForIdle();

QTime time;
time.start();

Expand Down

0 comments on commit 251c21d

Please sign in to comment.