// Assert //------------------------------------------------------------------------------ /*static*/ bool UnitTestManager::AssertFailure( const char * message, const char * file, uint32_t line ) { OUTPUT( "\n-------- TEST ASSERTION FAILED --------\n" ); OUTPUT( "%s(%i): Assert: %s", file, line, message ); OUTPUT( "\n-----^^^ TEST ASSERTION FAILED ^^^-----\n" ); if ( IsDebuggerAttached() ) { return true; // tell the calling code to break at the failure sight } // throw will be caught by the unit test framework and noted as a failure throw "Test Failed"; }
// CONSTRUCTOR //------------------------------------------------------------------------------ UnitTestManager::UnitTestManager() { // manage singleton ASSERT( s_Instance == nullptr ); s_Instance = this; // if we're running outside the debugger, we don't want // failures to pop up a dialog. We want them to throw so // the test framework can catch the exception #ifdef ASSERTS_ENABLED if ( IsDebuggerAttached() == false ) { AssertHandler::SetThrowOnAssert( true ); } #endif }
NTSTATUS DriverEntry(PDRIVER_OBJECT DrvObj, PUNICODE_STRING RegPath) { PDEVICE_OBJECT DevObj = NULL; NTSTATUS status; UNREFERENCED_PARAMETER(RegPath); #if _AMD64_ if (IsDebuggerAttached() == 0) { DbgPrint("fasttrap.sys : debugger not attached. Load failed\n"); return STATUS_INSUFFICIENT_RESOURCES; } #endif if (IsNtVirtualFunc() == 0) { dprintf("fasttrap.sys : Nt*VirtualMemory functions not found. Load failed\n"); return STATUS_INSUFFICIENT_RESOURCES; } status = IoCreateDevice(DrvObj, 0, &deviceName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &DevObj); if(!NT_SUCCESS(status)) { return status; } DrvObj->MajorFunction[IRP_MJ_CREATE] = FasttrapOpen; DrvObj->MajorFunction[IRP_MJ_CLOSE] = FasttrapClose; DrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FasttrapIoctl; DrvObj->DriverUnload = FasttrapUnload; status = IoCreateSymbolicLink (&deviceLink, &deviceName); if (!NT_SUCCESS(status)) { IoDeleteDevice( DevObj); return status; } fasttrap_load(); if (PsSetCreateProcessNotifyRoutine(CreateProcFunc, FALSE) != STATUS_SUCCESS) { dprintf("fasttrap.sys: PsSetCreateProcessNotifyRoutine registrartion failed\n"); return STATUS_INSUFFICIENT_RESOURCES; } return status; }
// DESTRUCTOR //------------------------------------------------------------------------------ UnitTestManager::~UnitTestManager() { #ifdef ASSERTS_ENABLED if ( IsDebuggerAttached() == false ) { AssertHandler::SetThrowOnAssert( false ); } #endif // free all registered tests UnitTest * testGroup = s_FirstTest; while ( testGroup ) { UnitTest * next = testGroup->m_NextTestGroup; FDELETE testGroup; testGroup = next; } // manage singleton ASSERT( s_Instance == this ); s_Instance = nullptr; }