test/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java

Thu, 05 Jul 2018 18:27:02 +0200

author
sgehwolf
date
Thu, 05 Jul 2018 18:27:02 +0200
changeset 9346
5ba59d58d976
parent 7889
0b7060827bca
child 10020
a9ac0a2b370f
permissions
-rw-r--r--

8206425: .gnu_debuglink sections added unconditionally when no debuginfo is stripped
Summary: Only add .gnu_debuglink sections when there is some stripping done.
Reviewed-by: erikj, dholmes

bmoloden@7796 1 /*
aph@7889 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
bmoloden@7796 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bmoloden@7796 4 *
bmoloden@7796 5 * This code is free software; you can redistribute it and/or modify it
bmoloden@7796 6 * under the terms of the GNU General Public License version 2 only, as
bmoloden@7796 7 * published by the Free Software Foundation.
bmoloden@7796 8 *
bmoloden@7796 9 * This code is distributed in the hope that it will be useful, but WITHOUT
bmoloden@7796 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bmoloden@7796 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bmoloden@7796 12 * version 2 for more details (a copy is included in the LICENSE file that
bmoloden@7796 13 * accompanied this code).
bmoloden@7796 14 *
bmoloden@7796 15 * You should have received a copy of the GNU General Public License version
bmoloden@7796 16 * 2 along with this work; if not, write to the Free Software Foundation,
bmoloden@7796 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bmoloden@7796 18 *
bmoloden@7796 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bmoloden@7796 20 * or visit www.oracle.com if you need additional information or have any
bmoloden@7796 21 * questions.
bmoloden@7796 22 */
bmoloden@7796 23
bmoloden@7796 24 import com.oracle.java.testlibrary.Asserts;
bmoloden@7796 25 import com.oracle.java.testlibrary.Platform;
bmoloden@7796 26
bmoloden@7796 27 import java.lang.reflect.InvocationTargetException;
bmoloden@7796 28 import java.lang.reflect.Method;
bmoloden@7796 29 import java.util.Arrays;
bmoloden@7796 30 import java.util.Collections;
bmoloden@7796 31 import java.util.EnumSet;
bmoloden@7796 32 import java.util.HashSet;
bmoloden@7796 33 import java.util.List;
bmoloden@7796 34 import java.util.Set;
bmoloden@7796 35
bmoloden@7796 36 /**
bmoloden@7796 37 * @test
bmoloden@7796 38 * @summary Verify that for each group of mutually exclusive predicates defined
bmoloden@7796 39 * in com.oracle.java.testlibrary.Platform one and only one predicate
bmoloden@7796 40 * evaluates to true.
bmoloden@7796 41 * @library /testlibrary
bmoloden@7796 42 * @run main TestMutuallyExclusivePlatformPredicates
bmoloden@7796 43 */
bmoloden@7796 44 public class TestMutuallyExclusivePlatformPredicates {
bmoloden@7796 45 private static enum MethodGroup {
aph@7889 46 ARCH("isARM", "isPPC", "isSparc", "isX86", "isX64", "isAArch64"),
bmoloden@7796 47 BITNESS("is32bit", "is64bit"),
bmoloden@7796 48 OS("isAix", "isLinux", "isSolaris", "isWindows", "isOSX"),
bmoloden@7796 49 VM_TYPE("isClient", "isServer", "isGraal", "isMinimal"),
bmoloden@7796 50 IGNORED("isEmbedded", "isDebugBuild", "shouldSAAttach",
bmoloden@7796 51 "canPtraceAttachLinux", "canAttachOSX");
bmoloden@7796 52
bmoloden@7796 53 public final List<String> methodNames;
bmoloden@7796 54
bmoloden@7796 55 private MethodGroup(String... methodNames) {
bmoloden@7796 56 this.methodNames = Collections.unmodifiableList(
bmoloden@7796 57 Arrays.asList(methodNames));
bmoloden@7796 58 }
bmoloden@7796 59 }
bmoloden@7796 60
bmoloden@7796 61 public static void main(String args[]) {
bmoloden@7796 62 EnumSet<MethodGroup> notIgnoredMethodGroups
bmoloden@7796 63 = EnumSet.complementOf(EnumSet.of(MethodGroup.IGNORED));
bmoloden@7796 64
bmoloden@7796 65 notIgnoredMethodGroups.forEach(
bmoloden@7796 66 TestMutuallyExclusivePlatformPredicates::verifyPredicates);
bmoloden@7796 67
bmoloden@7796 68 TestMutuallyExclusivePlatformPredicates.verifyCoverage();
bmoloden@7796 69 }
bmoloden@7796 70
bmoloden@7796 71 /**
bmoloden@7796 72 * Verifies that one and only one predicate method defined in
bmoloden@7796 73 * {@link com.oracle.java.testlibrary.Platform}, whose name included into
bmoloden@7796 74 * methodGroup will return {@code true}.
bmoloden@7796 75 * @param methodGroup The group of methods that should be tested.
bmoloden@7796 76 */
bmoloden@7796 77 private static void verifyPredicates(MethodGroup methodGroup) {
bmoloden@7796 78 System.out.println("Verifying method group: " + methodGroup.name());
bmoloden@7796 79 long truePredicatesCount = methodGroup.methodNames.stream()
bmoloden@7796 80 .filter(TestMutuallyExclusivePlatformPredicates
bmoloden@7796 81 ::evaluatePredicate)
bmoloden@7796 82 .count();
bmoloden@7796 83
bmoloden@7796 84 Asserts.assertEQ(truePredicatesCount, 1L, String.format(
bmoloden@7796 85 "Only one predicate from group %s should be evaluated to true "
bmoloden@7796 86 + "(Actually %d predicates were evaluated to true).",
bmoloden@7796 87 methodGroup.name(), truePredicatesCount));
bmoloden@7796 88 }
bmoloden@7796 89
bmoloden@7796 90 /**
bmoloden@7796 91 * Verifies that all predicates defined in
bmoloden@7796 92 * {@link com.oracle.java.testlibrary.Platform} were either tested or
bmoloden@7796 93 * explicitly ignored.
bmoloden@7796 94 */
bmoloden@7796 95 private static void verifyCoverage() {
bmoloden@7796 96 Set<String> allMethods = new HashSet<>();
bmoloden@7796 97 for (MethodGroup group : MethodGroup.values()) {
bmoloden@7796 98 allMethods.addAll(group.methodNames);
bmoloden@7796 99 }
bmoloden@7796 100
bmoloden@7796 101 for (Method m : Platform.class.getMethods()) {
bmoloden@7796 102 if (m.getParameterCount() == 0
bmoloden@7796 103 && m.getReturnType() == boolean.class) {
bmoloden@7796 104 Asserts.assertTrue(allMethods.contains(m.getName()),
bmoloden@7796 105 "All Platform's methods with signature '():Z' should "
bmoloden@7796 106 + "be tested ");
bmoloden@7796 107 }
bmoloden@7796 108 }
bmoloden@7796 109 }
bmoloden@7796 110
bmoloden@7796 111 /**
bmoloden@7796 112 * Evaluates predicate method with name {@code name} defined in
bmoloden@7796 113 * {@link com.oracle.java.testlibrary.Platform}.
bmoloden@7796 114 *
bmoloden@7796 115 * @param name The name of a predicate to be evaluated.
bmoloden@7796 116 * @return evaluated predicate's value.
bmoloden@7796 117 * @throws java.lang.Error if predicate is not defined or could not be
bmoloden@7796 118 * evaluated.
bmoloden@7796 119 */
bmoloden@7796 120 private static boolean evaluatePredicate(String name) {
bmoloden@7796 121 try {
bmoloden@7796 122 System.out.printf("Trying to evaluate predicate with name %s%n",
bmoloden@7796 123 name);
bmoloden@7796 124 boolean value
bmoloden@7796 125 = (Boolean) Platform.class.getMethod(name).invoke(null);
bmoloden@7796 126 System.out.printf("Predicate evaluated to: %s%n", value);
bmoloden@7796 127 return value;
bmoloden@7796 128 } catch (NoSuchMethodException e) {
bmoloden@7796 129 throw new Error("Predicate with name " + name
bmoloden@7796 130 + " is not defined in " + Platform.class.getName(), e);
bmoloden@7796 131 } catch (IllegalAccessException | InvocationTargetException e) {
bmoloden@7796 132 throw new Error("Unable to evaluate predicate " + name, e);
bmoloden@7796 133 }
bmoloden@7796 134 }
bmoloden@7796 135 }

mercurial