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

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

Issue 1177153005: Enables clean VM shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove debug print 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/json_stream.h" 10 #include "vm/json_stream.h"
(...skipping 10 matching lines...) Expand all
21 EXPECT_EQ(isolate, Isolate::Current()); 21 EXPECT_EQ(isolate, Isolate::Current());
22 Metric metric; 22 Metric metric;
23 23
24 // Initialize metric. 24 // Initialize metric.
25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter); 25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter);
26 EXPECT_EQ(0, metric.value()); 26 EXPECT_EQ(0, metric.value());
27 metric.increment(); 27 metric.increment();
28 EXPECT_EQ(1, metric.value()); 28 EXPECT_EQ(1, metric.value());
29 metric.set_value(44); 29 metric.set_value(44);
30 EXPECT_EQ(44, metric.value()); 30 EXPECT_EQ(44, metric.value());
31
32 Dart::ShutdownIsolate();
31 } 33 }
32 34
33 class MyMetric : public Metric { 35 class MyMetric : public Metric {
34 protected: 36 protected:
35 int64_t Value() const { 37 int64_t Value() const {
36 // 99 bytes. 38 // 99 bytes.
37 return 99; 39 return 99;
38 } 40 }
39 41
40 public: 42 public:
41 // Just used for testing. 43 // Just used for testing.
42 int64_t LeakyValue() const { return Value(); } 44 int64_t LeakyValue() const { return Value(); }
43 }; 45 };
44 46
45 UNIT_TEST_CASE(Metric_OnDemand) { 47 UNIT_TEST_CASE(Metric_OnDemand) {
46 Isolate::Flags vm_flags; 48 Isolate::Flags vm_flags;
47 Dart_IsolateFlags api_flags; 49 Dart_IsolateFlags api_flags;
48 vm_flags.CopyTo(&api_flags); 50 vm_flags.CopyTo(&api_flags);
49 Isolate* isolate = Isolate::Init(NULL, api_flags); 51 Isolate* isolate = Isolate::Init(NULL, api_flags);
50 EXPECT_EQ(isolate, Isolate::Current()); 52 EXPECT_EQ(isolate, Isolate::Current());
51 StackZone zone(isolate); 53 {
52 HANDLESCOPE(isolate); 54 StackZone zone(isolate);
53 MyMetric metric; 55 HANDLESCOPE(isolate);
56 MyMetric metric;
54 57
55 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte); 58 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte);
56 // value is still the default value. 59 // value is still the default value.
57 EXPECT_EQ(0, metric.value()); 60 EXPECT_EQ(0, metric.value());
58 // Call LeakyValue to confirm that Value returns constant 99. 61 // Call LeakyValue to confirm that Value returns constant 99.
59 EXPECT_EQ(99, metric.LeakyValue()); 62 EXPECT_EQ(99, metric.LeakyValue());
60 63
61 // Serialize to JSON. 64 // Serialize to JSON.
62 JSONStream js; 65 JSONStream js;
63 metric.PrintJSON(&js); 66 metric.PrintJSON(&js);
64 const char* json = js.ToCString(); 67 const char* json = js.ToCString();
65 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" 68 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":"
66 "\"foobar\",\"unit\":\"byte\"," 69 "\"foobar\",\"unit\":\"byte\","
67 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" 70 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\""
68 ",\"value\":99.000000}", json); 71 ",\"value\":99.000000}", json);
72 }
73 Dart::ShutdownIsolate();
69 } 74 }
70 75
71 } // namespace dart 76 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698