15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_TEST_TEST_TIMEOUTS_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_TEST_TEST_TIMEOUTS_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns common timeouts to use in tests. Makes it possible to adjust
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the timeouts for different environments (like Valgrind).
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestTimeouts {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the timeouts. Non thread-safe. Should be called exactly once
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // by the test suite.
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void Initialize();
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Timeout for actions that are expected to finish "almost instantly".
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static base::TimeDelta tiny_timeout() {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(initialized_);
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return base::TimeDelta::FromMilliseconds(tiny_timeout_ms_);
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Timeout to wait for something to happen. If you are not sure
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // which timeout to use, this is the one you want.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static base::TimeDelta action_timeout() {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(initialized_);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return base::TimeDelta::FromMilliseconds(action_timeout_ms_);
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Timeout longer than the above, but still suitable to use
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // multiple times in a single test. Use if the timeout above
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is not sufficient.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static base::TimeDelta action_max_timeout() {
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(initialized_);
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return base::TimeDelta::FromMilliseconds(action_max_timeout_ms_);
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Timeout for a single test launched used built-in test launcher.
4268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Do not use outside of the test launcher.
4368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static base::TimeDelta test_launcher_timeout() {
4468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    DCHECK(initialized_);
4568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    return base::TimeDelta::FromMilliseconds(test_launcher_timeout_ms_);
4668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  }
4768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool initialized_;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static int tiny_timeout_ms_;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static int action_timeout_ms_;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static int action_max_timeout_ms_;
5468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  static int test_launcher_timeout_ms_;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(TestTimeouts);
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // BASE_TEST_TEST_TIMEOUTS_H_
60