diff --git a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java index e8adf1f00b..28d9607a09 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java @@ -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() { @@ -145,16 +146,24 @@ public void testIteratorParentChild() { Set uniqueEntryIdSet = new HashSet(); // 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" @@ -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); @@ -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)); }