File indexing completed on 2024-12-22 04:10:30
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_swapped_data_store_test.h" 0008 #include <simpletest.h> 0009 0010 #include "kis_debug.h" 0011 0012 #include "kis_image_config.h" 0013 0014 #include "tiles3/kis_tile_data.h" 0015 #include "tiles_test_utils.h" 0016 0017 #include "tiles3/kis_tile_data_store.h" 0018 0019 0020 #define COLUMN2COLOR(col) (col%255) 0021 0022 void KisSwappedDataStoreTest::testRoundTrip() 0023 { 0024 const qint32 pixelSize = 1; 0025 const quint8 defaultPixel = 128; 0026 const qint32 NUM_TILES = 10000; 0027 0028 KisImageConfig config(false); 0029 config.setMaxSwapSize(4); 0030 config.setSwapSlabSize(1); 0031 config.setSwapWindowSize(1); 0032 0033 0034 KisSwappedDataStore store; 0035 0036 QList<KisTileData*> tileDataList; 0037 for(qint32 i = 0; i < NUM_TILES; i++) 0038 tileDataList.append(new KisTileData(pixelSize, &defaultPixel, KisTileDataStore::instance())); 0039 0040 for(qint32 i = 0; i < NUM_TILES; i++) { 0041 KisTileData *td = tileDataList[i]; 0042 QVERIFY(memoryIsFilled(defaultPixel, td->data(), TILESIZE)); 0043 0044 memset(td->data(), COLUMN2COLOR(i), TILESIZE); 0045 QVERIFY(memoryIsFilled(COLUMN2COLOR(i), td->data(), TILESIZE)); 0046 0047 // FIXME: take a lock of the tile data 0048 QVERIFY(store.trySwapOutTileData(td)); 0049 } 0050 0051 store.debugStatistics(); 0052 0053 for(qint32 i = 0; i < NUM_TILES; i++) { 0054 KisTileData *td = tileDataList[i]; 0055 QVERIFY(!td->data()); 0056 // TODO: check num clones 0057 0058 // FIXME: take a lock of the tile data 0059 store.swapInTileData(td); 0060 QVERIFY(memoryIsFilled(COLUMN2COLOR(i), td->data(), TILESIZE)); 0061 } 0062 0063 store.debugStatistics(); 0064 0065 for(qint32 i = 0; i < NUM_TILES; i++) 0066 delete tileDataList[i]; 0067 } 0068 0069 void KisSwappedDataStoreTest::processTileData(qint32 column, KisTileData *td, KisSwappedDataStore &store) 0070 { 0071 if(td->data()) { 0072 memset(td->data(), COLUMN2COLOR(column), TILESIZE); 0073 QVERIFY(memoryIsFilled(COLUMN2COLOR(column), td->data(), TILESIZE)); 0074 0075 // FIXME: take a lock of the tile data 0076 QVERIFY(store.trySwapOutTileData(td)); 0077 } 0078 else { 0079 // TODO: check num clones 0080 // FIXME: take a lock of the tile data 0081 store.swapInTileData(td); 0082 QVERIFY(memoryIsFilled(COLUMN2COLOR(column), td->data(), TILESIZE)); 0083 } 0084 } 0085 0086 void KisSwappedDataStoreTest::testRandomAccess() 0087 { 0088 qsrand(10); 0089 const qint32 pixelSize = 1; 0090 const quint8 defaultPixel = 128; 0091 const qint32 NUM_CYCLES = 50000; 0092 const qint32 NUM_TILES = 10000; 0093 0094 KisImageConfig config(false); 0095 config.setMaxSwapSize(40); 0096 config.setSwapSlabSize(1); 0097 config.setSwapWindowSize(1); 0098 0099 0100 KisSwappedDataStore store; 0101 0102 QList<KisTileData*> tileDataList; 0103 for(qint32 i = 0; i < NUM_TILES; i++) 0104 tileDataList.append(new KisTileData(pixelSize, &defaultPixel, KisTileDataStore::instance())); 0105 0106 for(qint32 i = 0; i < NUM_CYCLES; i++) { 0107 if(!(i%5000)) 0108 dbgKrita << i << "of" << NUM_CYCLES; 0109 0110 qint32 col = qrand() % NUM_TILES; 0111 0112 KisTileData *td = tileDataList[col]; 0113 processTileData(col, td, store); 0114 } 0115 0116 store.debugStatistics(); 0117 0118 for(qint32 i = 0; i < NUM_TILES; i++) 0119 delete tileDataList[i]; 0120 } 0121 0122 SIMPLE_TEST_MAIN(KisSwappedDataStoreTest) 0123