| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_ | 5 #ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_ |
| 6 #define MOJO_EDK_SYSTEM_TEST_UTILS_H_ | 6 #define MOJO_EDK_SYSTEM_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include "base/test/test_io_thread.h" |
| 8 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "mojo/edk/test/scoped_ipc_support.h" |
| 9 #include "mojo/public/c/system/types.h" | 11 #include "mojo/public/c/system/types.h" |
| 10 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 14 |
| 12 namespace mojo { | 15 namespace mojo { |
| 13 namespace system { | 16 namespace edk { |
| 14 namespace test { | 17 namespace test { |
| 15 | 18 |
| 16 MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds); | 19 MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds); |
| 17 | 20 |
| 18 // A timeout smaller than |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. | 21 // A timeout smaller than |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. |
| 19 // Warning: This may lead to flakiness, but this is unavoidable if, e.g., you're | 22 // Warning: This may lead to flakiness, but this is unavoidable if, e.g., you're |
| 20 // trying to ensure that functions with timeouts are reasonably accurate. We | 23 // trying to ensure that functions with timeouts are reasonably accurate. We |
| 21 // want this to be as small as possible without causing too much flakiness. | 24 // want this to be as small as possible without causing too much flakiness. |
| 22 MojoDeadline EpsilonDeadline(); | 25 MojoDeadline EpsilonDeadline(); |
| 23 | 26 |
| 24 // |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. (Expect this to be on | 27 // |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. (Expect this to be on |
| 25 // the order of 100 ms.) | 28 // the order of 100 ms.) |
| 26 MojoDeadline TinyDeadline(); | 29 MojoDeadline TinyDeadline(); |
| 27 | 30 |
| 28 // |TestTimeouts::action_timeout()|, as a |MojoDeadline|. (Expect this to be on | 31 // |TestTimeouts::action_timeout()|, as a |MojoDeadline|.(Expect this to be on |
| 29 // the order of 10 s.) | 32 // the order of 10 s.) |
| 30 MojoDeadline ActionDeadline(); | 33 MojoDeadline ActionDeadline(); |
| 31 | 34 |
| 32 // Sleeps for at least the specified duration. | 35 // Sleeps for at least the specified duration. |
| 33 void Sleep(MojoDeadline deadline); | 36 void Sleep(MojoDeadline deadline); |
| 34 | 37 |
| 35 // Stopwatch ------------------------------------------------------------------- | 38 // Stopwatch ------------------------------------------------------------------- |
| 36 | 39 |
| 37 // A simple "stopwatch" for measuring time elapsed from a given starting point. | 40 // A simple "stopwatch" for measuring time elapsed from a given starting point. |
| 38 class Stopwatch { | 41 class Stopwatch { |
| 39 public: | 42 public: |
| 40 Stopwatch(); | 43 Stopwatch(); |
| 41 ~Stopwatch(); | 44 ~Stopwatch(); |
| 42 | 45 |
| 43 void Start(); | 46 void Start(); |
| 44 // Returns the amount of time elapsed since the last call to |Start()| (in | 47 // Returns the amount of time elapsed since the last call to |Start()| (in |
| 45 // microseconds). | 48 // microseconds). |
| 46 MojoDeadline Elapsed(); | 49 MojoDeadline Elapsed(); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 base::TimeTicks start_time_; | 52 base::TimeTicks start_time_; |
| 50 | 53 |
| 51 MOJO_DISALLOW_COPY_AND_ASSIGN(Stopwatch); | 54 MOJO_DISALLOW_COPY_AND_ASSIGN(Stopwatch); |
| 52 }; | 55 }; |
| 53 | 56 |
| 57 // A base class which initializes and shuts down the necessary objects so that |
| 58 // Mojo system calls can be made. |
| 59 class MojoSystemTest : public testing::Test { |
| 60 public: |
| 61 MojoSystemTest(); |
| 62 ~MojoSystemTest() override; |
| 63 |
| 64 private: |
| 65 base::MessageLoop message_loop_; |
| 66 base::TestIOThread test_io_thread_; |
| 67 test::ScopedIPCSupport ipc_support_; |
| 68 |
| 69 MOJO_DISALLOW_COPY_AND_ASSIGN(MojoSystemTest); |
| 70 }; |
| 71 |
| 54 } // namespace test | 72 } // namespace test |
| 55 } // namespace system | 73 } // namespace edk |
| 56 } // namespace mojo | 74 } // namespace mojo |
| 57 | 75 |
| 58 #endif // MOJO_EDK_SYSTEM_TEST_UTILS_H_ | 76 #endif // MOJO_EDK_SYSTEM_TEST_UTILS_H_ |
| OLD | NEW |