Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8279022: JCmdTestFileSafety.java should check file time stamp for test result #6904

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 27 additions & 10 deletions test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestFileSafety.java
Expand Up @@ -38,6 +38,9 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.attribute.FileTime;
import java.nio.file.Files;
import java.nio.file.Paths;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;
Expand All @@ -61,6 +64,13 @@ static void checkContainAbsoluteLogPath(OutputAnalyzer output) throws Exception
}
}

private static void removeFile(String fileName) throws Exception {
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
}

static void test() throws Exception {
buildJars();

Expand All @@ -75,17 +85,25 @@ static void test() throws Exception {
}
outputDirFile.setWritable(true);
String localFileName = subDir + File.separator + "MyStaticDump.jsa";
removeFile(localFileName);

setIsStatic(true/*static*/);
// Set target dir not writable, do static dump
print2ln(test_count++ + " Set target dir not writable, do static dump");
setKeepArchive(true);
app = createLingeredApp("-cp", allJars);
pid = app.getPid();
test(localFileName, pid, noBoot, EXPECT_PASS);
checkFileExistence(localFileName, true/*exist*/);
FileTime ft1 = Files.getLastModifiedTime(Paths.get(localFileName));
outputDirFile.setWritable(false);
test(localFileName, pid, noBoot, EXPECT_FAIL);
FileTime ft2 = Files.getLastModifiedTime(Paths.get(localFileName));
if (!ft2.equals(ft1)) {
throw new RuntimeException("Archive file " + localFileName + " should not be updated");
}
removeFile(localFileName);
outputDirFile.setWritable(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've added the setWritable(true) here, do you still need the existing one at line 116?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be removed, but better keep it --- the testing result of last step is deleted just in case it could affect next test. I would like remove the result file anyway. Since the file name keep changing, I will update with a function with the file name (String) to delete the file. Thanks.

checkFileExistence(localFileName, true/*exist*/);

// Illegal character in file name
localFileName = "mystatic:.jsa";
Expand All @@ -103,18 +121,17 @@ static void test() throws Exception {
pid = app.getPid();
localFileName = subDir + File.separator + "MyDynamicDump.jsa";
test(localFileName, pid, noBoot, EXPECT_PASS);
app.stopApp();
// cannot dynamically dump twice, restart
app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo");
pid = app.getPid();
checkFileExistence(localFileName, true/*exist*/);
ft1 = Files.getLastModifiedTime(Paths.get(localFileName));
outputDirFile.setWritable(false);
test(localFileName, pid, noBoot, EXPECT_FAIL);
outputDirFile.setWritable(true);
ft2 = Files.getLastModifiedTime(Paths.get(localFileName));
if (!ft2.equals(ft1)) {
throw new RuntimeException("Archive file " + localFileName + " should not be updated");
}
app.stopApp();
// MyDynamicDump.jsa should exist
checkFileExistence(localFileName, true);
File rmFile = new File(localFileName);
rmFile.delete();
removeFile(localFileName);
outputDirFile.setWritable(true);
outputDirFile.delete();
}

Expand Down