Author: tfaber
Date: Wed Jun 29 08:51:00 2011
New Revision: 52489
URL:
http://svn.reactos.org/svn/reactos?rev=52489&view=rev
Log:
[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
Modified:
branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c
branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_public.h
branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h
branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c
branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c
Modified: branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/e…
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c [iso-8859-1] Wed Jun 29
08:51:00 2011
@@ -25,10 +25,20 @@
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);
}
Modified: branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_public.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/i…
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_public.h [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_public.h [iso-8859-1] Wed Jun 29
08:51:00 2011
@@ -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_ */
Modified: branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/i…
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h [iso-8859-1] Wed Jun 29
08:51:00 2011
@@ -27,9 +27,11 @@
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 @@
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 ok_(test, file, line, ...) KmtOk(test, file ":" KMT_STRINGIZE(line),
__VA_ARGS__)
-#define trace_(file, line, ...) KmtTrace( 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, ...);
+#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)
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 @@
Buffer->Successes = 0;
Buffer->Failures = 0;
+ Buffer->Skipped = 0;
Buffer->LogBufferLength = 0;
Buffer->LogBufferMaxLength = LogBufferMaxLength;
@@ -109,44 +123,57 @@
}
#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)
- {
- SIZE_T Length = min(BufferMaxLength, strlen(Prepend1));
- memcpy(Buffer, Prepend1, Length);
+ if (FileAndLine)
+ {
+ 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)
- {
- SIZE_T Length = min(BufferMaxLength, strlen(Prepend2));
- memcpy(Buffer, Prepend2, Length);
+ if (Prepend)
+ {
+ Length = min(BufferMaxLength, strlen(Prepend));
+ memcpy(Buffer, Prepend, Length);
Buffer += Length;
BufferLength += Length;
BufferMaxLength -= Length;
}
- Length = KmtVSNPrintF(Buffer, BufferMaxLength, Format, Arguments);
- /* vsnprintf can return more than maxLength, we don't want to do that */
- BufferLength += min(Length, BufferMaxLength);
+ 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 @@
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 @@
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 @@
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_ */
Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/k…
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c [iso-8859-1] Wed Jun 29
08:51:00 2011
@@ -158,11 +158,8 @@
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;
Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/k…
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c [iso-8859-1] Wed Jun 29
08:51:00 2011
@@ -29,7 +29,7 @@
{
PKMT_RESULTBUFFER ResultBuffer;
PMDL Mdl;
-} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
+} KMT_DEVICE_EXTENSION, *PKMT_DEVICE_EXTENSION;
/* Globals */
static PDEVICE_OBJECT MainDeviceObject;
@@ -47,11 +47,15 @@
*
* @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 @@
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 @@
* @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 @@
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 @@
*
* @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 @@
*
* @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 @@
*
* @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 @@
}
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,