NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Force TestStand Crash to Test Crash Recovery

How can I force SeqEdit crash to test crash recovery? Crash due to out of memory is not supported in the crash recovery procedure.

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 1 of 2
(62 Views)

Causing an exception in a non-execution thread that cannot be handled by TestStand, so the following C++ code causes a crash, which I would hope would be caught in the TestStand handler that you want to test:

 

 

// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <stdexcept>  // For std::runtime_error


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

#include <windows.h>
#include <process.h>  // For _beginthreadex

// Function that the thread will execute
unsigned __stdcall ThreadFunction(void* param)
{
    // Do something here
    MessageBox(NULL, L"Thread Function Called!", L"Thread Message", MB_OK);
    
    throw std::runtime_error("Exception from DLL");

    return 0;
}

// Function that creates the new thread
extern "C" __declspec(dllexport) void CreateNewThread()
{
    // Create a thread that runs ThreadFunction
    uintptr_t threadHandle = _beginthreadex(
        NULL,               // Default security attributes
        0,                  // Default stack size
        ThreadFunction,     // Pointer to the thread function
        NULL,               // Thread function parameter
        0,                  // Run immediately after creation
        NULL                // Optionally receive thread identifier
    );

    if (threadHandle == 0) {
        MessageBox(NULL, L"Failed to create thread", L"Error", MB_OK);
    }
    else {
        // Optionally close the thread handle if not needed
        CloseHandle((HANDLE)threadHandle);
    }
}

 

 

Scott Richardson
https://testeract.com
0 Kudos
Message 2 of 2
(21 Views)