xref: /glogg/tests/logdataPerfTest.cpp (revision 653377b63177ff63943e126bf71462b35ceb8b9d)
11ee847caSNicolas Bonnefon #include <QTest>
21ee847caSNicolas Bonnefon #include <QSignalSpy>
31ee847caSNicolas Bonnefon 
41ee847caSNicolas Bonnefon #include "log.h"
51ee847caSNicolas Bonnefon #include "test_utils.h"
61ee847caSNicolas Bonnefon 
71ee847caSNicolas Bonnefon #include "data/logdata.h"
81ee847caSNicolas Bonnefon 
91ee847caSNicolas Bonnefon #include "gmock/gmock.h"
101ee847caSNicolas Bonnefon 
111ee847caSNicolas Bonnefon #define TMPDIR "/tmp"
121ee847caSNicolas Bonnefon 
131ee847caSNicolas Bonnefon static const qint64 VBL_NB_LINES = 4999999LL;
141ee847caSNicolas Bonnefon static const int VBL_LINE_PER_PAGE = 70;
151ee847caSNicolas Bonnefon static const char* vbl_format="LOGDATA is a part of glogg, we are going to test it thoroughly, this is line\t\t%07d\n";
161ee847caSNicolas Bonnefon static const int VBL_LINE_LENGTH = (76+2+7) ; // Without the final '\n' !
171ee847caSNicolas Bonnefon static const int VBL_VISIBLE_LINE_LENGTH = (76+8+4+7); // Without the final '\n' !
181ee847caSNicolas Bonnefon 
191ee847caSNicolas Bonnefon class PerfLogData : public testing::Test {
201ee847caSNicolas Bonnefon   public:
PerfLogData()211ee847caSNicolas Bonnefon     PerfLogData() {
221ee847caSNicolas Bonnefon         FILELog::setReportingLevel( logERROR );
231ee847caSNicolas Bonnefon 
241ee847caSNicolas Bonnefon         generateDataFiles();
251ee847caSNicolas Bonnefon     }
261ee847caSNicolas Bonnefon 
generateDataFiles()271ee847caSNicolas Bonnefon     bool generateDataFiles() {
281ee847caSNicolas Bonnefon         char newLine[90];
291ee847caSNicolas Bonnefon 
301ee847caSNicolas Bonnefon         QFile file( TMPDIR "/verybiglog.txt" );
311ee847caSNicolas Bonnefon         if ( file.open( QIODevice::WriteOnly ) ) {
321ee847caSNicolas Bonnefon             for (int i = 0; i < VBL_NB_LINES; i++) {
331ee847caSNicolas Bonnefon                 snprintf(newLine, 89, vbl_format, i);
341ee847caSNicolas Bonnefon                 file.write( newLine, qstrlen(newLine) );
351ee847caSNicolas Bonnefon             }
361ee847caSNicolas Bonnefon         }
371ee847caSNicolas Bonnefon         else {
381ee847caSNicolas Bonnefon             return false;
391ee847caSNicolas Bonnefon         }
401ee847caSNicolas Bonnefon         file.close();
411ee847caSNicolas Bonnefon 
421ee847caSNicolas Bonnefon         return true;
431ee847caSNicolas Bonnefon     }
441ee847caSNicolas Bonnefon };
451ee847caSNicolas Bonnefon 
TEST_F(PerfLogData,simpleLoad)461ee847caSNicolas Bonnefon TEST_F( PerfLogData, simpleLoad ) {
471ee847caSNicolas Bonnefon     LogData log_data;
481ee847caSNicolas Bonnefon     QSignalSpy progressSpy( &log_data, SIGNAL( loadingProgressed( int ) ) );
491ee847caSNicolas Bonnefon     QSignalSpy endSpy( &log_data, SIGNAL( loadingFinished( LoadingStatus ) ) );
501ee847caSNicolas Bonnefon 
511ee847caSNicolas Bonnefon     {
521ee847caSNicolas Bonnefon         TestTimer t;
531ee847caSNicolas Bonnefon 
541ee847caSNicolas Bonnefon         log_data.attachFile( TMPDIR "/verybiglog.txt" );
551ee847caSNicolas Bonnefon         ASSERT_TRUE( endSpy.wait( 20000 ) );
561ee847caSNicolas Bonnefon     }
571ee847caSNicolas Bonnefon 
58*653377b6SNicolas Bonnefon     ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES );
59*653377b6SNicolas Bonnefon     ASSERT_THAT( log_data.getMaxLength(), VBL_VISIBLE_LINE_LENGTH );
60*653377b6SNicolas Bonnefon     ASSERT_THAT( log_data.getLineLength( 123 ), VBL_VISIBLE_LINE_LENGTH );
61*653377b6SNicolas Bonnefon     ASSERT_THAT( log_data.getFileSize(), VBL_NB_LINES * (VBL_LINE_LENGTH+1LL) );
62*653377b6SNicolas Bonnefon 
631ee847caSNicolas Bonnefon     // Blocks of 5 MiB + 1 for the start notification (0%)
641ee847caSNicolas Bonnefon     ASSERT_THAT( progressSpy.count(), log_data.getFileSize() / (5LL*1024*1024) + 2 );
651ee847caSNicolas Bonnefon     ASSERT_THAT( endSpy.count(), 1 );
661ee847caSNicolas Bonnefon     QList<QVariant> arguments = endSpy.takeFirst();
671ee847caSNicolas Bonnefon     ASSERT_THAT( arguments.at(0).toInt(),
681ee847caSNicolas Bonnefon             static_cast<int>( LoadingStatus::Successful ) );
691ee847caSNicolas Bonnefon }
701ee847caSNicolas Bonnefon 
711ee847caSNicolas Bonnefon class PerfLogDataRead : public PerfLogData {
721ee847caSNicolas Bonnefon   public:
PerfLogDataRead()73dfb2a39cSNicolas Bonnefon     PerfLogDataRead() : PerfLogData(), log_data(), endSpy(
741ee847caSNicolas Bonnefon             &log_data, SIGNAL( loadingFinished( LoadingStatus ) ) ) {
751ee847caSNicolas Bonnefon         log_data.attachFile( TMPDIR "/verybiglog.txt" );
76dfb2a39cSNicolas Bonnefon         endSpy.wait( 20000 );
771ee847caSNicolas Bonnefon     }
781ee847caSNicolas Bonnefon 
791ee847caSNicolas Bonnefon     LogData log_data;
801ee847caSNicolas Bonnefon     SafeQSignalSpy endSpy;
811ee847caSNicolas Bonnefon };
821ee847caSNicolas Bonnefon 
TEST_F(PerfLogDataRead,sequentialRead)831ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, sequentialRead ) {
84dfb2a39cSNicolas Bonnefon     ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES );
851ee847caSNicolas Bonnefon     // Read all lines sequentially
861ee847caSNicolas Bonnefon     QString s;
871ee847caSNicolas Bonnefon     {
881ee847caSNicolas Bonnefon         TestTimer t;
891ee847caSNicolas Bonnefon 
901ee847caSNicolas Bonnefon         for (int i = 0; i < VBL_NB_LINES; i++) {
911ee847caSNicolas Bonnefon             s = log_data.getLineString(i);
921ee847caSNicolas Bonnefon         }
931ee847caSNicolas Bonnefon     }
941ee847caSNicolas Bonnefon }
951ee847caSNicolas Bonnefon 
TEST_F(PerfLogDataRead,sequentialReadExpanded)961ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, sequentialReadExpanded ) {
97dfb2a39cSNicolas Bonnefon     ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES );
981ee847caSNicolas Bonnefon     // Read all lines sequentially (expanded)
991ee847caSNicolas Bonnefon     QString s;
1001ee847caSNicolas Bonnefon     {
1011ee847caSNicolas Bonnefon         TestTimer t;
1021ee847caSNicolas Bonnefon 
1031ee847caSNicolas Bonnefon         for (int i = 0; i < VBL_NB_LINES; i++) {
1041ee847caSNicolas Bonnefon             s = log_data.getExpandedLineString(i);
1051ee847caSNicolas Bonnefon         }
1061ee847caSNicolas Bonnefon     }
1071ee847caSNicolas Bonnefon }
1081ee847caSNicolas Bonnefon 
TEST_F(PerfLogDataRead,randomPageRead)1091ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, randomPageRead ) {
110dfb2a39cSNicolas Bonnefon     ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES );
1111ee847caSNicolas Bonnefon     // Read page by page from the beginning and the end, using the QStringList
1121ee847caSNicolas Bonnefon     // function
1131ee847caSNicolas Bonnefon     QStringList list;
1141ee847caSNicolas Bonnefon     {
1151ee847caSNicolas Bonnefon         TestTimer t;
1161ee847caSNicolas Bonnefon 
1171ee847caSNicolas Bonnefon         for (int page = 0; page < (VBL_NB_LINES/VBL_LINE_PER_PAGE)-1; page++)
1181ee847caSNicolas Bonnefon         {
1191ee847caSNicolas Bonnefon             list = log_data.getLines( page*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE );
120dfb2a39cSNicolas Bonnefon             ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE);
1211ee847caSNicolas Bonnefon             int page_from_end = (VBL_NB_LINES/VBL_LINE_PER_PAGE) - page - 1;
1221ee847caSNicolas Bonnefon             list = log_data.getLines( page_from_end*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE );
123dfb2a39cSNicolas Bonnefon             ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE);
1241ee847caSNicolas Bonnefon         }
1251ee847caSNicolas Bonnefon     }
1261ee847caSNicolas Bonnefon }
1271ee847caSNicolas Bonnefon 
TEST_F(PerfLogDataRead,randomPageReadExpanded)1281ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, randomPageReadExpanded ) {
129dfb2a39cSNicolas Bonnefon     ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES );
1301ee847caSNicolas Bonnefon     // Read page by page from the beginning and the end, using the QStringList
1311ee847caSNicolas Bonnefon     // function
1321ee847caSNicolas Bonnefon     QStringList list;
1331ee847caSNicolas Bonnefon     {
1341ee847caSNicolas Bonnefon         TestTimer t;
1351ee847caSNicolas Bonnefon 
1361ee847caSNicolas Bonnefon         for (int page = 0; page < (VBL_NB_LINES/VBL_LINE_PER_PAGE)-1; page++)
1371ee847caSNicolas Bonnefon         {
1381ee847caSNicolas Bonnefon             list = log_data.getExpandedLines( page*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE );
139dfb2a39cSNicolas Bonnefon             ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE);
1401ee847caSNicolas Bonnefon             int page_from_end = (VBL_NB_LINES/VBL_LINE_PER_PAGE) - page - 1;
1411ee847caSNicolas Bonnefon             list = log_data.getExpandedLines( page_from_end*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE );
142dfb2a39cSNicolas Bonnefon             ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE);
1431ee847caSNicolas Bonnefon         }
1441ee847caSNicolas Bonnefon     }
1451ee847caSNicolas Bonnefon }
146