[NTDLL_APITEST] Add tests for alignment for NtWriteFile

This mimics the usage of WriteFile which is done in rosautotest.

 CORE-15973
This commit is contained in:
Pierre Schweitzer 2019-05-02 12:07:46 +02:00
parent 9d00413754
commit 64b6327dd7
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B

View file

@ -211,4 +211,88 @@ START_TEST(NtWriteFile)
&BufferSize,
MEM_RELEASE);
ok_hex(Status, STATUS_SUCCESS);
/* Now, testing aligned/non aligned writes */
BufferSize = 4096; /* We assume max sector size */
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
&Buffer,
0,
&BufferSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_READONLY);
if (!NT_SUCCESS(Status))
{
skip("Failed to allocate memory, status %lx\n", Status);
return;
}
Status = NtCreateFile(&FileHandle,
FILE_WRITE_DATA | DELETE | SYNCHRONIZE,
&ObjectAttributes,
&IoStatus,
NULL,
0,
0,
FILE_SUPERSEDE,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT |
FILE_NO_INTERMEDIATE_BUFFERING |
FILE_WRITE_THROUGH,
NULL,
0);
ok_hex(Status, STATUS_SUCCESS);
/* non-cached, broken length -- fails with invalid parameter */
ByteOffset.QuadPart = 0;
Status = NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatus,
Buffer,
4,
&ByteOffset,
NULL);
ok_hex(Status, STATUS_INVALID_PARAMETER);
/* non-cached, broken offset -- fails with invalid parameter */
ByteOffset.QuadPart = 4;
Status = NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatus,
Buffer,
BufferSize,
&ByteOffset,
NULL);
ok_hex(Status, STATUS_INVALID_PARAMETER);
/* non-cached, good length and offset -- succeeds */
ByteOffset.QuadPart = 0;
Status = NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatus,
Buffer,
BufferSize,
&ByteOffset,
NULL);
ok_hex(Status, STATUS_SUCCESS);
DispositionInfo.DeleteFile = TRUE;
Status = NtSetInformationFile(FileHandle,
&IoStatus,
&DispositionInfo,
sizeof(DispositionInfo),
FileDispositionInformation);
ok_hex(Status, STATUS_SUCCESS);
Status = NtClose(FileHandle);
ok_hex(Status, STATUS_SUCCESS);
Status = NtFreeVirtualMemory(NtCurrentProcess(),
&Buffer,
&BufferSize,
MEM_RELEASE);
ok_hex(Status, STATUS_SUCCESS);
}