Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 88310)
+++ /trunk/include/iprt/mangling.h	(revision 88311)
@@ -2397,4 +2397,6 @@
 # define RTTestDestroy                                  RT_MANGLER(RTTestDestroy)
 # define RTTestDisableAssertions                        RT_MANGLER(RTTestDisableAssertions)
+# define RTTestErrContext                               RT_MANGLER(RTTestErrContext)
+# define RTTestErrContextV                              RT_MANGLER(RTTestErrContextV)
 # define RTTestErrorCount                               RT_MANGLER(RTTestErrorCount)
 # define RTTestErrorInc                                 RT_MANGLER(RTTestErrorInc)
@@ -2408,4 +2410,6 @@
 # define RTTestGuardedFree                              RT_MANGLER(RTTestGuardedFree)
 # define RTTestIDisableAssertions                       RT_MANGLER(RTTestIDisableAssertions)
+# define RTTestIErrContext                              RT_MANGLER(RTTestIErrContext)
+# define RTTestIErrContextV                             RT_MANGLER(RTTestIErrContextV)
 # define RTTestIErrorCount                              RT_MANGLER(RTTestIErrorCount)
 # define RTTestIErrorInc                                RT_MANGLER(RTTestIErrorInc)
Index: /trunk/include/iprt/test.h
===================================================================
--- /trunk/include/iprt/test.h	(revision 88310)
+++ /trunk/include/iprt/test.h	(revision 88311)
@@ -639,4 +639,28 @@
 
 /**
+ * Sets error context info to be printed with the first failure.
+ *
+ * @returns IPRT status code.
+ * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
+ *                      associated with the calling thread.
+ * @param   pszFormat   The message, no trailing newline.  NULL to clear the
+ *                      context message.
+ * @param   va          The arguments.
+ */
+RTR3DECL(int) RTTestErrContextV(RTTEST hTest, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
+
+/**
+ * Sets error context info to be printed with the first failure.
+ *
+ * @returns IPRT status code.
+ * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
+ *                      associated with the calling thread.
+ * @param   pszFormat   The message, no trailing newline.  NULL to clear the
+ *                      context message.
+ * @param   ...         The arguments.
+ */
+RTR3DECL(int) RTTestErrContext(RTTEST hTest, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
+
+/**
  * Disables and shuts up assertions.
  *
@@ -1115,4 +1139,24 @@
  */
 RTR3DECL(int) RTTestIFailureDetails(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
+
+/**
+ * Sets error context info to be printed with the first failure.
+ *
+ * @returns IPRT status code.
+ * @param   pszFormat   The message, no trailing newline.  NULL to clear the
+ *                      context message.
+ * @param   va          The arguments.
+ */
+RTR3DECL(int) RTTestIErrContextV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
+
+/**
+ * Sets error context info to be printed with the first failure.
+ *
+ * @returns IPRT status code.
+ * @param   pszFormat   The message, no trailing newline.  NULL to clear the
+ *                      context message.
+ * @param   ...         The arguments.
+ */
+RTR3DECL(int) RTTestIErrContext(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
 
 /**
Index: /trunk/src/VBox/Runtime/r3/test.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/test.cpp	(revision 88310)
+++ /trunk/src/VBox/Runtime/r3/test.cpp	(revision 88311)
@@ -125,4 +125,7 @@
     /** The number of sub tests that failed. */
     uint32_t            cSubTestsFailed;
+
+    /** Error context message. */
+    char               *pszErrCtx;
 
     /** Set if XML output is enabled. */
@@ -520,4 +523,6 @@
     RTStrFree((char *)pTest->pszTest);
     pTest->pszTest = NULL;
+    RTStrFree(pTest->pszErrCtx);
+    pTest->pszErrCtx = NULL;
     RTMemFree(pTest);
     return VINF_SUCCESS;
@@ -1259,4 +1264,6 @@
         pTest->fSubTestReported = true;
     }
+    RTStrFree(pTest->pszErrCtx);
+    pTest->pszErrCtx = NULL;
     return cch;
 }
@@ -1711,4 +1718,10 @@
         RTCritSectEnter(&pTest->OutputLock);
         cch += rtTestPrintf(pTest, fHasNewLine ? "%N" : "%N\n", pszFormat, &va2);
+        if (pTest->pszErrCtx)
+        {
+            cch += rtTestPrintf(pTest, "context: %s\n", pTest->pszErrCtx);
+            RTStrFree(pTest->pszErrCtx);
+            pTest->pszErrCtx = NULL;
+        }
         RTCritSectLeave(&pTest->OutputLock);
 
@@ -1775,4 +1788,33 @@
 
 
+RTR3DECL(int) RTTestErrContextV(RTTEST hTest, const char *pszFormat, va_list va)
+{
+    PRTTESTINT pTest = hTest;
+    RTTEST_GET_VALID_RETURN(pTest);
+
+    RTStrFree(pTest->pszErrCtx);
+    pTest->pszErrCtx = NULL;
+
+    if (pszFormat && *pszFormat)
+    {
+        pTest->pszErrCtx = RTStrAPrintf2V(pszFormat, va);
+        AssertReturn(pTest->pszErrCtx, VERR_NO_STR_MEMORY);
+        RTStrStripR(pTest->pszErrCtx);
+    }
+
+    return VINF_SUCCESS;
+}
+
+
+RTR3DECL(int) RTTestErrContext(RTTEST hTest, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTTestErrContextV(hTest, pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
 RTR3DECL(int) RTTestDisableAssertions(RTTEST hTest)
 {
Index: /trunk/src/VBox/Runtime/r3/testi.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/testi.cpp	(revision 88310)
+++ /trunk/src/VBox/Runtime/r3/testi.cpp	(revision 88311)
@@ -176,4 +176,20 @@
 
 
+RTR3DECL(int) RTTestIErrContextV(const char *pszFormat, va_list va)
+{
+    return RTTestErrContextV(NIL_RTTEST, pszFormat, va);
+}
+
+
+RTR3DECL(int) RTTestErrContext(const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTTestIErrContextV(pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
 RTR3DECL(int) RTTestIDisableAssertions(void)
 {
