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

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

Issue 920813003: Refactor service code and service method parameters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
« no previous file with comments | « runtime/vm/service_isolate.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 _msg = new_msg; 82 _msg = new_msg;
83 } 83 }
84 84
85 const char* msg() const { return _msg; } 85 const char* msg() const { return _msg; }
86 86
87 private: 87 private:
88 char* _msg; 88 char* _msg;
89 }; 89 };
90 90
91 91
92 static RawArray* Eval(Dart_Handle lib, const char* expr) { 92 static RawArray* EvalVM(Dart_Handle lib, const char* expr) {
93 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr)); 93 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr));
94 EXPECT_VALID(expr_val); 94 EXPECT_VALID(expr_val);
95 Isolate* isolate = Isolate::Current(); 95 Isolate* isolate = Isolate::Current();
96 const GrowableObjectArray& value =
97 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val);
98 const Array& result = Array::Handle(Array::MakeArray(value));
99 GrowableObjectArray& growable = GrowableObjectArray::Handle();
100 growable ^= result.At(3);
101 Array& array = Array::Handle(Array::MakeArray(growable));
102 result.SetAt(3, array);
103 growable ^= result.At(4);
104 array = Array::MakeArray(growable);
105 result.SetAt(4, array);
106 return result.raw();
107 }
108
109
110 static RawArray* Eval(Dart_Handle lib, const char* expr) {
111 const String& dummy_isolate_id = String::Handle(String::New("isolateId"));
112 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr));
113 EXPECT_VALID(expr_val);
114 Isolate* isolate = Isolate::Current();
96 const GrowableObjectArray& value = 115 const GrowableObjectArray& value =
97 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val); 116 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val);
98 const Array& result = Array::Handle(Array::MakeArray(value)); 117 const Array& result = Array::Handle(Array::MakeArray(value));
99 GrowableObjectArray& growable = GrowableObjectArray::Handle(); 118 GrowableObjectArray& growable = GrowableObjectArray::Handle();
100 growable ^= result.At(3); 119 growable ^= result.At(3);
120 // Append dummy isolate id to parameter values.
121 growable.Add(dummy_isolate_id);
101 Array& array = Array::Handle(Array::MakeArray(growable)); 122 Array& array = Array::Handle(Array::MakeArray(growable));
102 result.SetAt(3, array); 123 result.SetAt(3, array);
103 growable ^= result.At(4); 124 growable ^= result.At(4);
125 // Append dummy isolate id to parameter values.
126 growable.Add(dummy_isolate_id);
104 array = Array::MakeArray(growable); 127 array = Array::MakeArray(growable);
105 result.SetAt(4, array); 128 result.SetAt(4, array);
106 return result.raw(); 129 return result.raw();
107 } 130 }
108 131
109 132
110 static RawArray* EvalF(Dart_Handle lib, const char* fmt, ...) { 133 static RawArray* EvalF(Dart_Handle lib, const char* fmt, ...) {
111 Isolate* isolate = Isolate::Current(); 134 Isolate* isolate = Isolate::Current();
112 135
113 va_list args; 136 va_list args;
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 EXPECT_VALID(lib); 1068 EXPECT_VALID(lib);
1046 1069
1047 // Build a mock message handler and wrap it in a dart port. 1070 // Build a mock message handler and wrap it in a dart port.
1048 ServiceTestMessageHandler handler; 1071 ServiceTestMessageHandler handler;
1049 Dart_Port port_id = PortMap::CreatePort(&handler); 1072 Dart_Port port_id = PortMap::CreatePort(&handler);
1050 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1073 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1051 EXPECT_VALID(port); 1074 EXPECT_VALID(port);
1052 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 1075 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1053 1076
1054 Array& service_msg = Array::Handle(); 1077 Array& service_msg = Array::Handle();
1055 service_msg = Eval(lib, "[0, port, 'getVM', [], []]"); 1078 service_msg = EvalVM(lib, "[0, port, 'getVM', [], []]");
1056 1079
1057 Service::HandleRootMessage(service_msg); 1080 Service::HandleRootMessage(service_msg);
1058 handler.HandleNextMessage(); 1081 handler.HandleNextMessage();
1059 EXPECT_SUBSTRING("\"type\":\"VM\",\"id\":\"vm\"", handler.msg()); 1082 EXPECT_SUBSTRING("\"type\":\"VM\",\"id\":\"vm\"", handler.msg());
1060 EXPECT_SUBSTRING("\"targetCPU\"", handler.msg()); 1083 EXPECT_SUBSTRING("\"targetCPU\"", handler.msg());
1061 EXPECT_SUBSTRING("\"hostCPU\"", handler.msg()); 1084 EXPECT_SUBSTRING("\"hostCPU\"", handler.msg());
1062 EXPECT_SUBSTRING("\"version\"", handler.msg()); 1085 EXPECT_SUBSTRING("\"version\"", handler.msg());
1063 EXPECT_SUBSTRING("\"uptime\"", handler.msg()); 1086 EXPECT_SUBSTRING("\"uptime\"", handler.msg());
1064 EXPECT_SUBSTRING("\"isolates\"", handler.msg()); 1087 EXPECT_SUBSTRING("\"isolates\"", handler.msg());
1065 } 1088 }
(...skipping 11 matching lines...) Expand all
1077 EXPECT_VALID(lib); 1100 EXPECT_VALID(lib);
1078 1101
1079 // Build a mock message handler and wrap it in a dart port. 1102 // Build a mock message handler and wrap it in a dart port.
1080 ServiceTestMessageHandler handler; 1103 ServiceTestMessageHandler handler;
1081 Dart_Port port_id = PortMap::CreatePort(&handler); 1104 Dart_Port port_id = PortMap::CreatePort(&handler);
1082 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1105 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1083 EXPECT_VALID(port); 1106 EXPECT_VALID(port);
1084 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 1107 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1085 1108
1086 Array& service_msg = Array::Handle(); 1109 Array& service_msg = Array::Handle();
1087 service_msg = Eval(lib, "[0, port, 'getFlagList', [], []]"); 1110 service_msg = EvalVM(lib, "[0, port, 'getFlagList', [], []]");
1088 1111
1089 // Make sure we can get the FlagList. 1112 // Make sure we can get the FlagList.
1090 Service::HandleRootMessage(service_msg); 1113 Service::HandleRootMessage(service_msg);
1091 handler.HandleNextMessage(); 1114 handler.HandleNextMessage();
1092 EXPECT_SUBSTRING("\"type\":\"FlagList\",\"id\":\"flags\"", handler.msg()); 1115 EXPECT_SUBSTRING("\"type\":\"FlagList\",\"id\":\"flags\"", handler.msg());
1093 EXPECT_SUBSTRING( 1116 EXPECT_SUBSTRING(
1094 "\"name\":\"service_testing_flag\",\"comment\":\"Comment\"," 1117 "\"name\":\"service_testing_flag\",\"comment\":\"Comment\","
1095 "\"flagType\":\"bool\",\"valueAsString\":\"false\"", 1118 "\"flagType\":\"bool\",\"valueAsString\":\"false\"",
1096 handler.msg()); 1119 handler.msg());
1097 1120
1098 // Modify a flag through the vm service. 1121 // Modify a flag through the vm service.
1099 service_msg = Eval(lib, 1122 service_msg = EvalVM(lib,
1100 "[0, port, 'setFlag', " 1123 "[0, port, 'setFlag', "
1101 "['name', 'value'], ['service_testing_flag', 'true']]"); 1124 "['name', 'value'], ['service_testing_flag', 'true']]");
1102 Service::HandleRootMessage(service_msg); 1125 Service::HandleRootMessage(service_msg);
1103 handler.HandleNextMessage(); 1126 handler.HandleNextMessage();
1104 EXPECT_SUBSTRING("Success", handler.msg()); 1127 EXPECT_SUBSTRING("Success", handler.msg());
1105 1128
1106 // Make sure that the flag changed. 1129 // Make sure that the flag changed.
1107 service_msg = Eval(lib, "[0, port, 'getFlagList', [], []]"); 1130 service_msg = EvalVM(lib, "[0, port, 'getFlagList', [], []]");
1108 Service::HandleRootMessage(service_msg); 1131 Service::HandleRootMessage(service_msg);
1109 handler.HandleNextMessage(); 1132 handler.HandleNextMessage();
1110 EXPECT_SUBSTRING( 1133 EXPECT_SUBSTRING(
1111 "\"name\":\"service_testing_flag\",\"comment\":\"Comment\"," 1134 "\"name\":\"service_testing_flag\",\"comment\":\"Comment\","
1112 "\"flagType\":\"bool\",\"valueAsString\":\"true\"", 1135 "\"flagType\":\"bool\",\"valueAsString\":\"true\"",
1113 handler.msg()); 1136 handler.msg());
1114 } 1137 }
1115 1138
1116 1139
1117 TEST_CASE(Service_Scripts) { 1140 TEST_CASE(Service_Scripts) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 ServiceTestMessageHandler handler; 1451 ServiceTestMessageHandler handler;
1429 Dart_Port port_id = PortMap::CreatePort(&handler); 1452 Dart_Port port_id = PortMap::CreatePort(&handler);
1430 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1453 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1431 EXPECT_VALID(port); 1454 EXPECT_VALID(port);
1432 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 1455 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1433 1456
1434 Array& service_msg = Array::Handle(); 1457 Array& service_msg = Array::Handle();
1435 service_msg = Eval(lib, "[0, port, 'getCpuProfile', [], []]"); 1458 service_msg = Eval(lib, "[0, port, 'getCpuProfile', [], []]");
1436 Service::HandleIsolateMessage(isolate, service_msg); 1459 Service::HandleIsolateMessage(isolate, service_msg);
1437 handler.HandleNextMessage(); 1460 handler.HandleNextMessage();
1438 // Expect profile 1461 // Expect error (tags required).
1439 EXPECT_SUBSTRING("\"type\":\"CpuProfile\"", handler.msg()); 1462 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1440 1463
1441 service_msg = 1464 service_msg =
1442 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['None']]"); 1465 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['None']]");
1443 Service::HandleIsolateMessage(isolate, service_msg); 1466 Service::HandleIsolateMessage(isolate, service_msg);
1444 handler.HandleNextMessage(); 1467 handler.HandleNextMessage();
1445 // Expect profile 1468 // Expect profile
1446 EXPECT_SUBSTRING("\"type\":\"CpuProfile\"", handler.msg()); 1469 EXPECT_SUBSTRING("\"type\":\"CpuProfile\"", handler.msg());
1447 1470
1448 service_msg = 1471 service_msg =
1449 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['Bogus']]"); 1472 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['Bogus']]");
1450 Service::HandleIsolateMessage(isolate, service_msg); 1473 Service::HandleIsolateMessage(isolate, service_msg);
1451 handler.HandleNextMessage(); 1474 handler.HandleNextMessage();
1452 // Expect error. 1475 // Expect error.
1453 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 1476 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1454 } 1477 }
1455 1478
1456 #endif // !defined(TARGET_ARCH_ARM64) 1479 #endif // !defined(TARGET_ARCH_ARM64)
1457 1480
1458 } // namespace dart 1481 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service_isolate.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698