1919#include < QString>
2020#include < QTemporaryFile>
2121#include < qgsapplication.h>
22+ #include < chrono>
2223
2324// header for class being tested
2425#include < qgsopenclutils.h>
25-
26+ #include < qgshillshaderenderer.h>
27+ #include < qgsrasterlayer.h>
2628
2729class TestQgsOpenClUtils : public QObject
2830{
@@ -46,7 +48,11 @@ class TestQgsOpenClUtils: public QObject
4648
4749 private:
4850
51+ // For performance testing
52+ void testHillshade ();
53+
4954 void _testMakeRunProgram ();
55+ void _testMakeHillshade ( const QString title, const int loops );
5056
5157 cl::Program buildProgram ( const cl::Context &context, const QString &source )
5258 {
@@ -67,11 +73,15 @@ class TestQgsOpenClUtils: public QObject
6773 return pgm;
6874
6975 }
76+
77+ QgsRasterLayer *mFloat32RasterLayer = nullptr ;
7078};
7179
7280
7381void TestQgsOpenClUtils::init ()
7482{
83+ // Reset to default in case some tests mess it up
84+ QgsOpenClUtils::setSourcePath ( QDir ( QgsApplication::pkgDataPath () ).absoluteFilePath ( QStringLiteral ( " resources/opencl_programs" ) ) );
7585}
7686
7787void TestQgsOpenClUtils::cleanup ()
@@ -89,6 +99,11 @@ void TestQgsOpenClUtils::initTestCase()
8999
90100 QgsApplication::init ();
91101 QgsApplication::initQgis ();
102+
103+ QString float32FileName = QStringLiteral ( TEST_DATA_DIR ) + ' /' + " /raster/band1_float32_noct_epsg4326.tif" ;
104+ QFileInfo float32RasterFileInfo ( float32FileName );
105+ mFloat32RasterLayer = new QgsRasterLayer ( float32RasterFileInfo.filePath (),
106+ float32RasterFileInfo.completeBaseName () );
92107}
93108
94109
@@ -183,6 +198,27 @@ void TestQgsOpenClUtils::testContext()
183198 QVERIFY ( QgsOpenClUtils::context ()() != nullptr );
184199}
185200
201+ void TestQgsOpenClUtils::_testMakeHillshade ( const QString title, const int loops )
202+ {
203+ std::chrono::time_point<std::chrono::system_clock> startTime ( std::chrono::system_clock::now () );
204+ for ( int i = 0 ; i < loops; i++ )
205+ {
206+ QgsHillshadeRenderer renderer ( mFloat32RasterLayer ->dataProvider (), 1 , 35.0 , 5000.0 );
207+ QgsRasterBlock *block = renderer.block ( 0 , mFloat32RasterLayer ->extent (), 401 , 401 );
208+ }
209+ qDebug () << QStringLiteral ( " %1 average for %2 loops: %3 ms" )
210+ .arg ( title )
211+ .arg ( loops )
212+ .arg ( std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now () - startTime ).count () / loops ) ;
213+ }
214+
215+ void TestQgsOpenClUtils::testHillshade ()
216+ {
217+ QgsOpenClUtils::setEnabled ( true );
218+ _testMakeHillshade ( QStringLiteral ( " OpenCL" ), 5 );
219+ QgsOpenClUtils::setEnabled ( false );
220+ _testMakeHillshade ( QStringLiteral ( " CPU" ), 5 );
221+ }
186222
187223QGSTEST_MAIN ( TestQgsOpenClUtils )
188224#include " testqgsopenclutils.moc"
0 commit comments