| 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
|
|
|