Cotton code
40 lines · 2.3 KB · PythonRaw
import importlib.utilfrom pathlib import Pathimport tempfileimport unittestspec = importlib.util.spec_from_file_location('speed_runtime', Path(__file__).with_name('runtime.py'))runtime = importlib.util.module_from_spec(spec)spec.loader.exec_module(runtime)PHONES = [{'name': 'iPhone 16', 'identifier': 'phone-16'}, {'name': 'iPhone 17', 'identifier': 'phone-17'},          {'name': 'iPad Pro', 'identifier': 'pad'}]def ios(version, build):    return {'identifier': f'com.apple.CoreSimulator.SimRuntime.iOS-{version.replace(".", "-")}',            'version': version, 'buildversion': build, 'name': f'iOS {version}', 'isAvailable': True}class SpeedRuntimeTests(unittest.TestCase):    # RULE: A speed figure is measured on the newest iOS runtime whose dyld_sim shared cache exists on the host, when one exists; a runtime with no cache loads every framework by hand and doubled the cold start (2.6 s vs 1.1-1.3 s, 14 Oct 2026); with no usable runtime the measurement refuses rather than report a simulator cost as the app's.    def test_newest_runtime_with_a_dyld_cache_wins(self):        with tempfile.TemporaryDirectory() as caches:            caches = Path(caches)            old, new = ios('26.5', '23F77'), ios('27.0', '24A434')            cache = caches / 'HOST' / f"{old['identifier']}.23F77"            cache.mkdir(parents=True)            (cache / 'dyld_sim_shared_cache_arm64').write_bytes(b'')            self.assertEqual(runtime.choose(PHONES, [old, new], 'HOST', 'arm64', caches),                             ('phone-17', old['identifier'], 'iOS 26.5'))            cache = caches / 'HOST' / f"{new['identifier']}.24A434"            cache.mkdir(parents=True)            (cache / 'dyld_sim_shared_cache_arm64').write_bytes(b'')            self.assertEqual(runtime.choose(PHONES, [old, new], 'HOST', 'arm64', caches)[1], new['identifier'])            # RULE: Without any cached runtime the newest runtime is measured and the figure's runtime name says "(no dyld cache)" — a cut is never refused for a simulator cache (speed is report-only until 1 Nov 2026).            self.assertEqual(runtime.choose(PHONES, [old, new], 'OTHER-HOST', 'arm64', caches),                             ('phone-17', new['identifier'], 'iOS 27.0 (no dyld cache)'))if __name__ == '__main__':    unittest.main()