< prev index next >

## src/com/sun/javatest/audit/Audit.java

Print this page

      89         tfq.setTestFinder(tf);
      90
      91         String[] tests = params.getTests();
      92         tfq.setTests(tests);
      93
      94         TestFilter[] filters = params.getFilters();
      95         tfq.setFilters(filters);
      96
      97         return tfq;
      98     }
      99
     100
     101     /**
     102      * Analyze a set of test results for validity, based on the given parameters.
     103      * @param tfq An enumerator for the set of tests to be run
     104      * @param excludeList The excludeList against which to check excluded test cases
     105      * @param workDir The set of results
     106      */
     107     public Audit(TestFinderQueue tfq, ExcludeList excludeList, WorkDirectory workDir)
     108     {
     109         Vector badChecksumTestsV = new Vector();
     110         Vector badTestDescriptionsV = new Vector();
     111         Vector badTestCaseTestsV = new Vector();
     112         Vector badTestsV = new Vector();
     113
     114         workDir.getTestResultTable().waitUntilReady();
     115
     116         TestDescription td;
     117         while ((td = tfq.next()) != null) {
     118             try {
     119                 TestResult tr = new TestResult(workDir, TestResult.getWorkRelativePath(td));
     120
     121                 testCount++;
     122                 statusCounts[tr.getStatus().getType()]++;
     123                 checksumCounts[tr.getChecksumState()]++;
     124
     125                 if (tr.getChecksumState() == TestResult.BAD_CHECKSUM)
     126                     badChecksumTestsV.addElement(tr);
     127
     128                 if (!equal(td, tr.getDescription()))
     129                     badTestDescriptionsV.addElement(tr);
     130
     131                 if (!checkTestCases(tr, excludeList))
     132                     badTestCaseTestsV.addElement(tr);
     133
     134                 Map trEnv = tr.getEnvironment();
     135                 for (Iterator i = trEnv.entrySet().iterator(); i.hasNext(); ) {
     136                     Map.Entry e = (Map.Entry) (i.next());
     137                     String key = (String) (e.getKey());
     138                     String value = (String) (e.getValue());
     139                     Vector allValuesForKey = (Vector)(envTable.get(key));
     140                     if (allValuesForKey == null) {
     141                         allValuesForKey = new Vector();
     142                         envTable.put(key, allValuesForKey);
     143                     }
     144                     if (!allValuesForKey.contains(value))
     145                         allValuesForKey.addElement(value);
     146                 }
     147
     148                 String start = tr.getProperty(TestResult.START);
     149                 if (start == null) {
     150                     badDates = true;
     151                 }
     152                 else {
     153                     Date d = parseDate(start);
     154                     if (d == null)
     155                         badDates = true;
     156                     else {
     157                         if (earliestStart == null || d.before(earliestStart))
     158                             earliestStart = d;
     159                         if (latestStart == null || d.after(latestStart))
     160                             latestStart = d;
     161                     }
     162                 }
     163             }
     164             catch (TestResult.Fault e) {
     165                 //System.err.println(td.getRootRelativeURL() + " " + TestResult.getWorkRelativePath(td) + " " + e);
     166                 badTestsV.addElement(td);
     167             }
     168         }
     169
     170         for (Enumeration e = envTable.keys(); e.hasMoreElements(); ) {
     171             String key = (String)(e.nextElement());
     172             Vector allValuesForKey = (Vector)(envTable.get(key));
     173             envCounts[allValuesForKey.size() == 1 ? 0 : 1]++;
     174         }
     175
     176         if (badChecksumTestsV.size() > 0) {
     177             badChecksumTests = new TestResult[badChecksumTestsV.size()];
     178             badChecksumTestsV.copyInto(badChecksumTests);
     179         }
     180
     181         if (badTestDescriptionsV.size() > 0) {
     182             badTestDescriptions = new TestResult[badTestDescriptionsV.size()];
     183             badTestDescriptionsV.copyInto(badTestDescriptions);
     184         }
     185
     186         if (badTestCaseTestsV.size() > 0) {
     187             badTestCaseTests = new TestResult[badTestCaseTestsV.size()];
     188             badTestCaseTestsV.copyInto(badTestCaseTests);
     189         }
     190
     191         if (badTestsV.size() > 0) {
     192             badTests = new TestDescription[badTestsV.size()];
     475             else {
     476                 out.println(i18n.getString("adt.env.count",
     477                                            new Object[] {
     478                                                new Integer(u),
     479                                                new Integer((u > 0 && m > 0) ? 1 : 0),
     480                                                new Integer(m)
     481                                                    } ));
     482             }
     483         }
     484     }
     485
     486     /**
     487      * Print out a listing of some or all of the env values used by the tests.
     488      * @param showAll show all environment values (uniquely and multiply defined.)
     489      * The default is to just show the multiple defined values.
     490      */
     491     private void showEnvValues(boolean showAll) {
     492         out.println();
     493         out.print(i18n.getString("adt.envList.title"));
     494
     495         SortedSet ss = new TreeSet();
     496         for (Enumeration e = envTable.keys(); e.hasMoreElements(); ) {
     497             String key = (String)(e.nextElement());
     498             ss.add(key);
     499         }
     500
     501         for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
     502             String key = (String) (iter.next());
     503             Vector allValuesForKey = (Vector)(envTable.get(key));
     504             if (allValuesForKey.size() == 1) {
     505                 if (showAll)
     506                     out.println(i18n.getString("adt.envKeyValue",
     507                                             new Object[] {key, allValuesForKey.elementAt(0)}));
     508             }
     509             else {
     510                 out.println(i18n.getString("adt.envKey", key));
     511                 for (int j = 0; j < allValuesForKey.size(); j++) {
     512                     out.println(i18n.getString("adt.envValue",
     513                                             allValuesForKey.elementAt(j)));
     514                 }
     515             }
     516         }
     517     }
     518
     519     /**
     520      * Print out a short summary report of the checksum statistics.
     521      */
     522     private void showChecksumCounts() {
     523         if (testCount > 0) {
     675                 if (i > 0) {
     676                     DateFormat tmp = dateFormats[i];
     677                     System.arraycopy(dateFormats, 0, dateFormats, 1, i);
     678                     dateFormats[0] = tmp;
     679                 }
     680                 return d;
     681             }
     682             catch (ParseException e) {
     683                 //System.err.println("pattern: " + ((SimpleDateFormat)dateFormats[i]).toPattern());
     684                 //System.err.println("  value: " + s);
     685                 //System.err.println("example: " + dateFormats[i].format(new Date()));
     686             }
     687         }
     688         return null;
     689     }
     690
     691     private void initDateFormats() {
     692         // Create an array of possible date formats to parse dates in .jtr files.
     693         // Most likely is Unix C time in English; the array will be reordered in use
     694         // by moving the recently used entries to the front of the array.
     695         Vector v = new Vector();
     696
     697         // generic Java default
     698         // 10-Sep-99 3:25:11 PM
     699         v.addElement(DateFormat.getDateTimeInstance());
     700         v.addElement(DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
     701                                                     DateFormat.DEFAULT,
     702                                                     Locale.ENGLISH));
     703
     704         // standard IETF date syntax
     705         // Fri, 10 September 1999 03:25:12 PDT
     706         v.addElement(new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss zzz"));
     707         v.addElement(new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss zzz", Locale.ENGLISH));
     708
     709         // Unix C time
     710         // Fri Sep 10 14:41:37 PDT 1999
     711         v.addElement(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"));
     712         v.addElement(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH));
     713
     714         // allow user-specified format
     715         String s = System.getProperty("javatest.date.format");
     716         if (s != null)
     717             v.addElement(new SimpleDateFormat(s));
     718
     719         dateFormats = new DateFormat[v.size()];
     720         v.copyInto(dateFormats);
     721     }
     722
     723     private int testCount;
     724     private int[] checksumCounts = new int[TestResult.NUM_CHECKSUM_STATES];
     725     private int[] envCounts = new int[2];
     726     private int[] statusCounts = new int[5];
     727     private boolean badDates = false;
     728     private TestDescription[] badTests;
     729     private TestResult[] badTestCaseTests;
     730     private TestResult[] badTestDescriptions;
     731     private TestResult[] badChecksumTests;
     732     private Date earliestStart;
     733     private Date latestStart;
     734     private DateFormat[] dateFormats;
     735
     736     private Hashtable envTable = new Hashtable();
     737     private PrintStream out;
     738     private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(Audit.class);
     739 }
      89         tfq.setTestFinder(tf);
      90
      91         String[] tests = params.getTests();
      92         tfq.setTests(tests);
      93
      94         TestFilter[] filters = params.getFilters();
      95         tfq.setFilters(filters);
      96
      97         return tfq;
      98     }
      99
     100
     101     /**
     102      * Analyze a set of test results for validity, based on the given parameters.
     103      * @param tfq An enumerator for the set of tests to be run
     104      * @param excludeList The excludeList against which to check excluded test cases
     105      * @param workDir The set of results
     106      */
     107     public Audit(TestFinderQueue tfq, ExcludeList excludeList, WorkDirectory workDir)
     108     {
     109         Vector<TestResult> badChecksumTestsV = new Vector<>();
     110         Vector<TestResult> badTestDescriptionsV = new Vector<>();
     111         Vector<TestResult> badTestCaseTestsV = new Vector<>();
     112         Vector<TestDescription> badTestsV = new Vector<>();
     113
     114         workDir.getTestResultTable().waitUntilReady();
     115
     116         TestDescription td;
     117         while ((td = tfq.next()) != null) {
     118             try {
     119                 TestResult tr = new TestResult(workDir, TestResult.getWorkRelativePath(td));
     120
     121                 testCount++;
     122                 statusCounts[tr.getStatus().getType()]++;
     123                 checksumCounts[tr.getChecksumState()]++;
     124
     125                 if (tr.getChecksumState() == TestResult.BAD_CHECKSUM)
     126                     badChecksumTestsV.addElement(tr);
     127
     128                 if (!equal(td, tr.getDescription()))
     129                     badTestDescriptionsV.addElement(tr);
     130
     131                 if (!checkTestCases(tr, excludeList))
     132                     badTestCaseTestsV.addElement(tr);
     133
     134                 Map trEnv = tr.getEnvironment();
     135                 for (Iterator i = trEnv.entrySet().iterator(); i.hasNext(); ) {
     136                     Map.Entry e = (Map.Entry) (i.next());
     137                     String key = (String) (e.getKey());
     138                     String value = (String) (e.getValue());
     139                     Vector<String> allValuesForKey = envTable.get(key);
     140                     if (allValuesForKey == null) {
     141                         allValuesForKey = new Vector<>();
     142                         envTable.put(key, allValuesForKey);
     143                     }
     144                     if (!allValuesForKey.contains(value))
     145                         allValuesForKey.addElement(value);
     146                 }
     147
     148                 String start = tr.getProperty(TestResult.START);
     149                 if (start == null) {
     150                     badDates = true;
     151                 }
     152                 else {
     153                     Date d = parseDate(start);
     154                     if (d == null)
     155                         badDates = true;
     156                     else {
     157                         if (earliestStart == null || d.before(earliestStart))
     158                             earliestStart = d;
     159                         if (latestStart == null || d.after(latestStart))
     160                             latestStart = d;
     161                     }
     162                 }
     163             }
     164             catch (TestResult.Fault e) {
     165                 //System.err.println(td.getRootRelativeURL() + " " + TestResult.getWorkRelativePath(td) + " " + e);
     166                 badTestsV.addElement(td);
     167             }
     168         }
     169
     170         for (Enumeration e = envTable.keys(); e.hasMoreElements(); ) {
     171             String key = (String)(e.nextElement());
     172             Vector allValuesForKey = envTable.get(key);
     173             envCounts[allValuesForKey.size() == 1 ? 0 : 1]++;
     174         }
     175
     176         if (badChecksumTestsV.size() > 0) {
     177             badChecksumTests = new TestResult[badChecksumTestsV.size()];
     178             badChecksumTestsV.copyInto(badChecksumTests);
     179         }
     180
     181         if (badTestDescriptionsV.size() > 0) {
     182             badTestDescriptions = new TestResult[badTestDescriptionsV.size()];
     183             badTestDescriptionsV.copyInto(badTestDescriptions);
     184         }
     185
     186         if (badTestCaseTestsV.size() > 0) {
     187             badTestCaseTests = new TestResult[badTestCaseTestsV.size()];
     188             badTestCaseTestsV.copyInto(badTestCaseTests);
     189         }
     190
     191         if (badTestsV.size() > 0) {
     192             badTests = new TestDescription[badTestsV.size()];
     475             else {
     476                 out.println(i18n.getString("adt.env.count",
     477                                            new Object[] {
     478                                                new Integer(u),
     479                                                new Integer((u > 0 && m > 0) ? 1 : 0),
     480                                                new Integer(m)
     481                                                    } ));
     482             }
     483         }
     484     }
     485
     486     /**
     487      * Print out a listing of some or all of the env values used by the tests.
     488      * @param showAll show all environment values (uniquely and multiply defined.)
     489      * The default is to just show the multiple defined values.
     490      */
     491     private void showEnvValues(boolean showAll) {
     492         out.println();
     493         out.print(i18n.getString("adt.envList.title"));
     494
     495         SortedSet<String> ss = new TreeSet<>();
     496         for (Enumeration e = envTable.keys(); e.hasMoreElements(); ) {
     497             String key = (String)(e.nextElement());
     498             ss.add(key);
     499         }
     500
     501         for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
     502             String key = (String) (iter.next());
     503             Vector allValuesForKey = envTable.get(key);
     504             if (allValuesForKey.size() == 1) {
     505                 if (showAll)
     506                     out.println(i18n.getString("adt.envKeyValue",
     507                                             new Object[] {key, allValuesForKey.elementAt(0)}));
     508             }
     509             else {
     510                 out.println(i18n.getString("adt.envKey", key));
     511                 for (int j = 0; j < allValuesForKey.size(); j++) {
     512                     out.println(i18n.getString("adt.envValue",
     513                                             allValuesForKey.elementAt(j)));
     514                 }
     515             }
     516         }
     517     }
     518
     519     /**
     520      * Print out a short summary report of the checksum statistics.
     521      */
     522     private void showChecksumCounts() {
     523         if (testCount > 0) {
     675                 if (i > 0) {
     676                     DateFormat tmp = dateFormats[i];
     677                     System.arraycopy(dateFormats, 0, dateFormats, 1, i);
     678                     dateFormats[0] = tmp;
     679                 }
     680                 return d;
     681             }
     682             catch (ParseException e) {
     683                 //System.err.println("pattern: " + ((SimpleDateFormat)dateFormats[i]).toPattern());
     684                 //System.err.println("  value: " + s);
     685                 //System.err.println("example: " + dateFormats[i].format(new Date()));
     686             }
     687         }
     688         return null;
     689     }
     690
     691     private void initDateFormats() {
     692         // Create an array of possible date formats to parse dates in .jtr files.
     693         // Most likely is Unix C time in English; the array will be reordered in use
     694         // by moving the recently used entries to the front of the array.
     695         Vector<DateFormat> v = new Vector<>();
     696
     697         // generic Java default
     698         // 10-Sep-99 3:25:11 PM
     699         v.addElement(DateFormat.getDateTimeInstance());
     700         v.addElement(DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
     701                                                     DateFormat.DEFAULT,
     702                                                     Locale.ENGLISH));
     703
     704         // standard IETF date syntax
     705         // Fri, 10 September 1999 03:25:12 PDT
     706         v.addElement(new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss zzz"));
     707         v.addElement(new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss zzz", Locale.ENGLISH));
     708
     709         // Unix C time
     710         // Fri Sep 10 14:41:37 PDT 1999
     711         v.addElement(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"));
     712         v.addElement(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH));
     713
     714         // allow user-specified format
     715         String s = System.getProperty("javatest.date.format");
     716         if (s != null)
     717             v.addElement(new SimpleDateFormat(s));
     718
     719         dateFormats = new DateFormat[v.size()];
     720         v.copyInto(dateFormats);
     721     }
     722
     723     private int testCount;
     724     private int[] checksumCounts = new int[TestResult.NUM_CHECKSUM_STATES];
     725     private int[] envCounts = new int[2];
     726     private int[] statusCounts = new int[5];
     727     private boolean badDates = false;
     728     private TestDescription[] badTests;
     729     private TestResult[] badTestCaseTests;
     730     private TestResult[] badTestDescriptions;
     731     private TestResult[] badChecksumTests;
     732     private Date earliestStart;
     733     private Date latestStart;
     734     private DateFormat[] dateFormats;
     735
     736     private Hashtable<String, Vector<String>> envTable = new Hashtable<>();
     737     private PrintStream out;
     738     private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(Audit.class);
     739 }

< prev index next >