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