test/jdk/java/lang/instrument/PremainClass/ZeroArgPremainAgentTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 38966 jdk/test/java/lang/instrument/PremainClass/ZeroArgPremainAgentTest.java@308f5cc7d5f6
child 51675 b487c1e914d0
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21800
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     1
/*
38966
308f5cc7d5f6 8158855: Fix remaining module dependences in java/lang
shurailine
parents: 30799
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
21800
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     4
 *
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     8
 *
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    13
 * accompanied this code).
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    14
 *
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    18
 *
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    21
 * questions.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    22
 */
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    23
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    24
import jdk.testlibrary.OutputAnalyzer;
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    25
import jdk.testlibrary.ProcessTools;
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    26
import jdk.testlibrary.Utils;
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    27
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    28
/*
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    29
 * @test
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    30
 * @bug 6289149
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    31
 * @summary test when the agent's class has a zero arg premain() function.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    32
 * @library /lib/testlibrary
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 27189
diff changeset
    33
 * @modules java.management
38966
308f5cc7d5f6 8158855: Fix remaining module dependences in java/lang
shurailine
parents: 30799
diff changeset
    34
 *          java.instrument
24366
57c0a8b7a936 8034960: Serviceability tests using @library failing with java.lang.NoClassDefFoundError
ykantser
parents: 21800
diff changeset
    35
 * @run build jdk.testlibrary.* DummyMain
21800
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    36
 * @run shell ../MakeJAR3.sh ZeroArgPremainAgent
30799
d2a195296378 8046869: Several java/lang/instrument/PremainClass/* tests fail due to timeout
jbachorik
parents: 30376
diff changeset
    37
 * @run main/othervm -XX:-CreateCoredumpOnCrash ZeroArgPremainAgentTest
21800
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    38
 */
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    39
public class ZeroArgPremainAgentTest {
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    40
    // Use a javaagent with a zero argument premain() function.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    41
    // Verify that we get the correct exception.
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    42
    public static void main(String[] a) throws Exception {
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    43
        String testArgs = String.format(
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    44
                "-javaagent:ZeroArgPremainAgent.jar -classpath %s DummyMain",
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    45
                System.getProperty("test.classes", "."));
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    46
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    47
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    48
                Utils.addTestJavaOpts(testArgs.split("\\s+")));
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    49
        System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    50
27189
b90845965ee9 8056143: interrupted java/lang/management/MemoryMXBean/LowMemoryTest.java leaves running process
jbachorik
parents: 24366
diff changeset
    51
        OutputAnalyzer output = ProcessTools.executeProcess(pb);
21800
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    52
        System.out.println("testjvm.stdout:" + output.getStdout());
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    53
        System.out.println("testjvm.stderr:" + output.getStderr());
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    54
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    55
        output.stderrShouldContain("java.lang.NoSuchMethodException");
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    56
        if (0 == output.getExitValue()) {
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    57
            throw new RuntimeException("Expected error but got exit value 0");
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    58
        }
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    59
    }
9be418e27be5 8023138: [TEST_BUG] java/lang/instrument/PremainClass/NoPremainAgent.sh fails intermittently
sla
parents:
diff changeset
    60
}