locked
Test hangs when agent thread terminates RRS feed

  • Question

  • For my unit tests I use a managed CPP wrapper class/dll to call arbitrary functions in a run-time loaded unmanaged dll.

    The wrapper looks like this:

    class wrapper {
    
    IntPtr module;
    
    public:
    
    wrapper (string dllname)
    {
     module = LoadLibrary(dllname);
    }
    ~wrapper (string dllname)
    {
     FreeLibrary(module);
    }
    
    Run(string function)
    {
    ...
    }
    
    }
    
    
    
    

     

    A typical test looks like this:

    [TestMethod]
    public void FFONLRunning_InitiateErrorTrans()
    {
     dll.Run("FFONLRunning::InitiateErrorTrans");
    }
    

    The Wrapper uses LoadLibrary/FreeLibary.

    Everything worked as long as I loaded the dll once before the tests

    Because I want to have an easy clean up after single tests, I tried to load the unmanaged dll during TestSetup and to unload it during TestCleanup.

    [TestCleanup()]
    public void MyTestCleanup() 
    {
     dll.Dispose();
     dll = null;
    }
    
    


    In the debugger I can see that the managed CPP destructor is called, correctly calls FreeLibrary, the Dll entry point is called and returns to some Ldrp function. Unfortunately control never returns to the managed CPP destructor, instead the debugger indicates that the thread has terminated with  return code 0. The test status thread seems to wait for an event that will never occur.

    To me it seems the test thread is terminated unexpectedly, but I don't understand why.

    Compiler version is VS2008.

    Every help is appreciated.

    Regards

    Jürgen


    • Edited by Jürgen Veidt Tuesday, June 14, 2011 1:49 PM Formatted again
    Tuesday, June 14, 2011 1:43 PM

Answers

  • Update:

    recently I found the reason for the termination: One of the unloaded dlls accidentally terminated the thread in its DllMain function.

    Unfortunately the test engine doesn't handle this case. 

    • Proposed as answer by Vikram Agrawal Tuesday, July 17, 2012 5:36 PM
    • Marked as answer by Jürgen Veidt Monday, August 27, 2012 3:33 PM
    Tuesday, July 17, 2012 2:59 PM