VirtualBox

Changeset 58303 in vbox


Ignore:
Timestamp:
Oct 18, 2015 10:46:23 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103499
Message:

RTTestCreateChild: Added new method for creating a test instance in a child process that won't mess up the XML report being submitted per pipe or file.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r58300 r58303  
    16591659# define RTTestChangeName                               RT_MANGLER(RTTestChangeName)
    16601660# define RTTestCreate                                   RT_MANGLER(RTTestCreate)
     1661# define RTTestCreateChild                              RT_MANGLER(RTTestCreateChild)
    16611662# define RTTestCreateEx                                 RT_MANGLER(RTTestCreateEx)
    16621663# define RTTestDestroy                                  RT_MANGLER(RTTestDestroy)
  • trunk/include/iprt/test.h

    r57944 r58303  
    8080RTR3DECL(int) RTTestCreate(const char *pszTest, PRTTEST phTest);
    8181
     82/**
     83 * Creates a test instance for a child process.
     84 *
     85 * This differs from RTTestCreate in that it disabled result reporting to file
     86 * and pipe in order to avoid producing invalid XML.
     87 *
     88 * @returns IPRT status code.
     89 * @param   pszTest     The test name.
     90 * @param   phTest      Where to store the test instance handle.
     91 */
     92RTR3DECL(int) RTTestCreateChild(const char *pszTest, PRTTEST phTest);
     93
    8294/** @name RTTEST_C_XXX - Flags for RTTestCreateEx.
    8395 * @{ */
     
    111123 * this flag is incompatible with using the RTTestIXxxx variant of the API. */
    112124#define RTTEST_C_NO_TLS                 RT_BIT(3)
     125/** Don't report to the pipe (IPRT_TEST_PIPE or other).   */
     126#define RTTEST_C_NO_XML_REPORTING_PIPE  RT_BIT(4)
     127/** Don't report to the results file (IPRT_TEST_FILE or other).   */
     128#define RTTEST_C_NO_XML_REPORTING_FILE  RT_BIT(4)
     129/** No XML reporting to pipes, file or anything.
     130 * Child processes may want to use this so they don't garble the output of
     131 * the main test process. */
     132#define RTTEST_C_NO_XML_REPORTING       (RTTEST_C_NO_XML_REPORTING_PIPE | RTTEST_C_NO_XML_REPORTING_FILE)
    113133/** Mask containing the valid bits. */
    114 #define RTTEST_C_VALID_MASK             UINT32_C(0x0000000f)
     134#define RTTEST_C_VALID_MASK             UINT32_C(0x0000003f)
    115135/** @} */
    116136
  • trunk/src/VBox/Runtime/r3/test.cpp

    r57944 r58303  
    315315                 * Any test driver we are connected or should connect to?
    316316                 */
    317                 if ((fFlags & RTTEST_C_USE_ENV) && iNativeTestPipe == -1)
     317                if (!(fFlags & RTTEST_C_NO_XML_REPORTING_PIPE))
    318318                {
    319                     rc = RTEnvGetEx(RTENV_DEFAULT, "IPRT_TEST_PIPE", szEnvVal, sizeof(szEnvVal), NULL);
    320                     if (RT_SUCCESS(rc))
     319                    if (   (fFlags & RTTEST_C_USE_ENV)
     320                        && iNativeTestPipe == -1)
    321321                    {
     322                        rc = RTEnvGetEx(RTENV_DEFAULT, "IPRT_TEST_PIPE", szEnvVal, sizeof(szEnvVal), NULL);
     323                        if (RT_SUCCESS(rc))
     324                        {
    322325#if ARCH_BITS == 64
    323                         rc = RTStrToInt64Full(szEnvVal, 0, &iNativeTestPipe);
     326                            rc = RTStrToInt64Full(szEnvVal, 0, &iNativeTestPipe);
    324327#else
    325                         rc = RTStrToInt32Full(szEnvVal, 0, &iNativeTestPipe);
     328                            rc = RTStrToInt32Full(szEnvVal, 0, &iNativeTestPipe);
    326329#endif
    327                         if (RT_FAILURE(rc))
     330                            if (RT_FAILURE(rc))
     331                            {
     332                                RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTStrToInt32Full(\"%s\") -> %Rrc\n",
     333                                             pszTest, szEnvVal, rc);
     334                                iNativeTestPipe = -1;
     335                            }
     336                        }
     337                        else if (rc != VERR_ENV_VAR_NOT_FOUND)
     338                            RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTEnvGetEx(IPRT_TEST_PIPE) -> %Rrc\n", pszTest, rc);
     339                    }
     340                    if (iNativeTestPipe != -1)
     341                    {
     342                        rc = RTPipeFromNative(&pTest->hXmlPipe, iNativeTestPipe, RTPIPE_N_WRITE);
     343                        if (RT_SUCCESS(rc))
     344                            pTest->fXmlEnabled = true;
     345                        else
    328346                        {
    329                             RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTStrToInt32Full(\"%s\") -> %Rrc\n",
    330                                          pszTest, szEnvVal, rc);
    331                             iNativeTestPipe = -1;
     347                            RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTPipeFromNative(,%p,WRITE) -> %Rrc\n",
     348                                         pszTest, iNativeTestPipe, rc);
     349                            pTest->hXmlPipe = NIL_RTPIPE;
    332350                        }
    333                     }
    334                     else if (rc != VERR_ENV_VAR_NOT_FOUND)
    335                         RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTEnvGetEx(IPRT_TEST_PIPE) -> %Rrc\n", pszTest, rc);
    336                 }
    337                 if (iNativeTestPipe != -1)
    338                 {
    339                     rc = RTPipeFromNative(&pTest->hXmlPipe, iNativeTestPipe, RTPIPE_N_WRITE);
    340                     if (RT_SUCCESS(rc))
    341                         pTest->fXmlEnabled = true;
    342                     else
    343                     {
    344                         RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTPipeFromNative(,%p,WRITE) -> %Rrc\n",
    345                                      pszTest, iNativeTestPipe, rc);
    346                         pTest->hXmlPipe = NIL_RTPIPE;
    347351                    }
    348352                }
     
    351355                 * Any test file we should write the test report to?
    352356                 */
    353                 if ((fFlags & RTTEST_C_USE_ENV) && pszXmlFile == NULL)
     357                if (!(fFlags & RTTEST_C_NO_XML_REPORTING_FILE))
    354358                {
    355                     rc = RTEnvGetEx(RTENV_DEFAULT, "IPRT_TEST_FILE", szEnvVal, sizeof(szEnvVal), NULL);
    356                     if (RT_SUCCESS(rc))
    357                         pszXmlFile = szEnvVal;
    358                     else if (rc != VERR_ENV_VAR_NOT_FOUND)
    359                         RTStrmPrintf(g_pStdErr, "%s: test pipe error: RTEnvGetEx(IPRT_TEST_MAX_LEVEL) -> %Rrc\n", pszTest, rc);
    360                 }
    361                 if (pszXmlFile && *pszXmlFile)
    362                 {
    363                     rc = RTFileOpen(&pTest->hXmlFile, pszXmlFile,
    364                                     RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE);
    365                     if (RT_SUCCESS(rc))
    366                         pTest->fXmlEnabled = true;
    367                     else
     359                    if ((fFlags & RTTEST_C_USE_ENV) && pszXmlFile == NULL)
    368360                    {
    369                         RTStrmPrintf(g_pStdErr, "%s: test file error: RTFileOpen(,\"%s\",) -> %Rrc\n", pszTest, pszXmlFile, rc);
    370                         pTest->hXmlFile = NIL_RTFILE;
     361                        rc = RTEnvGetEx(RTENV_DEFAULT, "IPRT_TEST_FILE", szEnvVal, sizeof(szEnvVal), NULL);
     362                        if (RT_SUCCESS(rc))
     363                            pszXmlFile = szEnvVal;
     364                        else if (rc != VERR_ENV_VAR_NOT_FOUND)
     365                            RTStrmPrintf(g_pStdErr, "%s: test file error: RTEnvGetEx(IPRT_TEST_MAX_LEVEL) -> %Rrc\n", pszTest, rc);
     366                    }
     367                    if (pszXmlFile && *pszXmlFile)
     368                    {
     369                        rc = RTFileOpen(&pTest->hXmlFile, pszXmlFile,
     370                                        RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE);
     371                        if (RT_SUCCESS(rc))
     372                            pTest->fXmlEnabled = true;
     373                        else
     374                        {
     375                            RTStrmPrintf(g_pStdErr, "%s: test file error: RTFileOpen(,\"%s\",) -> %Rrc\n",
     376                                         pszTest, pszXmlFile, rc);
     377                            pTest->hXmlFile = NIL_RTFILE;
     378                        }
    371379                    }
    372380                }
    373                 else if (rc != VERR_ENV_VAR_NOT_FOUND)
    374                     RTStrmPrintf(g_pStdErr, "%s: test file error: RTEnvGetEx(IPRT_TEST_FILE) -> %Rrc\n", pszTest, rc);
    375381
    376382                /*
     
    405411{
    406412    return RTTestCreateEx(pszTest, RTTEST_C_USE_ENV, RTTESTLVL_INVALID, -1 /*iNativeTestPipe*/, NULL /*pszXmlFile*/, phTest);
     413}
     414
     415
     416RTR3DECL(int) RTTestCreateChild(const char *pszTest, PRTTEST phTest)
     417{
     418    return RTTestCreateEx(pszTest, RTTEST_C_USE_ENV | RTTEST_C_NO_XML_REPORTING,
     419                          RTTESTLVL_INVALID, -1 /*iNativeTestPipe*/, NULL /*pszXmlFile*/, phTest);
    407420}
    408421
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