Path: blob/master/test/hotspot/jtreg/applications/jcstress/JcstressRunner.java
40942 views
/*1* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package applications.jcstress;2425import jdk.test.lib.Utils;26import jdk.test.lib.artifacts.Artifact;27import jdk.test.lib.artifacts.ArtifactResolver;28import jdk.test.lib.artifacts.ArtifactResolverException;29import jdk.test.lib.process.OutputAnalyzer;30import jdk.test.lib.process.ProcessTools;3132import java.io.File;33import java.nio.file.Files;34import java.nio.file.Path;35import java.nio.file.Paths;36import java.util.ArrayList;37import java.util.Map;38import java.util.List;3940/**41* jcstress tests wrapper42*/43@Artifact(organization = "org.openjdk.jcstress", name = "jcstress-tests-all",44revision = "0.5", extension = "jar", unpack = false)45public class JcstressRunner {4647public static final String MAIN_CLASS = "org.openjdk.jcstress.Main";4849public static Path pathToArtifact() {50Map<String, Path> artifacts;51try {52artifacts = ArtifactResolver.resolve(JcstressRunner.class);53} catch (ArtifactResolverException e) {54throw new Error("TESTBUG: Can not resolve artifacts for "55+ JcstressRunner.class.getName(), e);56}57return artifacts.get("org.openjdk.jcstress.jcstress-tests-all-0.5")58.toAbsolutePath();59}6061public static void main(String[] args) throws Throwable {62if (args.length < 1) {63throw new Error("Usage: [jcstress flag]*");64}65Path out = Paths.get("jcstress.out").toAbsolutePath();6667ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(getCmd(args))68.redirectErrorStream(true)69.redirectOutput(out.toFile());70OutputAnalyzer oa = ProcessTools.executeProcess(pb);71if (0 != oa.getExitValue()) {72String message = "jctress test finished with nonzero exitcode "73+ oa.getExitValue();74System.err.println(message);7576System.err.print("cmd = ");77System.err.println(pb.command());7879System.err.print("cout/cerr(");80System.err.print(out.toString());81System.err.println(")[");82Files.lines(out).forEach(System.err::println);83System.err.println("]cout/cerr");84throw new Error(message);85}86}8788private static String[] getCmd(String[] args) {89List<String> extraFlags = new ArrayList<>();9091// java.io.tmpdir is set for both harness and forked VM so temporary files92// created like this File.createTempFile("jcstress", "stdout");93// don't pollute temporary directories94extraFlags.add("-Djava.io.tmpdir=" + System.getProperty("user.dir"));9596// add jar with jcstress tests and harness to CP97extraFlags.add("-cp");98extraFlags.add(System.getProperty("java.class.path")99+ File.pathSeparator100+ pathToArtifact().toString());101102extraFlags.add(MAIN_CLASS);103104extraFlags.add("--jvmArgs");105extraFlags.add("-Djava.io.tmpdir=" + System.getProperty("user.dir"));106for (String jvmArg : Utils.getTestJavaOpts()) {107extraFlags.add("--jvmArgs");108extraFlags.add(jvmArg);109}110111String[] result = new String[extraFlags.size() + args.length];112extraFlags.toArray(result);113System.arraycopy(args, 0, result, extraFlags.size(), args.length);114return result;115}116}117118119