diff options
author | blundell <blundell@chromium.org> | 2015-01-19 09:18:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-19 17:19:27 +0000 |
commit | 70fb54767b472a5edfb859e489beeeec7abdb0e4 (patch) | |
tree | 28e534ec774391a9f6571a1770e12a0d63ebf833 /mojo/edk/system/waiter_unittest.cc | |
parent | ba5f0233fa38f949e24f6274ba891fa652eab640 (diff) | |
download | chromium_src-70fb54767b472a5edfb859e489beeeec7abdb0e4.zip chromium_src-70fb54767b472a5edfb859e489beeeec7abdb0e4.tar.gz chromium_src-70fb54767b472a5edfb859e489beeeec7abdb0e4.tar.bz2 |
Move //mojo/{public, edk} underneath //third_party
This CL move //mojo/public and //mojo/edk to live in the following locations:
- //third_party/mojo/src/mojo/public
- //third_party/mojo/src/mojo/edk
It moves the related gypfiles from //mojo to //third_party/mojo and updates
them as necessary to account for the file moves. It also updates clients of the
mojo SDK and EDK targets in both GYP and GN. (Note that for GN, the mojo SDK
and EDK build systems are maintained in the Mojo repo and designed to be
flexible wrt the location of the SDK/EDK in a client repo, so no changes are
needed.
This CL does not update include paths to the code being moved to limit the
number of moving parts, instead relying on the include_dirs that the SDK and
EDK targets supply to their direct dependents to ensure that include paths
continue to resolve correctly.
NOPRESUBMIT=true
Review URL: https://codereview.chromium.org/814543006
Cr-Commit-Position: refs/heads/master@{#312129}
Diffstat (limited to 'mojo/edk/system/waiter_unittest.cc')
-rw-r--r-- | mojo/edk/system/waiter_unittest.cc | 302 |
1 files changed, 0 insertions, 302 deletions
diff --git a/mojo/edk/system/waiter_unittest.cc b/mojo/edk/system/waiter_unittest.cc deleted file mode 100644 index 859ff0d..0000000 --- a/mojo/edk/system/waiter_unittest.cc +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a -// heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to -// increase tolerance and reduce observed flakiness (though doing so reduces the -// meaningfulness of the test). - -#include "mojo/edk/system/waiter.h" - -#include <stdint.h> - -#include "base/macros.h" -#include "base/synchronization/lock.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. -#include "base/threading/simple_thread.h" -#include "base/time/time.h" -#include "mojo/edk/system/test_utils.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace mojo { -namespace system { -namespace { - -const int64_t kMicrosPerMs = 1000; -const int64_t kPollTimeMicros = 10 * kMicrosPerMs; // 10 ms. - -class WaitingThread : public base::SimpleThread { - public: - explicit WaitingThread(MojoDeadline deadline) - : base::SimpleThread("waiting_thread"), - deadline_(deadline), - done_(false), - result_(MOJO_RESULT_UNKNOWN), - context_(static_cast<uint32_t>(-1)) { - waiter_.Init(); - } - - ~WaitingThread() override { Join(); } - - void WaitUntilDone(MojoResult* result, - uint32_t* context, - base::TimeDelta* elapsed) { - for (;;) { - { - base::AutoLock locker(lock_); - if (done_) { - *result = result_; - *context = context_; - *elapsed = elapsed_; - break; - } - } - - base::PlatformThread::Sleep( - base::TimeDelta::FromMicroseconds(kPollTimeMicros)); - } - } - - Waiter* waiter() { return &waiter_; } - - private: - void Run() override { - test::Stopwatch stopwatch; - MojoResult result; - uint32_t context = static_cast<uint32_t>(-1); - base::TimeDelta elapsed; - - stopwatch.Start(); - result = waiter_.Wait(deadline_, &context); - elapsed = stopwatch.Elapsed(); - - { - base::AutoLock locker(lock_); - done_ = true; - result_ = result; - context_ = context; - elapsed_ = elapsed; - } - } - - const MojoDeadline deadline_; - Waiter waiter_; // Thread-safe. - - base::Lock lock_; // Protects the following members. - bool done_; - MojoResult result_; - uint32_t context_; - base::TimeDelta elapsed_; - - DISALLOW_COPY_AND_ASSIGN(WaitingThread); -}; - -TEST(WaiterTest, Basic) { - MojoResult result; - uint32_t context; - base::TimeDelta elapsed; - - // Finite deadline. - - // Awake immediately after thread start. - { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); - thread.Start(); - thread.waiter()->Awake(MOJO_RESULT_OK, 1); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_OK, result); - EXPECT_EQ(1u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - // Awake before after thread start. - { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); - thread.waiter()->Awake(MOJO_RESULT_CANCELLED, 2); - thread.Start(); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_CANCELLED, result); - EXPECT_EQ(2u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - // Awake some time after thread start. - { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); - thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); - thread.waiter()->Awake(1, 3); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(1, result); - EXPECT_EQ(3u, context); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); - } - - // Awake some longer time after thread start. - { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); - thread.Start(); - base::PlatformThread::Sleep(5 * test::EpsilonTimeout()); - thread.waiter()->Awake(2, 4); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(2, result); - EXPECT_EQ(4u, context); - EXPECT_GT(elapsed, (5 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (5 + 1) * test::EpsilonTimeout()); - } - - // Don't awake -- time out (on another thread). - { - WaitingThread thread(2 * test::EpsilonTimeout().InMicroseconds()); - thread.Start(); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); - EXPECT_EQ(static_cast<uint32_t>(-1), context); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); - } - - // No (indefinite) deadline. - - // Awake immediately after thread start. - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.Start(); - thread.waiter()->Awake(MOJO_RESULT_OK, 5); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_OK, result); - EXPECT_EQ(5u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - // Awake before after thread start. - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.waiter()->Awake(MOJO_RESULT_CANCELLED, 6); - thread.Start(); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_CANCELLED, result); - EXPECT_EQ(6u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - // Awake some time after thread start. - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); - thread.waiter()->Awake(1, 7); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(1, result); - EXPECT_EQ(7u, context); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); - } - - // Awake some longer time after thread start. - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.Start(); - base::PlatformThread::Sleep(5 * test::EpsilonTimeout()); - thread.waiter()->Awake(2, 8); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(2, result); - EXPECT_EQ(8u, context); - EXPECT_GT(elapsed, (5 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (5 + 1) * test::EpsilonTimeout()); - } -} - -TEST(WaiterTest, TimeOut) { - test::Stopwatch stopwatch; - base::TimeDelta elapsed; - - Waiter waiter; - uint32_t context = 123; - - waiter.Init(); - stopwatch.Start(); - EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, &context)); - elapsed = stopwatch.Elapsed(); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - EXPECT_EQ(123u, context); - - waiter.Init(); - stopwatch.Start(); - EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, - waiter.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); - elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); - EXPECT_EQ(123u, context); - - waiter.Init(); - stopwatch.Start(); - EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, - waiter.Wait(5 * test::EpsilonTimeout().InMicroseconds(), &context)); - elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (5 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (5 + 1) * test::EpsilonTimeout()); - EXPECT_EQ(123u, context); -} - -// The first |Awake()| should always win. -TEST(WaiterTest, MultipleAwakes) { - MojoResult result; - uint32_t context; - base::TimeDelta elapsed; - - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.Start(); - thread.waiter()->Awake(MOJO_RESULT_OK, 1); - thread.waiter()->Awake(1, 2); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_OK, result); - EXPECT_EQ(1u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.waiter()->Awake(1, 3); - thread.Start(); - thread.waiter()->Awake(MOJO_RESULT_OK, 4); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(1, result); - EXPECT_EQ(3u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - { - WaitingThread thread(MOJO_DEADLINE_INDEFINITE); - thread.Start(); - thread.waiter()->Awake(10, 5); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); - thread.waiter()->Awake(20, 6); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(10, result); - EXPECT_EQ(5u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); - } - - { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); - thread.Start(); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); - thread.waiter()->Awake(MOJO_RESULT_FAILED_PRECONDITION, 7); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); - thread.waiter()->Awake(MOJO_RESULT_OK, 8); - thread.WaitUntilDone(&result, &context, &elapsed); - EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); - EXPECT_EQ(7u, context); - EXPECT_GT(elapsed, (1 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (1 + 1) * test::EpsilonTimeout()); - } -} - -} // namespace -} // namespace system -} // namespace mojo |