Skip to content

Commit

Permalink
Fix IOKitTest for M1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Mar 12, 2022
1 parent 7ed3fa4 commit f95c5a1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 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,16 +146,24 @@ 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) {
long id = controllerDevice.getRegistryEntryID();
IORegistryEntry rootHubDevice = iter.next();
while (rootHubDevice != null) {
long id = rootHubDevice.getRegistryEntryID();
// EntryIDs 0 thru 19 are reserved, all are unique
assertTrue(id > 19);
assertFalse(uniqueEntryIdSet.contains(id));
uniqueEntryIdSet.add(id);

// The parent of this device in IOService plane is the controller
IORegistryEntry controllerDevice = rootHubDevice.getParentEntry(IO_SERVICE);
assertEquals(0, rootHubDevice.release());

// Get device name
String controllerName = controllerDevice.getName();
// Root controllers always begin with "AppleUSB"
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

0 comments on commit f95c5a1

Please sign in to comment.