]> granicus.if.org Git - icu/commitdiff
ICU-9744 improve logknownissue
authorSteven R. Loomis <srl@icu-project.org>
Tue, 17 Sep 2013 00:21:47 +0000 (00:21 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Tue, 17 Sep 2013 00:21:47 +0000 (00:21 +0000)
X-SVN-Rev: 34340

icu4c/source/test/intltest/intltest.cpp
icu4c/source/test/intltest/ssearch.cpp
icu4c/source/tools/ctestfw/ctest.c
icu4c/source/tools/toolutil/udbgutil.cpp
icu4c/source/tools/toolutil/udbgutil.h

index e8063835f1b9b2d8c8eb86bd685c31a77c33695a..8dc42fd45301266eb00790463f3b900cada3492c 100644 (file)
@@ -50,7 +50,8 @@ static char* _testDataPath=NULL;
 
 // Static list of errors found
 static UnicodeString errorList;
-static UnicodeString knownList;
+static void *knownList = NULL; // known issues
+static UBool noKnownIssues = FALSE; // if TRUE, don't emit known issues
 
 //-----------------------------------------------------------------------------
 //convenience classes to ease porting code that uses the Java
@@ -963,18 +964,22 @@ UBool IntlTest::logKnownIssue(const char *ticket) {
 }
 
 UBool IntlTest::logKnownIssue(const char *ticket, const UnicodeString &msg) {
-  knownList.append(UnicodeString(ticket, ""));
-  knownList.append(UnicodeString(" ",""));
-  knownList.append(UnicodeString(basePath, ""));
-  knownList.append(UnicodeString(currName, ""));
-  knownList.append(UnicodeString(" ",""));
-  char URL[UDBG_KNOWNISSUE_LEN];
-  knownList.append(UnicodeString(udbg_knownIssueURLFrom(ticket, URL), ""));
-  knownList.append(UnicodeString(" ",""));
-  knownList.append(msg);
-  knownList.append(UnicodeString("\n", ""));
+  if(noKnownIssues) return FALSE;
 
-  return true;
+  char fullpath[2048];
+  strcpy(fullpath, basePath);
+  strcat(fullpath, currName);
+  UnicodeString msg2 =msg;
+  UBool firstForTicket, firstForWhere;
+  knownList = udbg_knownIssue_openU(knownList, ticket, fullpath, msg2.getTerminatedBuffer(), &firstForTicket, &firstForWhere);
+
+  if(firstForTicket || firstForWhere) {
+    infoln(UnicodeString("(Known issue #","") + UnicodeString(ticket,"")+ UnicodeString(") \"","") + msg);
+  } else {
+    logln(UnicodeString("(Known issue #","") + UnicodeString(ticket,"")+ UnicodeString(") \"","") + msg);
+  }
+
+  return TRUE;
 }
 
 /* convenience functions that include sprintf formatting */
@@ -1058,9 +1063,9 @@ void IntlTest::printErrors()
 
 UBool IntlTest::printKnownIssues()
 {
-  if(knownList.length()>0) {
-    IntlTest::LL_message( UnicodeString("KNOWN ISSUES:\n", ""), TRUE );
-    IntlTest::LL_message( knownList, TRUE );
+  if(knownList != NULL) {
+    udbg_knownIssue_print(knownList, NULL);
+    udbg_knownIssue_close(knownList);
     return TRUE;
   } else {
     return FALSE;
@@ -1201,6 +1206,9 @@ main(int argc, char* argv[])
             else if (strcmp("utf-8", str) == 0 ||
                      strcmp("u", str) == 0)
                 utf8 = TRUE;
+            else if (strcmp("noknownissues", str) == 0 ||
+                     strcmp("K", str) == 0)
+                noKnownIssues = TRUE;
             else if (strcmp("leaks", str) == 0 ||
                      strcmp("l", str) == 0)
                 leaks = TRUE;
@@ -1315,6 +1323,7 @@ main(int argc, char* argv[])
     fprintf(stdout, "   Leaks (l)                : %s\n", (leaks?             "On" : "Off"));
     fprintf(stdout, "   utf-8 (u)                : %s\n", (utf8?              "On" : "Off"));
     fprintf(stdout, "   notime (T)               : %s\n", (no_time?             "On" : "Off"));
+    fprintf(stdout, "   noknownissues (K)        : %s\n", (noKnownIssues?      "On" : "Off"));
     fprintf(stdout, "   Warn on missing data (w) : %s\n", (warnOnMissingData? "On" : "Off"));
 #if (ICU_USE_THREADS==0)
     fprintf(stdout, "   Threads                  : Disabled\n");
@@ -1470,7 +1479,9 @@ main(int argc, char* argv[])
     }
 
     fprintf(stdout, "\n--------------------------------------\n");
-    major.printKnownIssues();
+    if( major.printKnownIssues() ) {
+      fprintf(stdout, " To run suppressed tests, use the -K option. \n");
+    }
     if (major.getErrors() == 0) {
         /* Call it twice to make sure that the defaults were reset. */
         /* Call it before the OK message to verify proper cleanup. */
index fbbbd86e4eb95bb9c065eda36edf37a6f22a1a1b..fff44d3bdc92a8b2707980fd541f00ec0319d76f 100644 (file)
@@ -629,7 +629,7 @@ void SSearchTest::offsetTest()
     col->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
 
     for(int32_t i = 0; i < testCount; i += 1) {
-      if (i>=4 && i<=6 && logKnownIssue("9156")) {
+      if (i>=4 && i<=6 && logKnownIssue("9156", "was 8081")) {
             continue; // timebomb until ticket #9156 (was #8081) is resolved
         }
         UnicodeString ts = CharsToUnicodeString(test[i]);
index 45cc8632c612f8ef58b9b96a63fba7e5469d5bee..58934a34b14e3b3d10123d58310fd95cd150da71 100644 (file)
@@ -16,6 +16,7 @@
 #include "unicode/utrace.h"
 #include "unicode/uclean.h"
 #include "putilimp.h"
+#include "udbgutil.h"
 
 /* NOTES:
    3/20/1999 srl - strncpy called w/o setting nulls at the end
@@ -110,6 +111,9 @@ static int ERROR_COUNT = 0; /* Count of errors from all tests. */
 static int ONE_ERROR = 0; /* were there any other errors? */
 static int DATA_ERROR_COUNT = 0; /* count of data related errors or warnings */
 static int INDENT_LEVEL = 0;
+static UBool NO_KNOWN = FALSE;
+static void *knownList = NULL;
+static char gTestName[1024] = "";
 static UBool ON_LINE = FALSE; /* are we on the top line with our test name? */
 static UBool HANGING_OUTPUT = FALSE; /* did the user leave us without a trailing \n ? */
 static int GLOBAL_PRINT_COUNT = 0; /* global count of printouts */
@@ -380,6 +384,7 @@ static void iterateTestsWithLevel ( const TestNode* root,
 #if SHOW_TIMES
         startTime = uprv_getRawUTCtime();
 #endif
+        strcpy(gTestName, pathToFunction);
         root->test();   /* PERFORM THE TEST ************************/
 #if SHOW_TIMES
         stopTime = uprv_getRawUTCtime();
@@ -513,6 +518,13 @@ runTests ( const TestNode *root )
 
     ON_LINE=FALSE; /* just in case */
 
+    if(knownList != NULL) {
+      if( udbg_knownIssue_print(knownList, NULL) ) {
+        fprintf(stdout, "(To run suppressed tests, use the -K option.) \n\n");
+      }
+      udbg_knownIssue_close(knownList);
+    }
+
     if (ERROR_COUNT)
     {
         fprintf(stdout,"\nSUMMARY:\n");
@@ -688,9 +700,22 @@ static UBool vlog_knownIssue(const char *ticket, const char *pattern, va_list ap
     /*     fputs(prefix, stdout); */
     /* } */
     char buf[2048], url[1024];
+    UBool firstForTicket;
+    UBool firstForWhere;
+
+    if(NO_KNOWN) return FALSE;
+    if(pattern==NULL) pattern="";
+
     vsprintf(buf, pattern, ap);
+    knownList = udbg_knownIssue_open(knownList, ticket, gTestName, buf, &firstForTicket, &firstForWhere);
 
-    printf("KNOWN ISSUE: #%s %s\n", ticket, buf);
+    if(firstForTicket || firstForWhere) {
+      log_info("(Known issue #%s) %s", ticket, buf);
+    } else {
+      log_verbose("(Known issue #%s) %s", ticket, buf);
+    }
+
+    /*printf("KNOWN ISSUE: #%s %s\n", ticket, buf); */
 
     /* fflush(stdout); */
     /* va_end(ap); */
@@ -967,6 +992,10 @@ initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *co
         {
             QUICK = 0;
         }
+        else if (strcmp( argv[i], "-K") ==0)
+        {
+            NO_KNOWN = 1;
+        }
         else if (strncmp( argv[i], "-E",2) ==0)
         {
            SUMMARY_FILE=argv[i]+2;
@@ -1164,6 +1193,7 @@ static void help ( const char *argv0 )
     printf("    -v  To turn ON verbosity(same as -verbose)\n");
     printf("    -x file.xml   Write junit format output to file.xml\n");
     printf("    -h  To print this message\n");
+    printf("    -K  to turn OFF suppressing known issues\n");
     printf("    -n  To turn OFF printing error messages\n");
     printf("    -w  Don't fail on data-loading errs, just warn. Useful if\n"
            "        user has reduced/changed the common set of ICU data \n");
index 945828ec5de47198e5894976ef42d349acc10e43..8b6e55d94720e0364997530af9b75c01eb29828e 100644 (file)
@@ -599,3 +599,178 @@ U_CAPI char *udbg_knownIssueURLFrom(const char *ticket, char *buf) {
   }
   return buf;
 }
+
+
+#if !U_HAVE_STD_STRING
+const char *warning = "WARNING: Don't have std::string (STL) - known issue logs will be deficient.";
+
+U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket,
+                                   UBool *firstForWhere) {
+  if(ptr==NULL) {
+    puts(warning);
+  }
+  printf("%s\tKnown Issue #%s\n", where, ticket);
+
+  return (void*)warning;
+}
+
+U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket,
+                                   UBool *firstForWhere) {
+  if(ptr==NULL) {
+    puts(warning);
+  }
+  if(msg==NULL) msg = "";
+  printf("%s\tKnown Issue #%s  \"%s\n", where, ticket, msg);
+
+  return (void*)warning;
+}
+
+U_CAPI UBool udbg_knownIssue_print(void *ptr, FILE *output) {
+  puts(warning);
+  return FALSE;
+}
+
+U_CAPI void udbg_knownIssue_close(void *ptr) {
+  // nothing to do
+}
+#else
+
+#include <set>
+#include <map>
+#include <string>
+#include <ostream>
+#include <iostream>
+
+class KnownIssues {
+public:
+  KnownIssues();
+  ~KnownIssues();
+  void add(const char *ticket, const char *where, const UChar *msg, UBool *firstForTicket, UBool *firstForWhere);
+  void add(const char *ticket, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere);
+  UBool print(FILE *output) ;
+private:
+  std::map< std::string, 
+            std::map < std::string, std::set < std::string > > > fTable;
+};
+
+KnownIssues::KnownIssues()
+  : fTable()
+{
+}
+
+KnownIssues::~KnownIssues()
+{
+}
+
+void KnownIssues::add(const char *ticket, const char *where, const UChar *msg, UBool *firstForTicket, UBool *firstForWhere)
+{
+  if(fTable.find(ticket) == fTable.end()) {
+    if(firstForTicket!=NULL) *firstForTicket = TRUE;
+    fTable[ticket] = std::map < std::string, std::set < std::string > >();
+  } else {
+    if(firstForTicket!=NULL) *firstForTicket = FALSE;
+  }
+  if(where==NULL) return;
+
+  if(fTable[ticket].find(where) == fTable[ticket].end()) {
+    if(firstForWhere!=NULL) *firstForWhere = TRUE;
+    fTable[ticket][where] = std::set < std::string >();
+  } else {
+    if(firstForWhere!=NULL) *firstForWhere = FALSE;
+  }
+  if(msg==NULL || !*msg) return;
+
+  std::string str;
+  fTable[ticket][where].insert(UnicodeString(msg).toUTF8String(str));
+}
+
+void KnownIssues::add(const char *ticket, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere)
+{
+  if(fTable.find(ticket) == fTable.end()) {
+    if(firstForTicket!=NULL) *firstForTicket = TRUE;
+    fTable[ticket] = std::map < std::string, std::set < std::string > >();
+  } else {
+    if(firstForTicket!=NULL) *firstForTicket = FALSE;
+  }
+  if(where==NULL) return;
+
+  if(fTable[ticket].find(where) == fTable[ticket].end()) {
+    if(firstForWhere!=NULL) *firstForWhere = TRUE;
+    fTable[ticket][where] = std::set < std::string >();
+  } else {
+    if(firstForWhere!=NULL) *firstForWhere = FALSE;
+  }
+  if(msg==NULL || !*msg) return;
+
+  std::string str(msg);
+  fTable[ticket][where].insert(str);
+}
+
+UBool KnownIssues::print(FILE *output) 
+{
+  if(fTable.empty()) {
+    return FALSE;
+  }
+
+  std::cout << "KNOWN ISSUES" << std::endl;
+  for( std::map<  std::string,
+          std::map <  std::string,  std::set <  std::string > > >::iterator i = fTable.begin();
+       i != fTable.end();
+       i++ ) {
+    char URL[1024];
+    std::cout << '#' << (*i).first << " <" << udbg_knownIssueURLFrom( (*i).first.c_str(), URL ) << ">" << std::endl;
+
+    for( std::map< std::string, std::set < std::string > >::iterator ii = (*i).second.begin();
+         ii != (*i).second.end();
+         ii++ ) {
+      std::cout << "  " << (*ii).first << std::endl;
+      for ( std::set < std::string >::iterator iii = (*ii).second.begin();
+            iii != (*ii).second.end();
+            iii++ ) {
+        std::cout << "     " << '"' << (*iii) << '"' << std::endl;
+      }
+    }
+  }
+  return TRUE;
+}
+
+U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket,
+                                   UBool *firstForWhere) {
+  KnownIssues *t = static_cast<KnownIssues*>(ptr);
+  if(t==NULL) {
+    t = new KnownIssues();
+  }
+
+  t->add(ticket, where, msg, firstForTicket, firstForWhere);
+
+  return static_cast<void*>(t);
+}
+
+U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket,
+                                   UBool *firstForWhere) {
+  KnownIssues *t = static_cast<KnownIssues*>(ptr);
+  if(t==NULL) {
+    t = new KnownIssues();
+  }
+
+  t->add(ticket, where, msg, firstForTicket, firstForWhere);
+
+  return static_cast<void*>(t);
+}
+
+U_CAPI UBool udbg_knownIssue_print(void *ptr, FILE *output) {
+  KnownIssues *t = static_cast<KnownIssues*>(ptr);
+  if(t==NULL) {
+    return FALSE;
+  } else {
+    t->print(output);
+    return TRUE;
+  }
+}
+
+U_CAPI void udbg_knownIssue_close(void *ptr) {
+  KnownIssues *t = static_cast<KnownIssues*>(ptr);
+  delete t;
+}
+
+#endif
index dec4d5b2f9fd84226865719c065167e6afc13d94..b47d4e636ad02339378ee8191cefd058314a792d 100644 (file)
@@ -117,4 +117,36 @@ U_CAPI void udbg_writeIcuInfo(FILE *f);
  */
 U_CAPI char *udbg_knownIssueURLFrom(const char *ticket, char *buf);
 
+/**
+ * Open (or reopen) a 'known issue' table.
+ * @param ptr pointer to 'table'. Opaque.
+ * @return new or existing ptr
+ */
+U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket,
+                                   UBool *firstForWhere);
+
+
+/**
+ * Open (or reopen) a 'known issue' table.
+ * @param ptr pointer to 'table'. Opaque.
+ * @return new or existing ptr
+ */
+U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket,
+                                   UBool *firstForWhere);
+
+/**
+ * Print 'known issue' table.
+ * @param ptr pointer from udbg_knownIssue
+ * @param output file to print to
+ * @return TRUE if there were any issues.
+ */
+U_CAPI UBool udbg_knownIssue_print(void *ptr, FILE *output);
+
+/**
+ * Close 'known issue' table.
+ * @param ptr
+ */
+U_CAPI void udbg_knownIssue_close(void *ptr);
+
+
 #endif