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@101 | 28 | : Accessor(fileid), _size(size) |
paul@101 | 29 | { |
paul@101 | 30 | } |
paul@101 | 31 | |
paul@101 | 32 | /* Return the size of the file. */ |
paul@101 | 33 | |
paul@101 | 34 | offset_t TestFileAccessor::get_size() |
paul@6 | 35 | { |
paul@101 | 36 | return _size; |
paul@101 | 37 | } |
paul@101 | 38 | |
paul@101 | 39 | /* Update the size of the file. */ |
paul@101 | 40 | |
paul@101 | 41 | void TestFileAccessor::set_size(offset_t size) |
paul@101 | 42 | { |
paul@101 | 43 | _size = size; |
paul@6 | 44 | } |
paul@6 | 45 | |
paul@56 | 46 | /* Data transfer helper methods. */ |
paul@6 | 47 | |
paul@56 | 48 | void TestFileAccessor::fill_populated(Flexpage *flexpage) |
paul@6 | 49 | { |
paul@6 | 50 | Region *region = flexpage->region; |
paul@6 | 51 | offset_t filepos = flexpage->base_offset; |
paul@6 | 52 | |
paul@6 | 53 | /* Tag the region with file state. */ |
paul@6 | 54 | |
paul@6 | 55 | region->fill(fileid, filepos); |
paul@6 | 56 | |
paul@6 | 57 | /* Write some data to each page of the flexpage in each region. This |
paul@6 | 58 | allows each page to be tested regardless of how large each flexpage |
paul@6 | 59 | or region is. */ |
paul@6 | 60 | |
paul@6 | 61 | offset_t addr = flexpage->base_addr; |
paul@6 | 62 | offset_t limit = addr + flexpage->size; |
paul@6 | 63 | |
paul@6 | 64 | while (addr < limit) |
paul@6 | 65 | { |
paul@6 | 66 | /* Overwrite enough of any previous data to make the new data |
paul@6 | 67 | readable. */ |
paul@6 | 68 | |
paul@6 | 69 | char tag[32]; |
paul@6 | 70 | |
paul@6 | 71 | sprintf(tag, "%ld:%ld", fileid, filepos); |
paul@6 | 72 | |
paul@6 | 73 | memset((void *) addr, 0, strlen(tag) + 1); |
paul@6 | 74 | strcpy((char *) addr, tag); |
paul@6 | 75 | |
paul@6 | 76 | filepos += PAGE_SIZE; |
paul@6 | 77 | addr += PAGE_SIZE; |
paul@6 | 78 | } |
paul@6 | 79 | } |
paul@6 | 80 | |
paul@56 | 81 | void TestFileAccessor::flush_populated(Flexpage *flexpage) |
paul@6 | 82 | { |
paul@6 | 83 | flexpage->region->flush(); |
paul@6 | 84 | } |
paul@6 | 85 | |
paul@6 | 86 | // vim: tabstop=4 expandtab shiftwidth=4 |