[ros-diffs] [tfaber] 52359: [KMTESTS] - add the proper testing framework functions for winetest-like feel - remove thereby obsolete Log* functions - update example test to show usage of the new macros

tfaber at svn.reactos.org tfaber at svn.reactos.org
Sun Jun 19 09:23:03 UTC 2011


Author: tfaber
Date: Sun Jun 19 09:23:03 2011
New Revision: 52359

URL: http://svn.reactos.org/svn/reactos?rev=52359&view=rev
Log:
[KMTESTS]
- add the proper testing framework functions for winetest-like feel
- remove thereby obsolete Log* functions
- update example test to show usage of the new macros

Removed:
    branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_log.h
    branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/log.c
Modified:
    branches/GSoC_2011/KMTestSuite/kmtests/CMakeLists.txt
    branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c
    branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h
    branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c
    branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv.rbuild
    branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c

Modified: branches/GSoC_2011/KMTestSuite/kmtests/CMakeLists.txt
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/CMakeLists.txt?rev=52359&r1=52358&r2=52359&view=diff
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/CMakeLists.txt [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/CMakeLists.txt [iso-8859-1] Sun Jun 19 09:23:03 2011
@@ -11,7 +11,6 @@
 #
 list(APPEND KMTEST_DRV_SOURCE
     kmtest_drv/kmtest_drv.c
-    kmtest_drv/log.c
     kmtest_drv/testlist.c
 
     example/Example.c

Modified: branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c?rev=52359&r1=52358&r2=52359&view=diff
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/example/Example.c [iso-8859-1] Sun Jun 19 09:23:03 2011
@@ -7,10 +7,15 @@
 
 #include <ntddk.h>
 #include <kmt_test.h>
-#include <kmt_log.h>
 
 VOID Test_Example(VOID)
 {
-    /* TODO: this should be trace(), as in winetests */
-    LogPrint("Message from kernel\n");
+    KIRQL Irql;
+
+    ok(1, "This test should succeed.\n");
+    ok(0, "This test should fail.\n");
+    trace("Message from kernel, low-irql. %s. %ls.\n", "Format strings work", L"Even with Unicode");
+    KeRaiseIrql(HIGH_LEVEL, &Irql);
+    trace("Message from kernel, high-irql. %s. %ls.\n", "Format strings work", L"Even with Unicode");
+    KeLowerIrql(Irql);
 }

Removed: branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_log.h
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_log.h?rev=52358&view=auto
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_log.h [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_log.h (removed)
@@ -1,21 +1,0 @@
-/*
- * PROJECT:         ReactOS kernel-mode tests
- * LICENSE:         GPLv2+ - See COPYING in the top level directory
- * PURPOSE:         Kernel-Mode Test Suite Driver logging function declarations
- * PROGRAMMER:      Thomas Faber <thfabba at gmx.de>
- */
-
-#ifndef _KMTEST_LOG_H_
-#define _KMTEST_LOG_H_
-
-#include <ntddk.h>
-
-NTSTATUS LogInit(VOID);
-VOID LogFree(VOID);
-
-VOID LogPrint(IN PCSTR Message);
-VOID LogPrintF(IN PCSTR Format, ...);
-VOID LogVPrintF(IN PCSTR Format, va_list Arguments);
-SIZE_T LogRead(OUT PVOID Buffer, IN SIZE_T BufferSize);
-
-#endif /* !defined _KMTEST_LOG_H_ */

Modified: branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/include/kmt_test.h?rev=52359&r1=52358&r2=52359&view=diff
==============================================================================
--- 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] Sun Jun 19 09:23:03 2011
@@ -1,8 +1,13 @@
 /*
  * PROJECT:         ReactOS kernel-mode tests
  * LICENSE:         GPLv2+ - See COPYING in the top level directory
- * PURPOSE:         Kernel-Mode Test Suite test declarations
+ * PURPOSE:         Kernel-Mode Test Suite test framework declarations
  * PROGRAMMER:      Thomas Faber <thfabba at gmx.de>
+ */
+
+/* Inspired by Wine C unit tests, Copyright (C) 2002 Alexandre Julliard
+ * Inspired by ReactOS kernel-mode regression tests,
+ *                                Copyright (C) Aleksey Bragin, Filip Navara
  */
 
 #ifndef _KMTEST_TEST_H_
@@ -32,6 +37,18 @@
 
 extern PKMT_RESULTBUFFER ResultBuffer;
 
+#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, ...);
+
 #if defined KMT_DEFINE_TEST_FUNCTIONS
 PKMT_RESULTBUFFER ResultBuffer = NULL;
 
@@ -55,6 +72,8 @@
 #endif /* defined KMT_USER_MODE */
 
 #define KmtMemCpy memcpy
+#define KmtStrLen strlen
+#define KmtAssert assert
 
 static VOID KmtAddToLogBuffer(PKMT_RESULTBUFFER Buffer, PCSTR String, SIZE_T Length)
 {
@@ -82,6 +101,104 @@
 #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)
+{
+    SIZE_T BufferLength = 0;
+    SIZE_T Length;
+
+    if (Prepend1)
+    {
+        SIZE_T Length = min(BufferMaxLength, KmtStrLen(Prepend1));
+        KmtMemCpy(Buffer, Prepend1, Length);
+        Buffer += Length;
+        BufferLength += Length;
+        BufferMaxLength -= Length;
+    }
+    if (Prepend2)
+    {
+        SIZE_T Length = min(BufferMaxLength, KmtStrLen(Prepend2));
+        KmtMemCpy(Buffer, Prepend2, 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);
+    return BufferLength;
+}
+
+static SIZE_T KmtXSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Prepend1, PCSTR Prepend2, PCSTR Format, ...)
+{
+    SIZE_T BufferLength;
+    va_list Arguments;
+    va_start(Arguments, Format);
+    BufferLength = KmtXVSNPrintF(Buffer, BufferMaxLength, Prepend1, Prepend2, Format, Arguments);
+    va_end(Arguments);
+    return BufferLength;
+}
+
+VOID KmtFinishTest(PCSTR TestName)
+{
+    CHAR MessageBuffer[512];
+    SIZE_T MessageLength;
+
+    MessageLength = KmtXSNPrintF(MessageBuffer, sizeof MessageBuffer, NULL, NULL,
+                                    "%s: %d tests executed (0 marked as todo, %d failures), 0 skipped.\n",
+                                    TestName,
+                                    ResultBuffer->Successes + ResultBuffer->Failures,
+                                    ResultBuffer->Failures);
+    KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
+}
+
+VOID KmtVOk(INT Condition, PCSTR FileAndLine, PCSTR Format, va_list Arguments)
+{
+    CHAR MessageBuffer[512];
+    SIZE_T MessageLength;
+
+    if (Condition)
+    {
+        InterlockedIncrement(&ResultBuffer->Successes);
+
+        if (0/*KmtReportSuccess*/)
+        {
+            MessageLength = KmtXSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine, ": Test succeeded\n", "");
+            KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
+        }
+    }
+    else
+    {
+        InterlockedIncrement(&ResultBuffer->Failures);
+        MessageLength = KmtXVSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine, ": Test failed: ", Format, Arguments);
+        KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
+    }
+}
+
+VOID KmtOk(INT Condition, PCSTR FileAndLine, PCSTR Format, ...)
+{
+    va_list Arguments;
+    va_start(Arguments, Format);
+    KmtVOk(Condition, FileAndLine, Format, Arguments);
+    va_end(Arguments);
+}
+
+VOID KmtVTrace(PCSTR FileAndLine, PCSTR Format, va_list Arguments)
+{
+    CHAR MessageBuffer[512];
+    SIZE_T MessageLength;
+
+    MessageLength = KmtXVSNPrintF(MessageBuffer, sizeof MessageBuffer, FileAndLine, ": ", Format, Arguments);
+    KmtAddToLogBuffer(ResultBuffer, MessageBuffer, MessageLength);
+}
+
+VOID KmtTrace(PCSTR FileAndLine, PCSTR Format, ...)
+{
+    va_list Arguments;
+    va_start(Arguments, Format);
+    KmtVTrace(FileAndLine, Format, Arguments);
+    va_end(Arguments);
+}
+
 #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/kmtest/kmtest.c?rev=52359&r1=52358&r2=52359&view=diff
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest/kmtest.c [iso-8859-1] Sun Jun 19 09:23:03 2011
@@ -73,6 +73,8 @@
         error = GetLastError();
         goto cleanup;
     }
+
+    KmtFinishTest(testName);
 
     if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), ResultBuffer->LogBuffer, ResultBuffer->LogBufferLength, &bytesWritten, NULL))
     {

Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv.rbuild
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv.rbuild?rev=52359&r1=52358&r2=52359&view=diff
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv.rbuild [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv.rbuild [iso-8859-1] Sun Jun 19 09:23:03 2011
@@ -4,13 +4,37 @@
 	<library>ntdll</library>
 	<library>hal</library>
 	<library>pseh</library>
+	<library>kmtest_printf</library>
 	<define name="KMT_KERNEL_MODE" />
 	<directory name="kmtest_drv">
 		<file>kmtest_drv.c</file>
-		<file>log.c</file>
 		<file>testlist.c</file>
 	</directory>
 	<directory name="example">
 		<file>Example.c</file>
 	</directory>
 </module>
+<module name="kmtest_printf" type="staticlibrary">
+	<include base="crt">include</include>
+	<define name="_LIBCNT_" />
+	<define name="_USER32_WSPRINTF" />
+	<define name="wctomb">KmtWcToMb</define>
+	<directory name="kmtest_drv">
+		<file>printf_stubs.c</file>
+	</directory>
+	<directory name="..">
+		<directory name="..">
+			<directory name="..">
+				<directory name="lib">
+					<directory name="sdk">
+						<directory name="crt">
+							<directory name="printf">
+								<file>streamout.c</file>
+							</directory>
+						</directory>
+					</directory>
+				</directory>
+			</directory>
+		</directory>
+	</directory>
+</module>

Modified: branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/kmtest_drv.c?rev=52359&r1=52358&r2=52359&view=diff
==============================================================================
--- 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] Sun Jun 19 09:23:03 2011
@@ -14,7 +14,7 @@
 #include <debug.h>
 
 #include <kmt_public.h>
-#include <kmt_log.h>
+#define KMT_DEFINE_TEST_FUNCTIONS
 #include <kmt_test.h>
 
 /* Prototypes */
@@ -58,11 +58,6 @@
     UNREFERENCED_PARAMETER(RegistryPath);
 
     DPRINT("DriverEntry\n");
-
-    Status = LogInit();
-
-    if (!NT_SUCCESS(Status))
-        goto cleanup;
 
     RtlInitUnicodeString(&DeviceName, L"\\Device\\Kmtest");
     Status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), &DeviceName,
@@ -119,8 +114,6 @@
         ASSERT(!ResultBuffer);
         IoDeleteDevice(MainDeviceObject);
     }
-
-    LogFree();
 }
 
 /**

Removed: branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/log.c
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/log.c?rev=52358&view=auto
==============================================================================
--- branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/log.c [iso-8859-1] (original)
+++ branches/GSoC_2011/KMTestSuite/kmtests/kmtest_drv/log.c (removed)
@@ -1,102 +1,0 @@
-/*
- * PROJECT:         ReactOS kernel-mode tests
- * LICENSE:         GPLv2+ - See COPYING in the top level directory
- * PURPOSE:         Kernel-Mode Test Suite Driver logging functions
- * PROGRAMMER:      Thomas Faber <thfabba at gmx.de>
- */
-
-#include <ntddk.h>
-#include <ntstrsafe.h>
-
-#include <kmt_log.h>
-#define KMT_DEFINE_TEST_FUNCTIONS
-#include <kmt_test.h>
-
-/**
- * @name LogInit
- *
- * Initialize logging mechanism. Call from DriverEntry.
- *
- * @return Status
- */
-NTSTATUS LogInit(VOID)
-{
-    NTSTATUS Status = STATUS_SUCCESS;
-    PAGED_CODE();
-
-    return Status;
-}
-
-/**
- * @name LogFree
- *
- * Clean up logging mechanism. Call from Unload.
- *
- * @return None
- */
-VOID LogFree(VOID)
-{
-    PAGED_CODE();
-}
-
-/**
- * @name LogPrint
- *
- * Print a log message.
- *
- * @param Message
- *        Ansi string to be logged
- *
- * @return None
- */
-VOID LogPrint(IN PCSTR Message)
-{
-    size_t MessageLength;
-    ASSERT(NT_SUCCESS(RtlStringCbLengthA(Message, 512, &MessageLength)));
-
-    KmtAddToLogBuffer(ResultBuffer, Message, MessageLength);
-}
-
-/**
- * @name LogPrintF
- *
- * Print a formatted log message.
- *
- * @param Format
- *        printf-like format string
- * @param ...
- *        Arguments corresponding to the format
- *
- * @return None
- */
-VOID LogPrintF(IN PCSTR Format, ...)
-{
-    va_list Arguments;
-    PAGED_CODE();
-    va_start(Arguments, Format);
-    LogVPrintF(Format, Arguments);
-    va_end(Arguments);
-}
-
-/**
- * @name LogVPrintF
- *
- * Print a formatted log message.
- *
- * @param Format
- *        printf-like format string
- * @param Arguments
- *        Arguments corresponding to the format
- *
- * @return None
- */
-VOID LogVPrintF(IN PCSTR Format, va_list Arguments)
-{
-    CHAR Buffer[512];
-    /* TODO: make this work from any IRQL */
-    PAGED_CODE();
-
-    RtlStringCbVPrintfA(Buffer, sizeof Buffer, Format, Arguments);
-
-    LogPrint(Buffer);
-}




More information about the Ros-diffs mailing list