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