mirror of
https://github.com/winfsp/winfsp.git
synced 2025-06-08 04:52:10 -05:00
tst: winfsp-tests: oplock testing
This commit is contained in:
parent
aec7b34e13
commit
851a6145cd
@ -191,6 +191,7 @@
|
|||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\lock-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\lock-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\mount-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\mount-test.c" />
|
||||||
|
<ClCompile Include="..\..\..\tst\winfsp-tests\oplock-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\path-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\path-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\posix-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\posix-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\rdwr-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\rdwr-test.c" />
|
||||||
|
@ -73,6 +73,9 @@
|
|||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\hooks.c">
|
<ClCompile Include="..\..\..\tst\winfsp-tests\hooks.c">
|
||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\tst\winfsp-tests\oplock-test.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">
|
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">
|
||||||
|
92
tst/winfsp-tests/oplock-test.c
Normal file
92
tst/winfsp-tests/oplock-test.c
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* @file oplock-test.c
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the GNU
|
||||||
|
* General Public License version 3 as published by the Free Software
|
||||||
|
* Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <winfsp/winfsp.h>
|
||||||
|
#include <tlib/testsuite.h>
|
||||||
|
#include <strsafe.h>
|
||||||
|
#include "memfs.h"
|
||||||
|
|
||||||
|
#include "winfsp-tests.h"
|
||||||
|
|
||||||
|
void oplock_not_granted_dotest(ULONG Flags, PWSTR Prefix)
|
||||||
|
{
|
||||||
|
void *memfs = memfs_start(Flags);
|
||||||
|
|
||||||
|
HANDLE Handle1, Handle2;
|
||||||
|
BOOLEAN Success;
|
||||||
|
WCHAR FilePath[MAX_PATH];
|
||||||
|
OVERLAPPED Overlapped;
|
||||||
|
DWORD BytesTransferred;
|
||||||
|
|
||||||
|
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0",
|
||||||
|
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||||
|
|
||||||
|
Handle1 = CreateFileW(FilePath,
|
||||||
|
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
ASSERT(INVALID_HANDLE_VALUE != Handle1);
|
||||||
|
|
||||||
|
Handle2 = CreateFileW(FilePath,
|
||||||
|
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
|
||||||
|
ASSERT(INVALID_HANDLE_VALUE != Handle2);
|
||||||
|
|
||||||
|
memset(&Overlapped, 0, sizeof Overlapped);
|
||||||
|
Success = DeviceIoControl(Handle2, FSCTL_REQUEST_FILTER_OPLOCK, 0, 0, 0, 0, &BytesTransferred,
|
||||||
|
&Overlapped);
|
||||||
|
ASSERT(!Success);
|
||||||
|
ASSERT(ERROR_OPLOCK_NOT_GRANTED == GetLastError() || ERROR_IO_PENDING == GetLastError());
|
||||||
|
if (ERROR_IO_PENDING == GetLastError())
|
||||||
|
{
|
||||||
|
Success = GetOverlappedResult(Handle2, &Overlapped, &BytesTransferred, TRUE);
|
||||||
|
ASSERT(!Success && ERROR_OPLOCK_NOT_GRANTED == GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
Success = CloseHandle(Handle2);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = CloseHandle(Handle1);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = DeleteFileW(FilePath);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
memfs_stop(memfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void oplock_not_granted_test(void)
|
||||||
|
{
|
||||||
|
if (OptOplock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (NtfsTests)
|
||||||
|
{
|
||||||
|
WCHAR DirBuf[MAX_PATH];
|
||||||
|
GetTestDirectory(DirBuf);
|
||||||
|
oplock_not_granted_dotest(-1, DirBuf);
|
||||||
|
}
|
||||||
|
if (WinFspDiskTests)
|
||||||
|
oplock_not_granted_dotest(MemfsDisk, 0);
|
||||||
|
if (WinFspNetTests)
|
||||||
|
oplock_not_granted_dotest(MemfsNet, L"\\\\memfs\\share");
|
||||||
|
}
|
||||||
|
|
||||||
|
void oplock_tests(void)
|
||||||
|
{
|
||||||
|
if (OptOplock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TEST(oplock_not_granted_test);
|
||||||
|
}
|
@ -194,6 +194,7 @@ int main(int argc, char *argv[])
|
|||||||
TESTSUITE(dirctl_tests);
|
TESTSUITE(dirctl_tests);
|
||||||
TESTSUITE(reparse_tests);
|
TESTSUITE(reparse_tests);
|
||||||
TESTSUITE(stream_tests);
|
TESTSUITE(stream_tests);
|
||||||
|
TESTSUITE(oplock_tests);
|
||||||
|
|
||||||
atexit(exiting);
|
atexit(exiting);
|
||||||
signal(SIGABRT, abort_handler);
|
signal(SIGABRT, abort_handler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user