[KMTESTS]

- Move out definitions for user/kernel test utility functions into their own header (still not pretty, but at least the one header won't get as huge
- Make KmtStartThread/KmtFinishThread available to all tests

svn path=/trunk/; revision=65256
This commit is contained in:
Thomas Faber 2014-11-04 20:55:16 +00:00
parent f1f1a19b03
commit 902e8bb68e
5 changed files with 225 additions and 206 deletions

View file

@ -132,6 +132,8 @@ VOID KmtSetIrql(IN KIRQL NewIrql);
BOOLEAN KmtAreInterruptsEnabled(VOID);
ULONG KmtGetPoolTag(PVOID Memory);
USHORT KmtGetPoolType(PVOID Memory);
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL);
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL);
#elif defined KMT_USER_MODE
DWORD KmtRunKernelTest(IN PCSTR TestName);
@ -242,143 +244,9 @@ VOID KmtFreeGuarded(PVOID Pointer);
#if defined KMT_DEFINE_TEST_FUNCTIONS
#if defined KMT_KERNEL_MODE
BOOLEAN KmtIsCheckedBuild;
BOOLEAN KmtIsMultiProcessorBuild;
PCSTR KmtMajorFunctionNames[] =
{
"Create",
"CreateNamedPipe",
"Close",
"Read",
"Write",
"QueryInformation",
"SetInformation",
"QueryEa",
"SetEa",
"FlushBuffers",
"QueryVolumeInformation",
"SetVolumeInformation",
"DirectoryControl",
"FileSystemControl",
"DeviceControl",
"InternalDeviceControl/Scsi",
"Shutdown",
"LockControl",
"Cleanup",
"CreateMailslot",
"QuerySecurity",
"SetSecurity",
"Power",
"SystemControl",
"DeviceChange",
"QueryQuota",
"SetQuota",
"Pnp/PnpPower"
};
VOID KmtSetIrql(IN KIRQL NewIrql)
{
KIRQL Irql = KeGetCurrentIrql();
if (Irql > NewIrql)
KeLowerIrql(NewIrql);
else if (Irql < NewIrql)
KeRaiseIrql(NewIrql, &Irql);
}
BOOLEAN KmtAreInterruptsEnabled(VOID)
{
return (__readeflags() & (1 << 9)) != 0;
}
typedef struct _POOL_HEADER
{
union
{
struct
{
#ifdef _M_AMD64
USHORT PreviousSize:8;
USHORT PoolIndex:8;
USHORT BlockSize:8;
USHORT PoolType:8;
#else
USHORT PreviousSize:9;
USHORT PoolIndex:7;
USHORT BlockSize:9;
USHORT PoolType:7;
#endif
};
ULONG Ulong1;
};
#ifdef _M_AMD64
ULONG PoolTag;
#endif
union
{
#ifdef _M_AMD64
PEPROCESS ProcessBilled;
#else
ULONG PoolTag;
#endif
struct
{
USHORT AllocatorBackTraceIndex;
USHORT PoolTagHash;
};
};
} POOL_HEADER, *PPOOL_HEADER;
ULONG KmtGetPoolTag(PVOID Memory)
{
PPOOL_HEADER Header;
/* it's not so easy for allocations of PAGE_SIZE */
if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
return 'TooL';
Header = Memory;
Header--;
return Header->PoolTag;
}
USHORT KmtGetPoolType(PVOID Memory)
{
PPOOL_HEADER Header;
/* it's not so easy for allocations of PAGE_SIZE */
if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
return 0;
Header = Memory;
Header--;
return Header->PoolType;
}
INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 3, 0);
#include "kmt_test_kernel.h"
#elif defined KMT_USER_MODE
static PKMT_RESULTBUFFER KmtAllocateResultBuffer(SIZE_T ResultBufferSize)
{
PKMT_RESULTBUFFER Buffer = HeapAlloc(GetProcessHeap(), 0, ResultBufferSize);
if (!Buffer)
return NULL;
Buffer->Successes = 0;
Buffer->Failures = 0;
Buffer->Skipped = 0;
Buffer->LogBufferLength = 0;
Buffer->LogBufferMaxLength = (ULONG)ResultBufferSize - FIELD_OFFSET(KMT_RESULTBUFFER, LogBuffer);
return Buffer;
}
static VOID KmtFreeResultBuffer(PKMT_RESULTBUFFER Buffer)
{
HeapFree(GetProcessHeap(), 0, Buffer);
}
#define KmtVSNPrintF vsnprintf
#include "kmt_test_user.h"
#endif /* defined KMT_USER_MODE */
PKMT_RESULTBUFFER ResultBuffer = NULL;

View file

@ -0,0 +1,184 @@
/*
* PROJECT: ReactOS kernel-mode tests
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
* PURPOSE: Kernel-Mode Test Suite test framework declarations
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#ifndef _KMTEST_TEST_KERNEL_H_
#define _KMTEST_TEST_KERNEL_H_
#if !defined _KMTEST_TEST_H_
#error include kmt_test.h instead of including kmt_test_kernel.h
#endif /* !defined _KMTEST_TEST_H_ */
BOOLEAN KmtIsCheckedBuild;
BOOLEAN KmtIsMultiProcessorBuild;
PCSTR KmtMajorFunctionNames[] =
{
"Create",
"CreateNamedPipe",
"Close",
"Read",
"Write",
"QueryInformation",
"SetInformation",
"QueryEa",
"SetEa",
"FlushBuffers",
"QueryVolumeInformation",
"SetVolumeInformation",
"DirectoryControl",
"FileSystemControl",
"DeviceControl",
"InternalDeviceControl/Scsi",
"Shutdown",
"LockControl",
"Cleanup",
"CreateMailslot",
"QuerySecurity",
"SetSecurity",
"Power",
"SystemControl",
"DeviceChange",
"QueryQuota",
"SetQuota",
"Pnp/PnpPower"
};
VOID KmtSetIrql(IN KIRQL NewIrql)
{
KIRQL Irql = KeGetCurrentIrql();
if (Irql > NewIrql)
KeLowerIrql(NewIrql);
else if (Irql < NewIrql)
KeRaiseIrql(NewIrql, &Irql);
}
BOOLEAN KmtAreInterruptsEnabled(VOID)
{
return (__readeflags() & (1 << 9)) != 0;
}
typedef struct _POOL_HEADER
{
union
{
struct
{
#ifdef _M_AMD64
USHORT PreviousSize:8;
USHORT PoolIndex:8;
USHORT BlockSize:8;
USHORT PoolType:8;
#else
USHORT PreviousSize:9;
USHORT PoolIndex:7;
USHORT BlockSize:9;
USHORT PoolType:7;
#endif
};
ULONG Ulong1;
};
#ifdef _M_AMD64
ULONG PoolTag;
#endif
union
{
#ifdef _M_AMD64
PEPROCESS ProcessBilled;
#else
ULONG PoolTag;
#endif
struct
{
USHORT AllocatorBackTraceIndex;
USHORT PoolTagHash;
};
};
} POOL_HEADER, *PPOOL_HEADER;
ULONG KmtGetPoolTag(PVOID Memory)
{
PPOOL_HEADER Header;
/* it's not so easy for allocations of PAGE_SIZE */
if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
return 'TooL';
Header = Memory;
Header--;
return Header->PoolTag;
}
USHORT KmtGetPoolType(PVOID Memory)
{
PPOOL_HEADER Header;
/* it's not so easy for allocations of PAGE_SIZE */
if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
return 0;
Header = Memory;
Header--;
return Header->PoolType;
}
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE ThreadHandle;
PVOID ThreadObject = NULL;
InitializeObjectAttributes(&ObjectAttributes,
NULL,
OBJ_KERNEL_HANDLE,
NULL,
NULL);
ThreadHandle = INVALID_HANDLE_VALUE;
Status = PsCreateSystemThread(&ThreadHandle,
SYNCHRONIZE,
&ObjectAttributes,
NULL,
NULL,
StartRoutine,
StartContext);
ok_eq_hex(Status, STATUS_SUCCESS);
if (!skip(NT_SUCCESS(Status) && ThreadHandle != NULL && ThreadHandle != INVALID_HANDLE_VALUE, "No thread\n"))
{
Status = ObReferenceObjectByHandle(ThreadHandle,
SYNCHRONIZE,
*PsThreadType,
KernelMode,
&ThreadObject,
NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ObCloseHandle(ThreadHandle, KernelMode);
}
return ThreadObject;
}
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
{
NTSTATUS Status;
if (skip(Thread != NULL, "No thread\n"))
return;
if (Event)
KeSetEvent(Event, IO_NO_INCREMENT, TRUE);
Status = KeWaitForSingleObject(Thread,
Executive,
KernelMode,
FALSE,
NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ObDereferenceObject(Thread);
}
INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 3, 0);
#endif /* !defined _KMTEST_TEST_KERNEL_H_ */

View file

@ -0,0 +1,37 @@
/*
* PROJECT: ReactOS kernel-mode tests
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
* PURPOSE: Kernel-Mode Test Suite test framework declarations
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#ifndef _KMTEST_TEST_USER_H_
#define _KMTEST_TEST_USER_H_
#if !defined _KMTEST_TEST_H_
#error include kmt_test.h instead of including kmt_test_user.h
#endif /* !defined _KMTEST_TEST_H_ */
static PKMT_RESULTBUFFER KmtAllocateResultBuffer(SIZE_T ResultBufferSize)
{
PKMT_RESULTBUFFER Buffer = HeapAlloc(GetProcessHeap(), 0, ResultBufferSize);
if (!Buffer)
return NULL;
Buffer->Successes = 0;
Buffer->Failures = 0;
Buffer->Skipped = 0;
Buffer->LogBufferLength = 0;
Buffer->LogBufferMaxLength = (ULONG)ResultBufferSize - FIELD_OFFSET(KMT_RESULTBUFFER, LogBuffer);
return Buffer;
}
static VOID KmtFreeResultBuffer(PKMT_RESULTBUFFER Buffer)
{
HeapFree(GetProcessHeap(), 0, Buffer);
}
#define KmtVSNPrintF vsnprintf
#endif /* !defined _KMTEST_TEST_USER_H_ */

View file

@ -713,62 +713,3 @@ TriggerWork(
KeSetEvent(&Context->StartWorkEvent, IO_NO_INCREMENT, TRUE);
return WaitForWork(Context, MilliSeconds);
}
PKTHREAD
KmtStartThread(
IN PKSTART_ROUTINE StartRoutine,
IN PVOID StartContext OPTIONAL)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE ThreadHandle;
PVOID ThreadObject = NULL;
InitializeObjectAttributes(&ObjectAttributes,
NULL,
OBJ_KERNEL_HANDLE,
NULL,
NULL);
ThreadHandle = INVALID_HANDLE_VALUE;
Status = PsCreateSystemThread(&ThreadHandle,
SYNCHRONIZE,
&ObjectAttributes,
NULL,
NULL,
StartRoutine,
StartContext);
ok_eq_hex(Status, STATUS_SUCCESS);
if (!skip(NT_SUCCESS(Status) && ThreadHandle != NULL && ThreadHandle != INVALID_HANDLE_VALUE, "No thread\n"))
{
Status = ObReferenceObjectByHandle(ThreadHandle,
SYNCHRONIZE,
*PsThreadType,
KernelMode,
&ThreadObject,
NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ObCloseHandle(ThreadHandle, KernelMode);
}
return ThreadObject;
}
VOID
KmtFinishThread(
IN PKTHREAD Thread OPTIONAL,
IN PKEVENT Event OPTIONAL)
{
NTSTATUS Status;
if (skip(Thread != NULL, "No thread\n"))
return;
if (Event)
KeSetEvent(Event, IO_NO_INCREMENT, TRUE);
Status = KeWaitForSingleObject(Thread,
Executive,
KernelMode,
FALSE,
NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ObDereferenceObject(Thread);
}

View file

@ -211,15 +211,4 @@ TriggerWork(
IN PTHREAD_CONTEXT Context,
IN ULONG MilliSeconds);
PKTHREAD
KmtStartThread(
IN PKSTART_ROUTINE StartRoutine,
IN PVOID StartContext OPTIONAL);
VOID
KmtFinishThread(
IN PKTHREAD Thread OPTIONAL,
IN PKEVENT Event OPTIONAL);
#endif /* !defined _KMTEST_NPFS_H_ */