diff options
| author | Andrey Loskutov | 2021-03-24 14:52:25 +0000 |
|---|---|---|
| committer | Andrey Loskutov | 2021-03-24 14:52:25 +0000 |
| commit | 09bb69aa67a0339779e60595227112c004cfd25d (patch) | |
| tree | 4b392dc73abc453ee748f2088156b17ecc8e7750 | |
| parent | 78de0d2d64a735454171b079f5f80ed8fb740cc5 (diff) | |
| download | eclipse.jdt.core-09bb69aa67a0339779e60595227112c004cfd25d.tar.gz eclipse.jdt.core-09bb69aa67a0339779e60595227112c004cfd25d.tar.xz eclipse.jdt.core-09bb69aa67a0339779e60595227112c004cfd25d.zip | |
Bug 571640 - JDT Gerrit tests failing with "Cannot run program lsof:I20210325-1800I20210324-1800
error=2"
DOn't ask for all files opened, just check concrete file in hand.
Change-Id: I7dbde74a0c90389adb84fab135183268866da6da
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
| -rw-r--r-- | org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java index 6f45710150..8ba47dc4e0 100644 --- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java +++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java @@ -14,11 +14,16 @@ package org.eclipse.jdt.core.tests.builder; import java.io.BufferedReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.eclipse.core.resources.IFile; @@ -36,6 +41,8 @@ public abstract class AbstractLeakTest extends BuilderTests { static boolean WINDOWS; static boolean LINUX; static boolean MAC; + static boolean lsofCheckDone; + static { String os = System.getProperty("os.name").toLowerCase(); WINDOWS = os.contains("windows"); @@ -69,6 +76,10 @@ public abstract class AbstractLeakTest extends BuilderTests { } private void internalTestUsedLibraryLeaks(int kind) throws Exception { + if(LINUX && !lsofCheckDone) { + selfTestLsof(); + } + String projectName = getName(); IPath projectPath = env.addProject(projectName, getCompatibilityLevel()); env.setOutputFolder(projectPath, ""); @@ -157,22 +168,42 @@ public abstract class AbstractLeakTest extends BuilderTests { } private void checkOpenDescriptors(IFile file) throws Exception { - List<String> openDescriptors = getOpenDescriptors(); - assertFalse("Failed to read opened file descriptors", openDescriptors.isEmpty()); - if(openDescriptors.contains(file.getLocation().toOSString())) { + List<String> processes = getProcessesOpenedFile(Paths.get(file.getLocation().toOSString())); + if(!processes.isEmpty()) { throw new IllegalStateException("File leaked during build: " + file); } } - private static List<String> getOpenDescriptors() throws Exception { + + private void selfTestLsof() throws Exception { + Path tempFile = Files.createTempFile("testLsof", "tmp"); + Files.deleteIfExists(tempFile); + Files.write(tempFile, "Hello\nselfTestLsof".getBytes()); + try(InputStream is = new FileInputStream(tempFile.toFile())){ + is.read(); + List<String> list = getProcessesOpenedFile(tempFile); + assertEquals("lsof doesn't work in this environment!", 1, list.size()); + lsofCheckDone = true; + } + } + + private static List<String> getProcessesOpenedFile(Path path) throws Exception { int pid = getPid(); - assertTrue("JVM PID must be > 0 : " + pid, pid > 0); + // assertTrue("JVM PID must be > 0 : " + pid, pid > 0); // -F n : to print only name column (note: all lines start with "n") // -a : to "and" all following options // -b :to avoid blocking calls // -p <pid>: to select process with opened files - List<String> lines = readLsofLines("lsof -F n -a -p " + pid + " -b", true); - return lines; + // List<String> lines = readLsofLines("lsof -F n -a -p " + pid + " -b", true); + + // Code above seem to hang... + List<String> lines = readLsofLines("lsof " + path, true); + for (String line : lines) { + if(line.contains("" + pid)) { + return lines; + } + } + return Collections.emptyList(); } private static int getPid() throws Exception { |
