Home | History | Annotate | Download | only in system
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_
      6 #define MOJO_EDK_SYSTEM_TEST_UTILS_H_
      7 
      8 #include "base/macros.h"
      9 #include "base/time/time.h"
     10 #include "mojo/public/c/system/types.h"
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 
     13 namespace mojo {
     14 namespace edk {
     15 namespace test {
     16 
     17 MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds);
     18 
     19 // A timeout smaller than |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|.
     20 // Warning: This may lead to flakiness, but this is unavoidable if, e.g., you're
     21 // trying to ensure that functions with timeouts are reasonably accurate. We
     22 // want this to be as small as possible without causing too much flakiness.
     23 MojoDeadline EpsilonDeadline();
     24 
     25 // |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. (Expect this to be on
     26 // the order of 100 ms.)
     27 MojoDeadline TinyDeadline();
     28 
     29 // |TestTimeouts::action_timeout()|, as a |MojoDeadline|. (Expect this to be on
     30 // the order of 10 s.)
     31 MojoDeadline ActionDeadline();
     32 
     33 // Sleeps for at least the specified duration.
     34 void Sleep(MojoDeadline deadline);
     35 
     36 // Stopwatch -------------------------------------------------------------------
     37 
     38 // A simple "stopwatch" for measuring time elapsed from a given starting point.
     39 class Stopwatch {
     40  public:
     41   Stopwatch();
     42   ~Stopwatch();
     43 
     44   void Start();
     45   // Returns the amount of time elapsed since the last call to |Start()| (in
     46   // microseconds).
     47   MojoDeadline Elapsed();
     48 
     49  private:
     50   base::TimeTicks start_time_;
     51 
     52   DISALLOW_COPY_AND_ASSIGN(Stopwatch);
     53 };
     54 
     55 }  // namespace test
     56 }  // namespace edk
     57 }  // namespace mojo
     58 
     59 #endif  // MOJO_EDK_SYSTEM_TEST_UTILS_H_
     60