1/* 2 * Copyright (c) 2011 Apple Inc. All rights reserved. 3 * 4 * @APPLE_APACHE_LICENSE_HEADER_START@ 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * @APPLE_APACHE_LICENSE_HEADER_END@ 19 */ 20// 21// WhiteBoxTest.m 22// Copyright (c) 2009-2011 Apple Inc. All rights reserved. 23// 24 25#import "WhiteBoxTest.h" 26 27@implementation WhiteBoxTest 28 29static BOOL _skip; 30 31/* Test probe functions */ 32#define PROBE_IMPL(message) do { WhiteBoxTest *script = [TestCase currentTestCase]; if (script) { message;}} while (0) 33 34static void auto_probe_auto_zone_collect(auto_zone_options_t options) 35{ 36 PROBE_IMPL([script autoZoneCollect:options]); 37} 38 39static void auto_probe_admin_deallocate(void *address) 40{ 41 PROBE_IMPL([script adminDeallocate:address]); 42} 43 44static void auto_probe_begin_heap_scan(boolean_t generational) 45{ 46 PROBE_IMPL([script beginHeapScan:generational]); 47} 48 49static void auto_probe_begin_local_scan() 50{ 51 PROBE_IMPL([script beginLocalScan]); 52} 53 54static void auto_probe_collection_complete() 55{ 56 PROBE_IMPL([script collectionComplete]); 57} 58 59static void auto_probe_end_heap_scan(size_t garbage_count, void **garbage_blocks) 60{ 61 PROBE_IMPL([script endHeapScanWithGarbage:garbage_blocks count:garbage_count]); 62} 63 64static void auto_probe_end_local_scan(size_t garbage_count, void **garbage_blocks) 65{ 66 PROBE_IMPL([script endLocalScanWithGarbage:garbage_blocks count:garbage_count]); 67} 68 69static void auto_scan_barrier() 70{ 71 PROBE_IMPL([script scanBarrier]); 72} 73 74static void auto_probe_end_thread_scan() 75{ 76 PROBE_IMPL([script endThreadScan]); 77} 78 79static void auto_probe_heap_collection_complete() 80{ 81 PROBE_IMPL([script heapCollectionComplete]); 82} 83 84static void auto_probe_local_collection_complete() 85{ 86 PROBE_IMPL([script localCollectionComplete]); 87} 88 89static void auto_probe_mature(void *address, unsigned char age) 90{ 91 PROBE_IMPL([script blockMatured:address newAge:age]); 92} 93 94static void auto_probe_make_global(void *address, unsigned char age) 95{ 96 PROBE_IMPL([script blockBecameGlobal:address withAge:age]); 97} 98 99static void auto_probe_scan_range(void *address, void *end) 100{ 101 PROBE_IMPL([script scanBlock:address endAddress:end]); 102} 103 104static void auto_probe_scan_with_layout(void *address, void *end, const unsigned char *map) 105{ 106 PROBE_IMPL([script scanBlock:address endAddress:end withLayout:map]); 107} 108 109static void auto_probe_did_scan_with_layout(void *address, void *end, const unsigned char *map) 110{ 111 PROBE_IMPL([script didScanBlock:address endAddress:end withLayout:map]); 112} 113 114static void auto_probe_set_pending(void *block) 115{ 116 PROBE_IMPL([script setPending:block]); 117} 118 119static void auto_probe_unregistered_thread_error() 120{ 121 PROBE_IMPL([script threadRegistrationError]); 122} 123 124AutoProbeFunctions auto_tester_probe_runctions = { 125 auto_probe_auto_zone_collect, 126 auto_probe_admin_deallocate, 127 auto_probe_begin_heap_scan, 128 auto_probe_begin_local_scan, 129 auto_probe_collection_complete, 130 auto_probe_end_heap_scan, 131 auto_probe_end_local_scan, 132 auto_scan_barrier, 133 auto_probe_end_thread_scan, 134 auto_probe_heap_collection_complete, 135 auto_probe_local_collection_complete, 136 auto_probe_mature, 137 auto_probe_make_global, 138 auto_probe_scan_range, 139 auto_probe_scan_with_layout, 140 auto_probe_did_scan_with_layout, 141 auto_probe_set_pending, 142 auto_probe_unregistered_thread_error, 143}; 144 145 146+ (void)initialize 147{ 148 if ([WhiteBoxTest class] == self) { 149 if (!auto_set_probe_functions(&auto_tester_probe_runctions)) { 150 _skip = YES; 151 } else { 152 auto_set_probe_functions(NULL); 153 } 154 } 155} 156 157- (NSString *)shouldSkip 158{ 159 if (_skip) 160 return @"Probe callouts not present in loaded version of libauto."; 161 else 162 return [super shouldSkip]; 163} 164 165- (void)startTest 166{ 167 auto_set_probe_functions(&auto_tester_probe_runctions); 168 [super startTest]; 169} 170 171- (void)testFinished 172{ 173 auto_set_probe_functions(NULL); 174 [super testFinished]; 175} 176 177/* 178 Methods invoked via probe points in the collector, in alphabetical order. 179 */ 180- (void)autoZoneCollect:(auto_zone_options_t)options 181{ 182} 183 184- (void)adminDeallocate:(void *)address 185{ 186} 187 188- (void)beginHeapScan:(BOOL)generational 189{ 190} 191 192- (void)beginLocalScan 193{ 194} 195 196- (void)blockBecameGlobal:(void *)block withAge:(uint32_t)age 197{ 198} 199 200- (void)blockMatured:(void *)block newAge:(uint32_t)age 201{ 202} 203 204- (void)collectionComplete 205{ 206} 207 208- (void)endHeapScanWithGarbage:(void **)garbage_list count:(size_t)count 209{ 210} 211 212- (void)endLocalScanWithGarbage:(void **)garbage_list count:(size_t)count 213{ 214} 215 216- (void)scanBarrier 217{ 218} 219 220- (void)endThreadScan 221{ 222} 223 224- (void)heapCollectionComplete 225{ 226} 227 228- (void)localCollectionComplete 229{ 230} 231 232- (void)scanBlock:(void *)block endAddress:(void *)end 233{ 234} 235 236- (void)scanBlock:(void *)block endAddress:(void *)end withLayout:(const unsigned char *)map 237{ 238} 239 240- (void)didScanBlock:(void *)block endAddress:(void *)end withLayout:(const unsigned char *)map 241{ 242} 243 244- (void)setPending:(void *)block 245{ 246} 247 248- (void)threadRegistrationError 249{ 250} 251 252@end 253