1/* 2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * 30 */ 31 32#include <IOKit/IODeviceTreeSupport.h> 33#include <libkern/c++/OSContainers.h> 34#include <IOKit/IOLib.h> 35 36#include <assert.h> 37 38 39extern "C" { 40extern int debug_container_malloc_size; 41extern int debug_ivars_size; 42} 43 44static void DumpTree( void ) 45{ 46 IORegistryEntry * next; 47 IORegistryEntry * packages = 0; 48 IORegistryEntry * deblocker = 0; 49 IORegistryEntry * keyboard = 0; 50 IORegistryIterator * iter; 51 OSOrderedSet * all; 52 53 IOLog("ivars %08x, containers %08x\n", 54 debug_ivars_size, debug_container_malloc_size); 55 56 iter = IORegistryIterator::iterateOver( gIODTPlane ); 57 assert( iter ); 58 59 all = iter->iterateAll(); 60 IOLog("\nCount %d\n", all->getCount() ); 61 all->release(); 62 63 iter->reset(); 64 while( (next = iter->nextEntryRecursive())) { 65 if( 0 == strcmp( "packages", next->getName())) 66 packages = next; 67 if( 0 == strcmp( "deblocker", next->getName())) 68 deblocker = next; 69 if( 0 == strcmp( "keyboard", next->getName())) 70 keyboard = next; 71 } 72 73 if( deblocker && keyboard) 74 deblocker->attachToParent( keyboard, gIODTPlane); 75 76 iter->reset(); 77 while( (next = iter->nextEntryRecursive())) { 78 IOLog("%s=%d,", next->getName(), next->getDepth( gIODTPlane )); 79 if( 0 == strcmp( "gc", next->getName())) { 80 packages = next; 81 } 82 } 83 84 IOLog("ivars %08x, containers %08x\n", 85 debug_ivars_size, debug_container_malloc_size); 86 87 if( packages) 88 packages->detachAll( gIODTPlane); 89 all = iter->iterateAll(); 90 IOLog("del gc/, count now %d\n", all->getCount() ); 91 all->release(); 92 93 iter->release(); 94 95 IOLog("ivars %08x, containers %08x\n", 96 debug_ivars_size, debug_container_malloc_size); 97 98} 99 100extern "C" { 101void PathTests( void ) 102{ 103 const char * tests[] = { 104 "IODeviceTree:/bandit", 105 "IODeviceTree:/", 106 "IODeviceTree:/xxxx", 107 "IODeviceTree:/bandit/xxx", 108 "IODeviceTree:/bandit@F2000000", 109 "IODeviceTree:/bandit/gc", 110 "IODeviceTree:/bandit/gc/mace:17.202.42.95,\\mach_kernel", 111 "IODeviceTree:/bandit/@10/mesh", 112 "IODeviceTree:enet:17.202", 113 "IODeviceTree:scsi/@0:0", 114 "IODeviceTree:scsi-int", 115 "IODeviceTree:/bandit/gc@10/mesh", 116 "IODeviceTree:/bandit/gc/53c94/disk@0:6,mach_kernel", 117 "IOService:/", 118 "IOService:/ApplePlatformExpert", 119 "IOService:/ApplePlatformExpert/hammerhead@F8000000", 120 "IOService:/ApplePlatformExpert/bandit/AppleMacRiscPCI" 121 }; 122 123 IORegistryEntry * entry; 124 char str[256]; 125 int len; 126 127 for( unsigned int i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { 128 129 len = sizeof( str ); 130 entry = IORegistryEntry::fromPath( tests[i], 0, str, &len ); 131 IOLog("\"%s\" ", tests[i] ); 132 if( entry) { 133 IOLog("found %s, tail = \"%s\"\n", entry->getName(), str ); 134 len = sizeof( str ); 135 if( entry->getPath( str, &len, 136 IORegistryEntry::getPlane("IODeviceTree"))) { 137 IOLog("path = \"%s\"\n", str); 138 } 139 entry->release(); 140 } else 141 IOLog("not found\n"); 142 } 143} 144} 145 146void TestsCpp( void * dtTop ) 147{ 148 IORegistryEntry * dt; 149 150 IOLog("\nivars %08x, containers %08x\n", 151 debug_ivars_size, debug_container_malloc_size); 152 153 OSMetaClass::printInstanceCounts(); 154 dt = IODeviceTreeAlloc( dtTop ); 155 assert( dt ); 156 157// OSMetaClass::printInstanceCounts(); 158 DumpTree(); 159// OSMetaClass::printInstanceCounts(); 160 dt->detachAll( gIODTPlane); 161 OSMetaClass::printInstanceCounts(); 162 IOLog("ivars %08x, containers %08x\n", 163 debug_ivars_size, debug_container_malloc_size); 164} 165 166