RFR: 8325532: serviceability/dcmd/compiler/PerfMapTest.java leaves created files in the /tmp dir.
Kevin Walls
kevinw at openjdk.org
Wed Feb 28 11:09:54 UTC 2024
On Fri, 23 Feb 2024 21:55:15 GMT, Chris Plummer <cjplummer at openjdk.org> wrote:
> PerfMapTest.java issues the Compiler.perfmap jcmd with a filename argument to write the perfmap to. It does this in 3 different modes. 2 of the modes result in a perfmap file being left in the tmp directory that is not removed after the test executes (and should be removed). The 3rd mode creates the perfmap file in the directory specified by the test.dir property, and is ok to leave the file there. I've added code to delete the /tmp files that are created.
>
> I did a bit of extra testing by hand. I created /tmp/perf-<pid>.map as root. As expected the Files.deleteIfExists() call threw an exception due to the lack of permissions to delete the file. However, I then realized the file had a size of 0, which means the test was not even doing a proper job of testing that the perfrmap jcmd was working. In other words, the test should have failed long before getting to the Files.deleteIfExists(), so I added a size check to make sure it fails when the file is not written to.
Looks good.
Adding the file size check is great. Just a nit on the message, if you are interested: I was wondering if "Possible file permission issue" isn't the right error for seeing a zero byte file? Fine to just say that it's a zero byte file.
Seems like a permission failure would not create, or not truncate the file.
If somebody else created the file, and we fail to overwrite it, it's going to have whatever size they left it with. 8-)
But then I notice that if it fails due to permissions, that should be caught by the checks that output is empty, as it should show:
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file file.txt due to Permission denied
..so it shouldn't get this far if jcmd printed an error.
-------------
Marked as reviewed by kevinw (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/17992#pullrequestreview-1905966982
More information about the serviceability-dev
mailing list