add gputemperature tests

This commit is contained in:
Evgenii Alekseev 2016-06-08 12:33:55 +03:00
parent 5a0541d06d
commit bc2071a493
4 changed files with 129 additions and 16 deletions

View File

@ -55,19 +55,19 @@ GPUTemperatureSource::~GPUTemperatureSource()
QString GPUTemperatureSource::autoGpu()
{
QString gpu = QString("disable");
QFile moduleFile(QString("/proc/modules"));
if (!moduleFile.open(QIODevice::ReadOnly))
return gpu;
QString output = moduleFile.readAll();
if (output.contains(QString("fglrx")))
gpu = QString("ati");
else if (output.contains(QString("nvidia")))
gpu = QString("nvidia");
qCInfo(LOG_ESM) << "Device" << gpu;
QString gpu = QString("disable");
QFile moduleFile(QString("/proc/modules"));
if (!moduleFile.open(QIODevice::ReadOnly))
return gpu;
QString output = moduleFile.readAll();
if (output.contains(QString("fglrx")))
gpu = QString("ati");
else if (output.contains(QString("nvidia")))
gpu = QString("nvidia");
qCInfo(LOG_ESM) << "Device" << gpu;
return gpu;
}
@ -78,7 +78,7 @@ QVariant GPUTemperatureSource::data(QString source)
if (source == QString("gpu/temperature"))
run();
return m_value;
return m_values[source];
}
@ -140,7 +140,7 @@ void GPUTemperatureSource::updateValue()
continue;
QString temp = str.remove(QString("<gpu_temp>"))
.remove(QString("C</gpu_temp>"));
m_value = temp.toFloat();
m_values[QString("gpu/temperature")] = temp.toFloat();
break;
}
} else if (m_device == QString("ati")) {
@ -148,8 +148,10 @@ void GPUTemperatureSource::updateValue()
if (!str.contains(QString("Temperature")))
continue;
QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4);
m_value = temp.toFloat();
m_values[QString("gpu/temperature")] = temp.toFloat();
break;
}
}
emit(dataReceived(m_values));
}

View File

@ -43,7 +43,7 @@ private:
// configuration and values
QString m_device;
QProcess *m_process = nullptr;
QVariant m_value;
QVariantHash m_values;
};

View File

@ -0,0 +1,64 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "testgputempsource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "gputempsource.h"
void TestGPUTemperatureSource::initTestCase()
{
device = GPUTemperatureSource::autoGpu();
QVERIFY(!device.isEmpty());
gputempSource = new GPUTemperatureSource(this, QStringList() << device);
}
void TestGPUTemperatureSource::cleanupTestCase()
{
delete gputempSource;
}
void TestGPUTemperatureSource::test_sources()
{
QCOMPARE(gputempSource->sources(), QStringList() << source);
}
void TestGPUTemperatureSource::test_gputemp()
{
if (device == QString("disable"))
QSKIP("Not supported device, test will be skipped");
QSignalSpy spy(gputempSource, SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = gputempSource->data(source).toFloat();
QCOMPARE(firstValue, 0.0f);
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
float secondValue = arguments[source].toFloat();
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
}
QTEST_MAIN(TestGPUTemperatureSource);

View File

@ -0,0 +1,47 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef TESTGPUTEMPSOURCE_H
#define TESTGPUTEMPSOURCE_H
#include <QObject>
class GPUTemperatureSource;
class TestGPUTemperatureSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_gputemp();
private:
GPUTemperatureSource *gputempSource = nullptr;
QString device;
QString source = QString("gpu/temperature");
QPair<float, float> temp = QPair<float, float>(0.0f, 40.0f);
};
#endif /* TESTGPUTEMPSOURCE_H */