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

Side by Side Diff: runtime/vm/service_test.cc

Issue 1132323002: Add Service ID zones to service protocol (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 102
103 static RawClass* GetClass(const Library& lib, const char* name) { 103 static RawClass* GetClass(const Library& lib, const char* name) {
104 const Class& cls = Class::Handle( 104 const Class& cls = Class::Handle(
105 lib.LookupClass(String::Handle(Symbols::New(name)))); 105 lib.LookupClass(String::Handle(Symbols::New(name))));
106 EXPECT(!cls.IsNull()); // No ambiguity error expected. 106 EXPECT(!cls.IsNull()); // No ambiguity error expected.
107 return cls.raw(); 107 return cls.raw();
108 } 108 }
109 109
110 110
111 TEST_CASE(Service_IdZones) {
112 Isolate* isolate = Isolate::Current();
113
114 const String& test_a = String::Handle(isolate, String::New("a"));
115 const String& test_b = String::Handle(isolate, String::New("b"));
116 const String& test_c = String::Handle(isolate, String::New("c"));
117 const String& test_d = String::Handle(isolate, String::New("d"));
118
119 // Both RingServiceIdZones share the same backing store and id space.
120
121 // Always allocate a new id.
122 RingServiceIdZone always_new_zone(ObjectIdRing::kNewId);
123 EXPECT_STREQ("objects/0", always_new_zone.GetServiceId(test_a));
124 EXPECT_STREQ("objects/1", always_new_zone.GetServiceId(test_a));
125 EXPECT_STREQ("objects/2", always_new_zone.GetServiceId(test_a));
126 EXPECT_STREQ("objects/3", always_new_zone.GetServiceId(test_b));
127 EXPECT_STREQ("objects/4", always_new_zone.GetServiceId(test_c));
128
129 // Reuse an existing id or allocate a new id.
130 RingServiceIdZone reuse_zone(ObjectIdRing::kExistingOrNewId);
131 EXPECT_STREQ("objects/0", reuse_zone.GetServiceId(test_a));
132 EXPECT_STREQ("objects/0", reuse_zone.GetServiceId(test_a));
133 EXPECT_STREQ("objects/3", reuse_zone.GetServiceId(test_b));
134 EXPECT_STREQ("objects/3", reuse_zone.GetServiceId(test_b));
135 EXPECT_STREQ("objects/4", reuse_zone.GetServiceId(test_c));
136 EXPECT_STREQ("objects/4", reuse_zone.GetServiceId(test_c));
137 EXPECT_STREQ("objects/5", reuse_zone.GetServiceId(test_d));
138 EXPECT_STREQ("objects/5", reuse_zone.GetServiceId(test_d));
139
140 // Growable object array as storage.
141 const GrowableObjectArray& storage =
142 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New());
143 // Zone whose id's will be "growable/index".
144 GrowableServiceIdZone growable_zone("growable/%" Pd "", storage);
145
146 // Prime the table with test_c and test_d. This has the side effect of giving
147 // test_c and test_d indexes 0 and 1 respectively.
148 storage.Add(test_c);
149 storage.Add(test_d);
150
151 // Verify that we get expect ids back for primed objects.
152 EXPECT_STREQ("growable/0", growable_zone.GetServiceId(test_c));
153 EXPECT_STREQ("growable/0", growable_zone.GetServiceId(test_c));
154 EXPECT_STREQ("growable/1", growable_zone.GetServiceId(test_d));
155 EXPECT_STREQ("growable/1", growable_zone.GetServiceId(test_d));
156
157 // Add new object.
158 EXPECT_STREQ("growable/2", growable_zone.GetServiceId(test_a));
159 EXPECT_STREQ("growable/2", growable_zone.GetServiceId(test_a));
160
161 // Add new object.
162 EXPECT_STREQ("growable/3", growable_zone.GetServiceId(test_b));
163 EXPECT_STREQ("growable/3", growable_zone.GetServiceId(test_b));
164
165 // Verify contents of storage.
166 EXPECT_EQ(test_c.raw(), storage.At(0));
167 EXPECT_EQ(test_d.raw(), storage.At(1));
168 EXPECT_EQ(test_a.raw(), storage.At(2));
169 EXPECT_EQ(test_b.raw(), storage.At(3));
170 }
171
172
111 TEST_CASE(Service_Code) { 173 TEST_CASE(Service_Code) {
112 const char* kScript = 174 const char* kScript =
113 "var port;\n" // Set to our mock port by C++. 175 "var port;\n" // Set to our mock port by C++.
114 "\n" 176 "\n"
115 "class A {\n" 177 "class A {\n"
116 " var a;\n" 178 " var a;\n"
117 " dynamic b() {}\n" 179 " dynamic b() {}\n"
118 " dynamic c() {\n" 180 " dynamic c() {\n"
119 " var d = () { b(); };\n" 181 " var d = () { b(); };\n"
120 " return d;\n" 182 " return d;\n"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['Bogus']]"); 650 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['Bogus']]");
589 Service::HandleIsolateMessage(isolate, service_msg); 651 Service::HandleIsolateMessage(isolate, service_msg);
590 handler.HandleNextMessage(); 652 handler.HandleNextMessage();
591 // Expect error. 653 // Expect error.
592 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 654 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
593 } 655 }
594 656
595 #endif // !defined(TARGET_ARCH_ARM64) 657 #endif // !defined(TARGET_ARCH_ARM64)
596 658
597 } // namespace dart 659 } // namespace dart
OLDNEW
« runtime/vm/service/vmservice.dart ('K') | « runtime/vm/service/vmservice.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698