Example #1
0
bool Run::AddRun(_In_z_ const PAL_Char *name, _In_z_ const PAL_Char *test)
{
    if (name[0] == '\0')
        return true;

    //Find out if this module is already loaded.
    Module *match = NULL;
    for (DWORD i = 0; i < Modules().size(); i++)
    {
        if (Equals(Modules()[i]->GetName(), name))
        {
            match = Modules()[i];
            break;
        }
    }
    
    if (match == NULL)
    {
        AddModule(name);
        match = m_loadingModule;

        /* Set m_runLock so that NitsIsActivated() returns true in here. This
         * prevents the test code from thinking that NITS is inactive during
         * initialization. */
        System &system = System::GetInstance();
        Globals &globals = system.GetGlobals();
        bool setRunLock = (Atomic_CompareAndSwap(&globals.m_runLock, 0, 1) == 0);

        Shlib *lib = NULL;

        lib = Shlib_Open_Injected(name, NitsReservedCallSite());

        if (setRunLock)
        {
            Atomic_CompareAndSwap(&globals.m_runLock, 1, 0);
        }


        if(!lib)
        {
            PAL_Char *err;
            err = Shlib_Err(); 
            Tprintf(PAL_T("%T%T%T%T%T"), PAL_T("ERROR: Could not load test module. File='"), tcs(name), PAL_T("', Reason="), tcs(err), PAL_T("\n"));
            if (err)
                Shlib_FreeErr(err);
            return false;
        }

        match->SetLibrary(lib);
    }

    match->AddRun(test);
    return true;
}