Index: CMakeLists.txt =================================================================== --- modules/rostests/kmtests/CMakeLists.txt (revision 58805) +++ modules/rostests/kmtests/CMakeLists.txt (working copy) @@ -5,6 +5,7 @@ # subdirectories containing special-purpose drivers # add_subdirectory(example) +add_subdirectory(kernel32) add_subdirectory(ntos_io) list(APPEND COMMON_SOURCE @@ -87,6 +88,7 @@ kmtest/testlist.c example/Example_user.c + kernel32/FindFile_user.c ntos_io/IoDeviceObject_user.c ${COMMON_SOURCE} Index: include/kmt_test.h =================================================================== --- modules/rostests/kmtests/include/kmt_test.h (revision 58805) +++ modules/rostests/kmtests/include/kmt_test.h (working copy) @@ -66,6 +66,7 @@ TESTENTRY_NO_CREATE_DEVICE = 1, TESTENTRY_NO_REGISTER_DISPATCH = 2, TESTENTRY_NO_REGISTER_UNLOAD = 4, + TESTENTRY_NO_EXCLUSIVE_DEVICE = 8, } KMT_TESTENTRY_FLAGS; NTSTATUS TestEntry(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags); @@ -334,6 +335,7 @@ } while (InterlockedCompareExchange(&Buffer->LogBufferLength, NewLength, OldLength) != OldLength); memcpy(&Buffer->LogBuffer[OldLength], String, Length); + DbgPrint("%.*s", (int)Length, String); } KMT_FORMAT(ms_printf, 5, 0) Index: kernel32 =================================================================== --- modules/rostests/kmtests/kernel32 (revision 0) +++ modules/rostests/kmtests/kernel32 (working copy) Property changes on: kernel32 ___________________________________________________________________ Added: bugtraq:logregex ## -0,0 +1,2 ## +([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))? +(\d+) \ No newline at end of property Added: bugtraq:url ## -0,0 +1 ## +http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID% \ No newline at end of property Added: bugtraq:message ## -0,0 +1 ## +See issue #%BUGID% for more details. \ No newline at end of property Added: tsvn:logminsize ## -0,0 +1 ## +10 \ No newline at end of property Index: kernel32/CMakeLists.txt =================================================================== --- modules/rostests/kmtests/kernel32/CMakeLists.txt (revision 0) +++ modules/rostests/kmtests/kernel32/CMakeLists.txt (working copy) @@ -0,0 +1,16 @@ +include_directories( + ../include) + +list(APPEND FINDFILE_DRV_SOURCE + ../kmtest_drv/kmtest_standalone.c + FindFile_drv.c) + +add_library(findfile_drv SHARED ${FINDFILE_DRV_SOURCE}) + +set_module_type(findfile_drv kernelmodedriver) +target_link_libraries(findfile_drv kmtest_printf ${PSEH_LIB}) +add_importlibs(findfile_drv ntoskrnl hal) +add_target_compile_definitions(findfile_drv KMT_STANDALONE_DRIVER) +#add_pch(findfile_drv ../include/kmt_test.h) + +add_cd_file(TARGET findfile_drv DESTINATION reactos/bin FOR all) Index: kernel32/FindFile.h =================================================================== --- modules/rostests/kmtests/kernel32/FindFile.h (revision 0) +++ modules/rostests/kmtests/kernel32/FindFile.h (working copy) @@ -0,0 +1,13 @@ +/* + * PROJECT: ReactOS kernel-mode tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Kernel-Mode Test Suite Example Test declarations + * PROGRAMMER: Thomas Faber + */ + +#ifndef _KMTEST_FINDFILE_H_ +#define _KMTEST_FINDFILE_H_ + +#define IOCTL_EXPECT 1 + +#endif /* !defined _KMTEST_FINDFILE_H_ */ Index: kernel32/FindFile_drv.c =================================================================== --- modules/rostests/kmtests/kernel32/FindFile_drv.c (revision 0) +++ modules/rostests/kmtests/kernel32/FindFile_drv.c (working copy) @@ -0,0 +1,138 @@ +/* + * PROJECT: ReactOS kernel-mode tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Kernel-Mode Test Suite Example Test Driver + * PROGRAMMER: Thomas Faber + */ + +#include + +//#define NDEBUG +#include + +#include "FindFile.h" + +static KMT_MESSAGE_HANDLER TestMessageHandler; +static KMT_IRP_HANDLER TestIrpHandler; + +static PDRIVER_OBJECT TestDriverObject; + +NTSTATUS +TestEntry( + IN PDRIVER_OBJECT DriverObject, + IN PCUNICODE_STRING RegistryPath, + OUT PCWSTR *DeviceName, + IN OUT INT *Flags) +{ + NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); + + UNREFERENCED_PARAMETER(RegistryPath); + + DPRINT("Entry!\n"); + + ok_irql(PASSIVE_LEVEL); + TestDriverObject = DriverObject; + + *DeviceName = L"FindFile"; + *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE; + + trace("Hi, this is the FindFile driver\n"); + + KmtRegisterIrpHandler(IRP_MJ_DIRECTORY_CONTROL, NULL, TestIrpHandler); + KmtRegisterMessageHandler(0, NULL, TestMessageHandler); + + return Status; +} + +VOID +TestUnload( + IN PDRIVER_OBJECT DriverObject) +{ + PAGED_CODE(); + + DPRINT("Unload!\n"); + + ok_irql(PASSIVE_LEVEL); + ok_eq_pointer(DriverObject, TestDriverObject); + + trace("Unloading FindFile driver\n"); +} + +static +NTSTATUS +TestMessageHandler( + IN PDEVICE_OBJECT DeviceObject, + IN ULONG ControlCode, + IN PVOID Buffer OPTIONAL, + IN SIZE_T InLength, + IN OUT PSIZE_T OutLength) +{ + NTSTATUS Status = STATUS_SUCCESS; + + switch (ControlCode) + { + case IOCTL_EXPECT: + { + static int TimesReceived = 0; + ANSI_STRING ExpectedString = RTL_CONSTANT_STRING("yay"); + ANSI_STRING ReceivedString; + + ++TimesReceived; + ok(TimesReceived == 1, "Received control code 1 %d times\n", TimesReceived); + ok(Buffer != NULL, "Buffer is NULL\n"); + ok_eq_ulong((ULONG)InLength, (ULONG)ExpectedString.Length); + ok_eq_ulong((ULONG)*OutLength, 0LU); + ReceivedString.MaximumLength = ReceivedString.Length = (USHORT)InLength; + ReceivedString.Buffer = Buffer; + ok(RtlCompareString(&ExpectedString, &ReceivedString, FALSE) == 0, "Received string: %Z\n", &ReceivedString); + trace("Received string: %Z\n", &ReceivedString); + break; + } + default: + ok(0, "Got an unknown message! DeviceObject=%p, ControlCode=%lu, Buffer=%p, In=%lu, Out=%lu bytes\n", + DeviceObject, ControlCode, Buffer, InLength, *OutLength); + break; + } + + return Status; +} + +static +NTSTATUS +TestIrpHandler( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp, + IN PIO_STACK_LOCATION IoStackLocation) +{ + NTSTATUS Status = STATUS_SUCCESS; + + DPRINT("IRP!\n"); + + ok_irql(PASSIVE_LEVEL); + ok_eq_pointer(DeviceObject->DriverObject, TestDriverObject); + + if (IoStackLocation->MajorFunction == IRP_MJ_DIRECTORY_CONTROL) + { + trace("Got IRP_MJ_DIRECTORY_CONTROL, minor=%x!\n", IoStackLocation->MinorFunction); + Status = Irp->IoStatus.Status; + if (IoStackLocation->MinorFunction == IRP_MN_QUERY_DIRECTORY) + { + trace("IRP_MN_QUERY_DIRECTORY, Class=%x\n", IoStackLocation->Parameters.QueryDirectory.FileInformationClass); + if (IoStackLocation->Parameters.QueryDirectory.FileInformationClass == FileBothDirectoryInformation) + { + trace("FileBothDirectoryInformation! File=%wZ\n", IoStackLocation->Parameters.QueryDirectory.FileName); + } + } + } + else + trace("Got an IRP!\n"); + + Irp->IoStatus.Status = Status; + Irp->IoStatus.Information = 0; + + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return Status; +} Index: kernel32/FindFile_user.c =================================================================== --- modules/rostests/kmtests/kernel32/FindFile_user.c (revision 0) +++ modules/rostests/kmtests/kernel32/FindFile_user.c (working copy) @@ -0,0 +1,34 @@ +/* + * PROJECT: ReactOS kernel-mode tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Kernel-Mode Test Suite Example user-mode test part + * PROGRAMMER: Thomas Faber + */ + +#include + +#include "FindFile.h" + +START_TEST(FindFile) +{ + HANDLE FindHandle; + WIN32_FIND_DATAW FindData; + + KmtLoadDriver(L"FindFile", TRUE); + trace("After Entry\n"); + KmtOpenDriver(); + trace("After Create\n"); + + ok(KmtSendStringToDriver(IOCTL_EXPECT, "yay") == ERROR_SUCCESS, "\n"); + FindHandle = FindFirstFileW(L"\\\\.\\Global\\GLOBALROOT\\Device\\Kmtest-FindFile\\Hello", &FindData); + trace("Error: %lu\n", GetLastError()); + trace("Handle: %p\n", (PVOID)FindHandle); + + if (FindHandle != INVALID_HANDLE_VALUE) + FindClose(FindHandle); + + KmtCloseDriver(); + trace("After Close\n"); + KmtUnloadDriver(); + trace("After Unload\n"); +} Index: kmtest/testlist.c =================================================================== --- modules/rostests/kmtests/kmtest/testlist.c (revision 58805) +++ modules/rostests/kmtests/kmtest/testlist.c (working copy) @@ -8,6 +8,7 @@ #include KMT_TESTFUNC Test_Example; +KMT_TESTFUNC Test_FindFile; KMT_TESTFUNC Test_IoDeviceObject; KMT_TESTFUNC Test_RtlAvlTree; KMT_TESTFUNC Test_RtlException; @@ -19,6 +20,7 @@ const KMT_TEST TestList[] = { { "Example", Test_Example }, + { "FindFile", Test_FindFile }, { "IoDeviceObject", Test_IoDeviceObject }, { "RtlAvlTree", Test_RtlAvlTree }, { "RtlException", Test_RtlException }, Index: kmtest_drv/kmtest_standalone.c =================================================================== --- modules/rostests/kmtests/kmtest_drv/kmtest_standalone.c (revision 58805) +++ modules/rostests/kmtests/kmtest_drv/kmtest_standalone.c (working copy) @@ -122,7 +122,8 @@ Status = IoCreateDevice(DriverObject, 0, &DeviceName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN | FILE_READ_ONLY_DEVICE, - TRUE, &TestDeviceObject); + Flags & TESTENTRY_NO_EXCLUSIVE_DEVICE ? FALSE : TRUE, + &TestDeviceObject); if (!NT_SUCCESS(Status)) {