2016-05-14 11:31:40 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-03-10 09:33:53 -08:00
|
|
|
#if defined(WEBRTC_WIN)
|
|
|
|
|
// clang-format off
|
|
|
|
|
#include <windows.h> // Must come first.
|
|
|
|
|
#include <mmsystem.h>
|
|
|
|
|
// clang-format on
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stdint.h>
|
2016-05-14 11:31:40 -07:00
|
|
|
#include <memory>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <utility>
|
2016-05-14 11:31:40 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "absl/memory/memory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/bind.h"
|
|
|
|
|
#include "rtc_base/event.h"
|
2019-03-26 14:37:01 +01:00
|
|
|
#include "rtc_base/task_queue_for_test.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2016-05-14 11:31:40 -07:00
|
|
|
|
|
|
|
|
namespace rtc {
|
2018-02-13 19:47:50 +01:00
|
|
|
|
2017-03-10 09:33:53 -08:00
|
|
|
namespace {
|
|
|
|
|
// Noop on all platforms except Windows, where it turns on high precision
|
|
|
|
|
// multimedia timers which increases the precision of TimeMillis() while in
|
|
|
|
|
// scope.
|
|
|
|
|
class EnableHighResTimers {
|
|
|
|
|
public:
|
|
|
|
|
#if !defined(WEBRTC_WIN)
|
|
|
|
|
EnableHighResTimers() {}
|
|
|
|
|
#else
|
|
|
|
|
EnableHighResTimers() : enabled_(timeBeginPeriod(1) == TIMERR_NOERROR) {}
|
|
|
|
|
~EnableHighResTimers() {
|
|
|
|
|
if (enabled_)
|
|
|
|
|
timeEndPeriod(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const bool enabled_;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
2016-05-14 11:31:40 -07:00
|
|
|
|
2017-09-04 05:18:21 -07:00
|
|
|
void CheckCurrent(Event* signal, TaskQueue* queue) {
|
2016-05-14 11:31:40 -07:00
|
|
|
EXPECT_TRUE(queue->IsCurrent());
|
|
|
|
|
if (signal)
|
|
|
|
|
signal->Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2017-03-10 09:33:53 -08:00
|
|
|
// This task needs to be run manually due to the slowness of some of our bots.
|
|
|
|
|
// TODO(tommi): Can we run this on the perf bots?
|
|
|
|
|
TEST(TaskQueueTest, DISABLED_PostDelayedHighRes) {
|
|
|
|
|
EnableHighResTimers high_res_scope;
|
|
|
|
|
|
|
|
|
|
static const char kQueueName[] = "PostDelayedHighRes";
|
2018-11-07 08:43:50 +01:00
|
|
|
Event event;
|
2019-03-26 14:37:01 +01:00
|
|
|
webrtc::TaskQueueForTest queue(kQueueName, TaskQueue::Priority::HIGH);
|
2017-03-10 09:33:53 -08:00
|
|
|
|
|
|
|
|
uint32_t start = Time();
|
2017-09-04 05:18:21 -07:00
|
|
|
queue.PostDelayedTask(Bind(&CheckCurrent, &event, &queue), 3);
|
2017-03-10 09:33:53 -08:00
|
|
|
EXPECT_TRUE(event.Wait(1000));
|
|
|
|
|
uint32_t end = TimeMillis();
|
|
|
|
|
// These tests are a little relaxed due to how "powerful" our test bots can
|
|
|
|
|
// be. Most recently we've seen windows bots fire the callback after 94-99ms,
|
|
|
|
|
// which is why we have a little bit of leeway backwards as well.
|
|
|
|
|
EXPECT_GE(end - start, 3u);
|
|
|
|
|
EXPECT_NEAR(end - start, 3, 3u);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-14 11:31:40 -07:00
|
|
|
} // namespace rtc
|