tst: winfsp-tests: --resilient command line option

This commit is contained in:
Bill Zissimopoulos 2016-10-25 14:50:12 -07:00
parent 66d5fe98df
commit 319e5d4ee6
3 changed files with 51 additions and 7 deletions

View File

@ -1260,7 +1260,7 @@ static void stream_delete_pending_dotest(ULONG Flags, PWSTR Prefix, ULONG FileIn
BOOL Success; BOOL Success;
WCHAR Dir1Path[MAX_PATH], Dir1StreamPath[MAX_PATH]; WCHAR Dir1Path[MAX_PATH], Dir1StreamPath[MAX_PATH];
WCHAR FilePath[MAX_PATH], FileStreamPath[MAX_PATH]; WCHAR FilePath[MAX_PATH], FileStreamPath[MAX_PATH];
FILE_DISPOSITION_INFO DispositionInfo; MY_FILE_DISPOSITION_INFO DispositionInfo;
StringCbPrintfW(Dir1Path, sizeof Dir1Path, L"%s%s\\dir1", StringCbPrintfW(Dir1Path, sizeof Dir1Path, L"%s%s\\dir1",
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs)); Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
@ -1304,7 +1304,7 @@ static void stream_delete_pending_dotest(ULONG Flags, PWSTR Prefix, ULONG FileIn
DELETE, FILE_SHARE_DELETE, 0, DELETE, FILE_SHARE_DELETE, 0,
OPEN_EXISTING, 0, 0); OPEN_EXISTING, 0, 0);
ASSERT(INVALID_HANDLE_VALUE != Handle); ASSERT(INVALID_HANDLE_VALUE != Handle);
DispositionInfo.DeleteFile = TRUE; DispositionInfo.Disposition = TRUE;
Success = SetFileInformationByHandle(Handle, Success = SetFileInformationByHandle(Handle,
FileDispositionInfo, &DispositionInfo, sizeof DispositionInfo); FileDispositionInfo, &DispositionInfo, sizeof DispositionInfo);
ASSERT(Success); ASSERT(Success);
@ -1327,7 +1327,7 @@ static void stream_delete_pending_dotest(ULONG Flags, PWSTR Prefix, ULONG FileIn
DELETE, FILE_SHARE_DELETE, 0, DELETE, FILE_SHARE_DELETE, 0,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
ASSERT(INVALID_HANDLE_VALUE != Handle); ASSERT(INVALID_HANDLE_VALUE != Handle);
DispositionInfo.DeleteFile = TRUE; DispositionInfo.Disposition = TRUE;
Success = SetFileInformationByHandle(Handle, Success = SetFileInformationByHandle(Handle,
FileDispositionInfo, &DispositionInfo, sizeof DispositionInfo); FileDispositionInfo, &DispositionInfo, sizeof DispositionInfo);
ASSERT(Success); ASSERT(Success);

View File

@ -17,6 +17,7 @@ int NtfsTests = 0;
int WinFspDiskTests = 1; int WinFspDiskTests = 1;
int WinFspNetTests = 1; int WinFspNetTests = 1;
BOOLEAN OptResilient = FALSE;
BOOLEAN OptCaseInsensitive = FALSE; BOOLEAN OptCaseInsensitive = FALSE;
BOOLEAN OptCaseRandomize = FALSE; BOOLEAN OptCaseRandomize = FALSE;
WCHAR OptMountPointBuf[MAX_PATH], *OptMountPoint; WCHAR OptMountPointBuf[MAX_PATH], *OptMountPoint;
@ -201,6 +202,37 @@ HANDLE HookCreateFileW(
return h; return h;
} }
#undef DeleteFileW
BOOL HookDeleteFileW(
LPCWSTR lpFileName)
{
BOOL Success;
DWORD LastError;
Success = DeleteFileW(lpFileName);
LastError = GetLastError();
if (OptResilient && !Success)
{
ULONG MaxTries = 10;
while (!Success && ERROR_SHARING_VIOLATION == LastError && 0 != MaxTries--)
{
Sleep(300);
Success = DeleteFileW(lpFileName);
}
}
else
{
ULONG MaxTries = 3;
while (INVALID_FILE_ATTRIBUTES != GetFileAttributes(lpFileName) && 0 != MaxTries--)
{
Sleep(300);
}
}
SetLastError(LastError);
return Success;
}
static VOID DisableBackupRestorePrivileges(VOID) static VOID DisableBackupRestorePrivileges(VOID)
{ {
union union
@ -227,7 +259,7 @@ static VOID DisableBackupRestorePrivileges(VOID)
CloseHandle(Token); CloseHandle(Token);
} }
VOID AddNetShareIfNeeded(VOID) static VOID AddNetShareIfNeeded(VOID)
{ {
if (!OptShareName) if (!OptShareName)
return; return;
@ -247,7 +279,7 @@ VOID AddNetShareIfNeeded(VOID)
ABORT("cannot add network share"); ABORT("cannot add network share");
} }
VOID RemoveNetShareIfNeeded(VOID) static VOID RemoveNetShareIfNeeded(VOID)
{ {
if (!OptShareName) if (!OptShareName)
return; return;
@ -308,6 +340,11 @@ int main(int argc, char *argv[])
WinFspNetTests = 0; WinFspNetTests = 0;
rmarg(argv, argc, argi); rmarg(argv, argc, argi);
} }
else if (0 == strcmp("--resilient", a))
{
OptResilient = TRUE;
rmarg(argv, argc, argi);
}
else if (0 == strcmp("--case-insensitive", a)) else if (0 == strcmp("--case-insensitive", a))
{ {
OptCaseInsensitive = TRUE; OptCaseInsensitive = TRUE;

View File

@ -17,13 +17,20 @@ HANDLE HookCreateFileW(
DWORD dwFlagsAndAttributes, DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile); HANDLE hTemplateFile);
VOID AddNetShareIfNeeded(VOID); #define DeleteFileW HookDeleteFileW
VOID RemoveNetShareIfNeeded(VOID); BOOL HookDeleteFileW(
LPCWSTR lpFileName);
typedef struct
{
BOOLEAN Disposition;
} MY_FILE_DISPOSITION_INFO;
extern int NtfsTests; extern int NtfsTests;
extern int WinFspDiskTests; extern int WinFspDiskTests;
extern int WinFspNetTests; extern int WinFspNetTests;
extern BOOLEAN OptResilient;
extern BOOLEAN OptCaseInsensitive; extern BOOLEAN OptCaseInsensitive;
extern BOOLEAN OptCaseRandomize; extern BOOLEAN OptCaseRandomize;
extern WCHAR OptMountPointBuf[], *OptMountPoint; extern WCHAR OptMountPointBuf[], *OptMountPoint;