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

Unified Diff: third_party/mojo/src/mojo/edk/system/waiter_unittest.cc

Issue 1676913002: [mojo] Delete third_party/mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: let's try that again Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/edk/system/waiter_unittest.cc
diff --git a/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc b/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc
deleted file mode 100644
index de0e66284938e89fd2715621a18f5b7ea57e5b48..0000000000000000000000000000000000000000
--- a/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc
+++ /dev/null
@@ -1,298 +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::EpsilonDeadline()| may be increased to
-// increase tolerance and reduce observed flakiness (though doing so reduces the
-// meaningfulness of the test).
-
-#include "third_party/mojo/src/mojo/edk/system/waiter.h"
-
-#include <stdint.h>
-
-#include "base/threading/simple_thread.h"
-#include "mojo/public/cpp/system/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/mojo/src/mojo/edk/system/mutex.h"
-#include "third_party/mojo/src/mojo/edk/system/test_utils.h"
-
-namespace mojo {
-namespace system {
-namespace {
-
-const unsigned kPollTimeMs = 10;
-
-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<uintptr_t>(-1)) {
- waiter_.Init();
- }
-
- ~WaitingThread() override { Join(); }
-
- void WaitUntilDone(MojoResult* result,
- uintptr_t* context,
- MojoDeadline* elapsed) {
- for (;;) {
- {
- MutexLocker locker(&mutex_);
- if (done_) {
- *result = result_;
- *context = context_;
- *elapsed = elapsed_;
- break;
- }
- }
-
- test::Sleep(test::DeadlineFromMilliseconds(kPollTimeMs));
- }
- }
-
- Waiter* waiter() { return &waiter_; }
-
- private:
- void Run() override {
- test::Stopwatch stopwatch;
- MojoResult result;
- uintptr_t context = static_cast<uintptr_t>(-1);
- MojoDeadline elapsed;
-
- stopwatch.Start();
- result = waiter_.Wait(deadline_, &context);
- elapsed = stopwatch.Elapsed();
-
- {
- MutexLocker locker(&mutex_);
- done_ = true;
- result_ = result;
- context_ = context;
- elapsed_ = elapsed;
- }
- }
-
- const MojoDeadline deadline_;
- Waiter waiter_; // Thread-safe.
-
- Mutex mutex_;
- bool done_ MOJO_GUARDED_BY(mutex_);
- MojoResult result_ MOJO_GUARDED_BY(mutex_);
- uintptr_t context_ MOJO_GUARDED_BY(mutex_);
- MojoDeadline elapsed_ MOJO_GUARDED_BY(mutex_);
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(WaitingThread);
-};
-
-TEST(WaiterTest, Basic) {
- MojoResult result;
- uintptr_t context;
- MojoDeadline elapsed;
-
- // Finite deadline.
-
- // Awake immediately after thread start.
- {
- WaitingThread thread(10 * test::EpsilonDeadline());
- 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::EpsilonDeadline());
- }
-
- // Awake before after thread start.
- {
- WaitingThread thread(10 * test::EpsilonDeadline());
- 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::EpsilonDeadline());
- }
-
- // Awake some time after thread start.
- {
- WaitingThread thread(10 * test::EpsilonDeadline());
- thread.Start();
- test::Sleep(2 * test::EpsilonDeadline());
- thread.waiter()->Awake(1, 3);
- thread.WaitUntilDone(&result, &context, &elapsed);
- EXPECT_EQ(1u, result);
- EXPECT_EQ(3u, context);
- EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline());
- }
-
- // Awake some longer time after thread start.
- {
- WaitingThread thread(10 * test::EpsilonDeadline());
- thread.Start();
- test::Sleep(5 * test::EpsilonDeadline());
- thread.waiter()->Awake(2, 4);
- thread.WaitUntilDone(&result, &context, &elapsed);
- EXPECT_EQ(2u, result);
- EXPECT_EQ(4u, context);
- EXPECT_GT(elapsed, (5 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (5 + 1) * test::EpsilonDeadline());
- }
-
- // Don't awake -- time out (on another thread).
- {
- WaitingThread thread(2 * test::EpsilonDeadline());
- thread.Start();
- thread.WaitUntilDone(&result, &context, &elapsed);
- EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result);
- EXPECT_EQ(static_cast<uintptr_t>(-1), context);
- EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline());
- }
-
- // 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::EpsilonDeadline());
- }
-
- // 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::EpsilonDeadline());
- }
-
- // Awake some time after thread start.
- {
- WaitingThread thread(MOJO_DEADLINE_INDEFINITE);
- thread.Start();
- test::Sleep(2 * test::EpsilonDeadline());
- thread.waiter()->Awake(1, 7);
- thread.WaitUntilDone(&result, &context, &elapsed);
- EXPECT_EQ(1u, result);
- EXPECT_EQ(7u, context);
- EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline());
- }
-
- // Awake some longer time after thread start.
- {
- WaitingThread thread(MOJO_DEADLINE_INDEFINITE);
- thread.Start();
- test::Sleep(5 * test::EpsilonDeadline());
- thread.waiter()->Awake(2, 8);
- thread.WaitUntilDone(&result, &context, &elapsed);
- EXPECT_EQ(2u, result);
- EXPECT_EQ(8u, context);
- EXPECT_GT(elapsed, (5 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (5 + 1) * test::EpsilonDeadline());
- }
-}
-
-TEST(WaiterTest, TimeOut) {
- test::Stopwatch stopwatch;
- MojoDeadline elapsed;
-
- Waiter waiter;
- uintptr_t context = 123;
-
- waiter.Init();
- stopwatch.Start();
- EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, &context));
- elapsed = stopwatch.Elapsed();
- EXPECT_LT(elapsed, test::EpsilonDeadline());
- EXPECT_EQ(123u, context);
-
- waiter.Init();
- stopwatch.Start();
- EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
- waiter.Wait(2 * test::EpsilonDeadline(), &context));
- elapsed = stopwatch.Elapsed();
- EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline());
- EXPECT_EQ(123u, context);
-
- waiter.Init();
- stopwatch.Start();
- EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
- waiter.Wait(5 * test::EpsilonDeadline(), &context));
- elapsed = stopwatch.Elapsed();
- EXPECT_GT(elapsed, (5 - 1) * test::EpsilonDeadline());
- EXPECT_LT(elapsed, (5 + 1) * test::EpsilonDeadline());
- EXPECT_EQ(123u, context);
-}
-
-// The first |Awake()| should always win.
-TEST(WaiterTest, MultipleAwakes) {
- MojoResult result;
- uintptr_t context;
- MojoDeadline 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::EpsilonDeadline());
- }
-
- {
- 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(1u, result);
- EXPECT_EQ(3u, context);
- EXPECT_LT(elapsed, test::EpsilonDeadline());
- }
-
- {
- WaitingThread thread(MOJO_DEADLINE_INDEFINITE);
- thread.Start();
- thread.waiter()->Awake(10, 5);
- test::Sleep(2 * test::EpsilonDeadline());
- thread.waiter()->Awake(20, 6);
- thread.WaitUntilDone(&result, &context, &elapsed);
- EXPECT_EQ(10u, result);
- EXPECT_EQ(5u, context);
- EXPECT_LT(elapsed, test::EpsilonDeadline());
- }
-
- {
- WaitingThread thread(10 * test::EpsilonDeadline());
- thread.Start();
- test::Sleep(1 * test::EpsilonDeadline());
- thread.waiter()->Awake(MOJO_RESULT_FAILED_PRECONDITION, 7);
- test::Sleep(2 * test::EpsilonDeadline());
- 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::EpsilonDeadline());
- EXPECT_LT(elapsed, (1 + 1) * test::EpsilonDeadline());
- }
-}
-
-} // namespace
-} // namespace system
-} // namespace mojo
« no previous file with comments | « third_party/mojo/src/mojo/edk/system/waiter_test_utils.cc ('k') | third_party/mojo/src/mojo/edk/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698