< prev index next >

test/jdk/jdk/jfr/event/metadata/TestLookForUntestedEvents.java

Print this page




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.jfr.event.metadata;
  26 
  27 import java.io.File;
  28 import java.io.IOException;
  29 import java.lang.reflect.Field;
  30 import java.nio.file.Files;
  31 import java.nio.file.Path;
  32 import java.nio.file.Paths;
  33 import java.util.Arrays;
  34 import java.util.HashSet;
  35 import java.util.List;
  36 import java.util.Set;
  37 import java.util.stream.Collectors;
  38 import java.util.stream.Stream;
  39 
  40 import jdk.jfr.EventType;
  41 import jdk.jfr.Experimental;
  42 import jdk.jfr.FlightRecorder;
  43 import jdk.test.lib.jfr.EventNames;
  44 import jdk.test.lib.Utils;

  45 
  46 /**
  47  * @test Check for JFR events not covered by tests
  48  * @key jfr
  49  * @requires vm.hasJFR
  50  * @library /test/lib /test/jdk
  51  * @run main jdk.jfr.event.metadata.TestLookForUntestedEvents
  52  */
  53 public class TestLookForUntestedEvents {
  54     private static final Path jfrTestRoot = Paths.get(Utils.TEST_SRC).getParent().getParent();
  55     private static final String MSG_SEPARATOR = "==========================";
  56     private static Set<String> jfrEventTypes = new HashSet<>();
  57 
  58     private static final Set<String> knownEventsMissingFromEventNames = new HashSet<>(
  59         Arrays.asList(
  60             // The Z* events below should be marked as experimental; see: JDK-8213966
  61             "ZStatisticsSampler", "ZStatisticsCounter",
  62             "ZPageAllocation", "ZThreadPhase"
  63         )
  64     );
  65 
  66     private static final Set<String> hardToTestEvents = new HashSet<>(
  67         Arrays.asList(
  68             "DataLoss", "IntFlag", "ReservedStackActivation",
  69             "DoubleFlag", "UnsignedLongFlagChanged", "IntFlagChanged",
  70             "UnsignedIntFlag", "UnsignedIntFlagChanged", "DoubleFlagChanged")
  71     );
  72 
  73     // GC uses specific framework to test the events, instead of using event names literally.
  74     // GC tests were inspected, as well as runtime output of GC tests.
  75     // The following events below are know to be covered based on that inspection.
  76     private static final Set<String> coveredGcEvents = new HashSet<>(
  77         Arrays.asList(
  78             "MetaspaceGCThreshold", "MetaspaceAllocationFailure", "MetaspaceOOM",
  79             "MetaspaceChunkFreeListSummary", "G1HeapSummary", "ParallelOldGarbageCollection",
  80             "OldGarbageCollection", "G1GarbageCollection", "GCPhasePause",
  81             "GCPhasePauseLevel1", "GCPhasePauseLevel2", "GCPhasePauseLevel3",
  82             "GCPhasePauseLevel4", "GCPhaseConcurrent")
  83     );
  84 
  85     // This is a "known failure list" for this test.


 129             for (String event: eventsNotCoveredByTest) {
 130                 print(event);
 131             }
 132             print(MSG_SEPARATOR);
 133             throw new RuntimeException("Found JFR events not covered by tests");
 134         }
 135     }
 136 
 137     // Make sure all the JFR events are accounted for in jdk.test.lib.jfr.EventNames
 138     private static void checkEventNamesClass() throws Exception {
 139         // jdk.test.lib.jfr.EventNames
 140         Set<String> eventsFromEventNamesClass = new HashSet<>();
 141         for (Field f : EventNames.class.getFields()) {
 142             String name = f.getName();
 143             if (!name.equals("PREFIX")) {
 144                 String eventName = (String) f.get(null);
 145                 eventName = eventName.replace(EventNames.PREFIX, "");
 146                 eventsFromEventNamesClass.add(eventName);
 147             }
 148         }
 149 
 150         // Account for the events that are known to be missing from the EventNames.java
 151         eventsFromEventNamesClass.addAll(knownEventsMissingFromEventNames);
 152 
 153         if (!jfrEventTypes.equals(eventsFromEventNamesClass)) {
 154             String exceptionMsg = "Events declared in jdk.test.lib.jfr.EventNames differ " +
 155                          "from events returned by FlightRecorder.getEventTypes()";
 156             print(MSG_SEPARATOR);
 157             print(exceptionMsg);
 158             print("");
 159             printSetDiff(jfrEventTypes, eventsFromEventNamesClass,
 160                         "jfrEventTypes", "eventsFromEventNamesClass");
 161             print("");
 162 
 163             print("This could be because:");
 164             print("1) You forgot to write a unit test. Please do so in test/jdk/jdk/jfr/event/");
 165             print("2) You wrote a unit test, but you didn't reference the event in");
 166             print("   test/lib/jdk/test/lib/jfr/EventNames.java. ");
 167             print("3) It is not feasible to test the event, not even a sanity test. ");
 168             print("   Add the event name to test/lib/jdk/test/lib/jfr/EventNames.java ");
 169             print("   and a short comment why it can't be tested");
 170             print("4) The event is experimental. Please add 'experimental=\"true\"' to <Event> ");
 171             print("   element in metadata.xml if it is a native event, or @Experimental if it is a ");




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.jfr.event.metadata;
  26 

  27 import java.io.IOException;
  28 import java.lang.reflect.Field;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.util.Arrays;
  33 import java.util.HashSet;
  34 import java.util.List;
  35 import java.util.Set;
  36 import java.util.stream.Collectors;
  37 import java.util.stream.Stream;
  38 
  39 import jdk.jfr.EventType;
  40 import jdk.jfr.Experimental;
  41 import jdk.jfr.FlightRecorder;

  42 import jdk.test.lib.Utils;
  43 import jdk.test.lib.jfr.EventNames;
  44 
  45 /**
  46  * @test Check for JFR events not covered by tests
  47  * @key jfr
  48  * @requires vm.hasJFR
  49  * @library /test/lib /test/jdk
  50  * @run main jdk.jfr.event.metadata.TestLookForUntestedEvents
  51  */
  52 public class TestLookForUntestedEvents {
  53     private static final Path jfrTestRoot = Paths.get(Utils.TEST_SRC).getParent().getParent();
  54     private static final String MSG_SEPARATOR = "==========================";
  55     private static Set<String> jfrEventTypes = new HashSet<>();
  56 








  57     private static final Set<String> hardToTestEvents = new HashSet<>(
  58         Arrays.asList(
  59             "DataLoss", "IntFlag", "ReservedStackActivation",
  60             "DoubleFlag", "UnsignedLongFlagChanged", "IntFlagChanged",
  61             "UnsignedIntFlag", "UnsignedIntFlagChanged", "DoubleFlagChanged")
  62     );
  63 
  64     // GC uses specific framework to test the events, instead of using event names literally.
  65     // GC tests were inspected, as well as runtime output of GC tests.
  66     // The following events below are know to be covered based on that inspection.
  67     private static final Set<String> coveredGcEvents = new HashSet<>(
  68         Arrays.asList(
  69             "MetaspaceGCThreshold", "MetaspaceAllocationFailure", "MetaspaceOOM",
  70             "MetaspaceChunkFreeListSummary", "G1HeapSummary", "ParallelOldGarbageCollection",
  71             "OldGarbageCollection", "G1GarbageCollection", "GCPhasePause",
  72             "GCPhasePauseLevel1", "GCPhasePauseLevel2", "GCPhasePauseLevel3",
  73             "GCPhasePauseLevel4", "GCPhaseConcurrent")
  74     );
  75 
  76     // This is a "known failure list" for this test.


 120             for (String event: eventsNotCoveredByTest) {
 121                 print(event);
 122             }
 123             print(MSG_SEPARATOR);
 124             throw new RuntimeException("Found JFR events not covered by tests");
 125         }
 126     }
 127 
 128     // Make sure all the JFR events are accounted for in jdk.test.lib.jfr.EventNames
 129     private static void checkEventNamesClass() throws Exception {
 130         // jdk.test.lib.jfr.EventNames
 131         Set<String> eventsFromEventNamesClass = new HashSet<>();
 132         for (Field f : EventNames.class.getFields()) {
 133             String name = f.getName();
 134             if (!name.equals("PREFIX")) {
 135                 String eventName = (String) f.get(null);
 136                 eventName = eventName.replace(EventNames.PREFIX, "");
 137                 eventsFromEventNamesClass.add(eventName);
 138             }
 139         }



 140 
 141         if (!jfrEventTypes.equals(eventsFromEventNamesClass)) {
 142             String exceptionMsg = "Events declared in jdk.test.lib.jfr.EventNames differ " +
 143                          "from events returned by FlightRecorder.getEventTypes()";
 144             print(MSG_SEPARATOR);
 145             print(exceptionMsg);
 146             print("");
 147             printSetDiff(jfrEventTypes, eventsFromEventNamesClass,
 148                         "jfrEventTypes", "eventsFromEventNamesClass");
 149             print("");
 150 
 151             print("This could be because:");
 152             print("1) You forgot to write a unit test. Please do so in test/jdk/jdk/jfr/event/");
 153             print("2) You wrote a unit test, but you didn't reference the event in");
 154             print("   test/lib/jdk/test/lib/jfr/EventNames.java. ");
 155             print("3) It is not feasible to test the event, not even a sanity test. ");
 156             print("   Add the event name to test/lib/jdk/test/lib/jfr/EventNames.java ");
 157             print("   and a short comment why it can't be tested");
 158             print("4) The event is experimental. Please add 'experimental=\"true\"' to <Event> ");
 159             print("   element in metadata.xml if it is a native event, or @Experimental if it is a ");


< prev index next >