mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add gputemperature tests
This commit is contained in:
parent
5a0541d06d
commit
bc2071a493
@ -55,19 +55,19 @@ GPUTemperatureSource::~GPUTemperatureSource()
|
|||||||
|
|
||||||
QString GPUTemperatureSource::autoGpu()
|
QString GPUTemperatureSource::autoGpu()
|
||||||
{
|
{
|
||||||
QString gpu = QString("disable");
|
QString gpu = QString("disable");
|
||||||
QFile moduleFile(QString("/proc/modules"));
|
QFile moduleFile(QString("/proc/modules"));
|
||||||
if (!moduleFile.open(QIODevice::ReadOnly))
|
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;
|
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"))
|
if (source == QString("gpu/temperature"))
|
||||||
run();
|
run();
|
||||||
|
|
||||||
return m_value;
|
return m_values[source];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ void GPUTemperatureSource::updateValue()
|
|||||||
continue;
|
continue;
|
||||||
QString temp = str.remove(QString("<gpu_temp>"))
|
QString temp = str.remove(QString("<gpu_temp>"))
|
||||||
.remove(QString("C</gpu_temp>"));
|
.remove(QString("C</gpu_temp>"));
|
||||||
m_value = temp.toFloat();
|
m_values[QString("gpu/temperature")] = temp.toFloat();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (m_device == QString("ati")) {
|
} else if (m_device == QString("ati")) {
|
||||||
@ -148,8 +148,10 @@ void GPUTemperatureSource::updateValue()
|
|||||||
if (!str.contains(QString("Temperature")))
|
if (!str.contains(QString("Temperature")))
|
||||||
continue;
|
continue;
|
||||||
QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4);
|
QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4);
|
||||||
m_value = temp.toFloat();
|
m_values[QString("gpu/temperature")] = temp.toFloat();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit(dataReceived(m_values));
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ private:
|
|||||||
// configuration and values
|
// configuration and values
|
||||||
QString m_device;
|
QString m_device;
|
||||||
QProcess *m_process = nullptr;
|
QProcess *m_process = nullptr;
|
||||||
QVariant m_value;
|
QVariantHash m_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
64
sources/test/testgputempsource.cpp
Normal file
64
sources/test/testgputempsource.cpp
Normal 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);
|
47
sources/test/testgputempsource.h
Normal file
47
sources/test/testgputempsource.h
Normal 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 */
|
Loading…
Reference in New Issue
Block a user