1//
2//  ZoneTest.mm
3//  auto
4//
5//  Created by Patrick Beard on 11/1/10.
6//  Copyright 2010 Apple Inc. All rights reserved.
7//
8
9#import "Zone.h"
10#import "BlackBoxTest.h"
11
12using namespace Auto;
13
14@interface ZoneTest : BlackBoxTest
15@end
16
17@implementation ZoneTest
18
19- (void)performTest {
20    Zone *zone = (Zone *)[self auto_zone];
21    Thread &thread = zone->register_thread();
22    
23    void *large_block = zone->block_allocate(thread, 4 * allocate_quantum_large, AUTO_MEMORY_UNSCANNED, false, false);
24    Large *large = zone->block_start_large(large_block);
25    if (!large) {
26        [self fail:@"Zone::block_start_large() failed."];
27        [self testFinished];
28        return;
29    }
30    
31    bool in_large_bitmap = zone->in_large_bitmap(large_block); 
32    bool in_large_memory = zone->in_large_memory(large_block); 
33    if (!in_large_bitmap || !in_large_memory) {
34        [self fail:@"large_block should be in large memory!"];
35        [self testFinished];
36        return;
37    }
38    
39    void *non_block = displace(large_block, large->vm_size());
40    Large *non_large = zone->block_start_large(non_block);
41    if (non_large == large) {
42        [self fail:@"non_block should NOT be part of large!"];
43        [self testFinished];
44        return;
45    }
46    
47    [self setTestResult:PASSED message:@"zone tests passed."];
48    [self testFinished];
49}
50
51@end
52