]> granicus.if.org Git - icu/commitdiff
ICU-11657 Synchronize intltest message output.
authorAndy Heninger <andy.heninger@gmail.com>
Tue, 6 Oct 2015 23:13:49 +0000 (23:13 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Tue, 6 Oct 2015 23:13:49 +0000 (23:13 +0000)
X-SVN-Rev: 38036

icu4c/source/test/intltest/intltest.cpp

index acb29bb1cb4b0d24813c5f58b7ae6abb4542d28c..ace7e6be14a0388246ef2c5d8616c58d608c4220 100644 (file)
  * IntlTest is a base class for tests.
  */
 
-#include <stdio.h>
-#include <string.h>
 #include <assert.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
-#include "unicode/unistr.h"
-#include "unicode/ures.h"
-#include "unicode/smpdtfmt.h"
-#include "unicode/ucnv.h"
-#include "unicode/uclean.h"
-#include "unicode/timezone.h"
+#include "unicode/ctest.h" // for str_timeDelta
 #include "unicode/curramt.h"
+#include "unicode/locid.h"
 #include "unicode/putil.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/timezone.h"
+#include "unicode/uclean.h"
+#include "unicode/ucnv.h"
+#include "unicode/unistr.h"
+#include "unicode/ures.h"
 
 #include "intltest.h"
+
 #include "caltztst.h"
-#include "itmajor.h"
-#include "cstring.h"
-#include "umutex.h"
-#include "uassert.h"
 #include "cmemory.h"
-#include "uoptions.h"
-
+#include "cstring.h"
+#include "itmajor.h"
+#include "mutex.h"
 #include "putilimp.h" // for uprv_getRawUTCtime()
-#include "unicode/locid.h"
-#include "unicode/ctest.h" // for str_timeDelta
+#include "uassert.h"
 #include "udbgutil.h"
+#include "umutex.h"
+#include "uoptions.h"
 
 #ifdef XP_MAC_CONSOLE
 #include <console.h>
@@ -948,6 +949,7 @@ void IntlTest::logln(const char *fmt, ...)
     vsprintf(buffer, fmt, ap);
     va_end(ap);
     if( verbose ) {
+        // TODO: change to default conversion in UnicodeString constructor.
         logln(UnicodeString(buffer, ""));
     }
 }
@@ -1079,8 +1081,16 @@ UBool IntlTest::printKnownIssues()
   }
 }
 
+static UMutex messageMutex = U_MUTEX_INITIALIZER;
+
 void IntlTest::LL_message( UnicodeString message, UBool newline )
 {
+    // Synchronize this function.
+    // All error messages generated by tests funnel through here.
+    // Multithreaded tests can concurrently generate errors, requiring syncronization
+    // to keep each message together.
+    Mutex lock(&messageMutex);
+
     // string that starts with a LineFeed character and continues
     // with spaces according to the current indentation
     static const UChar indentUChars[] = {
@@ -1096,6 +1106,7 @@ void IntlTest::LL_message( UnicodeString message, UBool newline )
         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
     };
+    U_ASSERT(1 + LL_indentlevel <= UPRV_LENGTHOF(indentUChars));
     UnicodeString indent(FALSE, indentUChars, 1 + LL_indentlevel);
 
     char buffer[30000];