Debug self-test function for testing a file object implementation, performs various behavior validity checks, random access etc. Output goes to fb2k console. Returns true on success, false on failure (buggy file object implementation).
143 f->read_till_eof(fileContent, aborter);
146 t_filesize sizeClaimed = f->get_size(aborter);
148 FB2K_console_formatter() <<
"File sanity: file reports unknown size, actual size read is " << fileContent.
get_size();
151 if (sizeClaimed != fileContent.
get_size()) {
152 FB2K_console_formatter() <<
"File sanity: file reports size of " << sizeClaimed <<
", actual size read is " << fileContent.
get_size();
153 throw std::runtime_error(
"File size mismatch");
156 FB2K_console_formatter() <<
"File sanity: file size check OK: " << sizeClaimed;
162 FB2K_console_formatter() <<
"File sanity: testing N-first-bytes reads...";
163 const size_t sizeUpTo = pfc::min_t<size_t>(fileContent.
get_size(), 1024 * 1024);
167 for (
size_t w = 1; w <= sizeUpTo; w <<= 1) {
169 size_t did = f->read(buf1.get_ptr(), w, aborter);
171 FB2K_console_formatter() <<
"File sanity: premature EOF reading first " << w <<
" bytes, got " << did;
172 throw std::runtime_error(
"Premature EOF");
174 if (memcmp(fileContent.
get_ptr(), buf1.get_ptr(), did) != 0) {
175 FB2K_console_formatter() <<
"File sanity: file content mismatch reading first " << w <<
" bytes";
176 throw std::runtime_error(
"File content mismatch");
181 FB2K_console_formatter() <<
"File sanity: testing random access...";
184 size_t sizeUpTo = pfc::min_t<size_t>(fileContent.
get_size(), 1024 * 1024);
185 for (
size_t w = 1; w < sizeUpTo; w <<= 1) {
189 for (
size_t w = 1; w < sizeUpTo; w <<= 1) {
195 FB2K_console_formatter() <<
"File sanity test: all OK";
199 FB2K_console_formatter() <<
"File sanity test failure: " << e.what();
const t_item * get_ptr() const
Special simplififed version of array class that avoids stepping on landmines with classes without pub...
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
t_uint64 t_filesize
Type used for file size related variables.
static void fileSanitySeek(file::ptr f, pfc::array_t< uint8_t > const &content, size_t offset, abort_callback &aborter)
void set_size_discard(t_size p_size)