Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Unified Diff: remoting/host/capture_scheduler_unittest.cc

Issue 12803008: Add unit tests for sub-components of CaptureScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/capture_scheduler_unittest.cc
diff --git a/remoting/host/capture_scheduler_unittest.cc b/remoting/host/capture_scheduler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b6d290f55579d76b1836ba2ff1d7f169b12ca6fe
--- /dev/null
+++ b/remoting/host/capture_scheduler_unittest.cc
@@ -0,0 +1,80 @@
+// 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 "remoting/host/capture_scheduler.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 };
+
+TEST(CaptureSchedulerTest, SingleSampleSameTimes) {
+ const int kTestResults[][arraysize(kTestInputs)] = {
+ { 400, 200, 120, 80, 50, 120, 240, 320 }, // One core.
+ { 200, 100, 60, 50, 50, 60, 120, 160 }, // Two cores.
+ { 100, 50, 50, 50, 50, 50, 60, 80 }, // Four cores.
+ { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores.
+ };
+
+ for (size_t i = 0; i < arraysize(kTestResults); ++i) {
+ for (size_t j = 0; j < arraysize(kTestInputs); ++j) {
+ CaptureScheduler scheduler;
+ scheduler.SetNumOfProcessorsForTest(1 << i);
+ scheduler.RecordCaptureTime(
+ base::TimeDelta::FromMilliseconds(kTestInputs[j]));
+ scheduler.RecordEncodeTime(
+ base::TimeDelta::FromMilliseconds(kTestInputs[j]));
+ EXPECT_EQ(kTestResults[i][j],
+ scheduler.NextCaptureDelay().InMilliseconds());
+ }
+ }
+}
+
+TEST(CaptureSchedulerTest, SingleSampleDifferentTimes) {
+ const int kTestResults[][arraysize(kTestInputs)] = {
+ { 360, 220, 120, 60, 60, 120, 220, 360 }, // One core.
+ { 180, 110, 60, 50, 50, 60, 110, 180 }, // Two cores.
+ { 90, 55, 50, 50, 50, 50, 55, 90 }, // Four cores.
+ { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores.
+ };
+
+ for (size_t i = 0; i < arraysize(kTestResults); ++i) {
+ for (size_t j = 0; j < arraysize(kTestInputs); ++j) {
+ CaptureScheduler scheduler;
+ scheduler.SetNumOfProcessorsForTest(1 << i);
+ scheduler.RecordCaptureTime(
+ base::TimeDelta::FromMilliseconds(kTestInputs[j]));
+ scheduler.RecordEncodeTime(
+ base::TimeDelta::FromMilliseconds(
+ kTestInputs[arraysize(kTestInputs) - 1 - j]));
+ EXPECT_EQ(kTestResults[i][j],
+ scheduler.NextCaptureDelay().InMilliseconds());
+ }
+ }
+}
+
+TEST(CaptureSchedulerTest, RollingAverageDifferentTimes) {
+ const int kTestResults[][arraysize(kTestInputs)] = {
+ { 360, 290, 233, 133, 80, 80, 133, 233 }, // One core.
alexeypa (please no reviews) 2013/03/18 19:39:39 nit: How are there values obtained? If CaptureSche
Wez 2013/03/19 23:23:14 Then we'd just have two copies of the same calcula
+ { 180, 145, 116, 66, 50, 50, 66, 116 }, // Two cores.
+ { 90, 72, 58, 50, 50, 50, 50, 58 }, // Four cores.
+ { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores.
+ };
+
+ for (size_t i = 0; i < arraysize(kTestResults); ++i) {
+ CaptureScheduler scheduler;
+ scheduler.SetNumOfProcessorsForTest(1 << i);
+ for (size_t j = 0; j < arraysize(kTestInputs); ++j) {
+ scheduler.RecordCaptureTime(
+ base::TimeDelta::FromMilliseconds(kTestInputs[j]));
+ scheduler.RecordEncodeTime(
+ base::TimeDelta::FromMilliseconds(
+ kTestInputs[arraysize(kTestInputs) - 1 - j]));
+ EXPECT_EQ(kTestResults[i][j],
+ scheduler.NextCaptureDelay().InMilliseconds());
+ }
+ }
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698