OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Test generating and running a simple precompiled snapshot of this script. | 5 // Test generating and running a simple precompiled snapshot of this script. |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 main(List args) { | 9 main(List args) { |
10 if (args.length > 0 && args[0] == "--hello") { | 10 if (args.length > 0 && args[0] == "--hello") { |
(...skipping 25 matching lines...) Expand all Loading... |
36 cc_flags = "-m32"; | 36 cc_flags = "-m32"; |
37 } else if (Platform.version.contains("arm")) { | 37 } else if (Platform.version.contains("arm")) { |
38 cc_flags = ""; | 38 cc_flags = ""; |
39 } else if (Platform.version.contains("mips")) { | 39 } else if (Platform.version.contains("mips")) { |
40 cc_flags = "-EL"; | 40 cc_flags = "-EL"; |
41 } else { | 41 } else { |
42 print("Architecture not supported: ${Platform.version}"); | 42 print("Architecture not supported: ${Platform.version}"); |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
| 46 print("Creating precompiled snapshot..."); |
46 var abs_package_root = Uri.parse(Platform.packageRoot).toFilePath(); | 47 var abs_package_root = Uri.parse(Platform.packageRoot).toFilePath(); |
47 var dart_executable = | 48 var dart_executable = |
48 Directory.current.path + Platform.pathSeparator + Platform.executable; | 49 Directory.current.path + Platform.pathSeparator + Platform.executable; |
49 Directory tmp; | 50 Directory tmp; |
50 try { | 51 try { |
51 tmp = Directory.current.createTempSync("temp_precompilation_test"); | 52 tmp = Directory.current.createTempSync("temp_precompilation_test"); |
52 var exec = "${dart_executable}_bootstrap"; | 53 var exec = "${dart_executable}_bootstrap"; |
53 var args = ["--package-root=$abs_package_root", | 54 var args = ["--package-root=$abs_package_root", |
54 "--gen-precompiled-snapshot", | 55 "--gen-precompiled-snapshot", |
55 "${abs_package_root}compiler/src/dart2js.dart"]; | 56 "${abs_package_root}compiler/src/dart2js.dart"]; |
56 print("$exec ${args.join(' ')}"); | 57 print("$exec ${args.join(' ')}"); |
57 var result = Process.runSync(exec, args, workingDirectory: tmp.path); | 58 var result = Process.runSync(exec, args, workingDirectory: tmp.path); |
58 if (result.exitCode != 0) { | 59 if (result.exitCode != 0) { |
59 print(result.stdout); | 60 print(result.stdout); |
60 print(result.stderr); | 61 print(result.stderr); |
61 throw "Snapshot generation failed."; | 62 throw "Snapshot generation failed."; |
62 } | 63 } |
63 | 64 |
64 // Check if gcc is present, and skip test if it is not. | 65 // Check if gcc is present, and skip test if it is not. |
| 66 print("Creating shared library..."); |
65 try { | 67 try { |
66 result = Process.runSync( | 68 result = Process.runSync( |
67 cc, | 69 cc, |
68 ["--version"], | 70 ["--version"], |
69 workingDirectory: tmp.path); | 71 workingDirectory: tmp.path); |
70 if (result.exitCode != 0) { | 72 if (result.exitCode != 0) { |
71 throw "$cc --version failed."; | 73 throw "$cc --version failed."; |
72 } | 74 } |
73 } catch(e) { | 75 } catch(e) { |
74 print("Skipping test because $cc is not present: $e"); | 76 print("Skipping test because $cc is not present: $e"); |
75 return; | 77 return; |
76 } | 78 } |
77 | 79 |
78 result = Process.runSync( | 80 result = Process.runSync( |
79 cc, | 81 cc, |
80 [shared, cc_flags, "-nostartfiles", "-o", libname, "precompiled.S"], | 82 [shared, cc_flags, "-nostartfiles", "-o", libname, "precompiled.S"], |
81 workingDirectory: tmp.path); | 83 workingDirectory: tmp.path); |
82 if (result.exitCode != 0) { | 84 if (result.exitCode != 0) { |
83 print(result.stdout); | 85 print(result.stdout); |
84 print(result.stderr); | 86 print(result.stderr); |
85 throw "Shared library creation failed!"; | 87 throw "Shared library creation failed!"; |
86 } | 88 } |
87 | 89 |
| 90 print("Running test program..."); |
88 var ld_library_path = new String.fromEnvironment("LD_LIBRARY_PATH"); | 91 var ld_library_path = new String.fromEnvironment("LD_LIBRARY_PATH"); |
89 ld_library_path = "${ld_library_path}:${tmp.path}"; | 92 ld_library_path = "${ld_library_path}:${tmp.path}"; |
90 exec = "${dart_executable}_precompiled_runtime"; | 93 exec = "${dart_executable}_precompiled_runtime"; |
91 args = ["--run-precompiled-snapshot", "ignored_script", "--version"]; | 94 args = ["--run-precompiled-snapshot", "ignored_script", "--version"]; |
92 print("LD_LIBRARY_PATH=$ld_library_path $exec ${args.join(' ')}"); | 95 print("LD_LIBRARY_PATH=$ld_library_path $exec ${args.join(' ')}"); |
93 result = Process.runSync(exec, args, | 96 result = Process.runSync(exec, args, |
94 workingDirectory: tmp.path, | 97 workingDirectory: tmp.path, |
95 environment: {"LD_LIBRARY_PATH": ld_library_path}); | 98 environment: {"LD_LIBRARY_PATH": ld_library_path}); |
96 if (result.exitCode != 0) { | 99 if (result.exitCode != 0) { |
97 print(result.stdout); | 100 print(result.stdout); |
98 print(result.stderr); | 101 print(result.stderr); |
99 throw "Precompiled binary failed."; | 102 throw "Precompiled binary failed."; |
100 } | 103 } |
101 print(result.stdout); | 104 print(result.stdout); |
102 if (!result.stdout.contains("Dart-to-JavaScript compiler")) { | 105 if (!result.stdout.contains("Dart-to-JavaScript compiler")) { |
103 throw "Precompiled binary output mismatch."; | 106 throw "Precompiled binary output mismatch."; |
104 } | 107 } |
105 } finally { | 108 } finally { |
106 tmp?.deleteSync(recursive: true); | 109 tmp?.deleteSync(recursive: true); |
107 } | 110 } |
108 } | 111 } |
OLD | NEW |