Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: mojo/dart/embedder/test/run_dart_tests.cc

Issue 1411843005: Dart: Removes C++ set for closing handles on an unhandled exception. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Format Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) {
34 base::FilePath path; 39 base::FilePath path;
35 PathService::Get(base::DIR_SOURCE_ROOT, &path); 40 PathService::Get(base::DIR_SOURCE_ROOT, &path);
36 path = path.AppendASCII("mojo") 41 path = path.AppendASCII("mojo")
37 .AppendASCII("dart") 42 .AppendASCII("dart")
38 .AppendASCII("test") 43 .AppendASCII("test")
39 .AppendASCII(test); 44 .AppendASCII(test);
40 45
41 // Setup the package root. 46 // Setup the package root.
42 base::FilePath package_root; 47 base::FilePath package_root;
43 PathService::Get(base::DIR_EXE, &package_root); 48 PathService::Get(base::DIR_EXE, &package_root);
44 package_root = package_root.AppendASCII("gen") 49 package_root = package_root.AppendASCII("gen")
45 .AppendASCII("dart-pkg") 50 .AppendASCII("dart-pkg")
46 .AppendASCII("packages"); 51 .AppendASCII("packages");
47 52
48 char* error = NULL; 53 char* error = NULL;
49 bool unhandled_exception = false; 54 bool unhandled_exception = false;
55 int64_t closed_handles = 0;
50 DartControllerConfig config; 56 DartControllerConfig config;
51 // Run with strict compilation even in Release mode so that ASAN testing gets 57 // Run with strict compilation even in Release mode so that ASAN testing gets
52 // coverage of Dart asserts, type-checking, etc. 58 // coverage of Dart asserts, type-checking, etc.
53 config.strict_compilation = true; 59 config.strict_compilation = true;
54 config.script_uri = path.AsUTF8Unsafe(); 60 config.script_uri = path.AsUTF8Unsafe();
55 config.package_root = package_root.AsUTF8Unsafe(); 61 config.package_root = package_root.AsUTF8Unsafe();
56 config.callbacks.exception = 62 config.callbacks.exception =
57 base::Bind(&exceptionCallback, &unhandled_exception); 63 base::Bind(&exceptionCallback, &unhandled_exception, &closed_handles);
58 config.entropy = generateEntropy; 64 config.entropy = generateEntropy;
59 config.SetVmFlags(extra_args, num_extra_args); 65 config.SetVmFlags(extra_args, num_extra_args);
60 config.error = &error; 66 config.error = &error;
61 67
62 bool success = DartController::RunSingleDartScript(config); 68 bool success = DartController::RunSingleDartScript(config);
63 EXPECT_TRUE(success) << error; 69 EXPECT_TRUE(success) << error;
64 EXPECT_FALSE(unhandled_exception); 70 if (expect_unhandled_exception) {
71 EXPECT_TRUE(unhandled_exception);
72 EXPECT_GT(closed_handles, 0);
Cutch 2015/10/26 17:10:03 Do we want to pass in the exact number of closed h
zra 2015/10/26 17:53:54 Done.
73 } else {
74 EXPECT_FALSE(unhandled_exception);
75 EXPECT_EQ(closed_handles, 0);
76 }
65 } 77 }
66 78
67 // TODO(zra): instead of listing all these tests, search //mojo/dart/test for 79 // TODO(zra): instead of listing all these tests, search //mojo/dart/test for
68 // _test.dart files. 80 // _test.dart files.
69 81
70 TEST(DartTest, hello_mojo) { 82 TEST(DartTest, hello_mojo) {
71 RunTest("hello_mojo.dart", nullptr, 0); 83 RunTest("hello_mojo.dart");
72 } 84 }
73 85
74 TEST(DartTest, core_types_test) { 86 TEST(DartTest, core_types_test) {
75 RunTest("core_types_test.dart", nullptr, 0); 87 RunTest("core_types_test.dart");
76 } 88 }
77 89
78 TEST(DartTest, async_test) { 90 TEST(DartTest, async_test) {
79 RunTest("async_test.dart", nullptr, 0); 91 RunTest("async_test.dart");
80 } 92 }
81 93
82 TEST(DartTest, isolate_test) { 94 TEST(DartTest, isolate_test) {
83 RunTest("isolate_test.dart", nullptr, 0); 95 RunTest("isolate_test.dart");
84 } 96 }
85 97
86 TEST(DartTest, import_mojo) { 98 TEST(DartTest, import_mojo) {
87 RunTest("import_mojo.dart", nullptr, 0); 99 RunTest("import_mojo.dart");
88 } 100 }
89 101
90 TEST(DartTest, simple_handle_watcher_test) { 102 TEST(DartTest, simple_handle_watcher_test) {
91 RunTest("simple_handle_watcher_test.dart", nullptr, 0); 103 RunTest("simple_handle_watcher_test.dart");
92 } 104 }
93 105
94 TEST(DartTest, ping_pong_test) { 106 TEST(DartTest, ping_pong_test) {
95 RunTest("ping_pong_test.dart", nullptr, 0); 107 RunTest("ping_pong_test.dart");
96 } 108 }
97 109
98 TEST(DartTest, timer_test) { 110 TEST(DartTest, timer_test) {
99 RunTest("timer_test.dart", nullptr, 0); 111 RunTest("timer_test.dart");
100 } 112 }
101 113
102 TEST(DartTest, async_await_test) { 114 TEST(DartTest, async_await_test) {
103 RunTest("async_await_test.dart", nullptr, 0); 115 RunTest("async_await_test.dart");
104 } 116 }
105 117
106 TEST(DartTest, core_test) { 118 TEST(DartTest, core_test) {
107 RunTest("core_test.dart", nullptr, 0); 119 RunTest("core_test.dart");
108 } 120 }
109 121
110 TEST(DartTest, codec_test) { 122 TEST(DartTest, codec_test) {
111 RunTest("codec_test.dart", nullptr, 0); 123 RunTest("codec_test.dart");
112 } 124 }
113 125
114 TEST(DartTest, handle_watcher_test) { 126 TEST(DartTest, handle_watcher_test) {
115 RunTest("handle_watcher_test.dart", nullptr, 0); 127 RunTest("handle_watcher_test.dart");
116 } 128 }
117 129
118 TEST(DartTest, bindings_generation_test) { 130 TEST(DartTest, bindings_generation_test) {
119 RunTest("bindings_generation_test.dart", nullptr, 0); 131 RunTest("bindings_generation_test.dart");
120 } 132 }
121 133
122 TEST(DartTest, compile_all_interfaces_test) { 134 TEST(DartTest, compile_all_interfaces_test) {
123 const char* args[] = { "--compile_all" }; 135 const char* args[] = { "--compile_all" };
124 RunTest("compile_all_interfaces_test.dart", &args[0], 1); 136 RunTest("compile_all_interfaces_test.dart", &args[0], 1);
125 } 137 }
126 138
127 TEST(DartTest, uri_base_test) { 139 TEST(DartTest, uri_base_test) {
128 RunTest("uri_base_test.dart", nullptr, 0); 140 RunTest("uri_base_test.dart");
129 } 141 }
130 142
131 TEST(DartTest, exception_test) { 143 TEST(DartTest, exception_test) {
132 RunTest("exception_test.dart", nullptr, 0); 144 RunTest("exception_test.dart");
133 } 145 }
134 146
135 TEST(DartTest, control_messages_test) { 147 TEST(DartTest, control_messages_test) {
136 RunTest("control_messages_test.dart", nullptr, 0); 148 RunTest("control_messages_test.dart");
137 } 149 }
138 150
139 TEST(DartTest, handle_finalizer_test) { 151 TEST(DartTest, handle_finalizer_test) {
140 const int kNumArgs = 2; 152 const int kNumArgs = 2;
141 const char* args[kNumArgs]; 153 const char* args[kNumArgs];
142 args[0] = "--new-gen-semi-max-size=1"; 154 args[0] = "--new-gen-semi-max-size=1";
143 args[1] = "--old_gen_growth_rate=1"; 155 args[1] = "--old_gen_growth_rate=1";
144 RunTest("handle_finalizer_test.dart", args, kNumArgs); 156 RunTest("handle_finalizer_test.dart", args, kNumArgs);
145 } 157 }
146 158
159 TEST(DartTest, unhandled_exception_test) {
160 RunTest("unhandled_exception_test.dart", nullptr, 0, true);
161 }
162
147 } // namespace 163 } // namespace
148 } // namespace dart 164 } // namespace dart
149 } // namespace mojo 165 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698