Skip to content

Commit 3b50850

Browse files
Diagnose JUnit Test
1 parent 17f4e59 commit 3b50850

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

contrib/platform/test/com/sun/jna/platform/linux/UdevTest.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.sun.jna.platform.linux.Udev.UdevDevice;
3030
import com.sun.jna.platform.linux.Udev.UdevEnumerate;
3131
import com.sun.jna.platform.linux.Udev.UdevListEntry;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
3234

3335
import junit.framework.TestCase;
3436

@@ -37,6 +39,8 @@
3739
*/
3840
public class UdevTest extends TestCase {
3941

42+
private static final Pattern SCSI_DISK_PATTERN = Pattern.compile(".*/sd[a-z](\\d+)$");
43+
4044
@Test
4145
public void testEnumerateDevices() {
4246
// Start with the context object
@@ -74,29 +78,40 @@ public void testEnumerateDevices() {
7478
// No additional reference is acquired from getParent
7579
if (parent != null && parent2 != null) {
7680
// Devnode should match same parent without restricting to block and disk
77-
assertEquals("Partition parent should match with and without filter",
81+
assertEquals(String.format(
82+
"Partition parent should match with and without filter (%s)",
83+
devnode
84+
),
7885
parent.getDevnode(), parent2.getDevnode());
7986
// Save the size and major
8087
parentSize = parent.getSysattrValue("size");
8188
parentMajor = parent.getPropertyValue("MAJOR");
8289
}
8390
}
8491
String size = device.getSysattrValue("size");
85-
assertTrue("Size must be nonnegative", 0 <= Long.parseLong(size));
92+
assertTrue(String.format("Size must be nonnegative (%s)", devnode), 0 <= Long.parseLong(size));
8693
if (parentSize != null) {
87-
assertTrue("Partition can't be bigger than its disk",
94+
assertTrue(String.format("Partition can't be bigger than its disk (%s)", devnode),
8895
Long.parseLong(size) <= Long.parseLong(parentSize));
8996
}
9097
String major = device.getPropertyValue("MAJOR");
91-
assertTrue("Major value must be nonnegative", 0 <= Long.parseLong(major));
98+
assertTrue(String.format("Major value must be nonnegative (%s)", devnode), 0 <= Long.parseLong(major));
9299
if (parentMajor != null) {
93-
assertEquals("Partition and its parent disk should have same major number", major,
94-
parentMajor);
100+
// For scsi disks only the first 15 Partitions have the
101+
// same major as their disk
102+
Matcher scsiMatcher = SCSI_DISK_PATTERN.matcher(devnode);
103+
boolean scsiDiskDynamicMinor = scsiMatcher.matches() && Integer.parseInt(scsiMatcher.group(1)) > 15;
104+
if(! scsiDiskDynamicMinor) {
105+
assertEquals(
106+
String.format("Partition and its parent disk should have same major number (%s)", devnode),
107+
major, parentMajor
108+
);
109+
}
95110
}
96-
assertEquals("DevType mismatch", devType, device.getDevtype());
97-
assertEquals("Subsystem mismatch", "block", device.getSubsystem());
98-
assertEquals("Syspath mismatch", syspath, device.getSyspath());
99-
assertTrue("Syspath should end with name", syspath.endsWith(device.getSysname()));
111+
assertEquals(String.format("DevType mismatch (%s)", devnode), devType, device.getDevtype());
112+
assertEquals(String.format("Subsystem mismatch (%s)", devnode), "block", device.getSubsystem());
113+
assertEquals(String.format("Syspath mismatch (%s)", devnode), syspath, device.getSyspath());
114+
assertTrue(String.format("Syspath should end with name (%s)", devnode), syspath.endsWith(device.getSysname()));
100115
}
101116
} finally {
102117
// Release the reference and iterate to the next device

0 commit comments

Comments
 (0)