Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit b4c1769

Browse files
committed
8251213: [TESTBUG] CDS tests shouldn't write output files into test.classes directory
Reviewed-by: minqi, ccheung
1 parent 3dc1bed commit b4c1769

25 files changed

+113
-87
lines changed

test/hotspot/jtreg/runtime/cds/appcds/AppendClasspath.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
3636
import java.nio.file.Files;
3737
import java.nio.file.Paths;
3838
import java.nio.file.StandardCopyOption;
39+
import jdk.test.lib.cds.CDSTestUtils;
3940
import jdk.test.lib.process.OutputAnalyzer;
4041

4142
public class AppendClasspath {
@@ -54,11 +55,11 @@ public static void main(String[] args) throws Exception {
5455
.assertNormalExit();
5556

5657
// PASS: 2) runtime has an non-existing jar in the -cp
57-
String classDir = System.getProperty("test.classes");
58+
String outDir = CDSTestUtils.getOutputDir();
5859
String newFile = "non-exist.jar";
59-
String nonExistPath = classDir + File.separator + newFile;
60+
String nonExistPath = outDir + File.separator + newFile;
6061
String classPath = appJar + File.pathSeparator + nonExistPath;
61-
File nonExistJar = new File(classDir, newFile);
62+
File nonExistJar = new File(outDir, newFile);
6263
if (nonExistJar.exists()) {
6364
nonExistJar.delete();
6465
}

test/hotspot/jtreg/runtime/cds/appcds/BootClassPathMismatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public void testBootClassPathMismatchTwoJars() throws Exception {
237237
}
238238

239239
private static void copyHelloToNewDir() throws Exception {
240-
String classDir = System.getProperty("test.classes");
240+
String classDir = CDSTestUtils.getOutputDir();
241241
String dstDir = classDir + File.separator + "newdir";
242242
try {
243243
Files.createDirectory(Paths.get(dstDir));

test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
3030
* @run driver/timeout=240 ClassPathAttr
3131
*/
3232

33+
import jdk.test.lib.cds.CDSTestUtils;
3334
import jdk.test.lib.process.OutputAnalyzer;
3435
import java.io.File;
3536
import java.nio.file.Files;
@@ -101,7 +102,7 @@ static void testNonExistentJars() throws Exception {
101102
buildCpAttr("cpattr6", "cpattr6.mf", "CpAttr6", "CpAttr6");
102103

103104
String cp = TestCommon.getTestJar("cpattr6.jar");
104-
String nonExistPath = System.getProperty("test.classes") + File.separator + "cpattrX.jar";
105+
String nonExistPath = CDSTestUtils.getOutputDir() + File.separator + "cpattrX.jar";
105106
(new File(nonExistPath)).delete();
106107

107108
TestCommon.testDump(cp, TestCommon.list("CpAttr6"),
@@ -129,7 +130,7 @@ static void testNonExistentJars() throws Exception {
129130
}
130131

131132
private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception {
132-
String jarClassesDir = System.getProperty("test.classes") + File.separator + jarName + "_classes";
133+
String jarClassesDir = CDSTestUtils.getOutputDir() + File.separator + jarName + "_classes";
133134
try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { }
134135

135136
JarBuilder.compile(jarClassesDir, System.getProperty("test.src") + File.separator +

test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333

3434
import jdk.test.lib.JDKToolFinder;
35+
import jdk.test.lib.cds.CDSTestUtils;
3536
import jdk.test.lib.compiler.CompilerUtils;
3637
import jdk.test.lib.process.OutputAnalyzer;
3738
import jdk.test.lib.process.ProcessTools;
@@ -48,7 +49,7 @@ public class JarBuilder {
4849
.orElseThrow(() -> new RuntimeException("ToolProvider for jar not found"));
4950

5051
public static String getJarFilePath(String jarName) {
51-
return classDir + File.separator + jarName + ".jar";
52+
return CDSTestUtils.getOutputDir() + File.separator + jarName + ".jar";
5253
}
5354

5455
// jar all files under dir, with manifest file man, with an optional versionArgs
@@ -59,15 +60,16 @@ public static String getJarFilePath(String jarName) {
5960
// -C <path to the base classes> .\
6061
// --release 9 -C <path to the versioned classes> .
6162
// the last line begins with "--release" corresponds to the optional versionArgs.
62-
public static void build(String jarName, File dir, String man, String ...versionArgs)
63+
public static String build(String jarName, File dir, String man, String ...versionArgs)
6364
throws Exception {
6465
ArrayList<String> args = new ArrayList<String>();
6566
if (man != null) {
6667
args.add("cfm");
6768
} else {
6869
args.add("cf");
6970
}
70-
args.add(classDir + File.separator + jarName + ".jar");
71+
String jarFile = getJarFilePath(jarName);
72+
args.add(jarFile);
7173
if (man != null) {
7274
args.add(man);
7375
}
@@ -78,6 +80,7 @@ public static void build(String jarName, File dir, String man, String ...version
7880
args.add(verArg);
7981
}
8082
createJar(args);
83+
return jarFile;
8184
}
8285

8386
public static String build(String jarName, String ...classNames)
@@ -259,8 +262,6 @@ public static void compileModule(Path src,
259262
public static void signJar() throws Exception {
260263
String keyTool = JDKToolFinder.getJDKTool("keytool");
261264
String jarSigner = JDKToolFinder.getJDKTool("jarsigner");
262-
String classDir = System.getProperty("test.classes");
263-
String FS = File.separator;
264265

265266
executeProcess(keyTool,
266267
"-genkey", "-keystore", "./keystore", "-alias", "mykey",
@@ -270,8 +271,8 @@ public static void signJar() throws Exception {
270271

271272
executeProcess(jarSigner,
272273
"-keystore", "./keystore", "-storepass", "abc123", "-keypass",
273-
"abc123", "-signedjar", classDir + FS + "signed_hello.jar",
274-
classDir + FS + "hello.jar", "mykey")
274+
"abc123", "-signedjar", getJarFilePath("signed_hello"),
275+
getJarFilePath("hello"), "mykey")
275276
.shouldHaveExitValue(0);
276277
}
277278

test/hotspot/jtreg/runtime/cds/appcds/LongClassListPath.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,14 +51,14 @@ public static void main(String[] args) throws Exception {
5151

5252
// Create a directory with long path and copy the classlist file to
5353
// the directory.
54-
Path classDir = Paths.get(System.getProperty("test.classes"));
54+
Path classDir = Paths.get(CDSTestUtils.getOutputDir());
5555
Path destDir = classDir;
5656
int subDirLen = MAX_PATH - classDir.toString().length() - 2;
5757
if (subDirLen > 0) {
5858
char[] chars = new char[subDirLen];
5959
Arrays.fill(chars, 'x');
6060
String subPath = new String(chars);
61-
destDir = Paths.get(System.getProperty("test.classes"), subPath);
61+
destDir = Paths.get(CDSTestUtils.getOutputDir(), subPath);
6262
}
6363
File longDir = destDir.toFile();
6464
longDir.mkdir();

test/hotspot/jtreg/runtime/cds/appcds/MoveJDKTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.nio.file.Path;
4242
import java.nio.file.Paths;
4343
import java.nio.file.StandardCopyOption;
44+
import jdk.test.lib.cds.CDSTestUtils;
4445
import jdk.test.lib.process.OutputAnalyzer;
4546

4647
public class MoveJDKTest {
@@ -178,12 +179,12 @@ static ProcessBuilder makeBuilder(String... args) throws Exception {
178179
}
179180

180181
private static String copyFakeModulesFromHelloJar() throws Exception {
181-
String classDir = System.getProperty("test.classes");
182+
String outDir = CDSTestUtils.getOutputDir();
182183
String newFile = "hello.modules";
183-
String path = classDir + File.separator + newFile;
184+
String path = outDir + File.separator + newFile;
184185

185-
Files.copy(Paths.get(classDir, "hello.jar"),
186-
Paths.get(classDir, newFile),
186+
Files.copy(Paths.get(outDir, "hello.jar"),
187+
Paths.get(outDir, newFile),
187188
StandardCopyOption.REPLACE_EXISTING);
188189
return path;
189190
}

test/hotspot/jtreg/runtime/cds/appcds/MultiReleaseJars.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
3434
import java.io.FileOutputStream;
3535
import java.io.PrintStream;
3636
import java.io.IOException;
37+
import jdk.test.lib.cds.CDSTestUtils;
3738
import jdk.test.lib.process.OutputAnalyzer;
3839

3940
public class MultiReleaseJars {
@@ -90,7 +91,7 @@ static void writeFile(File file, String... contents) throws Exception {
9091
* META-INF/versions/<major-version>/version/Version.class
9192
*/
9293
static void createClassFilesAndJar() throws Exception {
93-
String tempDir = System.getProperty("test.classes");
94+
String tempDir = CDSTestUtils.getOutputDir();
9495
File baseDir = new File(tempDir + File.separator + "base");
9596
File vDir = new File(tempDir + File.separator + MAJOR_VERSION_STRING);
9697

test/hotspot/jtreg/runtime/cds/appcds/NonExistClasspath.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
3636
import java.nio.file.Files;
3737
import java.nio.file.Paths;
3838
import java.nio.file.StandardCopyOption;
39+
import jdk.test.lib.cds.CDSTestUtils;
3940
import jdk.test.lib.process.OutputAnalyzer;
4041

4142
public class NonExistClasspath {
@@ -46,9 +47,9 @@ public static void main(String[] args) throws Exception {
4647
}
4748

4849
static void doTest(String appJar, boolean bootcp) throws Exception {
49-
String classDir = System.getProperty("test.classes");
50+
String outDir = CDSTestUtils.getOutputDir();
5051
String newFile = "non-exist.jar";
51-
String nonExistPath = classDir + File.separator + newFile;
52+
String nonExistPath = outDir + File.separator + newFile;
5253
final String errorMessage1 = "Unable to use shared archive";
5354
final String errorMessage2 = "shared class paths mismatch";
5455
final String errorMessage3 = (bootcp ? "BOOT" : "APP") + " classpath mismatch";
@@ -90,8 +91,8 @@ static void doTest(String appJar, boolean bootcp) throws Exception {
9091
.assertNormalExit();
9192

9293
// Now make nonExistPath exist. CDS will fail to load.
93-
Files.copy(Paths.get(classDir, "hello.jar"),
94-
Paths.get(classDir, newFile),
94+
Files.copy(Paths.get(outDir, "hello.jar"),
95+
Paths.get(outDir, newFile),
9596
StandardCopyOption.REPLACE_EXISTING);
9697

9798
TestCommon.run(make_args(bootcp,

test/hotspot/jtreg/runtime/cds/appcds/OldClassTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -45,10 +45,8 @@ public class OldClassTest implements Opcodes {
4545

4646
public static void main(String[] args) throws Exception {
4747
File jarSrcFile = new File(JarBuilder.getOrCreateHelloJar());
48-
49-
File dir = new File(System.getProperty("test.classes", "."));
50-
File jarFile = new File(dir, "OldClassTest_old.jar");
51-
String jar = jarFile.getPath();
48+
String jar = JarBuilder.getJarFilePath("OldClassTest_old");
49+
File jarFile = new File(jar);
5250

5351
if (!jarFile.exists() || jarFile.lastModified() < jarSrcFile.lastModified()) {
5452
createTestJarFile(jarSrcFile, jarFile);

test/hotspot/jtreg/runtime/cds/appcds/TestCommon.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -321,12 +321,11 @@ private static void patchJarForDynamicDump(String cp) throws Exception {
321321
firstJar = firstJar.substring(0, n);
322322
}
323323
String classDir = System.getProperty("test.classes");
324-
String expected1 = classDir + File.separator;
325-
String expected2 = System.getProperty("user.dir") + File.separator;
324+
String expected = getOutputDir() + File.separator;
326325

327-
if (!firstJar.startsWith(expected1) && !firstJar.startsWith(expected2)) {
326+
if (!firstJar.startsWith(expected)) {
328327
throw new RuntimeException("FIXME: jar file not at a supported location ('"
329-
+ expected1 + "', or '" + expected2 + "'): " + firstJar);
328+
+ expected + "'): " + firstJar);
330329
}
331330

332331
String replaceJar = firstJar + ".tmp";

test/hotspot/jtreg/runtime/cds/appcds/VerifierTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,15 +62,13 @@ public static void main(String[] args) throws Exception {
6262
String jarName_hi = "hi" + "_" + subCaseId;
6363

6464

65-
JarBuilder.build(jarName_verifier_test_tmp, "VerifierTest0", "VerifierTestA",
65+
File jarSrcFile = new File(JarBuilder.build(jarName_verifier_test_tmp, "VerifierTest0", "VerifierTestA",
6666
"VerifierTestB", "VerifierTestC", "VerifierTestD", "VerifierTestE",
67-
"UnverifiableBase", "UnverifiableIntf", "UnverifiableIntfSub");
67+
"UnverifiableBase", "UnverifiableIntf", "UnverifiableIntfSub"));
6868
JarBuilder.build(jarName_greet, "Greet");
6969
JarBuilder.build(jarName_hi, "Hi", "Hi$MyClass");
7070

71-
File dir = new File(System.getProperty("test.classes", "."));
72-
File jarSrcFile = new File(dir, jarName_verifier_test_tmp + ".jar");
73-
File jarFile = new File(dir, jarName_verifier_test + ".jar");
71+
File jarFile = new File(JarBuilder.getJarFilePath(jarName_verifier_test));
7472
String jar = jarFile.getPath();
7573

7674
if (!jarFile.exists() || jarFile.lastModified() < jarSrcFile.lastModified()) {

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/CDSStreamTestDriver.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@
3636
*/
3737

3838
import org.testng.annotations.Test;
39-
4039
import java.io.File;
41-
4240
import jtreg.SkippedException;
43-
4441
import sun.hotspot.gc.GC;
4542

4643
@Test
@@ -58,8 +55,7 @@ public void testMain() throws Exception {
5855

5956
static void doTest() throws Exception {
6057
String topArchiveName = getNewArchiveName();
61-
JarBuilder.build("streamapp", new File(classDir), null);
62-
String appJar = classDir + File.separator + "streamapp.jar";
58+
String appJar = JarBuilder.build("streamapp", new File(classDir), null);
6359

6460
String[] classPaths = javaClassPath.split(File.pathSeparator);
6561
String testngJar = null;

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/DoubleSumAverageTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public static void main(String[] args) throws Exception {
4747

4848
static void testImpl() throws Exception {
4949
String topArchiveName = getNewArchiveName();
50-
JarBuilder.build("stream", new File(classDir), null);
51-
String appJar = classDir + File.separator + "stream.jar";
50+
String appJar = JarBuilder.build("stream", new File(classDir), null);
5251

5352
dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
5453
"-cp", appJar, mainClass);

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/HelloDynamicCustom.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
*/
3737

3838
import java.io.File;
39+
import jdk.test.lib.cds.CDSTestUtils;
3940
import jdk.test.lib.process.OutputAnalyzer;
4041

4142
public class HelloDynamicCustom extends DynamicArchiveTestBase {
42-
private static final String ARCHIVE_NAME =
43-
System.getProperty("test.classes") + File.separator + "HelloDynamicCustom-top.jsa";
43+
private static final String ARCHIVE_NAME = CDSTestUtils.getOutputFileName("top.jsa");
4444

4545
public static void main(String[] args) throws Exception {
4646
runTest(HelloDynamicCustom::testDefaultBase);

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/HelloDynamicCustomUnload.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
*/
4040

4141
import java.io.File;
42+
import jdk.test.lib.cds.CDSTestUtils;
4243

4344
public class HelloDynamicCustomUnload extends DynamicArchiveTestBase {
44-
private static final String ARCHIVE_NAME =
45-
System.getProperty("test.classes") + File.separator + "HelloDynamicCustomUnload.jsa";
45+
private static final String ARCHIVE_NAME = CDSTestUtils.getOutputFileName("top.jsa");
4646

4747
public static void main(String[] args) throws Exception {
4848
runTest(HelloDynamicCustomUnload::testDefaultBase);

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/LambdaForClassInBaseArchive.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
*/
3838

3939
import java.io.File;
40+
import jdk.test.lib.cds.CDSTestUtils;
4041
import jdk.test.lib.process.OutputAnalyzer;
4142
import jdk.test.lib.process.ProcessTools;
4243

4344
public class LambdaForClassInBaseArchive extends DynamicArchiveTestBase {
44-
static final String classList = System.getProperty("test.classes") +
45-
File.separator + "LambdaForClassInBaseArchive.list";
45+
static final String classList = CDSTestUtils.getOutputFileName("classlist");
4646
static final String appClass = "SimpleApp";
4747

4848
public static void main(String[] args) throws Exception {

0 commit comments

Comments
 (0)