hotspot/test/native/GTestWrapper.java
author vtewari
Tue, 13 Sep 2016 17:00:06 +0530
changeset 40937 f72e61ec734b
parent 40631 ed82623d7831
child 41705 332239c052cc
permissions -rw-r--r--
8075484: SocketInputStream.socketRead0 can hang even with soTimeout set Reviewed-by: chegar, dsamersoff, msheppar, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38307
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     1
/*
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     4
 *
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     8
 *
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    14
 *
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    18
 *
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    21
 * questions.
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    22
 *
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    23
 */
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    24
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    25
/* @test
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    26
 * @summary a jtreg wrapper for gtest tests
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38731
diff changeset
    27
 * @library /test/lib
38307
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    29
 * @run main/native GTestWrapper
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    30
 */
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    31
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    32
import java.util.Arrays;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    33
import java.util.List;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    34
import java.util.stream.Stream;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    35
import java.util.stream.Collectors;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    36
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    37
import java.nio.file.Paths;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    38
import java.nio.file.Path;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    39
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    40
import jdk.test.lib.Platform;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    41
import jdk.test.lib.Utils;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    42
import jdk.test.lib.process.ProcessTools;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    43
import jdk.test.lib.process.OutputAnalyzer;
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    44
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    45
public class GTestWrapper {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    46
    public static void main(String[] args) throws Throwable {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    47
        // gtestLauncher is located in <test_image>/hotspot/gtest/<vm_variant>/
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    48
        // nativePath points either to <test_image>/hotspot/jtreg/native or to <test_image>/hotspot/gtest
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    49
        Path nativePath = Paths.get(System.getProperty("test.nativepath"));
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    50
        String jvmVariantDir = getJVMVariantSubDir();
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    51
        // let's assume it's <test_image>/hotspot/gtest
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    52
        Path path = nativePath.resolve(jvmVariantDir);
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    53
        if (!path.toFile().exists()) {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    54
            // maybe it is <test_image>/hotspot/jtreg/native
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    55
            path = nativePath.getParent()
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    56
                             .getParent()
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    57
                             .resolve("gtest")
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    58
                             .resolve(jvmVariantDir);
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    59
        }
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    60
        if (!path.toFile().exists()) {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    61
            throw new Error("TESTBUG: the library has not been found in " + nativePath);
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    62
        }
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    63
        path = path.resolve("gtestLauncher" + (Platform.isWindows() ? ".exe" : ""));
38731
2c741a995b07 8158106: native/GTestWrapper.java gets SIGABR
ctornqvi
parents: 38307
diff changeset
    64
        ProcessTools.executeCommand(new String[] {
2c741a995b07 8158106: native/GTestWrapper.java gets SIGABR
ctornqvi
parents: 38307
diff changeset
    65
                path.toString(),
2c741a995b07 8158106: native/GTestWrapper.java gets SIGABR
ctornqvi
parents: 38307
diff changeset
    66
                "-jdk",
2c741a995b07 8158106: native/GTestWrapper.java gets SIGABR
ctornqvi
parents: 38307
diff changeset
    67
                System.getProperty("test.jdk")
2c741a995b07 8158106: native/GTestWrapper.java gets SIGABR
ctornqvi
parents: 38307
diff changeset
    68
        }).shouldHaveExitValue(0);
38307
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    69
    }
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    70
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    71
    private static String getJVMVariantSubDir() {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    72
        if (Platform.isServer()) {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    73
            return "server";
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    74
        } else if (Platform.isClient()) {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    75
            return "client";
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    76
        } else if (Platform.isMinimal()) {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    77
            return "minimal";
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    78
        } else {
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    79
            throw new Error("TESTBUG: unsuppported vm variant");
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    80
        }
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    81
    }
c9555da2ae99 8156681: Add jtreg wrapper for hotspot gtest tests
iignatyev
parents:
diff changeset
    82
}