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