| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "mojo/dart/embedder/dart_controller.h" | 9 #include "mojo/dart/embedder/dart_controller.h" |
| 10 #include "mojo/public/c/system/types.h" | 10 #include "mojo/public/c/system/types.h" |
| 11 #include "mojo/public/cpp/environment/environment.h" | 11 #include "mojo/public/cpp/environment/environment.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 // TODO(zra): Pull vm options from the test scripts. | 14 // TODO(zra): Pull vm options from the test scripts. |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace dart { | 17 namespace dart { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 static bool generateEntropy(uint8_t* buffer, intptr_t length) { | 20 static bool generateEntropy(uint8_t* buffer, intptr_t length) { |
| 21 base::RandBytes(static_cast<void*>(buffer), length); | 21 base::RandBytes(static_cast<void*>(buffer), length); |
| 22 return true; | 22 return true; |
| 23 } | 23 } |
| 24 | 24 |
| 25 static void exceptionCallback(bool* exception, Dart_Handle error) { | 25 static void exceptionCallback(bool* exception, |
| 26 int64_t* closed_handles, |
| 27 Dart_Handle error, |
| 28 int64_t count) { |
| 26 *exception = true; | 29 *exception = true; |
| 30 *closed_handles = count; |
| 27 } | 31 } |
| 28 | 32 |
| 29 static void RunTest(const std::string& test, | 33 static void RunTest(const std::string& test, |
| 30 const char** extra_args, | 34 const char** extra_args = nullptr, |
| 31 int num_extra_args) { | 35 int num_extra_args = 0, |
| 36 bool expect_unhandled_exception = false, |
| 37 int expected_unclosed_handles = 0) { |
| 32 base::FilePath path; | 38 base::FilePath path; |
| 33 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 39 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 34 path = path.AppendASCII("mojo") | 40 path = path.AppendASCII("mojo") |
| 35 .AppendASCII("dart") | 41 .AppendASCII("dart") |
| 36 .AppendASCII("test") | 42 .AppendASCII("test") |
| 37 .AppendASCII(test); | 43 .AppendASCII(test); |
| 38 | 44 |
| 39 // Setup the package root. | 45 // Setup the package root. |
| 40 base::FilePath package_root; | 46 base::FilePath package_root; |
| 41 PathService::Get(base::DIR_EXE, &package_root); | 47 PathService::Get(base::DIR_EXE, &package_root); |
| 42 package_root = package_root.AppendASCII("gen") | 48 package_root = package_root.AppendASCII("gen") |
| 43 .AppendASCII("dart-pkg") | 49 .AppendASCII("dart-pkg") |
| 44 .AppendASCII("packages"); | 50 .AppendASCII("packages"); |
| 45 | 51 |
| 46 char* error = NULL; | 52 char* error = NULL; |
| 47 bool unhandled_exception = false; | 53 bool unhandled_exception = false; |
| 54 int64_t closed_handles = 0; |
| 48 DartControllerConfig config; | 55 DartControllerConfig config; |
| 49 // Run with strict compilation even in Release mode so that ASAN testing gets | 56 // Run with strict compilation even in Release mode so that ASAN testing gets |
| 50 // coverage of Dart asserts, type-checking, etc. | 57 // coverage of Dart asserts, type-checking, etc. |
| 51 config.strict_compilation = true; | 58 config.strict_compilation = true; |
| 52 config.script_uri = path.AsUTF8Unsafe(); | 59 config.script_uri = path.AsUTF8Unsafe(); |
| 53 config.package_root = package_root.AsUTF8Unsafe(); | 60 config.package_root = package_root.AsUTF8Unsafe(); |
| 54 config.callbacks.exception = | 61 config.callbacks.exception = |
| 55 base::Bind(&exceptionCallback, &unhandled_exception); | 62 base::Bind(&exceptionCallback, &unhandled_exception, &closed_handles); |
| 56 config.entropy = generateEntropy; | 63 config.entropy = generateEntropy; |
| 57 config.SetVmFlags(extra_args, num_extra_args); | 64 config.SetVmFlags(extra_args, num_extra_args); |
| 58 config.error = &error; | 65 config.error = &error; |
| 59 | 66 |
| 60 bool success = DartController::RunSingleDartScript(config); | 67 bool success = DartController::RunSingleDartScript(config); |
| 61 EXPECT_TRUE(success) << error; | 68 EXPECT_TRUE(success) << error; |
| 62 EXPECT_FALSE(unhandled_exception); | 69 EXPECT_EQ(expect_unhandled_exception, unhandled_exception); |
| 70 EXPECT_EQ(expected_unclosed_handles, closed_handles); |
| 63 } | 71 } |
| 64 | 72 |
| 65 // TODO(zra): instead of listing all these tests, search //mojo/dart/test for | 73 // TODO(zra): instead of listing all these tests, search //mojo/dart/test for |
| 66 // _test.dart files. | 74 // _test.dart files. |
| 67 | 75 |
| 68 TEST(DartTest, hello_mojo) { | 76 TEST(DartTest, hello_mojo) { |
| 69 RunTest("hello_mojo.dart", nullptr, 0); | 77 RunTest("hello_mojo.dart"); |
| 70 } | 78 } |
| 71 | 79 |
| 72 TEST(DartTest, core_types_test) { | 80 TEST(DartTest, core_types_test) { |
| 73 RunTest("core_types_test.dart", nullptr, 0); | 81 RunTest("core_types_test.dart"); |
| 74 } | 82 } |
| 75 | 83 |
| 76 TEST(DartTest, async_test) { | 84 TEST(DartTest, async_test) { |
| 77 RunTest("async_test.dart", nullptr, 0); | 85 RunTest("async_test.dart"); |
| 78 } | 86 } |
| 79 | 87 |
| 80 TEST(DartTest, isolate_test) { | 88 TEST(DartTest, isolate_test) { |
| 81 RunTest("isolate_test.dart", nullptr, 0); | 89 RunTest("isolate_test.dart"); |
| 82 } | 90 } |
| 83 | 91 |
| 84 TEST(DartTest, import_mojo) { | 92 TEST(DartTest, import_mojo) { |
| 85 RunTest("import_mojo.dart", nullptr, 0); | 93 RunTest("import_mojo.dart"); |
| 86 } | 94 } |
| 87 | 95 |
| 88 TEST(DartTest, simple_handle_watcher_test) { | 96 TEST(DartTest, simple_handle_watcher_test) { |
| 89 RunTest("simple_handle_watcher_test.dart", nullptr, 0); | 97 RunTest("simple_handle_watcher_test.dart"); |
| 90 } | 98 } |
| 91 | 99 |
| 92 TEST(DartTest, ping_pong_test) { | 100 TEST(DartTest, ping_pong_test) { |
| 93 RunTest("ping_pong_test.dart", nullptr, 0); | 101 RunTest("ping_pong_test.dart"); |
| 94 } | 102 } |
| 95 | 103 |
| 96 TEST(DartTest, timer_test) { | 104 TEST(DartTest, timer_test) { |
| 97 RunTest("timer_test.dart", nullptr, 0); | 105 RunTest("timer_test.dart"); |
| 98 } | 106 } |
| 99 | 107 |
| 100 TEST(DartTest, async_await_test) { | 108 TEST(DartTest, async_await_test) { |
| 101 RunTest("async_await_test.dart", nullptr, 0); | 109 RunTest("async_await_test.dart"); |
| 102 } | 110 } |
| 103 | 111 |
| 104 TEST(DartTest, core_test) { | 112 TEST(DartTest, core_test) { |
| 105 RunTest("core_test.dart", nullptr, 0); | 113 RunTest("core_test.dart"); |
| 106 } | 114 } |
| 107 | 115 |
| 108 TEST(DartTest, codec_test) { | 116 TEST(DartTest, codec_test) { |
| 109 RunTest("codec_test.dart", nullptr, 0); | 117 RunTest("codec_test.dart"); |
| 110 } | 118 } |
| 111 | 119 |
| 112 TEST(DartTest, handle_watcher_test) { | 120 TEST(DartTest, handle_watcher_test) { |
| 113 RunTest("handle_watcher_test.dart", nullptr, 0); | 121 RunTest("handle_watcher_test.dart"); |
| 114 } | 122 } |
| 115 | 123 |
| 116 TEST(DartTest, bindings_generation_test) { | 124 TEST(DartTest, bindings_generation_test) { |
| 117 RunTest("bindings_generation_test.dart", nullptr, 0); | 125 RunTest("bindings_generation_test.dart"); |
| 118 } | 126 } |
| 119 | 127 |
| 120 TEST(DartTest, compile_all_interfaces_test) { | 128 TEST(DartTest, compile_all_interfaces_test) { |
| 121 const char* args[] = { "--compile_all" }; | 129 const char* args[] = { "--compile_all" }; |
| 122 RunTest("compile_all_interfaces_test.dart", &args[0], 1); | 130 RunTest("compile_all_interfaces_test.dart", &args[0], 1); |
| 123 } | 131 } |
| 124 | 132 |
| 125 TEST(DartTest, uri_base_test) { | 133 TEST(DartTest, uri_base_test) { |
| 126 RunTest("uri_base_test.dart", nullptr, 0); | 134 RunTest("uri_base_test.dart"); |
| 127 } | 135 } |
| 128 | 136 |
| 129 TEST(DartTest, exception_test) { | 137 TEST(DartTest, exception_test) { |
| 130 RunTest("exception_test.dart", nullptr, 0); | 138 RunTest("exception_test.dart"); |
| 131 } | 139 } |
| 132 | 140 |
| 133 TEST(DartTest, control_messages_test) { | 141 TEST(DartTest, control_messages_test) { |
| 134 RunTest("control_messages_test.dart", nullptr, 0); | 142 RunTest("control_messages_test.dart"); |
| 135 } | 143 } |
| 136 | 144 |
| 137 TEST(DartTest, handle_finalizer_test) { | 145 TEST(DartTest, handle_finalizer_test) { |
| 138 const int kNumArgs = 2; | 146 const int kNumArgs = 2; |
| 139 const char* args[kNumArgs]; | 147 const char* args[kNumArgs]; |
| 140 args[0] = "--new-gen-semi-max-size=1"; | 148 args[0] = "--new-gen-semi-max-size=1"; |
| 141 args[1] = "--old_gen_growth_rate=1"; | 149 args[1] = "--old_gen_growth_rate=1"; |
| 142 RunTest("handle_finalizer_test.dart", args, kNumArgs); | 150 RunTest("handle_finalizer_test.dart", args, kNumArgs); |
| 143 } | 151 } |
| 144 | 152 |
| 153 TEST(DartTest, unhandled_exception_test) { |
| 154 RunTest("unhandled_exception_test.dart", nullptr, 0, true, 2); |
| 155 } |
| 156 |
| 145 } // namespace | 157 } // namespace |
| 146 } // namespace dart | 158 } // namespace dart |
| 147 } // namespace mojo | 159 } // namespace mojo |
| OLD | NEW |