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

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

Issue 1293253005: Completely remove InterruptableThreadState and Fix ThreadRegistry leak (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 unified diff | Download patch
« no previous file with comments | « runtime/vm/thread_interrupter_macos.cc ('k') | runtime/vm/thread_interrupter_win.cc » ('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/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/thread_interrupter.h" 10 #include "vm/thread_interrupter.h"
11 #include "vm/unit_test.h" 11 #include "vm/unit_test.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 class ThreadInterrupterTestHelper : public AllStatic { 15 class ThreadInterrupterTestHelper : public AllStatic {
16 public: 16 public:
17 static void InterruptTest(const intptr_t run_time, const intptr_t period) { 17 static void InterruptTest(const intptr_t run_time, const intptr_t period) {
18 const double allowed_error = 0.25; // +/- 25% 18 const double allowed_error = 0.25; // +/- 25%
19 intptr_t count = 0; 19 intptr_t count = 0;
20 ThreadInterrupter::Unregister(); 20 Thread::EnsureInit();
21 Thread* thread = Thread::Current();
22 thread->SetThreadInterrupter(IncrementCallback, &count);
21 ThreadInterrupter::SetInterruptPeriod(period); 23 ThreadInterrupter::SetInterruptPeriod(period);
22 ThreadInterrupter::Register(IncrementCallback, &count);
23 OS::Sleep(run_time * kMillisecondsPerSecond); 24 OS::Sleep(run_time * kMillisecondsPerSecond);
24 ThreadInterrupter::Unregister(); 25 thread->SetThreadInterrupter(NULL, NULL);
25 intptr_t run_time_micros = run_time * kMicrosecondsPerSecond; 26 intptr_t run_time_micros = run_time * kMicrosecondsPerSecond;
26 intptr_t expected_interrupts = run_time_micros / period; 27 intptr_t expected_interrupts = run_time_micros / period;
27 intptr_t error = allowed_error * expected_interrupts; 28 intptr_t error = allowed_error * expected_interrupts;
28 intptr_t low_bar = expected_interrupts - error; 29 intptr_t low_bar = expected_interrupts - error;
29 intptr_t high_bar = expected_interrupts + error; 30 intptr_t high_bar = expected_interrupts + error;
30 EXPECT_GE(count, low_bar); 31 EXPECT_GE(count, low_bar);
31 EXPECT_LE(count, high_bar); 32 EXPECT_LE(count, high_bar);
32 } 33 }
33 34
34 static void IncrementCallback(const InterruptedThreadState& state, 35 static void IncrementCallback(const InterruptedThreadState& state,
(...skipping 21 matching lines...) Expand all
56 57
57 TEST_CASE(ThreadInterrupterLow) { 58 TEST_CASE(ThreadInterrupterLow) {
58 const intptr_t kRunTimeSeconds = 5; 59 const intptr_t kRunTimeSeconds = 5;
59 const intptr_t kInterruptPeriodMicros = 1000; 60 const intptr_t kInterruptPeriodMicros = 1000;
60 ThreadInterrupterTestHelper::InterruptTest(kRunTimeSeconds, 61 ThreadInterrupterTestHelper::InterruptTest(kRunTimeSeconds,
61 kInterruptPeriodMicros); 62 kInterruptPeriodMicros);
62 } 63 }
63 64
64 65
65 } // namespace dart 66 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread_interrupter_macos.cc ('k') | runtime/vm/thread_interrupter_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698