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

8321616: Retire binary test vectors in test/jdk/java/util/zip/ZipFile #17038

Closed
wants to merge 17 commits into from

Conversation

eirbjo
Copy link
Contributor

@eirbjo eirbjo commented Dec 8, 2023

This PR suggests we retire the binary test vectors ZipFile/input.zip, ZipFile/input.jar and ZipFile/crash.jar

Binary test vectors are harder to analyze, and sharing test vectors across unrelated tests increases maintenance burden. It would be better to have each test produce its own test vectors independently.

While visiting these dusty tests, we should take the opportunity to convert them to JUnit, add more comments and perform some mild modernization and cleanups where appropriate. We should also consider whether any test are duplicated and can be retired or moved into other test files as separate methods. See comments below.

To help reviewers, here are some comments on the updated tests:

Available.java
This test currently has no jtreg @test header, so isn't currently active. After discussion, we decided to merge this test into ReadZip.java. I added some checks to verify that reading from the stream reduces the number of available bytes accordingly, also checking the behavior when the stream is closed.

CopyJar.java
The concern of copying entries seems to now have better coverage in the test zip/CopyZipFile. We decided to retire this test rather than convert it and instead convert CopyZipFile to JUnit.

EnumAfterClose.java
To prevent confusion with Java Enums, I suggest we rename this test to EnumerateAfterClose.

FinalizeInflater.java
The code verified by this test has been updated to use cleaners instead of finalizers. Still, this test code relies on finalizers. Not sure if this is an issue, but this test will need to be updated when finalizers are finally removed.

GetDirEntry.java
We decided to merge this test into ReadZip.readDirectoryEntries rather than keeping it as a separate test.

ReadZip.java
Nothing exciting here, the single main method was split into multiple JUnit methods, each focusing on a separate concern. A new test case noentries() was added, resolving JDK-8322830

ReleaseInflater.java
Nothing exciting, tried to add some comment to help understanding of what is tested.

StreamZipEntriesTest.java
This test was using TestNG so was converted to JUnit for consistency. Added some comments to help understanding.

ReadAfterClose.java
This uses the binary test vector crash.jar. The test is converted to JUnit and moved to `ReadZip.readAfterClose´. The test is expanded to exercise more read methods.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8321616: Retire binary test vectors in test/jdk/java/util/zip/ZipFile (Enhancement - P4)
  • JDK-8322830: Add test case for ZipFile opening a ZIP with no entries (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17038/head:pull/17038
$ git checkout pull/17038

Update a local copy of the PR:
$ git checkout pull/17038
$ git pull https://git.openjdk.org/jdk.git pull/17038/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17038

View PR using the GUI difftool:
$ git pr show -t 17038

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17038.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 8, 2023

👋 Welcome back eirbjo! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 8, 2023

@eirbjo The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Dec 8, 2023
@eirbjo eirbjo marked this pull request as ready for review December 11, 2023 15:09
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 11, 2023
@mlbridge
Copy link

mlbridge bot commented Dec 11, 2023

@LanceAndersen
Copy link
Contributor

Thank you for tacking the conversion of this test to junit

One quick comment, if we are updating this test, we should look to get rid of input.zip which means we should also address as part of the change:

open/test/jdk/java/util/zip/ZipFile/EnumAfterClose.java
open/test/jdk/java/util/zip/ZipFile/FinalizeInflater.java
open/test/jdk/java/util/zip/ZipFile/StreamZipEntriesTest.java

@eirbjo
Copy link
Contributor Author

eirbjo commented Dec 11, 2023

One quick comment, if we are updating this test, we should look to get rid of input.zip

I started going down that road, but felt uneasy about the amount of unrelated changes in a single PR. I'd like to make efficient use of reviewer time, so my preference was to focus on the JUnit conversion, without too many other changes.

If you prefer that we get rid of input.zip and also convert the affected tests to JUnit in the same PR, then I'm happy to switch strategy.

Note that StreamZipEntriesTest also uses input.jar, this is also read by Available, CopyJar, GetDirEntry, ReleaseInflater. Should we get rid of input.jar as well, or perhaps defer that to a follow-up?

@LanceAndersen
Copy link
Contributor

One quick comment, if we are updating this test, we should look to get rid of input.zip

I started going down that road, but felt uneasy about the amount of unrelated changes in a single PR. I'd like to make efficient use of reviewer time, so my preference was to focus on the JUnit conversion, without too many other changes.

If you prefer that we get rid of input.zip and also convert the affected tests to JUnit in the same PR, then I'm happy to switch strategy.

Note that StreamZipEntriesTest also uses input.jar, this is also read by Available, CopyJar, GetDirEntry, ReleaseInflater. Should we get rid of input.jar as well, or perhaps defer that to a follow-up?

input.zip and input.jar are pretty trivial:

jar tvf test/jdk/java/util/zip/ZipFile/input.zip
506 Fri May 28 16:32:31 EDT 1999 ReadZip.java
jar tvf test/jdk/java/util/zip/ZipFile/input.jar
0 Tue Mar 23 13:09:08 EST 1999 META-INF/
86 Tue Mar 23 13:09:08 EST 1999 META-INF/MANIFEST.MF
728 Tue Mar 23 13:08:30 EST 1999 ReleaseInflater.java

So you could have the tests create the zip files on the fly or store the contents in an array within the tests.

If the tests create the zip file/jar on the fly, then we just need to make sure that we create it in the same fashion as the test needs.

I just think that we should take this opportunity as part of re-writing the tests to remove the need for the binary files in the workspace.

I don't have a preference whether we deal with input.jar separately, but these tests are not that complex so I do not see a risk if they are all converted at once, or done piece meal

@eirbjo
Copy link
Contributor Author

eirbjo commented Dec 11, 2023

I don't have a preference whether we deal with input.jar separately, but these tests are not that complex so I do not see a risk if they are all converted at once, or done piece meal

Thanks, I'll extend the goal of this PR to remove input.jar, input.zip and convert affected tests to JUnit along the way.

@eirbjo eirbjo marked this pull request as draft December 12, 2023 19:29
@openjdk openjdk bot removed the rfr Pull request is ready for review label Dec 12, 2023
@eirbjo eirbjo changed the title 8321616: Convert the ReadZip test to JUnit 8321616: Remove binary test vectors ZipFile/input.jar and ZipFile/input.zip Dec 13, 2023
@eirbjo eirbjo changed the title 8321616: Remove binary test vectors ZipFile/input.jar and ZipFile/input.zip 8321616: Retire binary test vectors ZipFile/input.jar and ZipFile/input.zip Dec 13, 2023
@eirbjo
Copy link
Contributor Author

eirbjo commented Dec 14, 2023

The scope of this PR has now expanded to removing uses of the input.zip and input.jar files, updating any test using them to produce their own test vectors, and convert affected tests to JUnit.

I'm marking the PR ready for review again. Before looking too closely at the code, it would be useful to discuss the following tests:

  • Available.java: This test has no jtreg header. I've added one and converted the test. Is this worthwhile, or should we rather remove it?
  • CopyJar.java: The concern tested seems to have superior coverage in the test zip/CopyZipFile.java. Should we retire CopyJar.java instead of coverting it?
  • DirEntry.java: There is duplication between this test and ReadZip.readDirectoryEntry(). Should we retire one of these?

@eirbjo eirbjo marked this pull request as ready for review December 14, 2023 10:13
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 14, 2023
@LanceAndersen
Copy link
Contributor

The scope of this PR has now expanded to removing uses of the input.zip and input.jar files, updating any test using them to produce their own test vectors, and convert affected tests to JUnit.

I'm marking the PR ready for review again. Before looking too closely at the code, it would be useful to discuss the following tests:

  • Available.java: This test has no jtreg header. I've added one and converted the test. Is this worthwhile, or should we rather remove it?

This could be moved into ReadZip. I do not believe we have a specific test and it is trivial

  • CopyJar.java: The concern tested seems to have superior coverage in the test zip/CopyZipFile.java. Should we retire CopyJar.java instead of coverting it?

Yes CopyZipFile already exercises Zipfile.ZipInputStream so it is safe to retire CopyJar (though CopyZipFile could use a junit conversion ;-)

  • DirEntry.java: There is duplication between this test and ReadZip.readDirectoryEntry(). Should we retire one of these?

I believe you meant GetDirEntry.java not DirEntry.java?

Having a test that specifically validates we can read META-INF is not a bad thing, but I suspect we have a test that already does that if not in the java/util/zip tests or java/util/jar tests. If not we should keep it but merge it as you suggest

@openjdk openjdk bot removed the rfr Pull request is ready for review label Dec 14, 2023
@eirbjo
Copy link
Contributor Author

eirbjo commented Dec 14, 2023

@LanceAndersen

Thanks for your guidance! I moved Available into ReadZip, deleted CopyJar and merged GetDirEntry into ReadZip.readDirectoryEntries (adding a 'META-INF/' directory just in case)

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 14, 2023
@eirbjo
Copy link
Contributor Author

eirbjo commented Dec 14, 2023

(though CopyZipFile could use a junit conversion ;-)

Agreed, I have included that conversion in this PR :-) This test can make good use of assertThrows and splitting different concerns into separate test methods.

@eirbjo
Copy link
Contributor Author

eirbjo commented Dec 14, 2023

Seeing that ReadAfterClose.java uses a binary test vector crash.jar, I think it makes sense to include it in this PR, convert it to JUnit and move it into ReadZip.readAfterClose.

This removes the last remaining binary test vector ZIP in the ZipFile/ directory.

@eirbjo eirbjo changed the title 8321616: Retire binary test vectors ZipFile/input.jar and ZipFile/input.zip 8321616: Retire binary test vectors in test/jdk/java/util/zip/ZipFile Dec 14, 2023
@LanceAndersen
Copy link
Contributor

Seeing that ReadAfterClose.java uses a binary test vector crash.jar, I think it makes sense to include it in this PR, convert it to JUnit and move it into ReadZip.readAfterClose.

This removes the last remaining binary test vector ZIP in the ZipFile/ directory.

These are on my list to review, thank you for the update.

One comment, for the tests that we are removing/retiring, we probably want to include the bug numbers and/or the name of the original test class in the new home for the tests to make it easier for future maintainers to chase back the history in the unlikely event that an issue arises...

@eirbjo
Copy link
Contributor Author

eirbjo commented Jan 2, 2024

/issue add 8322830

@openjdk
Copy link

openjdk bot commented Jan 2, 2024

@eirbjo
Adding additional issue to issue list: 8322830: Add test case for ZipFile opening a ZIP with no entries.

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Changes look fine. Probably need to change the copyright from 2023 -> 2024

// Create zip file with Zip64 end
URI uri = URI.create("jar:" + zip.toUri());
Map<String, Object> env = Map.of("create", "true", "forceZIP64End", "true");
try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No Need to use a URI here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

test/jdk/java/util/zip/ZipFile/ReadZip.java Outdated Show resolved Hide resolved
// ZIP64 end record
if (Files.notExists(Paths.get("/usr/bin/zip")))
/**
* Read a zip file created via "echo hello | zip dst.zip -",
Copy link
Contributor

Choose a reason for hiding this comment

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

This was created using info-zip so I would clarify in the comments

*/
@Test
public void readZip64EndZipProcess() throws IOException, InterruptedException {
if (Files.notExists(Paths.get("/usr/bin/zip"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should address this as the test won't run on Windows. It would be better to store the zip as a byte array so that it can be processed on all platforms and by removing ProcessBuilder, the test run will speed up a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comment to reference Info-ZIP. Updated the code to read the ZIP from a hex-encoded string.

@openjdk
Copy link

openjdk bot commented Jan 8, 2024

@eirbjo This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8321616: Retire binary test vectors in test/jdk/java/util/zip/ZipFile
8322830: Add test case for ZipFile opening a ZIP with no entries

Reviewed-by: lancea

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 165 new commits pushed to the master branch:

  • e70cb4e: 8322565: (zipfs) Files.setPosixPermissions should preserve 'external file attributes' bits
  • d89602a: 8322982: CTW fails to build after 8308753
  • 3bd9042: 8320788: The system properties page is missing some properties
  • 525063b: 8322878: Including sealing information Class.toGenericString()
  • c1282b5: 8323540: assert((!((((method)->is_trace_flag_set(((1 << 4) << 8))))))) failed: invariant
  • 5ba69e1: 8322477: order of subclasses in the permits clause can differ between compilations
  • c96cbe4: 8313083: Print 'rss' and 'cache' as part of the container information
  • a7db4fe: 8323428: Shenandoah: Unused memory in regions compacted during a full GC should be mangled
  • b86c3b7: 8309218: java/util/concurrent/locks/Lock/OOMEInAQS.java still times out with ZGC, Generational ZGC, and SerialGC
  • 475306b: 7057369: (fs spec) FileStore getUsableSpace and getUnallocatedSpace could be clearer
  • ... and 155 more: https://git.openjdk.org/jdk/compare/e2042421187dafc1aea75ffe15caf8beb824205b...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 8, 2024
@eirbjo
Copy link
Contributor Author

eirbjo commented Jan 9, 2024

Changes look fine. Probably need to change the copyright from 2023 -> 2024

No IP was produced in 2024 for most of these files, but I've updated them anyhow.

@eirbjo
Copy link
Contributor Author

eirbjo commented Jan 9, 2024

Thanks for your review, @LanceAndersen!

You might want to take a quick look at the lastest updates addressing your review before I integrate.

@LanceAndersen
Copy link
Contributor

Thanks for your review, @LanceAndersen!

You might want to take a quick look at the lastest updates addressing your review before I integrate.

Looks good. I am running mach5 tiers1-3 internally once it completes, I will approve again

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Internal mach5 tiers 1-3 completed

@eirbjo
Copy link
Contributor Author

eirbjo commented Jan 11, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Jan 11, 2024

Going to push as commit 26de9e2.
Since your change was applied there have been 166 commits pushed to the master branch:

  • b530c02: 8317804: com/sun/jdi/JdwpAllowTest.java fails on Alpine 3.17 / 3.18
  • e70cb4e: 8322565: (zipfs) Files.setPosixPermissions should preserve 'external file attributes' bits
  • d89602a: 8322982: CTW fails to build after 8308753
  • 3bd9042: 8320788: The system properties page is missing some properties
  • 525063b: 8322878: Including sealing information Class.toGenericString()
  • c1282b5: 8323540: assert((!((((method)->is_trace_flag_set(((1 << 4) << 8))))))) failed: invariant
  • 5ba69e1: 8322477: order of subclasses in the permits clause can differ between compilations
  • c96cbe4: 8313083: Print 'rss' and 'cache' as part of the container information
  • a7db4fe: 8323428: Shenandoah: Unused memory in regions compacted during a full GC should be mangled
  • b86c3b7: 8309218: java/util/concurrent/locks/Lock/OOMEInAQS.java still times out with ZGC, Generational ZGC, and SerialGC
  • ... and 156 more: https://git.openjdk.org/jdk/compare/e2042421187dafc1aea75ffe15caf8beb824205b...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 11, 2024
@openjdk openjdk bot closed this Jan 11, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 11, 2024
@openjdk
Copy link

openjdk bot commented Jan 11, 2024

@eirbjo Pushed as commit 26de9e2.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants