VirtualBox

Changeset 10793

Show
Ignore:
Timestamp:
07/22/08 00:33:15 (3 months ago)
Author:
vboxsync
Message:

IPRT: Added a simple thread testcase for the latest insertion race.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r10788 r10793  
    8080        tstStrFormat \ 
    8181        tstStrToNum \ 
     82        tstThread-1 \ 
    8283        tstTime \ 
    8384        tstTime-2 \ 
     
    281282tstStrToNum_SOURCES = tstStrToNum.cpp 
    282283 
     284tstThread-1_SOURCES = tstThread-1.cpp 
     285 
    283286tstTime_SOURCES = tstTime.cpp 
    284287 
  • trunk/src/VBox/Runtime/testcase/tstThread-1.cpp

    r8245 r10793  
    11/* $Id$ */ 
    22/** @file 
    3  * IPRT Testcase - Native Loader
     3 * IPRT Testcase - Thread Testcase no.1
    44 */ 
    55 
     
    3030 
    3131 
    32 #include <iprt/ldr.h> 
     32/******************************************************************************* 
     33*   Header Files                                                               * 
     34*******************************************************************************/ 
     35#include <iprt/thread.h> 
    3336#include <iprt/stream.h> 
    34 #include <iprt/runtime.h> 
     37#include <iprt/initterm.h> 
    3538#include <iprt/err.h> 
     39 
     40/******************************************************************************* 
     41*   Global Variables                                                           * 
     42*******************************************************************************/ 
     43static unsigned volatile g_cErrors = 0; 
     44 
     45 
     46static DECLCALLBACK(int) tstThread1ReturnImmediately(RTTHREAD Thread, void *pvUser) 
     47{ 
     48    NOREF(pvUser); 
     49    return VINF_SUCCESS; 
     50} 
     51 
     52 
    3653 
    3754int main(int argc, const char * const *argv) 
    3855{ 
    39     int rcRet = 0; 
    40     RTR3Init(); 
     56    RTR3Init(false, 0); 
    4157 
    4258    /* 
    43      * If no args, display usage. 
     59     * A simple testcase for the termination race we used to have. 
    4460     */ 
    45     if (argc <= 1) 
     61    RTTHREAD ahThreads[128]; 
     62    RTPrintf("tstThread-1: TESTING - %u waitable immediate return threads\n", RT_ELEMENTS(ahThreads)); 
     63    for (unsigned j = 0; j < 10; j++) 
    4664    { 
    47         RTPrintf("Syntax: %s [so/dll [so/dll [..]]\n", argv[0]); 
    48         return 1; 
    49     } 
    50  
    51     /* 
    52      * Iterate the arguments and treat all of them as so/dll paths. 
    53      */ 
    54     for (int i = 1; i < argc; i++) 
    55     { 
    56         RTLDRMOD hLdrMod = (RTLDRMOD)0xbaadffaa; 
    57         int rc = RTLdrLoad(argv[i], &hLdrMod); 
    58         if (RT_SUCCESS(rc)) 
     65        RTPrintf("tstThread-1: Iteration %u...\n", j); 
     66        for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++) 
    5967        { 
    60             RTPrintf("tstLdrLoad: %d - %s\n", i, argv[i]); 
    61             rc = RTLdrClose(hLdrMod); 
     68            int rc = RTThreadCreate(&ahThreads[i], tstThread1ReturnImmediately, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1"); 
    6269            if (RT_FAILURE(rc)) 
    6370            { 
    64                 RTPrintf("tstLdrLoad: rc=%Rrc RTLdrClose()\n", rc); 
    65                 rcRet++; 
     71                RTPrintf("tstThread-1: FAILURE(%d) - %d/%d RTThreadCreate failed, rc=%Rrc\n", __LINE__, i, j, rc); 
     72                g_cErrors++; 
     73                ahThreads[i] = NIL_RTTHREAD; 
    6674            } 
    6775        } 
    68         else 
    69         { 
    70             RTPrintf("tstLdrLoad: rc=%Rrc RTLdrOpen('%s')\n", rc, argv[i]); 
    71             rcRet++; 
    72         } 
     76 
     77        /* 
     78         * Wait for the threads to complete. 
     79         */ 
     80        for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++) 
     81            if (ahThreads[i] != NIL_RTTHREAD) 
     82            { 
     83                int rc2; 
     84                int rc = RTThreadWait(ahThreads[i], RT_INDEFINITE_WAIT, &rc2); 
     85                if (RT_FAILURE(rc)) 
     86                { 
     87                    RTPrintf("tstThread-1: FAILURE(%d) - %d/%d RTThreadWait failed, rc=%Rrc\n", __LINE__, j, i, rc); 
     88                    g_cErrors++; 
     89                } 
     90                else if (RT_FAILURE(rc2)) 
     91                { 
     92                    RTPrintf("tstThread-1: FAILURE(%d) - %d/%d Thread failed, rc2=%Rrc\n", __LINE__, j, i, rc2); 
     93                    g_cErrors++; 
     94                } 
     95            } 
    7396    } 
    7497 
     
    7699     * Summary. 
    77100     */ 
    78     if (!rcRet
    79         RTPrintf("tstLdrLoad: SUCCESS\n"); 
     101    if (!g_cErrors
     102        RTPrintf("tstThread-1: SUCCESS\n"); 
    80103    else 
    81         RTPrintf("tstLdrLoad: FAILURE - %d errors\n", rcRet); 
     104        RTPrintf("tstThread-1: FAILURE - %d errors\n", g_cErrors); 
    82105 
    83     return !!rcRet
     106    return !!g_cErrors
    84107} 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy