Skip to content

Commit

Permalink
8213226: [TESTBUG] Reduce the usage of CDSTestUtils.executeAndLog()
Browse files Browse the repository at this point in the history
Reviewed-by: iklam, minqi
  • Loading branch information
calvinccheung committed Feb 1, 2021
1 parent b6a7367 commit 55d62a5
Show file tree
Hide file tree
Showing 32 changed files with 252 additions and 304 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,10 +46,9 @@ private static void createAndLoadSharedArchive(String create, String load)
String createCompactStringsArgument = "-XX:" + create + "CompactStrings";
String loadCompactStringsArgument = "-XX:" + load + "CompactStrings";

OutputAnalyzer out = CDSTestUtils.createArchive(createCompactStringsArgument);
CDSTestUtils.checkDump(out);
CDSTestUtils.createArchiveAndCheck(createCompactStringsArgument);

out = CDSTestUtils.runWithArchive(loadCompactStringsArgument);
OutputAnalyzer out = CDSTestUtils.runWithArchive(loadCompactStringsArgument);
CDSTestUtils.checkMappingFailure(out);

out.shouldMatch("The shared archive file's CompactStrings " +
Expand Down
20 changes: 7 additions & 13 deletions test/hotspot/jtreg/runtime/cds/DeterministicDump.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,10 +30,9 @@
* @run driver DeterministicDump
*/

import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -79,16 +78,11 @@ public static void doTest(boolean compressed) throws Exception {
static String dump(ArrayList<String> args, String... more) throws Exception {
String logName = "SharedArchiveFile" + (id++);
String archiveName = logName + ".jsa";
args = (ArrayList<String>)args.clone();
args.add("-XX:SharedArchiveFile=" + archiveName);
args.add("-Xshare:dump");
args.add("-Xlog:cds=debug");
for (String m : more) {
args.add(m);
}
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, logName);
CDSTestUtils.checkDump(out);
CDSOptions opts = (new CDSOptions())
.addPrefix("-Xlog:cds=debug")
.setArchiveName(archiveName)
.addSuffix(more);
CDSTestUtils.createArchiveAndCheck(opts);

return archiveName;
}
Expand Down
28 changes: 12 additions & 16 deletions test/hotspot/jtreg/runtime/cds/DumpSharedDictionary.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,7 @@
* @run driver DumpSharedDictionary
*/

import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
Expand All @@ -40,24 +41,19 @@ public class DumpSharedDictionary {
public static void main(String[] args) throws Exception {
if (args.length == 0) {
// Start this process
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:SharedArchiveFile=./DumpSharedDictionary.jsa",
"-Xshare:dump");

OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "dump");
out.shouldHaveExitValue(0);
CDSOptions opts = (new CDSOptions())
.setArchiveName("./DumpSharedDictionary.jsa");
CDSTestUtils.createArchiveAndCheck(opts);

String testjdkPath = System.getProperty("test.jdk");

pb = ProcessTools.createJavaProcessBuilder(
"-XX:SharedArchiveFile=./DumpSharedDictionary.jsa",
"-Dtest.jdk=" + testjdkPath,
"-Xshare:on", "DumpSharedDictionary", "test");

out = CDSTestUtils.executeAndLog(pb, "exec");
if (!CDSTestUtils.isUnableToMap(out)) {
out.shouldHaveExitValue(0);
}
opts = (new CDSOptions())
.setUseVersion(false)
.addSuffix("-XX:SharedArchiveFile=./DumpSharedDictionary.jsa",
"-Dtest.jdk=" + testjdkPath,
"DumpSharedDictionary", "test");
CDSTestUtils.run(opts)
.assertNormalExit();
} else {
// Grab my own PID
String pid = Long.toString(ProcessTools.getProcessId());
Expand Down
6 changes: 2 additions & 4 deletions test/hotspot/jtreg/runtime/cds/PrintSharedArchiveAndExit.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,14 +33,12 @@

import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;

public class PrintSharedArchiveAndExit {
public static void main(String[] args) throws Exception {
String archiveName = "PrintSharedArchiveAndExit.jsa";
CDSOptions opts = (new CDSOptions()).setArchiveName(archiveName);
OutputAnalyzer out = CDSTestUtils.createArchive(opts);
CDSTestUtils.checkDump(out);
CDSTestUtils.createArchiveAndCheck(opts);

// (1) With a valid archive
opts = (new CDSOptions())
Expand Down
32 changes: 14 additions & 18 deletions test/hotspot/jtreg/runtime/cds/SharedArchiveFile.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,33 +31,29 @@
* java.management
*/

import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;


// NOTE: This test serves as a sanity test and also as an example for simple
// use of SharedArchiveFile argument. For this reason it DOES NOT use the utility
// methods to form command line to create/use shared archive.
public class SharedArchiveFile {
public static void main(String[] args) throws Exception {
ProcessBuilder pb = ProcessTools.createTestJvm(
"-XX:SharedArchiveFile=./SharedArchiveFile.jsa",
"-Xshare:dump", "-Xlog:cds");
OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "SharedArchiveFile");
CDSTestUtils.checkDump(out);
CDSOptions opts = (new CDSOptions())
.addPrefix("-Xlog:cds")
.setArchiveName("./SharedArchiveFile.jsa");
CDSTestUtils.createArchiveAndCheck(opts);

// -XX:+DumpSharedSpaces should behave the same as -Xshare:dump
pb = ProcessTools.createTestJvm(
"-XX:SharedArchiveFile=./SharedArchiveFile.jsa",
"-XX:+DumpSharedSpaces", "-Xlog:cds");
out = CDSTestUtils.executeAndLog(pb, "SharedArchiveFile");
CDSTestUtils.checkDump(out);
opts = (new CDSOptions())
.addPrefix("-XX:+DumpSharedSpaces", "-Xlog:cds")
.setArchiveName("./SharedArchiveFile.jsa");
CDSTestUtils.createArchiveAndCheck(opts);

pb = ProcessTools.createTestJvm(
"-XX:SharedArchiveFile=./SharedArchiveFile.jsa",
"-Xshare:on", "-version");
out = CDSTestUtils.executeAndLog(pb, "SharedArchiveFile");
CDSTestUtils.checkExec(out);
opts = (new CDSOptions())
.setArchiveName("./SharedArchiveFile.jsa");
CDSTestUtils.run(opts)
.assertNormalExit();
}
}
9 changes: 3 additions & 6 deletions test/hotspot/jtreg/runtime/cds/SharedStringsDedup.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,18 +30,15 @@
*/

import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.File;

// The main purpose is to test the interaction between shared strings
// and -XX:+UseStringDeduplication. We run in -Xshare:auto mode so
// we don't need to worry about CDS archive mapping failure (which
// doesn't happen often so it won't impact coverage).
public class SharedStringsDedup {
public static void main(String[] args) throws Exception {
OutputAnalyzer out =
CDSTestUtils.createArchive();
CDSTestUtils.checkDump(out, "Shared string table stats");
CDSTestUtils.createArchiveAndCheck()
.shouldContain("Shared string table stats");
CDSTestUtils.runWithArchiveAndCheck("-XX:+UseStringDeduplication");
}
}
9 changes: 3 additions & 6 deletions test/hotspot/jtreg/runtime/cds/SharedStringsRunAuto.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,14 +30,11 @@
*/

import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.File;

public class SharedStringsRunAuto {
public static void main(String[] args) throws Exception {
OutputAnalyzer out =
CDSTestUtils.createArchive();
CDSTestUtils.checkDump(out, "Shared string table stats");
CDSTestUtils.createArchiveAndCheck()
.shouldContain( "Shared string table stats");
CDSTestUtils.runWithArchiveAndCheck();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -39,9 +39,8 @@ public static void main(String[] args) throws Exception {
int bucket_size = 8;

OutputAnalyzer output =
CDSTestUtils.createArchive("-XX:SharedSymbolTableBucketSize="
+ Integer.valueOf(bucket_size));
CDSTestUtils.checkDump(output);
CDSTestUtils.createArchiveAndCheck("-XX:SharedSymbolTableBucketSize="
+ Integer.valueOf(bucket_size));
CDSTestUtils.checkMappingFailure(output);

String s = output.firstMatch("Average bucket size : .*");
Expand Down
5 changes: 2 additions & 3 deletions test/hotspot/jtreg/runtime/cds/SpaceUtilizationCheck.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -55,8 +55,7 @@ public static void main(String[] args) throws Exception {
static void test(String... extra_options) throws Exception {
CDSOptions opts = new CDSOptions();
opts.addSuffix(extra_options);
OutputAnalyzer output = CDSTestUtils.createArchive(opts);
CDSTestUtils.checkDump(output);
OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts);
Pattern pattern = Pattern.compile("(..) space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
WhiteBox wb = WhiteBox.getWhiteBox();
long reserve_alignment = wb.metaspaceReserveAlignment();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -35,7 +35,6 @@
import jdk.test.lib.Platform;
import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.FileAlreadyExistsException;
Expand Down Expand Up @@ -187,8 +186,7 @@ public void testBootClassPathMatch() throws Exception {
*/
public void testBootClassPathMatchWithAppend() throws Exception {
CDSOptions opts = new CDSOptions().setUseVersion(false);
OutputAnalyzer out = CDSTestUtils.createArchive(opts);
CDSTestUtils.checkDump(out);
CDSTestUtils.createArchiveAndCheck(opts);

String appJar = JarBuilder.getOrCreateHelloJar();
opts.addPrefix("-Xbootclasspath/a:" + appJar, "-showversion").addSuffix("Hello");
Expand Down
43 changes: 23 additions & 20 deletions test/hotspot/jtreg/runtime/cds/appcds/DumpClassList.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,9 +32,9 @@
* @run driver DumpClassList
*/

import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.compiler.InMemoryJavaCompiler;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class DumpClassList {
public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -74,24 +74,27 @@ public static void main(String[] args) throws Exception {
String appendJar = JarBuilder.build("bootappend", "boot/append/Foo");

// dump class list
ProcessBuilder pb = ProcessTools.createTestJvm(
"-XX:DumpLoadedClassList=" + classList,
"--patch-module=java.base=" + patchJar,
"-Xbootclasspath/a:" + appendJar,
"-cp",
appJar,
appClass[0]);
OutputAnalyzer output = TestCommon.executeAndLog(pb, "dumpClassList");
TestCommon.checkExecReturn(output, 0, true,
"hello world",
"skip writing class java/lang/NewClass") // skip classes outside of jrt image
.shouldNotContain("skip writing class boot/append/Foo"); // but classes on -Xbootclasspath/a should not be skipped
CDSTestUtils.dumpClassList(classList,
"--patch-module=java.base=" + patchJar,
"-Xbootclasspath/a:" + appendJar,
"-cp",
appJar,
appClass[0])
.assertNormalExit(output -> {
output.shouldContain("hello world");
// skip classes outside of jrt image
output.shouldContain("skip writing class java/lang/NewClass");
// but classes on -Xbootclasspath/a should not be skipped
output.shouldNotContain("skip writing class boot/append/Foo");
});

output = TestCommon.createArchive(appJar, appClass,
"-Xbootclasspath/a:" + appendJar,
"-Xlog:class+load",
"-XX:SharedClassListFile=" + classList);
TestCommon.checkDump(output)
CDSOptions opts = (new CDSOptions())
.setClassList(appClass)
.addPrefix("-cp", appJar,
"-Xbootclasspath/a:" + appendJar,
"-Xlog:class+load",
"-XX:SharedClassListFile=" + classList);
CDSTestUtils.createArchiveAndCheck(opts)
.shouldNotContain("Preload Warning: Cannot find java/lang/invoke/LambdaForm")
.shouldNotContain("Preload Warning: Cannot find boot/append/Foo")
.shouldContain("[info][class,load] boot.append.Foo");
Expand Down

0 comments on commit 55d62a5

Please sign in to comment.