OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/isolate.h" | 6 #include "vm/isolate.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 #include "vm/thread.h" | 8 #include "vm/thread.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 | 33 |
34 UNIT_TEST_CASE(Monitor) { | 34 UNIT_TEST_CASE(Monitor) { |
35 // This unit test case needs a running isolate. | 35 // This unit test case needs a running isolate. |
36 Isolate* isolate = Isolate::Init(NULL); | 36 Isolate* isolate = Isolate::Init(NULL); |
37 | 37 |
38 Monitor* monitor = new Monitor(); | 38 Monitor* monitor = new Monitor(); |
39 monitor->Enter(); | 39 monitor->Enter(); |
40 monitor->Exit(); | 40 monitor->Exit(); |
41 | 41 |
42 { | 42 const int kNumAttempts = 5; |
| 43 int attempts = 0; |
| 44 while (attempts < kNumAttempts) { |
43 MonitorLocker ml(monitor); | 45 MonitorLocker ml(monitor); |
44 int64_t start = OS::GetCurrentTimeMillis(); | 46 int64_t start = OS::GetCurrentTimeMillis(); |
45 int64_t wait_time = 2017; | 47 int64_t wait_time = 2017; |
46 Monitor::WaitResult wait_result = ml.Wait(wait_time); | 48 Monitor::WaitResult wait_result = ml.Wait(wait_time); |
47 int64_t stop = OS::GetCurrentTimeMillis(); | 49 int64_t stop = OS::GetCurrentTimeMillis(); |
| 50 |
| 51 // We expect to be timing out here. |
48 EXPECT_EQ(Monitor::kTimedOut, wait_result); | 52 EXPECT_EQ(Monitor::kTimedOut, wait_result); |
| 53 |
| 54 // Check whether this attempt falls within the exptected time limits. |
| 55 int64_t wakeup_time = stop - start; |
| 56 OS::Print("wakeup_time: %"Pd64"\n", wakeup_time); |
49 const int kAcceptableTimeJitter = 20; // Measured in milliseconds. | 57 const int kAcceptableTimeJitter = 20; // Measured in milliseconds. |
50 EXPECT_LE(wait_time - kAcceptableTimeJitter, stop - start); | |
51 const int kAcceptableWakeupDelay = 150; // Measured in milliseconds. | 58 const int kAcceptableWakeupDelay = 150; // Measured in milliseconds. |
52 EXPECT_GE(wait_time + kAcceptableWakeupDelay, stop - start); | 59 if (((wait_time - kAcceptableTimeJitter) <= wakeup_time) && |
| 60 (wakeup_time <= (wait_time + kAcceptableWakeupDelay))) { |
| 61 break; |
| 62 } |
| 63 |
| 64 // Record the attempt. |
| 65 attempts++; |
53 } | 66 } |
| 67 EXPECT_LT(attempts, kNumAttempts); |
| 68 |
54 // The isolate shutdown and the destruction of the mutex are out-of-order on | 69 // The isolate shutdown and the destruction of the mutex are out-of-order on |
55 // purpose. | 70 // purpose. |
56 isolate->Shutdown(); | 71 isolate->Shutdown(); |
57 delete isolate; | 72 delete isolate; |
58 delete monitor; | 73 delete monitor; |
59 } | 74 } |
60 | 75 |
61 } // namespace dart | 76 } // namespace dart |
OLD | NEW |