Commit 29ad581e authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

mojo: Remove MojoDeadline type and test utilities for it.

Use base::TimeDelta instead.

Change-Id: I8065fbb31e0360180ed2d201fd3a1c31c20b8144
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522237Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825026}
parent 51b91ccd
...@@ -59,7 +59,6 @@ test("mojo_perftests") { ...@@ -59,7 +59,6 @@ test("mojo_perftests") {
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//mojo/core:embedder_internal", "//mojo/core:embedder_internal",
"//mojo/core:test_utils",
"//mojo/core/embedder", "//mojo/core/embedder",
"//testing/gtest", "//testing/gtest",
] ]
......
...@@ -264,27 +264,6 @@ if (is_chromeos || is_linux || is_android || is_win) { ...@@ -264,27 +264,6 @@ if (is_chromeos || is_linux || is_android || is_win) {
} }
} }
source_set("test_utils") {
testonly = true
sources = [
"test_utils.cc",
"test_utils.h",
]
public_deps = [
"//mojo/public/c/system",
"//mojo/public/cpp/system",
]
deps = [
"//base",
"//base/test:test_support",
"//mojo/core/test:test_support",
"//testing/gtest:gtest",
]
}
source_set("test_sources") { source_set("test_sources") {
testonly = true testonly = true
sources = [ sources = [
...@@ -316,7 +295,6 @@ source_set("test_sources") { ...@@ -316,7 +295,6 @@ source_set("test_sources") {
} }
deps = [ deps = [
":test_utils",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//mojo/core:embedder_internal", "//mojo/core:embedder_internal",
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/c/system/types.h" #include "mojo/public/c/system/types.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/core/core_test_base.h" #include "mojo/core/core_test_base.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/cpp/system/wait.h" #include "mojo/public/cpp/system/wait.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -35,7 +34,7 @@ TEST_F(CoreTest, GetTimeTicksNow) { ...@@ -35,7 +34,7 @@ TEST_F(CoreTest, GetTimeTicksNow) {
const MojoTimeTicks start = core()->GetTimeTicksNow(); const MojoTimeTicks start = core()->GetTimeTicksNow();
ASSERT_NE(static_cast<MojoTimeTicks>(0), start) ASSERT_NE(static_cast<MojoTimeTicks>(0), start)
<< "GetTimeTicksNow should return nonzero value"; << "GetTimeTicksNow should return nonzero value";
test::Sleep(test::DeadlineFromMilliseconds(15)); base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(15));
const MojoTimeTicks finish = core()->GetTimeTicksNow(); const MojoTimeTicks finish = core()->GetTimeTicksNow();
// Allow for some fuzz in sleep. // Allow for some fuzz in sleep.
ASSERT_GE((finish - start), static_cast<MojoTimeTicks>(8000)) ASSERT_GE((finish - start), static_cast<MojoTimeTicks>(8000))
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "mojo/core/test/mojo_test_base.h" #include "mojo/core/test/mojo_test_base.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/c/system/data_pipe.h" #include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/functions.h" #include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/message_pipe.h" #include "mojo/public/c/system/message_pipe.h"
...@@ -45,6 +44,28 @@ const int kMultiprocessMaxIter = 5; ...@@ -45,6 +44,28 @@ const int kMultiprocessMaxIter = 5;
// Capacity that will cause data pipe creation to fail. // Capacity that will cause data pipe creation to fail.
constexpr size_t kOversizedCapacity = std::numeric_limits<uint32_t>::max(); constexpr size_t kOversizedCapacity = std::numeric_limits<uint32_t>::max();
// A timeout smaller than |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|.
// Warning: This may lead to flakiness, but this is unavoidable if, e.g., you're
// trying to ensure that functions with timeouts are reasonably accurate. We
// want this to be as small as possible without causing too much flakiness.
base::TimeDelta EpsilonDeadline() {
const int64_t tiny_timeout = TestTimeouts::tiny_timeout().InMicroseconds();
// Originally, our epsilon timeout was 10 ms, which was mostly fine but flaky on
// some Windows bots. I don't recall ever seeing flakes on other bots. At 30 ms
// tests seem reliable on Windows bots, but not at 25 ms. We'd like this timeout
// to be as small as possible (see the description in the .h file).
//
// Currently, |tiny_timeout()| is usually 100 ms (possibly scaled under ASAN,
// etc.). Based on this, set it to (usually be) 30 ms on Windows and 20 ms
// elsewhere.
#if defined(OS_WIN) || defined(OS_ANDROID)
const int64_t deadline = (tiny_timeout * 3) / 10;
#else
const int64_t deadline = (tiny_timeout * 2) / 10;
#endif
return base::TimeDelta::FromMicroseconds(deadline);
}
// TODO(rockot): There are many uses of ASSERT where EXPECT would be more // TODO(rockot): There are many uses of ASSERT where EXPECT would be more
// appropriate. Fix this. // appropriate. Fix this.
...@@ -948,7 +969,7 @@ TEST_F(DataPipeTest, AllOrNone) { ...@@ -948,7 +969,7 @@ TEST_F(DataPipeTest, AllOrNone) {
if (num_bytes >= 10u * sizeof(int32_t)) if (num_bytes >= 10u * sizeof(int32_t))
break; break;
test::Sleep(test::EpsilonDeadline()); base::PlatformThread::Sleep(EpsilonDeadline());
} }
ASSERT_EQ(10u * sizeof(int32_t), num_bytes); ASSERT_EQ(10u * sizeof(int32_t), num_bytes);
...@@ -1154,7 +1175,7 @@ TEST_F(DataPipeTest, WriteCloseProducerRead) { ...@@ -1154,7 +1175,7 @@ TEST_F(DataPipeTest, WriteCloseProducerRead) {
if (num_bytes >= 2u * kTestDataSize) if (num_bytes >= 2u * kTestDataSize)
break; break;
test::Sleep(test::EpsilonDeadline()); base::PlatformThread::Sleep(EpsilonDeadline());
} }
ASSERT_EQ(2u * kTestDataSize, num_bytes); ASSERT_EQ(2u * kTestDataSize, num_bytes);
...@@ -1423,7 +1444,7 @@ TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) { ...@@ -1423,7 +1444,7 @@ TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) {
// Wait a bit, to make sure that if a signal were (incorrectly) sent, it'd // Wait a bit, to make sure that if a signal were (incorrectly) sent, it'd
// have time to propagate. // have time to propagate.
test::Sleep(test::EpsilonDeadline()); base::PlatformThread::Sleep(EpsilonDeadline());
// Still no data. // Still no data.
num_bytes = 1000u; num_bytes = 1000u;
...@@ -1441,7 +1462,7 @@ TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) { ...@@ -1441,7 +1462,7 @@ TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) {
ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EndWriteData(0u)); ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EndWriteData(0u));
// Wait a bit (as above). // Wait a bit (as above).
test::Sleep(test::EpsilonDeadline()); base::PlatformThread::Sleep(EpsilonDeadline());
// Still no data. // Still no data.
num_bytes = 1000u; num_bytes = 1000u;
...@@ -1460,7 +1481,7 @@ TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) { ...@@ -1460,7 +1481,7 @@ TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) {
ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EndWriteData(0u)); ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EndWriteData(0u));
// Wait a bit (as above). // Wait a bit (as above).
test::Sleep(test::EpsilonDeadline()); base::PlatformThread::Sleep(EpsilonDeadline());
// Still no data. // Still no data.
num_bytes = 1000u; num_bytes = 1000u;
...@@ -1705,7 +1726,7 @@ bool ReadAllData(MojoHandle consumer, ...@@ -1705,7 +1726,7 @@ bool ReadAllData(MojoHandle consumer,
if (num_bytes == 0) { if (num_bytes == 0) {
if (expect_empty) { if (expect_empty) {
// Expect no more data. // Expect no more data.
test::Sleep(test::TinyDeadline()); base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
MojoReadDataOptions options; MojoReadDataOptions options;
options.struct_size = sizeof(options); options.struct_size = sizeof(options);
options.flags = MOJO_READ_DATA_FLAG_QUERY; options.flags = MOJO_READ_DATA_FLAG_QUERY;
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "mojo/core/core.h" #include "mojo/core/core.h"
#include "mojo/core/shared_buffer_dispatcher.h" #include "mojo/core/shared_buffer_dispatcher.h"
#include "mojo/core/test/mojo_test_base.h" #include "mojo/core/test/mojo_test_base.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/c/system/core.h" #include "mojo/public/c/system/core.h"
#include "mojo/public/cpp/system/handle.h" #include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "mojo/core/handle_signals_state.h" #include "mojo/core/handle_signals_state.h"
#include "mojo/core/test/mojo_test_base.h" #include "mojo/core/test/mojo_test_base.h"
#include "mojo/core/test/test_utils.h" #include "mojo/core/test/test_utils.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/c/system/functions.h" #include "mojo/public/c/system/functions.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/core/test/mojo_test_base.h" #include "mojo/core/test/mojo_test_base.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/c/system/core.h" #include "mojo/public/c/system/core.h"
#include "mojo/public/c/system/types.h" #include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "mojo/core/handle_signals_state.h" #include "mojo/core/handle_signals_state.h"
#include "mojo/core/test/mojo_test_base.h" #include "mojo/core/test/mojo_test_base.h"
#include "mojo/core/test/test_utils.h" #include "mojo/core/test/test_utils.h"
#include "mojo/core/test_utils.h"
#include "mojo/public/c/system/buffer.h" #include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/functions.h" #include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/types.h" #include "mojo/public/c/system/types.h"
......
// 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.
#include "mojo/core/test_utils.h"
#include <stdint.h>
#include <limits>
#include "base/check_op.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h" // For |Sleep()|.
#include "build/build_config.h"
namespace mojo {
namespace core {
namespace test {
MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds) {
return static_cast<MojoDeadline>(milliseconds) * 1000;
}
MojoDeadline EpsilonDeadline() {
// Originally, our epsilon timeout was 10 ms, which was mostly fine but flaky on
// some Windows bots. I don't recall ever seeing flakes on other bots. At 30 ms
// tests seem reliable on Windows bots, but not at 25 ms. We'd like this timeout
// to be as small as possible (see the description in the .h file).
//
// Currently, |tiny_timeout()| is usually 100 ms (possibly scaled under ASAN,
// etc.). Based on this, set it to (usually be) 30 ms on Windows and 20 ms
// elsewhere.
#if defined(OS_WIN) || defined(OS_ANDROID)
return (TinyDeadline() * 3) / 10;
#else
return (TinyDeadline() * 2) / 10;
#endif
}
MojoDeadline TinyDeadline() {
return static_cast<MojoDeadline>(
TestTimeouts::tiny_timeout().InMicroseconds());
}
MojoDeadline ActionDeadline() {
return static_cast<MojoDeadline>(
TestTimeouts::action_timeout().InMicroseconds());
}
void Sleep(MojoDeadline deadline) {
CHECK_LE(deadline,
static_cast<MojoDeadline>(std::numeric_limits<int64_t>::max()));
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(static_cast<int64_t>(deadline)));
}
Stopwatch::Stopwatch() = default;
Stopwatch::~Stopwatch() = default;
void Stopwatch::Start() {
start_time_ = base::TimeTicks::Now();
}
MojoDeadline Stopwatch::Elapsed() {
int64_t result = (base::TimeTicks::Now() - start_time_).InMicroseconds();
// |DCHECK_GE|, not |CHECK_GE|, since this may be performance-important.
DCHECK_GE(result, 0);
return static_cast<MojoDeadline>(result);
}
} // namespace test
} // namespace core
} // namespace mojo
// 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.
#ifndef MOJO_CORE_TEST_UTILS_H_
#define MOJO_CORE_TEST_UTILS_H_
#include "base/macros.h"
#include "base/time/time.h"
#include "mojo/public/c/system/types.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace core {
namespace test {
MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds);
// A timeout smaller than |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|.
// Warning: This may lead to flakiness, but this is unavoidable if, e.g., you're
// trying to ensure that functions with timeouts are reasonably accurate. We
// want this to be as small as possible without causing too much flakiness.
MojoDeadline EpsilonDeadline();
// |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. (Expect this to be on
// the order of 100 ms.)
MojoDeadline TinyDeadline();
// |TestTimeouts::action_timeout()|, as a |MojoDeadline|. (Expect this to be on
// the order of 10 s.)
MojoDeadline ActionDeadline();
// Sleeps for at least the specified duration.
void Sleep(MojoDeadline deadline);
// Stopwatch -------------------------------------------------------------------
// A simple "stopwatch" for measuring time elapsed from a given starting point.
class Stopwatch {
public:
Stopwatch();
~Stopwatch();
void Start();
// Returns the amount of time elapsed since the last call to |Start()| (in
// microseconds).
MojoDeadline Elapsed();
private:
base::TimeTicks start_time_;
DISALLOW_COPY_AND_ASSIGN(Stopwatch);
};
} // namespace test
} // namespace core
} // namespace mojo
#endif // MOJO_CORE_TEST_UTILS_H_
...@@ -124,18 +124,6 @@ const MojoResult MOJO_RESULT_SHOULD_WAIT = 17; ...@@ -124,18 +124,6 @@ const MojoResult MOJO_RESULT_SHOULD_WAIT = 17;
#define MOJO_RESULT_SHOULD_WAIT ((MojoResult)17) #define MOJO_RESULT_SHOULD_WAIT ((MojoResult)17)
#endif #endif
// |MojoDeadline|: Used to specify deadlines (timeouts), in microseconds (except
// for |MOJO_DEADLINE_INDEFINITE|).
// |MOJO_DEADLINE_INDEFINITE| - Used to indicate "forever".
typedef uint64_t MojoDeadline;
#ifdef __cplusplus
const MojoDeadline MOJO_DEADLINE_INDEFINITE = static_cast<MojoDeadline>(-1);
#else
#define MOJO_DEADLINE_INDEFINITE ((MojoDeadline)-1)
#endif
// Flags passed to |MojoInitialize()| via |MojoInitializeOptions|. // Flags passed to |MojoInitialize()| via |MojoInitializeOptions|.
typedef uint32_t MojoInitializeFlags; typedef uint32_t MojoInitializeFlags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment