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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 1287543003: Refactor Dart_TimelineGetTrace to use a StreamConsumer callback (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index d0cc14a9c3ecb795c39b06538305ee70bb7e1d78..d2158107648ba53544f15cf9e6042ce15523a98d 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -9279,6 +9279,40 @@ TEST_CASE(Timeline_Dart_TimelineAsync) {
}
+struct AppendData {
+ uint8_t* buffer;
+ intptr_t buffer_length;
+};
+
+
+static void AppendStreamConsumer(intptr_t state,
+ const char* stream_name,
+ uint8_t* buffer,
+ intptr_t buffer_length,
+ void* user_data) {
+ if (state == DART_STREAM_CONSUMER_STATE_FINISH) {
+ return;
+ }
+ AppendData* data = reinterpret_cast<AppendData*>(user_data);
+ if (state == DART_STREAM_CONSUMER_STATE_START) {
+ // Initialize append data.
+ data->buffer = NULL;
+ data->buffer_length = 0;
+ return;
+ }
+ ASSERT(state == DART_STREAM_CONSUMER_STATE_DATA);
+ // Grow buffer.
+ data->buffer = reinterpret_cast<uint8_t*>(
+ realloc(data->buffer, data->buffer_length + buffer_length));
+ // Copy new data.
+ memmove(&data->buffer[data->buffer_length],
+ buffer,
+ buffer_length);
+ // Update length.
+ data->buffer_length += buffer_length;
+}
+
+
TEST_CASE(Timeline_Dart_TimelineGetTrace) {
const char* kScriptChars =
"foo() => 'a';\n"
@@ -9303,16 +9337,21 @@ TEST_CASE(Timeline_Dart_TimelineGetTrace) {
EXPECT_VALID(result);
// Grab the trace.
- success = Dart_TimelineGetTrace(&buffer, &buffer_length);
+ AppendData data;
+ success = Dart_TimelineGetTrace(AppendStreamConsumer, &data);
EXPECT(success);
+ buffer = reinterpret_cast<char*>(data.buffer);
+ buffer_length = data.buffer_length;
EXPECT(buffer_length > 0);
EXPECT(buffer != NULL);
+
// Heartbeat test.
EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer);
EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer);
EXPECT_SUBSTRING("\"function\":\"main\"", buffer);
- // Free buffer acquired by Dart_TimelineGetTrace call.
- free(const_cast<char*>(buffer));
+
+ // Free buffer allocated by AppendStreamConsumer
+ free(data.buffer);
}
} // namespace dart
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698