1 /* 2 * A test accessor producing generated content. 3 * 4 * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <stdio.h> 23 #include <string.h> 24 25 #include "test_file_accessor.h" 26 27 TestFileAccessor::TestFileAccessor(fileid_t fileid, offset_t size) 28 : Accessor(fileid), _size(size) 29 { 30 } 31 32 /* Return the size of the file. */ 33 34 offset_t TestFileAccessor::get_size() 35 { 36 return _size; 37 } 38 39 /* Update the size of the file. */ 40 41 void TestFileAccessor::set_size(offset_t size) 42 { 43 _size = size; 44 } 45 46 /* Data transfer helper methods. */ 47 48 void TestFileAccessor::fill_populated(Flexpage *flexpage) 49 { 50 Region *region = flexpage->region; 51 offset_t filepos = flexpage->base_offset; 52 53 /* Tag the region with file state. */ 54 55 region->fill(fileid, filepos); 56 57 /* Write some data to each page of the flexpage in each region. This 58 allows each page to be tested regardless of how large each flexpage 59 or region is. */ 60 61 offset_t addr = flexpage->base_addr; 62 offset_t limit = addr + flexpage->size; 63 64 while (addr < limit) 65 { 66 /* Overwrite enough of any previous data to make the new data 67 readable. */ 68 69 char tag[32]; 70 71 sprintf(tag, "%ld:%lld", fileid, filepos); 72 73 memset((void *) addr, 0, strlen(tag) + 1); 74 strcpy((char *) addr, tag); 75 76 filepos += PAGE_SIZE; 77 addr += PAGE_SIZE; 78 } 79 } 80 81 void TestFileAccessor::flush_populated(Flexpage *flexpage) 82 { 83 flexpage->region->flush(); 84 } 85 86 // vim: tabstop=4 expandtab shiftwidth=4