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 2 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
@@ -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;
@@ -76,17 +79,29 @@ static void test() throws Exception {
outputDirFile.setWritable(true);
String localFileName = subDir + File.separator + "MyStaticDump.jsa";
setIsStatic(true/*static*/);
File fileLocal = new File(localFileName);
if (fileLocal.exists()) {
fileLocal.delete();
}
// 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);
outputDirFile.setWritable(true);
checkFileExistence(localFileName, true/*exist*/);
FileTime ft2 = Files.getLastModifiedTime(Paths.get(localFileName));
if (!ft2.equals(ft1)) {
throw new RuntimeException("Archive file " + localFileName + " should not be updated");
}

if (fileLocal.exists()) {
fileLocal.delete();
}
outputDirFile.setWritable(true);
Copy link
Member

@calvinccheung calvinccheung Dec 21, 2021

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

@yminqi yminqi Dec 21, 2021

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.

// Illegal character in file name
localFileName = "mystatic:.jsa";
OutputAnalyzer output = test(localFileName, pid, noBoot, EXPECT_FAIL);
@@ -103,18 +118,19 @@ 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();
if (fileLocal.exists()) {
fileLocal.delete();
}
outputDirFile.setWritable(true);
outputDirFile.delete();
}