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

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

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/assert.h"
6
7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h"
10 #include "vm/thread_interrupter.h"
11 #include "vm/unit_test.h"
12
13 namespace dart {
14
15 class ThreadInterrupterTestHelper : public AllStatic {
16 public:
17 static void InterruptTest(const intptr_t run_time, const intptr_t period) {
18 const double allowed_error = 0.25; // +/- 25%
19 intptr_t count = 0;
20 ThreadInterrupter::Unregister();
21 ThreadInterrupter::SetInterruptPeriod(period);
22 ThreadInterrupter::Register(IncrementCallback, &count);
23 OS::Sleep(run_time * kMillisecondsPerSecond);
24 ThreadInterrupter::Unregister();
25 intptr_t run_time_micros = run_time * kMicrosecondsPerSecond;
26 intptr_t expected_interrupts = run_time_micros / period;
27 intptr_t error = allowed_error * expected_interrupts;
28 intptr_t low_bar = expected_interrupts - error;
29 intptr_t high_bar = expected_interrupts + error;
30 EXPECT_GE(count, low_bar);
31 EXPECT_LE(count, high_bar);
32 }
33
34 static void IncrementCallback(const InterruptedThreadState& state,
35 void* data) {
36 ASSERT(data != NULL);
37 intptr_t* counter = reinterpret_cast<intptr_t*>(data);
38 *counter = *counter + 1;
39 }
40 };
41
42
43 TEST_CASE(ThreadInterrupterHigh) {
44 const intptr_t kRunTimeSeconds = 5;
45 const intptr_t kInterruptPeriodMicros = 250;
46 ThreadInterrupterTestHelper::InterruptTest(kRunTimeSeconds,
47 kInterruptPeriodMicros);
48 }
49
50 TEST_CASE(ThreadInterrupterMedium) {
51 const intptr_t kRunTimeSeconds = 5;
52 const intptr_t kInterruptPeriodMicros = 500;
53 ThreadInterrupterTestHelper::InterruptTest(kRunTimeSeconds,
54 kInterruptPeriodMicros);
55 }
56
57 TEST_CASE(ThreadInterrupterLow) {
58 const intptr_t kRunTimeSeconds = 5;
59 const intptr_t kInterruptPeriodMicros = 1000;
60 ThreadInterrupterTestHelper::InterruptTest(kRunTimeSeconds,
61 kInterruptPeriodMicros);
62 }
63
64
65 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698