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

Fix IOKitTest for M1 compatibility #1420

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class IOKitTest {
private static final SystemB SYS = SystemB.INSTANCE;

private static final String IO_SERVICE = "IOService";
private static final String IOUSB = "IOUSB";

@Test
public void testMatching() {
Expand Down Expand Up @@ -145,10 +146,18 @@ public void testIteratorParentChild() {
Set<Long> uniqueEntryIdSet = new HashSet<Long>();
// Iterate over USB Controllers. All devices are children of one of
// these controllers in the "IOService" plane
IOIterator iter = IOKitUtil.getMatchingServices("IOUSBController");
// On M1 the IOUSBController service doesn't exist so we navigate from root of
// IOUSB plane to find the Root Hubs which have a 1:1 correspondence with
// controllers
IORegistryEntry root = IOKitUtil.getRoot();
IOIterator iter = root.getChildIterator(IOUSB);
assertNotNull(iter);
IORegistryEntry controllerDevice = iter.next();
while (controllerDevice != null) {
IORegistryEntry rootHubDevice = iter.next();
while (rootHubDevice != null) {
// The parent of this device in IOService plane is the controller
IORegistryEntry controllerDevice = rootHubDevice.getParentEntry(IO_SERVICE);
assertEquals(0, rootHubDevice.release());

long id = controllerDevice.getRegistryEntryID();
// EntryIDs 0 thru 19 are reserved, all are unique
assertTrue(id > 19);
Expand All @@ -163,8 +172,6 @@ public void testIteratorParentChild() {
// Get the first child, to test vs. iterator
boolean testFirstChild = true;
IORegistryEntry firstChild = controllerDevice.getChildEntry(IO_SERVICE);
// If this returns non-null, we have at least one child entry to
// test. If not, the iterator will never check whether to test

// Now iterate the children of this device in the "IOService" plane.
IOIterator childIter = controllerDevice.getChildIterator(IO_SERVICE);
Expand Down Expand Up @@ -196,9 +203,10 @@ public void testIteratorParentChild() {

// Release this controller and iterate to the next one
assertEquals(0, controllerDevice.release());
controllerDevice = iter.next();
rootHubDevice = iter.next();
}
assertEquals(0, iter.release());
assertEquals(0, root.release());
assertEquals(0, SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort));
}

Expand Down