mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 00:43:00 -05:00
winfsp-tests: rdwr_mixed_test
This commit is contained in:
parent
b44c6d64db
commit
ab1391c349
@ -574,6 +574,103 @@ static void rdwr_mmap_dotest(ULONG Flags, PWSTR VolPrefix, PWSTR Prefix, ULONG F
|
||||
memfs_stop(memfs);
|
||||
}
|
||||
|
||||
static void rdwr_mixed_dotest(ULONG Flags, PWSTR VolPrefix, PWSTR Prefix, ULONG FileInfoTimeout)
|
||||
{
|
||||
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
|
||||
|
||||
HANDLE Handle0, Handle1;
|
||||
BOOL Success;
|
||||
WCHAR FilePath[MAX_PATH];
|
||||
SYSTEM_INFO SystemInfo;
|
||||
DWORD SectorsPerCluster;
|
||||
DWORD BytesPerSector;
|
||||
DWORD FreeClusters;
|
||||
DWORD TotalClusters;
|
||||
PVOID AllocBuffer[2], Buffer[2];
|
||||
ULONG AllocBufferSize;
|
||||
DWORD BytesTransferred;
|
||||
DWORD FilePointer;
|
||||
|
||||
GetSystemInfo(&SystemInfo);
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\",
|
||||
VolPrefix ? L"" : L"\\\\?\\GLOBALROOT", VolPrefix ? VolPrefix : memfs_volumename(memfs));
|
||||
|
||||
Success = GetDiskFreeSpaceW(FilePath, &SectorsPerCluster, &BytesPerSector, &FreeClusters, &TotalClusters);
|
||||
ASSERT(Success);
|
||||
AllocBufferSize = 16 * SystemInfo.dwPageSize;
|
||||
|
||||
AllocBuffer[0] = _aligned_malloc(AllocBufferSize, SystemInfo.dwPageSize);
|
||||
AllocBuffer[1] = _aligned_malloc(AllocBufferSize, SystemInfo.dwPageSize);
|
||||
ASSERT(0 != AllocBuffer[0] && 0 != AllocBuffer[1]);
|
||||
|
||||
srand((unsigned)time(0));
|
||||
for (PUINT8 Bgn = AllocBuffer[0], End = Bgn + AllocBufferSize; End > Bgn; Bgn++)
|
||||
*Bgn = rand();
|
||||
|
||||
Buffer[0] = (PVOID)((PUINT8)AllocBuffer[0] + BytesPerSector);
|
||||
Buffer[1] = (PVOID)((PUINT8)AllocBuffer[1] + BytesPerSector);
|
||||
|
||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0",
|
||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||
|
||||
Handle0 = CreateFileW(FilePath,
|
||||
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle0);
|
||||
|
||||
Handle1 = CreateFileW(FilePath,
|
||||
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, 0);
|
||||
ASSERT(INVALID_HANDLE_VALUE != Handle0);
|
||||
|
||||
FilePointer = SetFilePointer(Handle0, 0, 0, FILE_BEGIN);
|
||||
ASSERT(0 == FilePointer);
|
||||
Success = WriteFile(Handle0, Buffer[0], BytesPerSector, &BytesTransferred, 0);
|
||||
ASSERT(Success);
|
||||
ASSERT(BytesPerSector == BytesTransferred);
|
||||
ASSERT(FilePointer + BytesTransferred == SetFilePointer(Handle0, 0, 0, FILE_CURRENT));
|
||||
|
||||
FilePointer = SetFilePointer(Handle1, 2 * BytesPerSector, 0, FILE_BEGIN);
|
||||
ASSERT(2 * BytesPerSector == FilePointer);
|
||||
Success = WriteFile(Handle1, Buffer[0], BytesPerSector, &BytesTransferred, 0);
|
||||
ASSERT(Success);
|
||||
ASSERT(BytesPerSector == BytesTransferred);
|
||||
ASSERT(FilePointer + BytesTransferred == SetFilePointer(Handle1, 0, 0, FILE_CURRENT));
|
||||
|
||||
FilePointer = SetFilePointer(Handle0, 0, 0, FILE_BEGIN);
|
||||
ASSERT(0 == FilePointer);
|
||||
memset(AllocBuffer[1], 0, AllocBufferSize);
|
||||
Success = ReadFile(Handle0, Buffer[1], BytesPerSector, &BytesTransferred, 0);
|
||||
ASSERT(Success);
|
||||
ASSERT(BytesPerSector == BytesTransferred);
|
||||
ASSERT(FilePointer + BytesTransferred == SetFilePointer(Handle0, 0, 0, FILE_CURRENT));
|
||||
ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred));
|
||||
|
||||
FilePointer = SetFilePointer(Handle1, 0, 0, FILE_BEGIN);
|
||||
ASSERT(0 == FilePointer);
|
||||
memset(AllocBuffer[1], 0, AllocBufferSize);
|
||||
Success = ReadFile(Handle1, Buffer[1], BytesPerSector, &BytesTransferred, 0);
|
||||
ASSERT(Success);
|
||||
ASSERT(BytesPerSector == BytesTransferred);
|
||||
ASSERT(FilePointer + BytesTransferred == SetFilePointer(Handle1, 0, 0, FILE_CURRENT));
|
||||
ASSERT(0 == memcmp(Buffer[0], Buffer[1], BytesTransferred));
|
||||
|
||||
Success = CloseHandle(Handle0);
|
||||
ASSERT(Success);
|
||||
|
||||
Success = CloseHandle(Handle1);
|
||||
ASSERT(Success);
|
||||
|
||||
Success = DeleteFileW(FilePath);
|
||||
ASSERT(Success);
|
||||
|
||||
_aligned_free(AllocBuffer[0]);
|
||||
_aligned_free(AllocBuffer[1]);
|
||||
|
||||
memfs_stop(memfs);
|
||||
}
|
||||
|
||||
void rdwr_noncached_test(void)
|
||||
{
|
||||
if (NtfsTests)
|
||||
@ -769,6 +866,26 @@ void rdwr_mmap_test(void)
|
||||
}
|
||||
}
|
||||
|
||||
void rdwr_mixed_test(void)
|
||||
{
|
||||
if (NtfsTests)
|
||||
{
|
||||
WCHAR DirBuf[MAX_PATH] = L"\\\\?\\";
|
||||
GetCurrentDirectoryW(MAX_PATH - 4, DirBuf + 4);
|
||||
rdwr_mixed_dotest(-1, L"C:", DirBuf, 0);
|
||||
}
|
||||
if (WinFspDiskTests)
|
||||
{
|
||||
rdwr_mixed_dotest(MemfsDisk, 0, 0, 1000);
|
||||
rdwr_mixed_dotest(MemfsDisk, 0, 0, INFINITE);
|
||||
}
|
||||
if (WinFspNetTests)
|
||||
{
|
||||
rdwr_mixed_dotest(MemfsNet, L"\\\\memfs\\share", L"\\\\memfs\\share", 1000);
|
||||
rdwr_mixed_dotest(MemfsNet, L"\\\\memfs\\share", L"\\\\memfs\\share", INFINITE);
|
||||
}
|
||||
}
|
||||
|
||||
void rdwr_tests(void)
|
||||
{
|
||||
TEST(rdwr_noncached_test);
|
||||
@ -778,4 +895,5 @@ void rdwr_tests(void)
|
||||
TEST(rdwr_writethru_test);
|
||||
TEST(rdwr_writethru_overlapped_test);
|
||||
TEST(rdwr_mmap_test);
|
||||
TEST(rdwr_mixed_test);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user