/*
* 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@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_
#define _KMTEST_TEST_H_
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;
#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)
{
#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_ */
+++ /dev/null
-/*
- * 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@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);
-}