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