Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions io/fs/AlignedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@ class AlignedBuffer {

_buffer = other._buffer;
_size = other._size;
_capacity = other._capacity;
other._buffer = nullptr;
other._size = 0;
other._capacity = 0;
}

AlignedBuffer& operator=(AlignedBuffer&& other) noexcept {
if (this == &other) {
return *this;
}

free(_buffer);

_buffer = other._buffer;
_size = other._size;
_capacity = other._capacity;
other._buffer = nullptr;
other._size = 0;
other._capacity = 0;

return *this;
}
Expand Down
11 changes: 4 additions & 7 deletions io/fs/FilePageWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <fcntl.h>
#include <unistd.h>

#include <algorithm>

#include "BioAssert.h"

using namespace fs;
Expand Down Expand Up @@ -80,9 +82,6 @@ void FilePageWriter::finish() {
}

if (_buffer.size() > 0) {
if (_buffer.size() != _buffer.capacity()) {
std::memset(_buffer.data() + _buffer.size(), 0, _buffer.avail());
}
flush();
sync();
}
Expand All @@ -92,10 +91,6 @@ void FilePageWriter::finish() {
}

void FilePageWriter::nextPage() {
if (_buffer.size() != _buffer.capacity()) {
std::memset(_buffer.data() + _buffer.size(), 0, _buffer.avail());
}

flush();
}

Expand All @@ -114,6 +109,8 @@ void FilePageWriter::reserveSpace(size_t byteCount) {
}

void FilePageWriter::flush() {
std::fill_n(_buffer.data() + _buffer.size(), _buffer.avail(), 0);

ssize_t remainingBytes = buffer().capacity();
ssize_t bytesWritten = 0;

Expand Down
35 changes: 35 additions & 0 deletions test/io/AlignedBufferMoveTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <utility>

#include "TuringTest.h"

#include "AlignedBuffer.h"

using namespace turing::test;

namespace {

constexpr size_t CAPACITY = 16384;

}

class AlignedBufferMoveTest : public TuringTest {
};

TEST_F(AlignedBufferMoveTest, MoveConstructionKeepsTheCapacity) {
fs::AlignedBuffer buffer(CAPACITY);
const fs::AlignedBuffer moved(std::move(buffer));

EXPECT_EQ(moved.capacity(), CAPACITY);
}

TEST_F(AlignedBufferMoveTest, MoveAssignmentKeepsTheCapacity) {
fs::AlignedBuffer buffer(CAPACITY);
fs::AlignedBuffer assigned;
assigned = std::move(buffer);

EXPECT_EQ(assigned.capacity(), CAPACITY);
}

int main(int argc, char** argv) {
return turing::test::turingTestMain(argc, argv);
}
2 changes: 2 additions & 0 deletions test/io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
add_turing_test(test_io_path PathTest.cpp)
add_turing_test(test_io_aligned_buffer_move AlignedBufferMoveTest.cpp)
add_turing_test(test_io_bytebufferiterator ByteBufferIteratorTest.cpp)
add_turing_test(test_io_unaligned_scalar_read UnalignedScalarReadTest.cpp)
add_turing_test(test_io_filewriter FileWriterTest.cpp)
add_turing_test(test_io_filepagewriter FilePageWriterTest.cpp)
add_turing_test(test_io_filepagewriter_zero_tail FilePageWriterZeroTailTest.cpp)
add_turing_test(test_io_filepagereader FilePageReaderTest.cpp)
add_turing_test(test_io_fileresult FileResultTest.cpp)
add_turing_test(test_io_s3 S3Test.cpp)
Expand Down
99 changes: 99 additions & 0 deletions test/io/FilePageWriterZeroTailTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <stdint.h>
#include <string.h>

#include <algorithm>
#include <fstream>
#include <iterator>
#include <span>
#include <vector>

#include "TuringTest.h"

#include "FilePageWriter.h"
#include "Path.h"

using namespace turing::test;

namespace {

constexpr size_t PAGE_SIZE = 16384;
constexpr uint64_t VALUE = 42;

}

class FilePageWriterZeroTailTest : public TuringTest {
protected:
void initialize() override {
_path = fs::Path {_outDir + "/pages"};
}

void writeStalePageThenValue(fs::FilePageWriter& writer) {
const std::vector<uint8_t> stalePage(PAGE_SIZE, 0xFF);
writer.writeToCurrentPage(std::span<const uint8_t> {stalePage});
writer.nextPage();

writer.writeToCurrentPage(VALUE);
}

void expectZerosAfterValue() {
std::ifstream file(_path.c_str(), std::ios::binary);
const std::vector<uint8_t> bytes {std::istreambuf_iterator<char> {file},
std::istreambuf_iterator<char> {}};
ASSERT_EQ(bytes.size(), 2 * PAGE_SIZE);

const uint8_t* secondPage = bytes.data() + PAGE_SIZE;
uint64_t value {0};
memcpy(&value, secondPage, sizeof(uint64_t));
EXPECT_EQ(value, VALUE);

const bool tailIsZero = std::all_of(secondPage + sizeof(uint64_t),
bytes.data() + bytes.size(),
[](uint8_t byte) { return byte == 0; });
EXPECT_TRUE(tailIsZero);
}

fs::Path _path;
};

TEST_F(FilePageWriterZeroTailTest, SeekWritesZerosAfterTheBytesOfItsPage) {
{
auto writer = fs::FilePageWriter::open(_path, PAGE_SIZE);
ASSERT_TRUE(writer.has_value());

writeStalePageThenValue(writer.value());
writer->seek(0);
ASSERT_FALSE(writer->errorOccured());
}

expectZerosAfterValue();
}

TEST_F(FilePageWriterZeroTailTest, NextPageWritesZerosAfterTheBytesOfItsPage) {
{
auto writer = fs::FilePageWriter::open(_path, PAGE_SIZE);
ASSERT_TRUE(writer.has_value());

writeStalePageThenValue(writer.value());
writer->nextPage();
ASSERT_FALSE(writer->errorOccured());
}

expectZerosAfterValue();
}

TEST_F(FilePageWriterZeroTailTest, FinishWritesZerosAfterTheBytesOfItsPage) {
{
auto writer = fs::FilePageWriter::open(_path, PAGE_SIZE);
ASSERT_TRUE(writer.has_value());

writeStalePageThenValue(writer.value());
writer->finish();
ASSERT_FALSE(writer->errorOccured());
}

expectZerosAfterValue();
}

int main(int argc, char** argv) {
return turing::test::turingTestMain(argc, argv);
}
2 changes: 1 addition & 1 deletion test/io/FileWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST_F(FileWriterTest, General) {
// FileWriter with small buffer
writer.setFile(&file);

std::array<uint8_t, 256> bytes;
std::array<uint8_t, 256> bytes {};
bytes[0] = 0;
bytes[3] = 3;
bytes[6] = 6;
Expand Down
18 changes: 14 additions & 4 deletions test/query/ir/subquery/SubqueryWrittenEntityMatrixTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdlib.h>

#include <iterator>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -544,16 +545,25 @@ std::string_view consumerName(Consumer consumer) {
return "";
}

std::string caseName(const testing::TestParamInfo<WrittenEntityCase>& info) {
const WrittenEntityCase& testCase = info.param;

std::string name {formName(testCase._form)};
void buildCaseName(const WrittenEntityCase& testCase, std::string& name) {
name = formName(testCase._form);
name += testCase._entity == Entity::NODE ? "_Node_" : "_Edge_";
name += writeName(testCase._remyWrite);
name += "_";
name += writeName(testCase._otherWrite);
name += testCase._optional ? "_Optional_" : "_";
name += consumerName(testCase._consumer);
}

void PrintTo(const WrittenEntityCase& testCase, std::ostream* stream) {
std::string name;
buildCaseName(testCase, name);
*stream << name;
}

std::string caseName(const testing::TestParamInfo<WrittenEntityCase>& info) {
std::string name;
buildCaseName(info.param, name);

return name;
}
Expand Down
2 changes: 1 addition & 1 deletion test/storage/dump/PropertyDumpFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST_F(PropertyDumpFormatTest, stringDumpBytes) {

uint64_t hash = 0;
hashDumpFileContent(path, hash);
EXPECT_EQ(hash, 3120130461636103366ull);
EXPECT_EQ(hash, 5183985201322724322ull);

{
auto reader = fs::FilePageReader::open(path, DumpConfig::PAGE_SIZE);
Expand Down
Loading