VirtualBox

Changeset 88311 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Mar 29, 2021 12:59:22 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143530
Message:

IPRT/test: Added RTTestErrContext (with variations) for setting a print-once-on-failure message to help put a failure in context w/o needing to get verbose on successful runs. bugref:9890

Location:
trunk/src/VBox/Runtime/r3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/test.cpp

    r82968 r88311  
    125125    /** The number of sub tests that failed. */
    126126    uint32_t            cSubTestsFailed;
     127
     128    /** Error context message. */
     129    char               *pszErrCtx;
    127130
    128131    /** Set if XML output is enabled. */
     
    520523    RTStrFree((char *)pTest->pszTest);
    521524    pTest->pszTest = NULL;
     525    RTStrFree(pTest->pszErrCtx);
     526    pTest->pszErrCtx = NULL;
    522527    RTMemFree(pTest);
    523528    return VINF_SUCCESS;
     
    12591264        pTest->fSubTestReported = true;
    12601265    }
     1266    RTStrFree(pTest->pszErrCtx);
     1267    pTest->pszErrCtx = NULL;
    12611268    return cch;
    12621269}
     
    17111718        RTCritSectEnter(&pTest->OutputLock);
    17121719        cch += rtTestPrintf(pTest, fHasNewLine ? "%N" : "%N\n", pszFormat, &va2);
     1720        if (pTest->pszErrCtx)
     1721        {
     1722            cch += rtTestPrintf(pTest, "context: %s\n", pTest->pszErrCtx);
     1723            RTStrFree(pTest->pszErrCtx);
     1724            pTest->pszErrCtx = NULL;
     1725        }
    17131726        RTCritSectLeave(&pTest->OutputLock);
    17141727
     
    17751788
    17761789
     1790RTR3DECL(int) RTTestErrContextV(RTTEST hTest, const char *pszFormat, va_list va)
     1791{
     1792    PRTTESTINT pTest = hTest;
     1793    RTTEST_GET_VALID_RETURN(pTest);
     1794
     1795    RTStrFree(pTest->pszErrCtx);
     1796    pTest->pszErrCtx = NULL;
     1797
     1798    if (pszFormat && *pszFormat)
     1799    {
     1800        pTest->pszErrCtx = RTStrAPrintf2V(pszFormat, va);
     1801        AssertReturn(pTest->pszErrCtx, VERR_NO_STR_MEMORY);
     1802        RTStrStripR(pTest->pszErrCtx);
     1803    }
     1804
     1805    return VINF_SUCCESS;
     1806}
     1807
     1808
     1809RTR3DECL(int) RTTestErrContext(RTTEST hTest, const char *pszFormat, ...)
     1810{
     1811    va_list va;
     1812    va_start(va, pszFormat);
     1813    int rc = RTTestErrContextV(hTest, pszFormat, va);
     1814    va_end(va);
     1815    return rc;
     1816}
     1817
     1818
    17771819RTR3DECL(int) RTTestDisableAssertions(RTTEST hTest)
    17781820{
  • trunk/src/VBox/Runtime/r3/testi.cpp

    r82968 r88311  
    176176
    177177
     178RTR3DECL(int) RTTestIErrContextV(const char *pszFormat, va_list va)
     179{
     180    return RTTestErrContextV(NIL_RTTEST, pszFormat, va);
     181}
     182
     183
     184RTR3DECL(int) RTTestErrContext(const char *pszFormat, ...)
     185{
     186    va_list va;
     187    va_start(va, pszFormat);
     188    int rc = RTTestIErrContextV(pszFormat, va);
     189    va_end(va);
     190    return rc;
     191}
     192
     193
    178194RTR3DECL(int) RTTestIDisableAssertions(void)
    179195{
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette