Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- * * Copyright (c) 2021 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #import <XCTest/XCTest.h> #include "NewSharedCacheBuilder.h" #include "BuilderFileSystem.h" using namespace cache_builder; @interface CacheLayoutTests : XCTestCase @end @implementation CacheLayoutTests { // Everyone shares a default file system const FileSystemMRM fileSystem; // Parameters to Options //std::string_view archName; //dyld3::Platform platform; bool dylibsRemovedFromDisk; bool isLocallyBuiltCache; CacheKind cacheKind; bool forceDevelopmentSubCacheSuffix; } - (void)setUp { // Put setup code here. This method is called before the invocation of each test method in the class. // Reset default options dylibsRemovedFromDisk = true; isLocallyBuiltCache = true; cacheKind = CacheKind::development; forceDevelopmentSubCacheSuffix = false; } - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. } // macOS caches should have no .development or other suffixes, just the number - (void)testSubCacheNames_macOS { // Arrange: mock up builder and subcaches cache_builder::BuilderOptions options("x86_64", dyld3::Platform::macOS, dylibsRemovedFromDisk, isLocallyBuiltCache, cacheKind, forceDevelopmentSubCacheSuffix); SharedCacheBuilder builder(options, fileSystem); // Add a main subCache builder.subCaches.reserve(3); SubCache& mainSubCache = builder.subCaches.emplace_back(SubCache::makeMainCache(options, true)); SubCache& subCache1 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& subCache2 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); mainSubCache.subCaches.push_back(&subCache1); mainSubCache.subCaches.push_back(&subCache2); // Act: builder.setSubCacheNames(); // Assert: XCTAssertTrue(mainSubCache.fileSuffix == ""); XCTAssertTrue(subCache1.fileSuffix == ".01"); XCTAssertTrue(subCache2.fileSuffix == ".02"); } // Simulator caches should have no .development or other suffixes, just the number - (void)testSubCacheNames_iOS_Simulator { // Arrange: mock up builder and subcaches cache_builder::BuilderOptions options("arm64", dyld3::Platform::iOS_simulator, dylibsRemovedFromDisk, isLocallyBuiltCache, cacheKind, forceDevelopmentSubCacheSuffix); SharedCacheBuilder builder(options, fileSystem); // Add a main subCache builder.subCaches.reserve(3); SubCache& mainSubCache = builder.subCaches.emplace_back(SubCache::makeMainCache(options, true)); SubCache& subCache1 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& subCache2 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); mainSubCache.subCaches.push_back(&subCache1); mainSubCache.subCaches.push_back(&subCache2); // Act: builder.setSubCacheNames(); // Assert: XCTAssertTrue(mainSubCache.fileSuffix == ""); XCTAssertTrue(subCache1.fileSuffix == ".01"); XCTAssertTrue(subCache2.fileSuffix == ".02"); } // iOS development main caches should end in .developent // iOS sub caches shouldn't have an extension - (void)testSubCacheNames_iOS_development { // Arrange: mock up builder and subcaches cacheKind = CacheKind::universal; cache_builder::BuilderOptions options("arm64", dyld3::Platform::iOS, dylibsRemovedFromDisk, isLocallyBuiltCache, cacheKind, forceDevelopmentSubCacheSuffix); SharedCacheBuilder builder(options, fileSystem); // Add a main subCache builder.subCaches.reserve(3); SubCache& mainSubCache = builder.subCaches.emplace_back(SubCache::makeMainCache(options, true)); SubCache& subCache1 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& subCache2 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); mainSubCache.subCaches.push_back(&subCache1); mainSubCache.subCaches.push_back(&subCache2); // Act: builder.setSubCacheNames(); // Assert: XCTAssertTrue(mainSubCache.fileSuffix == ".development"); XCTAssertTrue(subCache1.fileSuffix == ".01"); XCTAssertTrue(subCache2.fileSuffix == ".02"); } // iOS customer main caches should have no extension // iOS sub caches shouldn't have an extension - (void)testSubCacheNames_iOS_customer { // Arrange: mock up builder and subcaches cacheKind = CacheKind::universal; cache_builder::BuilderOptions options("arm64", dyld3::Platform::iOS, dylibsRemovedFromDisk, isLocallyBuiltCache, cacheKind, forceDevelopmentSubCacheSuffix); SharedCacheBuilder builder(options, fileSystem); // Add a main subCache builder.subCaches.reserve(3); SubCache& mainSubCache = builder.subCaches.emplace_back(SubCache::makeMainCache(options, false)); SubCache& subCache1 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& subCache2 = builder.subCaches.emplace_back(SubCache::makeSubCache(options)); mainSubCache.subCaches.push_back(&subCache1); mainSubCache.subCaches.push_back(&subCache2); // Act: builder.setSubCacheNames(); // Assert: XCTAssertTrue(mainSubCache.fileSuffix == ""); XCTAssertTrue(subCache1.fileSuffix == ".01"); XCTAssertTrue(subCache2.fileSuffix == ".02"); } // This combines all of the above names // main caches should have either .development or no extension // sub caches should either no extension, .dylddata, or .dyldlinkedit // stub caches should have no extension or .development // symbols files should end in .symbols - (void)testSubCacheNames_iOS_universal { // Arrange: mock up builder and subcaches cacheKind = CacheKind::universal; cache_builder::BuilderOptions options("arm64", dyld3::Platform::iOS, dylibsRemovedFromDisk, isLocallyBuiltCache, cacheKind, forceDevelopmentSubCacheSuffix); SharedCacheBuilder builder(options, fileSystem); auto& subCaches = builder.subCaches; // Add the following: // main dev cache // main customer cache // text subcache // stubs dev cache // stubs customer cache // text subcache // stubs dev cache // stubs customer cache // data sub cache // linkedit sub cache // text subcache // stubs dev cache // stubs customer cache // text subcache // stubs dev cache // stubs customer cache // data sub cache // linkedit sub cache subCaches.reserve(20); SubCache& mainDevCache = subCaches.emplace_back(SubCache::makeMainCache(options, true)); SubCache& mainCustCache = subCaches.emplace_back(SubCache::makeMainCache(options, false)); SubCache& textCache1 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& stubsDevCache2 = subCaches.emplace_back(SubCache::makeStubsCache(options, true)); SubCache& stubsCustCache2 = subCaches.emplace_back(SubCache::makeStubsCache(options, false)); SubCache& textCache3 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& stubsDevCache4 = subCaches.emplace_back(SubCache::makeStubsCache(options, true)); SubCache& stubsCustCache4 = subCaches.emplace_back(SubCache::makeStubsCache(options, false)); SubCache& dataCache5 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& linkeditCache6 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& textCache7 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& stubsDevCache8 = subCaches.emplace_back(SubCache::makeStubsCache(options, true)); SubCache& stubsCustCache8 = subCaches.emplace_back(SubCache::makeStubsCache(options, false)); SubCache& textCache9 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& stubsDevCache10 = subCaches.emplace_back(SubCache::makeStubsCache(options, true)); SubCache& stubsCustCache10 = subCaches.emplace_back(SubCache::makeStubsCache(options, false)); SubCache& dataCache11 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& linkeditCache12 = subCaches.emplace_back(SubCache::makeSubCache(options)); SubCache& symbolsCache = subCaches.emplace_back(SubCache::makeSymbolsCache()); // Add some data/linkedit to the required subcaches ObjCStringsChunk dataChunk1; ObjCStringsChunk linkeditChunk1; ObjCStringsChunk dataChunk2; ObjCStringsChunk dataConstChunk2; ObjCStringsChunk authChunk2; ObjCStringsChunk authConstChunk2; ObjCStringsChunk linkeditChunk2; dataCache5.addDataChunk(&dataChunk1); linkeditCache6.addLinkeditChunk(&linkeditChunk1); dataCache11.addDataChunk(&dataChunk2); dataCache11.addDataConstChunk(&dataConstChunk2); dataCache11.addAuthChunk(&authChunk2); dataCache11.addAuthConstChunk(&authConstChunk2); linkeditCache12.addLinkeditChunk(&linkeditChunk2); // Track all subCaches on the main caches // Development mainDevCache.subCaches.push_back(&textCache1); mainDevCache.subCaches.push_back(&stubsDevCache2); mainDevCache.subCaches.push_back(&textCache3); mainDevCache.subCaches.push_back(&stubsDevCache4); mainDevCache.subCaches.push_back(&dataCache5); mainDevCache.subCaches.push_back(&linkeditCache6); mainDevCache.subCaches.push_back(&textCache7); mainDevCache.subCaches.push_back(&stubsDevCache8); mainDevCache.subCaches.push_back(&textCache9); mainDevCache.subCaches.push_back(&stubsDevCache10); mainDevCache.subCaches.push_back(&dataCache11); mainDevCache.subCaches.push_back(&linkeditCache12); // Customer mainCustCache.subCaches.push_back(&textCache1); mainCustCache.subCaches.push_back(&stubsCustCache2); mainCustCache.subCaches.push_back(&textCache3); mainCustCache.subCaches.push_back(&stubsCustCache4); mainCustCache.subCaches.push_back(&dataCache5); mainCustCache.subCaches.push_back(&linkeditCache6); mainCustCache.subCaches.push_back(&textCache7); mainCustCache.subCaches.push_back(&stubsCustCache8); mainCustCache.subCaches.push_back(&textCache9); mainCustCache.subCaches.push_back(&stubsCustCache10); mainCustCache.subCaches.push_back(&dataCache11); mainCustCache.subCaches.push_back(&linkeditCache12); // Act: builder.setSubCacheNames(); // Assert: XCTAssertTrue(mainDevCache.fileSuffix == ".development"); XCTAssertTrue(mainCustCache.fileSuffix == ""); XCTAssertTrue(textCache1.fileSuffix == ".01"); XCTAssertTrue(stubsDevCache2.fileSuffix == ".02.development"); XCTAssertTrue(stubsCustCache2.fileSuffix == ".02"); XCTAssertTrue(textCache3.fileSuffix == ".03"); XCTAssertTrue(stubsDevCache4.fileSuffix == ".04.development"); XCTAssertTrue(stubsCustCache4.fileSuffix == ".04"); XCTAssertTrue(dataCache5.fileSuffix == ".05.dylddata"); XCTAssertTrue(linkeditCache6.fileSuffix == ".06.dyldlinkedit"); XCTAssertTrue(textCache7.fileSuffix == ".07"); XCTAssertTrue(stubsDevCache8.fileSuffix == ".08.development"); XCTAssertTrue(stubsCustCache8.fileSuffix == ".08"); XCTAssertTrue(textCache9.fileSuffix == ".09"); XCTAssertTrue(stubsDevCache10.fileSuffix == ".10.development"); XCTAssertTrue(stubsCustCache10.fileSuffix == ".10"); XCTAssertTrue(dataCache11.fileSuffix == ".11.dylddata"); XCTAssertTrue(linkeditCache12.fileSuffix == ".12.dyldlinkedit"); XCTAssertTrue(symbolsCache.fileSuffix == ".symbols"); } @end |