Ticket #823: xapian-1.4-ioblock-fix.patch

File xapian-1.4-ioblock-fix.patch, 1.8 KB (added by Olly Betts, 11 months ago)

candidate patch

  • xapian-core/tests/unittest.cc

    diff --git a/xapian-core/tests/unittest.cc b/xapian-core/tests/unittest.cc
    index 36ab22c3e3cb..f371723c8ac0 100644
    a b  
    3030#include <cstring>
    3131#include <iostream>
    3232#include <limits>
     33#include <random>
    3334#include <utility>
    3435
    3536#include "safeunistd.h"
    try {  
    912913    int fd = io_open_block_wr(tmp_file, true);
    913914    TEST_REL(fd, >=, 0);
    914915
    915     string buf(BLOCK_SIZE, 'x');
     916    mt19937 gen;
     917    gen.seed(42);
     918    uniform_int_distribution<> distribution(0, 255);
     919    string buf(BLOCK_SIZE, '\0');
     920    for (int i = 0; i != BLOCK_SIZE; ++i) {
     921        buf[i] = static_cast<char>(distribution(gen));
     922    }
    916923    string out;
    917924
    918925    io_write_block(fd, buf.data(), BLOCK_SIZE, 1);
    try {  
    924931    // any effect is much harder to do.
    925932    TEST(io_sync(fd));
    926933
     934    for (int i = 0; i != BLOCK_SIZE; ++i) {
     935        buf[i] = static_cast<char>(distribution(gen));
     936    }
    927937    io_write_block(fd, buf.data(), BLOCK_SIZE, 12);
    928938    out.resize(BLOCK_SIZE);
    929939    io_read_block(fd, &out[0], BLOCK_SIZE, 12);
    try {  
    954964    // which truncate the offset used.
    955965    constexpr off_t high_offset = (off_t{1} << 32) + BLOCK_SIZE;
    956966    constexpr off_t high_block = high_offset / BLOCK_SIZE;
     967    for (int i = 0; i != BLOCK_SIZE; ++i) {
     968        buf[i] = static_cast<char>(distribution(gen));
     969    }
    957970    try {
    958971        io_write_block(fd, buf.data(), BLOCK_SIZE, high_block);
    959972    } catch (const Xapian::DatabaseError& e) {
    try {  
    982995#else
    983996    close(fd);
    984997    io_unlink(tmp_file);
    985     SKIP_TEST("Skipping rest of testcase - FS doesn't support holes");
     998    SKIP_TEST("Skipping rest of testcase - FS doesn't support holes or compressed blocks");
    986999#endif
    9871000} catch (const Xapian::Error& e) {
    9881001    // Translate Xapian::Error exceptions to std::string exceptions which