mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 17:56:06 +00:00
[KMTESTS]
- add skip() functionality (with more useful syntax than Wine's) - add format attributes for GCC - do not show the full path of the source file for failed tests - general cleanup svn path=/branches/GSoC_2011/KMTestSuite/; revision=52489
This commit is contained in:
parent
7a0fe29b5e
commit
991bc0e366
5 changed files with 131 additions and 46 deletions
|
@ -25,10 +25,20 @@ START_TEST(Example)
|
|||
ok_eq_ulong(3LU, 4LU);
|
||||
ok_eq_pointer((PVOID)8, (PVOID)9);
|
||||
ok_eq_hex(0x1234LU, 0x5678LU);
|
||||
ok_eq_bool(TRUE, TRUE);
|
||||
ok_eq_bool(TRUE, FALSE);
|
||||
ok_eq_bool(FALSE, TRUE);
|
||||
ok_bool_true(FALSE, "foo");
|
||||
ok_bool_false(TRUE, "bar");
|
||||
ok_eq_print(1, 2, "%i");
|
||||
ok_eq_str("Hello", "world");
|
||||
ok_eq_wstr(L"ABC", L"DEF");
|
||||
|
||||
if (!skip(KeGetCurrentIrql() == HIGH_LEVEL, "This should only work on HIGH_LEVEL\n"))
|
||||
{
|
||||
/* do tests depending on HIGH_LEVEL here */
|
||||
ok(1, "This is fine\n");
|
||||
}
|
||||
|
||||
KeLowerIrql(Irql);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
|
||||
#define KMTEST_DEVICE_NAME L"Kmtest"
|
||||
#define KMTEST_DEVICE_PATH (L"\\\\.\\Global\\GLOBALROOT\\Device\\" KMTEST_DEVICE_NAME)
|
||||
#define KMTEST_DEVICE_DRIVER_PATH L"\\Device\\" KMTEST_DEVICE_NAME
|
||||
#define KMTEST_DEVICE_PATH L"\\\\.\\Global\\GLOBALROOT" KMTEST_DEVICE_DRIVER_PATH
|
||||
|
||||
#endif /* !defined _KMTEST_PUBLIC_H_ */
|
||||
|
|
|
@ -27,9 +27,11 @@ typedef const KMT_TEST CKMT_TEST, *PCKMT_TEST;
|
|||
|
||||
extern const KMT_TEST TestList[];
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
volatile LONG Successes;
|
||||
volatile LONG Failures;
|
||||
volatile LONG Skipped;
|
||||
volatile LONG LogBufferLength;
|
||||
LONG LogBufferMaxLength;
|
||||
CHAR LogBuffer[ANYSIZE_ARRAY];
|
||||
|
@ -37,32 +39,43 @@ typedef struct {
|
|||
|
||||
extern PKMT_RESULTBUFFER ResultBuffer;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define KMT_FORMAT(type, fmt, first) __attribute__((__format__(type, fmt, first)))
|
||||
#elif !defined __GNUC__
|
||||
#define KMT_FORMAT(type, fmt, first)
|
||||
#endif /* !defined __GNUC__ */
|
||||
|
||||
#define START_TEST(name) VOID Test_##name(VOID)
|
||||
|
||||
#define KMT_STRINGIZE(x) #x
|
||||
#define ok(test, ...) ok_(test, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define trace(...) trace_( __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define skip(test, ...) skip_(test, __FILE__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#define ok_(test, file, line, ...) KmtOk(test, file ":" KMT_STRINGIZE(line), __VA_ARGS__)
|
||||
#define trace_(file, line, ...) KmtTrace( file ":" KMT_STRINGIZE(line), __VA_ARGS__)
|
||||
#define skip_(test, file, line, ...) KmtSkip(test, file ":" KMT_STRINGIZE(line), __VA_ARGS__)
|
||||
|
||||
VOID KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments);
|
||||
VOID KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...);
|
||||
VOID KmtVTrace(PCSTR FileAndLine, PCSTR Format, va_list Arguments);
|
||||
VOID KmtTrace(PCSTR FileAndLine, PCSTR Format, ...);
|
||||
VOID KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 3, 0);
|
||||
VOID KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...) KMT_FORMAT(ms_printf, 3, 4);
|
||||
VOID KmtVTrace(PCSTR FileAndLine, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 2, 0);
|
||||
VOID KmtTrace(PCSTR FileAndLine, PCSTR Format, ...) KMT_FORMAT(ms_printf, 2, 3);
|
||||
BOOLEAN KmtVSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 3, 0);
|
||||
BOOLEAN KmtSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, ...) KMT_FORMAT(ms_printf, 3, 4);
|
||||
|
||||
#ifdef KMT_KERNEL_MODE
|
||||
#define ok_irql(irql) ok(KeGetCurrentIrql() == irql, "IRQL is %d, expected %d\n", KeGetCurrentIrql(), irql)
|
||||
#endif /* defined KMT_KERNEL_MODE */
|
||||
#define ok_eq_print(value, expected, spec) ok(value == expected, #value " = " spec ", expected " spec "\n", value, expected)
|
||||
#define ok_eq_print(value, expected, spec) ok((value) == (expected), #value " = " spec ", expected " spec "\n", value, expected)
|
||||
#define ok_eq_pointer(value, expected) ok_eq_print(value, expected, "%p")
|
||||
#define ok_eq_int(value, expected) ok_eq_print(value, expected, "%d")
|
||||
#define ok_eq_uint(value, expected) ok_eq_print(value, expected, "%u")
|
||||
#define ok_eq_long(value, expected) ok_eq_print(value, expected, "%ld")
|
||||
#define ok_eq_ulong(value, expected) ok_eq_print(value, expected, "%lu")
|
||||
#define ok_eq_hex(value, expected) ok_eq_print(value, expected, "0x%08lx")
|
||||
#define ok_bool_true(value, desc) ok(value == TRUE, desc " FALSE, expected TRUE\n")
|
||||
#define ok_bool_false(value, desc) ok(value == FALSE, desc " TRUE, expected FALSE\n")
|
||||
#define ok_bool_true(value, desc) ok((value) == TRUE, desc " FALSE, expected TRUE\n")
|
||||
#define ok_bool_false(value, desc) ok((value) == FALSE, desc " TRUE, expected FALSE\n")
|
||||
#define ok_eq_bool(value, expected) ok((value) == (expected), #value " = %s, expected %s\n", (value) ? "TRUE" : "FALSE", (expected) ? "TRUE" : "FALSE")
|
||||
#define ok_eq_str(value, expected) ok(!strcmp(value, expected), #value " = \"%s\", expected \"%s\"\n", value, expected)
|
||||
#define ok_eq_wstr(value, expected) ok(!wcscmp(value, expected), #value " = \"%ls\", expected \"%ls\"\n", value, expected)
|
||||
|
||||
|
@ -76,6 +89,7 @@ static PKMT_RESULTBUFFER KmtAllocateResultBuffer(SIZE_T LogBufferMaxLength)
|
|||
|
||||
Buffer->Successes = 0;
|
||||
Buffer->Failures = 0;
|
||||
Buffer->Skipped = 0;
|
||||
Buffer->LogBufferLength = 0;
|
||||
Buffer->LogBufferMaxLength = LogBufferMaxLength;
|
||||
|
||||
|
@ -109,44 +123,57 @@ static VOID KmtAddToLogBuffer(PKMT_RESULTBUFFER Buffer, PCSTR String, SIZE_T Len
|
|||
}
|
||||
|
||||
#ifdef KMT_KERNEL_MODE
|
||||
INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list Arguments);
|
||||
INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 3, 0);
|
||||
#elif defined KMT_USER_MODE
|
||||
#define KmtVSNPrintF vsnprintf
|
||||
#endif /* defined KMT_USER_MODE */
|
||||
|
||||
static SIZE_T KmtXVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Prepend1, PCSTR Prepend2, PCSTR Format, va_list Arguments)
|
||||
KMT_FORMAT(ms_printf, 5, 0)
|
||||
static SIZE_T KmtXVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR FileAndLine, PCSTR Prepend, PCSTR Format, va_list Arguments)
|
||||
{
|
||||
SIZE_T BufferLength = 0;
|
||||
SIZE_T Length;
|
||||
|
||||
if (Prepend1)
|
||||
if (FileAndLine)
|
||||
{
|
||||
SIZE_T Length = min(BufferMaxLength, strlen(Prepend1));
|
||||
memcpy(Buffer, Prepend1, Length);
|
||||
PCSTR Slash;
|
||||
Slash = strrchr(FileAndLine, '\\');
|
||||
if (Slash)
|
||||
FileAndLine = Slash + 1;
|
||||
Slash = strrchr(FileAndLine, '/');
|
||||
if (Slash)
|
||||
FileAndLine = Slash + 1;
|
||||
|
||||
Length = min(BufferMaxLength, strlen(FileAndLine));
|
||||
memcpy(Buffer, FileAndLine, Length);
|
||||
Buffer += Length;
|
||||
BufferLength += Length;
|
||||
BufferMaxLength -= Length;
|
||||
}
|
||||
if (Prepend2)
|
||||
if (Prepend)
|
||||
{
|
||||
SIZE_T Length = min(BufferMaxLength, strlen(Prepend2));
|
||||
memcpy(Buffer, Prepend2, Length);
|
||||
Length = min(BufferMaxLength, strlen(Prepend));
|
||||
memcpy(Buffer, Prepend, Length);
|
||||
Buffer += Length;
|
||||
BufferLength += Length;
|
||||
BufferMaxLength -= Length;
|
||||
}
|
||||
if (Format)
|
||||
{
|
||||
Length = KmtVSNPrintF(Buffer, BufferMaxLength, Format, Arguments);
|
||||
/* vsnprintf can return more than maxLength, we don't want to do that */
|
||||
BufferLength += min(Length, BufferMaxLength);
|
||||
}
|
||||
return BufferLength;
|
||||
}
|
||||
|
||||
static SIZE_T KmtXSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Prepend1, PCSTR Prepend2, PCSTR Format, ...)
|
||||
KMT_FORMAT(ms_printf, 5, 6)
|
||||
static SIZE_T KmtXSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR FileAndLine, PCSTR Prepend, PCSTR Format, ...)
|
||||
{
|
||||
SIZE_T BufferLength;
|
||||
va_list Arguments;
|
||||
va_start(Arguments, Format);
|
||||
BufferLength = KmtXVSNPrintF(Buffer, BufferMaxLength, Prepend1, Prepend2, Format, Arguments);
|
||||
BufferLength = KmtXVSNPrintF(Buffer, BufferMaxLength, FileAndLine, Prepend, Format, Arguments);
|
||||
va_end(Arguments);
|
||||
return BufferLength;
|
||||
}
|
||||
|
@ -157,10 +184,11 @@ VOID KmtFinishTest(PCSTR TestName)
|
|||
SIZE_T MessageLength;
|
||||
|
||||
MessageLength = KmtXSNPrintF(MessageBuffer, sizeof MessageBuffer, NULL, NULL,
|
||||
"%s: %d tests executed (0 marked as todo, %d failures), 0 skipped.\n",
|
||||
"%s: %ld tests executed (0 marked as todo, %ld failures), %ld skipped.\n",
|
||||
TestName,
|
||||
ResultBuffer->Successes + ResultBuffer->Failures,
|
||||
ResultBuffer->Failures);
|
||||
ResultBuffer->Failures,
|
||||
ResultBuffer->Skipped);
|
||||
KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
|
||||
}
|
||||
|
||||
|
@ -175,7 +203,7 @@ VOID KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
|
|||
|
||||
if (0/*KmtReportSuccess*/)
|
||||
{
|
||||
MessageLength = KmtXSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine, ": Test succeeded\n", "");
|
||||
MessageLength = KmtXSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine, ": Test succeeded\n", NULL);
|
||||
KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
|
||||
}
|
||||
}
|
||||
|
@ -212,6 +240,31 @@ VOID KmtTrace(PCSTR FileAndLine, PCSTR Format, ...)
|
|||
va_end(Arguments);
|
||||
}
|
||||
|
||||
BOOLEAN KmtVSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
|
||||
{
|
||||
CHAR MessageBuffer[512];
|
||||
SIZE_T MessageLength;
|
||||
|
||||
if (!Condition)
|
||||
{
|
||||
InterlockedIncrement(&ResultBuffer->Skipped);
|
||||
MessageLength = KmtXVSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine, ": Tests skipped: ", Format, Arguments);
|
||||
KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
|
||||
}
|
||||
|
||||
return !Condition;
|
||||
}
|
||||
|
||||
BOOLEAN KmtSkip(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
|
||||
{
|
||||
BOOLEAN Ret;
|
||||
va_list Arguments;
|
||||
va_start(Arguments, Format);
|
||||
Ret = KmtVSkip(Condition, FileAndLine, Format, Arguments);
|
||||
va_end(Arguments);
|
||||
return Ret;
|
||||
}
|
||||
|
||||
#endif /* defined KMT_DEFINE_TEST_FUNCTIONS */
|
||||
|
||||
#endif /* !defined _KMTEST_TEST_H_ */
|
||||
|
|
|
@ -158,11 +158,8 @@ int __cdecl main(int argc, char **argv)
|
|||
size_t len;
|
||||
|
||||
printf("Usage: %s test_name\n", programName);
|
||||
printf(" %s <Create|Start|Stop|Delete>\n", programName);
|
||||
puts("\nValid test names:");
|
||||
puts(" Create");
|
||||
puts(" Start");
|
||||
puts(" Stop");
|
||||
puts(" Delete");
|
||||
|
||||
error = ListTests(&testNames);
|
||||
testName = testNames;
|
||||
|
|
|
@ -29,7 +29,7 @@ typedef struct
|
|||
{
|
||||
PKMT_RESULTBUFFER ResultBuffer;
|
||||
PMDL Mdl;
|
||||
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
|
||||
} KMT_DEVICE_EXTENSION, *PKMT_DEVICE_EXTENSION;
|
||||
|
||||
/* Globals */
|
||||
static PDEVICE_OBJECT MainDeviceObject;
|
||||
|
@ -47,11 +47,15 @@ static PDEVICE_OBJECT MainDeviceObject;
|
|||
*
|
||||
* @return Status
|
||||
*/
|
||||
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
DriverEntry(
|
||||
IN PDRIVER_OBJECT DriverObject,
|
||||
IN PUNICODE_STRING RegistryPath)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
UNICODE_STRING DeviceName;
|
||||
PDEVICE_EXTENSION DeviceExtension;
|
||||
PKMT_DEVICE_EXTENSION DeviceExtension;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
|
@ -59,8 +63,9 @@ NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING Re
|
|||
|
||||
DPRINT("DriverEntry\n");
|
||||
|
||||
RtlInitUnicodeString(&DeviceName, L"\\Device\\Kmtest");
|
||||
Status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), &DeviceName,
|
||||
RtlInitUnicodeString(&DeviceName, KMTEST_DEVICE_DRIVER_PATH);
|
||||
Status = IoCreateDevice(DriverObject, sizeof(KMT_DEVICE_EXTENSION),
|
||||
&DeviceName,
|
||||
FILE_DEVICE_UNKNOWN,
|
||||
FILE_DEVICE_SECURE_OPEN | FILE_READ_ONLY_DEVICE,
|
||||
TRUE, &MainDeviceObject);
|
||||
|
@ -98,7 +103,11 @@ cleanup:
|
|||
* @param DriverObject
|
||||
* Driver Object
|
||||
*/
|
||||
static VOID NTAPI DriverUnload(IN PDRIVER_OBJECT DriverObject)
|
||||
static
|
||||
VOID
|
||||
NTAPI
|
||||
DriverUnload(
|
||||
IN PDRIVER_OBJECT DriverObject)
|
||||
{
|
||||
PAGED_CODE();
|
||||
|
||||
|
@ -108,7 +117,7 @@ static VOID NTAPI DriverUnload(IN PDRIVER_OBJECT DriverObject)
|
|||
|
||||
if (MainDeviceObject)
|
||||
{
|
||||
PDEVICE_EXTENSION DeviceExtension = MainDeviceObject->DeviceExtension;
|
||||
PKMT_DEVICE_EXTENSION DeviceExtension = MainDeviceObject->DeviceExtension;
|
||||
ASSERT(!DeviceExtension->Mdl);
|
||||
ASSERT(!DeviceExtension->ResultBuffer);
|
||||
ASSERT(!ResultBuffer);
|
||||
|
@ -128,11 +137,16 @@ static VOID NTAPI DriverUnload(IN PDRIVER_OBJECT DriverObject)
|
|||
*
|
||||
* @return Status
|
||||
*/
|
||||
static NTSTATUS NTAPI DriverCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
||||
static
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
DriverCreate(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PIO_STACK_LOCATION IoStackLocation;
|
||||
PDEVICE_EXTENSION DeviceExtension;
|
||||
PKMT_DEVICE_EXTENSION DeviceExtension;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
|
@ -166,11 +180,16 @@ static NTSTATUS NTAPI DriverCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
|||
*
|
||||
* @return Status
|
||||
*/
|
||||
static NTSTATUS NTAPI DriverClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
||||
static
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
DriverClose(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PIO_STACK_LOCATION IoStackLocation;
|
||||
PDEVICE_EXTENSION DeviceExtension;
|
||||
PKMT_DEVICE_EXTENSION DeviceExtension;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
|
@ -208,7 +227,12 @@ static NTSTATUS NTAPI DriverClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
|||
*
|
||||
* @return Status
|
||||
*/
|
||||
static NTSTATUS NTAPI DriverIoControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
||||
static
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
DriverIoControl(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PIO_STACK_LOCATION IoStackLocation;
|
||||
|
@ -283,7 +307,7 @@ static NTSTATUS NTAPI DriverIoControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Ir
|
|||
}
|
||||
case IOCTL_KMTEST_SET_RESULTBUFFER:
|
||||
{
|
||||
PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
||||
PKMT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
||||
|
||||
DPRINT("DriverIoControl. IOCTL_KMTEST_SET_RESULTBUFFER, inlen=%lu, outlen=%lu\n",
|
||||
IoStackLocation->Parameters.DeviceIoControl.InputBufferLength,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue