Skip to content

Commit

Permalink
8326591: New test JmodExcludedFiles.java fails on Windows when --with…
Browse files Browse the repository at this point in the history
…-external-symbols-in-bundles=public is used

Reviewed-by: mdoerr
Backport-of: 43c6f0b5880899b797fab2f851bd35be1c342439
  • Loading branch information
Sonia Zaldana Calles authored and TheRealMDoerr committed May 21, 2024
1 parent 1d6965f commit b8ee2aa
Showing 1 changed file with 45 additions and 18 deletions.
63 changes: 45 additions & 18 deletions test/jdk/jdk/modules/etc/JmodExcludedFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,78 @@
* @test
* @bug 8159927
* @modules java.base/jdk.internal.util
* @library /test/lib
* @run main JmodExcludedFiles
* @summary Test that JDK JMOD files do not include native debug symbols
*/

import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import jdk.test.lib.Platform;

public class JmodExcludedFiles {
private static String javaHome = System.getProperty("java.home");

public static void main(String[] args) throws Exception {
String javaHome = System.getProperty("java.home");
Path jmods = Path.of(javaHome, "jmods");
try (DirectoryStream<Path> stream = Files.newDirectoryStream(jmods, "*.jmod")) {
for (Path jmodFile : stream) {
try (ZipFile zip = new ZipFile(jmodFile.toFile())) {
JModSymbolFileMatcher jsfm = new JModSymbolFileMatcher(jmodFile.toString());
if (zip.stream().map(ZipEntry::getName)
.anyMatch(JmodExcludedFiles::isNativeDebugSymbol)) {
.anyMatch(jsfm::isNativeDebugSymbol)) {
throw new RuntimeException(jmodFile + " is expected not to include native debug symbols");
}
}
}
}
}

private static boolean isNativeDebugSymbol(String name) {
int index = name.indexOf("/");
if (index < 0) {
throw new RuntimeException("unexpected entry name: " + name);
static class JModSymbolFileMatcher {
private String jmod;

JModSymbolFileMatcher(String jmod) {
this.jmod = jmod;
}
String section = name.substring(0, index);
if (section.equals("lib") || section.equals("bin")) {
if (System.getProperty("os.name").toLowerCase().contains("os x")) {
String n = name.substring(index+1);
int i = n.indexOf("/");
if (i != -1) {
return n.substring(0, i).endsWith(".dSYM");

boolean isNativeDebugSymbol(String name) {
int index = name.indexOf("/");
if (index < 0) {
throw new RuntimeException("unexpected entry name: " + name);
}
String section = name.substring(0, index);
if (section.equals("lib") || section.equals("bin")) {
if (Platform.isOSX()) {
String n = name.substring(index + 1);
int i = n.indexOf("/");
if (i != -1) {
if (n.substring(0, i).endsWith(".dSYM")) {
System.err.println("Found symbols in " + jmod + ": " + name);
return true;
}
}
}
if (Platform.isWindows() && name.endsWith(".pdb")) {
// on Windows we check if we should have public symbols through --with-external-symbols-in-bundles=public (JDK-8237192)
String strippedpdb = javaHome + "/bin/" + name.substring(index + 1, name.length() - 4) + ".stripped.pdb";
if (!Files.exists(Paths.get(strippedpdb))) {
System.err.println("Found symbols in " + jmod + ": " + name +
". No stripped pdb file " + strippedpdb + " exists.");
return true;
}
}
if (name.endsWith(".diz")
|| name.endsWith(".debuginfo")
|| name.endsWith(".map")) {
System.err.println("Found symbols in " + jmod + ": " + name);
return true;
}
}
return name.endsWith(".diz")
|| name.endsWith(".debuginfo")
|| name.endsWith(".map")
|| name.endsWith(".pdb");
return false;
}
return false;
}
}

1 comment on commit b8ee2aa

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.