|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +// OtherResources=macos_dual_mapping_smoke_script.dart |
| 6 | + |
| 7 | +// Tests that dual mapping works on Mac OS. This is a smoke test for |
| 8 | +// functionality enabled in development mode on iOS 26 devices. |
| 9 | +// |
| 10 | +// To test this code path we use --force_dual_mapping_of_code_pages which |
| 11 | +// assumes that VM does not execute from a snapshot. Hence the need to run |
| 12 | +// from Kernel directly. |
| 13 | + |
| 14 | +import 'dart:io' show Platform, File; |
| 15 | + |
| 16 | +import 'package:expect/expect.dart'; |
| 17 | +import 'package:path/path.dart' as path; |
| 18 | +import 'snapshot_test_helper.dart'; |
| 19 | + |
| 20 | +compileAndRunMinimalDillTest(List<String> extraCompilationArgs) async { |
| 21 | + final testScriptUri = Platform.script.resolve( |
| 22 | + 'macos_dual_mapping_smoke_script.dart', |
| 23 | + ); |
| 24 | + final message = 'Round_trip_message'; |
| 25 | + final expectedResponse = '42$message'; |
| 26 | + |
| 27 | + await withTempDir((String temp) async { |
| 28 | + final minimalDillPath = path.join(temp, 'test.dill'); |
| 29 | + await runGenKernel('BUILD DILL FILE', [ |
| 30 | + '--no-link-platform', |
| 31 | + ...extraCompilationArgs, |
| 32 | + '--output=$minimalDillPath', |
| 33 | + testScriptUri.toFilePath(), |
| 34 | + ]); |
| 35 | + |
| 36 | + { |
| 37 | + final result = await runDart('RUN FROM DILL FILE', [ |
| 38 | + minimalDillPath, |
| 39 | + message, |
| 40 | + ]); |
| 41 | + expectOutput(expectedResponse, result); |
| 42 | + } |
| 43 | + |
| 44 | + final String unsignedDartExecutable; |
| 45 | + final entitlementsInfo = (await runBinary( |
| 46 | + 'CHECKING ENTITLEMENTS', |
| 47 | + 'codesign', |
| 48 | + ['-d', '--entitlements', '-', '--xml', Platform.executable], |
| 49 | + allowNonZeroExitCode: true, |
| 50 | + )).processResult; |
| 51 | + Expect.isTrue(entitlementsInfo.stderr.startsWith('Executable=')); |
| 52 | + if (entitlementsInfo.stdout.contains('<?xml') && |
| 53 | + !entitlementsInfo.stdout.contains( |
| 54 | + 'com.apple.security.cs.allow-unsigned-executable-memory', |
| 55 | + )) { |
| 56 | + // Non-empty entitlements without |
| 57 | + // com.apple.security.cs.allow-unsigned-executable-memory will make |
| 58 | + // this test fail so strip them. |
| 59 | + unsignedDartExecutable = path.join(temp, 'dart'); |
| 60 | + File(Platform.executable).copySync(unsignedDartExecutable); |
| 61 | + await runBinary('REMOVING SIGNATURE', 'codesign', [ |
| 62 | + '--remove-signature', |
| 63 | + unsignedDartExecutable, |
| 64 | + ]); |
| 65 | + await runBinary('RESIGNING', 'codesign', [ |
| 66 | + '-s', |
| 67 | + '-', |
| 68 | + unsignedDartExecutable, |
| 69 | + ]); |
| 70 | + } else { |
| 71 | + unsignedDartExecutable = Platform.executable; |
| 72 | + } |
| 73 | + |
| 74 | + { |
| 75 | + final result = await runDart('RUN FROM DILL FILE', [ |
| 76 | + '--force_dual_mapping_of_code_pages', |
| 77 | + minimalDillPath, |
| 78 | + message, |
| 79 | + ], dartExecutable: unsignedDartExecutable); |
| 80 | + expectOutput(expectedResponse, result); |
| 81 | + } |
| 82 | + }); |
| 83 | +} |
| 84 | + |
| 85 | +void main() async { |
| 86 | + // Only supported on MacOS. |
| 87 | + if (!Platform.isMacOS || isAOTRuntime) { |
| 88 | + return; |
| 89 | + } |
| 90 | + await compileAndRunMinimalDillTest([]); |
| 91 | +} |
0 commit comments