1 /* 2 * A test accessor producing generated content. 3 * 4 * Copyright (C) 2021 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) 29 { 30 } 31 32 /* Data transfer helper methods. */ 33 34 void TestFileAccessor::fill_populated(Flexpage *flexpage) 35 { 36 Region *region = flexpage->region; 37 offset_t filepos = flexpage->base_offset; 38 39 /* Tag the region with file state. */ 40 41 region->fill(fileid, filepos); 42 43 /* Write some data to each page of the flexpage in each region. This 44 allows each page to be tested regardless of how large each flexpage 45 or region is. */ 46 47 offset_t addr = flexpage->base_addr; 48 offset_t limit = addr + flexpage->size; 49 50 while (addr < limit) 51 { 52 /* Overwrite enough of any previous data to make the new data 53 readable. */ 54 55 char tag[32]; 56 57 sprintf(tag, "%ld:%ld", fileid, filepos); 58 59 memset((void *) addr, 0, strlen(tag) + 1); 60 strcpy((char *) addr, tag); 61 62 filepos += PAGE_SIZE; 63 addr += PAGE_SIZE; 64 } 65 } 66 67 void TestFileAccessor::flush_populated(Flexpage *flexpage) 68 { 69 flexpage->region->flush(); 70 } 71 72 // vim: tabstop=4 expandtab shiftwidth=4