winfsp unit tests and fixes
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
Scott E. Graves 2024-11-09 15:14:32 -06:00
parent f7ca4f8fa3
commit 2fd6f68c97

View File

@ -577,168 +577,179 @@ static void test_mixed_file(auto &&mount_location, auto &&file_path) {
EXPECT_TRUE(::DeleteFileA(file_path.c_str())); EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
} }
// static void test_mmap_file(auto &&mount_location, auto &&file_path, static void test_mmap_file(auto &&mount_location, auto &&file_path,
// auto &&flags) { auto &&flags, auto &&early_close) {
// SYSTEM_INFO sys_info{}; SYSTEM_INFO sys_info{};
// ::GetSystemInfo(&sys_info); ::GetSystemInfo(&sys_info);
//
// DWORD bytes_per_sector{}; DWORD bytes_per_sector{};
// DWORD free_clusters{}; DWORD free_clusters{};
// DWORD sectors_per_cluster{}; DWORD sectors_per_cluster{};
// DWORD total_clusters{}; DWORD total_clusters{};
// EXPECT_TRUE(::GetDiskFreeSpaceA(mount_location.c_str(), EXPECT_TRUE(::GetDiskFreeSpaceA(mount_location.c_str(), &sectors_per_cluster,
// &sectors_per_cluster, &bytes_per_sector, &free_clusters,
// &bytes_per_sector, &free_clusters, &total_clusters));
// &total_clusters)); const auto buffer_size = 16U * sys_info.dwPageSize;
// const auto buffer_size = 16U * sys_info.dwPageSize; auto write_buffer = utils::generate_secure_random<data_buffer>(buffer_size);
// auto write_buffer =
// utils::generate_secure_random<data_buffer>(buffer_size); auto handle =
// ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
// handle1 = CreateFileW(FilePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS,
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | flags, nullptr);
// FILE_ATTRIBUTE_NORMAL | CreateFlags, 0); EXPECT_NE(INVALID_HANDLE_VALUE, handle);
// ASSERT(INVALID_HANDLE_VALUE != handle1);
// DWORD file_size0{
// Mapping = CreateFileMappingW(handle1, 0, PAGE_READWRITE, 0, 2U * sys_info.dwAllocationGranularity,
// FileSize0 + FileSize1, 0); };
// ASSERT(0 != Mapping); DWORD file_size1{100U};
// auto *mapping = ::CreateFileMappingA(handle, nullptr, PAGE_READWRITE, 0,
// if (EarlyClose) { file_size0 + file_size1, nullptr);
// Success = CloseHandle(Handle); ASSERT_NE(nullptr, mapping);
// ASSERT(Success);
// } if (early_close) {
// EXPECT_TRUE(::CloseHandle(handle));
// MappedView = MapViewOfFile(Mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); }
// ASSERT(0 != MappedView);
// auto *view = MapViewOfFile(mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
// srand(seed); ASSERT_NE(nullptr, view);
// for (PUINT8 Bgn = MappedView + FileSize1 / 2, End = Bgn + FileSize0;
// End > Bgn; Bgn++) auto seed = static_cast<unsigned>(std::time(nullptr));
// *Bgn = rand() & 0xff; srand(seed);
// for (PUINT8 begin = reinterpret_cast<PUINT8>(view) + file_size1 / 2U,
// Success = UnmapViewOfFile(MappedView); end = begin + file_size0;
// ASSERT(Success); end > begin; ++begin) {
// *begin = rand() & 0xFF;
// MappedView = MapViewOfFile(Mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); }
// ASSERT(0 != MappedView);
// EXPECT_TRUE(::UnmapViewOfFile(view));
// srand(seed);
// for (PUINT8 Bgn = MappedView + FileSize1 / 2, End = Bgn + FileSize0; view = ::MapViewOfFile(mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
// End > Bgn; Bgn++) ASSERT_NE(nullptr, view);
// ASSERT(*Bgn == (rand() & 0xff));
// srand(seed);
// Success = UnmapViewOfFile(MappedView); for (PUINT8 begin = reinterpret_cast<PUINT8>(view) + file_size1 / 2U,
// ASSERT(Success); end = begin + file_size0;
// end > begin; begin++) {
// Success = CloseHandle(Mapping); EXPECT_EQ(*begin, (rand() & 0xFF));
// ASSERT(Success); }
//
// if (!EarlyClose) { EXPECT_TRUE(::UnmapViewOfFile(view));
// Success = CloseHandle(Handle);
// ASSERT(Success); EXPECT_TRUE(::CloseHandle(mapping));
// }
// if (not early_close) {
// handle1 = CreateFileW(FilePath, GENERIC_READ | GENERIC_WRITE, EXPECT_TRUE(::CloseHandle(handle));
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, }
// FILE_ATTRIBUTE_NORMAL | CreateFlags, 0);
// ASSERT(INVALID_HANDLE_VALUE != handle1); handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
// FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
// Mapping = CreateFileMappingW(handle1, 0, PAGE_READWRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | flags, nullptr);
// FileSize0 + FileSize1, 0); EXPECT_NE(INVALID_HANDLE_VALUE, handle);
// ASSERT(0 != Mapping);
// mapping = ::CreateFileMappingA(handle, nullptr, PAGE_READWRITE, 0,
// if (EarlyClose) { file_size0 + file_size1, nullptr);
// Success = CloseHandle(Handle); ASSERT_NE(nullptr, mapping);
// ASSERT(Success);
// } if (early_close) {
// EXPECT_TRUE(::CloseHandle(handle));
// MappedView = MapViewOfFile(Mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); }
// ASSERT(0 != MappedView);
// view = ::MapViewOfFile(mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
// srand(seed); ASSERT_NE(nullptr, view);
// for (PUINT8 Bgn = MappedView + FileSize1 / 2, End = Bgn + FileSize0;
// End > Bgn; Bgn++) srand(seed);
// ASSERT(*Bgn == (rand() & 0xff)); for (PUINT8 begin = reinterpret_cast<PUINT8>(view) + file_size1 / 2U,
// end = begin + file_size0;
// if (!EarlyClose) { end > begin; ++begin) {
// pointer = SetFilePointer(handle1, FileSize0 / 2, 0, FILE_BEGIN); EXPECT_EQ(*begin, (rand() & 0xFF));
// ASSERT(FileSize0 / 2 == pointer); }
// Success =
// WriteFile(handle1, Buffer[0], bytes_per_sector, &BytesTransferred, 0); if (not early_close) {
// ASSERT(Success); auto pointer = ::SetFilePointer(handle, file_size0 / 2U, 0, FILE_BEGIN);
// ASSERT(bytes_per_sector == BytesTransferred); EXPECT_EQ(file_size0 / 2U, pointer);
// ASSERT(pointer + BytesTransferred ==
// SetFilePointer(handle1, 0, 0, FILE_CURRENT)); DWORD bytes_written{};
// } EXPECT_TRUE(::WriteFile(handle, write_buffer.data(), bytes_per_sector,
// &bytes_written, nullptr));
// Success = UnmapViewOfFile(MappedView); EXPECT_EQ(bytes_per_sector, bytes_written);
// ASSERT(Success); EXPECT_EQ(pointer + bytes_written,
// ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
// Success = CloseHandle(Mapping); }
// ASSERT(Success);
// EXPECT_TRUE(::UnmapViewOfFile(view));
// if (!EarlyClose) {
// Success = CloseHandle(Handle); EXPECT_TRUE(::CloseHandle(mapping));
// ASSERT(Success);
// } if (not early_close) {
// EXPECT_TRUE(::CloseHandle(handle));
// handle1 = CreateFileW(FilePath, GENERIC_READ | GENERIC_WRITE, }
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
// FILE_ATTRIBUTE_NORMAL | CreateFlags, 0); handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
// ASSERT(INVALID_HANDLE_VALUE != handle1); FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
// OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | flags, nullptr);
// Mapping = CreateFileMappingW(handle1, 0, PAGE_READWRITE, 0, ASSERT_NE(INVALID_HANDLE_VALUE, handle);
// FileSize0 + FileSize1, 0);
// ASSERT(0 != Mapping); mapping = ::CreateFileMappingA(handle, nullptr, PAGE_READWRITE, 0,
// file_size0 + file_size1, nullptr);
// if (EarlyClose) { ASSERT_NE(nullptr, mapping);
// Success = CloseHandle(Handle);
// ASSERT(Success); if (early_close) {
// } EXPECT_TRUE(::CloseHandle(handle));
// }
// MappedView = MapViewOfFile(Mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
// ASSERT(0 != MappedView); view = ::MapViewOfFile(mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
// ASSERT_NE(nullptr, view);
// if (!EarlyClose) {
// pointer = SetFilePointer(handle1, FileSize0 / 2, 0, FILE_BEGIN); if (not early_close) {
// ASSERT(FileSize0 / 2 == pointer); auto pointer = ::SetFilePointer(handle, file_size0 / 2U, 0, FILE_BEGIN);
// memset(Buffer[1], 0, bytes_per_sector); EXPECT_EQ(file_size0 / 2U, pointer);
// Success = ReadFile(handle1, Buffer[1], bytes_per_sector, &BytesTransferred,
// 0); ASSERT(Success); ASSERT(bytes_per_sector == BytesTransferred); data_buffer read_buffer{};
// ASSERT(pointer + BytesTransferred == read_buffer.resize(buffer_size);
// SetFilePointer(handle1, 0, 0, FILE_CURRENT)); DWORD bytes_read{};
// ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred)); EXPECT_TRUE(::ReadFile(handle, read_buffer.data(), bytes_per_sector,
// } &bytes_read, nullptr));
// EXPECT_EQ(bytes_per_sector, bytes_read);
// srand(seed); EXPECT_EQ(pointer + bytes_read,
// for (PUINT8 Bgn = MappedView + FileSize1 / 2, ::SetFilePointer(handle, 0, 0, FILE_CURRENT));
// End = MappedView + FileSize0 / 2; EXPECT_EQ(0,
// End > Bgn; Bgn++) std::memcmp(write_buffer.data(), read_buffer.data(), bytes_read));
// ASSERT(*Bgn == (rand() & 0xff)); }
// if (!EarlyClose)
// ASSERT(0 == memcmp(Buffer[0], MappedView + FileSize0 / 2, srand(seed);
// bytes_per_sector)); for (PUINT8 begin = reinterpret_cast<PUINT8>(view) + file_size1 / 2U,
// for (size_t i = 0; bytes_per_sector > i; i++) end = reinterpret_cast<PUINT8>(view) + file_size0 / 2U;
// rand(); end > begin; begin++) {
// for (PUINT8 Bgn = MappedView + FileSize0 / 2 + bytes_per_sector, EXPECT_EQ(*begin, (rand() & 0xFF));
// End = MappedView + FileSize1 / 2 + FileSize0; }
// End > Bgn; Bgn++)
// ASSERT(*Bgn == (rand() & 0xff)); if (not early_close) {
// EXPECT_EQ(0, std::memcmp(write_buffer.data(), view + file_size0 / 2U,
// Success = UnmapViewOfFile(MappedView); bytes_per_sector));
// ASSERT(Success); }
//
// Success = CloseHandle(Mapping); for (size_t idx = 0U; bytes_per_sector > idx; ++idx) {
// ASSERT(Success); rand();
// }
// if (!EarlyClose) {
// Success = CloseHandle(Handle); for (PUINT8
// ASSERT(Success); begin = reinterpret_cast<PUINT8>(view) + file_size0 / 2U +
// } bytes_per_sector,
// end = reinterpret_cast<PUINT8>(view) + file_size1 / 2U + file_size0;
// Success = DeleteFileW(FilePath); end > begin; ++begin) {
// ASSERT(Success); EXPECT_EQ(*begin, (rand() & 0xFF));
// } }
EXPECT_TRUE(::UnmapViewOfFile(view));
EXPECT_TRUE(::CloseHandle(mapping));
if (not early_close) {
EXPECT_TRUE(::CloseHandle(handle));
}
EXPECT_TRUE(DeleteFileA(file_path.c_str()));
}
TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_no_flags) { TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_no_flags) {
auto file_path{ auto file_path{
@ -805,26 +816,32 @@ TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_overlapped_write_through) {
FILE_FLAG_WRITE_THROUGH); FILE_FLAG_WRITE_THROUGH);
} }
// TYPED_TEST(winfsp_test, rdrw_can_read_and_write_mmap_file_no_flags) { TYPED_TEST(winfsp_test, rdrw_can_read_and_write_mmap_file_no_flags) {
// auto file_path{ auto file_path{
// utils::path::combine(this->mount_location, {"test_file_5"}), utils::path::combine(this->mount_location, {"test_file_5"}),
// }; };
// test_mmap_file(this->mount_location, file_path, 0U); test_mmap_file(this->mount_location, file_path, 0U, false);
// } test_mmap_file(this->mount_location, file_path, 0U, true);
// }
// TYPED_TEST(winfsp_test, rdrw_can_read_and_write_mmap_file_no_buffering) {
// auto file_path{ TYPED_TEST(winfsp_test, rdrw_can_read_and_write_mmap_file_no_buffering) {
// utils::path::combine(this->mount_location, {"test_file_5"}), auto file_path{
// }; utils::path::combine(this->mount_location, {"test_file_5"}),
// test_mmap_file(this->mount_location, file_path, FILE_FLAG_NO_BUFFERING); };
// } test_mmap_file(this->mount_location, file_path, FILE_FLAG_NO_BUFFERING,
// false);
// TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_mmap_write_through) { test_mmap_file(this->mount_location, file_path, FILE_FLAG_NO_BUFFERING, true);
// auto file_path{ }
// utils::path::combine(this->mount_location, {"test_file_5"}),
// }; TYPED_TEST(winfsp_test, rdrw_can_read_and_write_file_mmap_write_through) {
// test_mmap_file(this->mount_location, file_path, FILE_FLAG_WRITE_THROUGH); auto file_path{
// } utils::path::combine(this->mount_location, {"test_file_5"}),
};
test_mmap_file(this->mount_location, file_path, FILE_FLAG_WRITE_THROUGH,
false);
test_mmap_file(this->mount_location, file_path, FILE_FLAG_WRITE_THROUGH,
true);
}
TYPED_TEST(winfsp_test, rdrw_can_read_and_write_mixed_file) { TYPED_TEST(winfsp_test, rdrw_can_read_and_write_mixed_file) {
auto file_path{ auto file_path{