| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, 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 // Test generating and running a simple precompiled snapshot of this script. | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 | |
| 9 main(List args) { | |
| 10 if (args.length > 0 && args[0] == "--hello") { | |
| 11 print("Hello"); | |
| 12 return; | |
| 13 } | |
| 14 | |
| 15 var cc, cc_flags, shared, libname; | |
| 16 if (Platform.isLinux) { | |
| 17 cc = 'gcc'; | |
| 18 shared = '-shared'; | |
| 19 libname = 'libprecompiled.so'; | |
| 20 } else if (Platform.isMacOS) { | |
| 21 cc = 'clang'; | |
| 22 shared = '-dynamiclib'; | |
| 23 libname = 'libprecompiled.dylib'; | |
| 24 } else { | |
| 25 print("Test only supports Linux and Mac"); | |
| 26 return; | |
| 27 } | |
| 28 | |
| 29 if (Platform.version.contains("x64")) { | |
| 30 cc_flags = "-m64"; | |
| 31 } else if (Platform.version.contains("simarm64")) { | |
| 32 cc_flags = "-m64"; | |
| 33 } else if (Platform.version.contains("simarm")) { | |
| 34 cc_flags = "-m32"; | |
| 35 } else if (Platform.version.contains("simmips")) { | |
| 36 cc_flags = "-m32"; | |
| 37 } else if (Platform.version.contains("arm")) { | |
| 38 cc_flags = ""; | |
| 39 } else if (Platform.version.contains("mips")) { | |
| 40 cc_flags = "-EL"; | |
| 41 } else { | |
| 42 print("Architecture not supported: ${Platform.version}"); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 print("Creating precompiled snapshot..."); | |
| 47 var dart_executable = | |
| 48 Directory.current.path + Platform.pathSeparator + Platform.executable; | |
| 49 Directory tmp; | |
| 50 try { | |
| 51 tmp = Directory.current.createTempSync("temp_precompilation_test"); | |
| 52 var result = Process.runSync( | |
| 53 "${dart_executable}_bootstrap", | |
| 54 ["--gen-precompiled-snapshot", Platform.script.path], | |
| 55 workingDirectory: tmp.path); | |
| 56 if (result.exitCode != 0) { | |
| 57 print(result.stdout); | |
| 58 print(result.stderr); | |
| 59 throw "Snapshot generation failed."; | |
| 60 } | |
| 61 | |
| 62 // Check if gcc is present, and skip test if it is not. | |
| 63 print("Creating shared library..."); | |
| 64 try { | |
| 65 result = Process.runSync( | |
| 66 cc, | |
| 67 ["--version"], | |
| 68 workingDirectory: tmp.path); | |
| 69 if (result.exitCode != 0) { | |
| 70 throw "$cc --version failed."; | |
| 71 } | |
| 72 } catch(e) { | |
| 73 print("Skipping test because $cc is not present: $e"); | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 result = Process.runSync( | |
| 78 cc, | |
| 79 [shared, cc_flags, "-nostartfiles", "-o", libname, "precompiled.S"], | |
| 80 workingDirectory: tmp.path); | |
| 81 if (result.exitCode != 0) { | |
| 82 print(result.stdout); | |
| 83 print(result.stderr); | |
| 84 throw "Shared library creation failed!"; | |
| 85 } | |
| 86 | |
| 87 print("Running test program..."); | |
| 88 var ld_library_path = new String.fromEnvironment("LD_LIBRARY_PATH"); | |
| 89 ld_library_path = "${ld_library_path}:${tmp.path}"; | |
| 90 | |
| 91 result = Process.runSync( | |
| 92 "${dart_executable}_precompiled_runtime", | |
| 93 ["--run-precompiled-snapshot", "ignored_script", "--hello"], | |
| 94 workingDirectory: tmp.path, | |
| 95 environment: {"LD_LIBRARY_PATH": ld_library_path}); | |
| 96 if (result.exitCode != 0) { | |
| 97 print(result.stdout); | |
| 98 print(result.stderr); | |
| 99 throw "Precompiled binary failed."; | |
| 100 } | |
| 101 print(result.stdout); | |
| 102 if (result.stdout != "Hello\n") { | |
| 103 throw "Precompiled binary output mismatch."; | |
| 104 } | |
| 105 } finally { | |
| 106 tmp?.deleteSync(recursive: true); | |
| 107 } | |
| 108 } | |
| OLD | NEW |