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

Unified Diff: remoting/host/host_stats_unittest.cc

Issue 2775983003: [Chromoting] Retrieve process resource usage (ProcessStats) and its tests (Closed)
Patch Set: Created 3 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
« remoting/host/host_stats_stub.h ('K') | « remoting/host/host_stats_stub.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/host_stats_unittest.cc
diff --git a/remoting/host/host_stats_unittest.cc b/remoting/host/host_stats_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..99dfe731cba2eb551dee69348228bdb29f491f8c
--- /dev/null
+++ b/remoting/host/host_stats_unittest.cc
@@ -0,0 +1,127 @@
+// Copyright 2017 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/host_stats.h"
+
+#include <stdint.h>
+
+#include <vector>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/time/time.h"
+#include "remoting/base/process_resource_usage.h"
+#include "remoting/host/host_stats_stub.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+namespace host {
+
+namespace {
+
+class MockHostStatsStub : public HostStatsStub {
+ public:
+ MockHostStatsStub() = default;
+ ~MockHostStatsStub() = default;
+
+ void OnHostStats(const ProcessResourceUsage& usage) override {
+ received_.push_back(usage);
+ }
+
+ const std::vector<ProcessResourceUsage>& received() const {
+ return received_;
+ }
+
+ void Clear() {
+ received_.clear();
+ }
+
+ private:
+ std::vector<ProcessResourceUsage> received_;
+};
+
+} // namespace
+
+TEST(HostStatsTest, ReportUsage) {
+ base::MessageLoop message_loop;
+ base::RunLoop run_loop;
+ MockHostStatsStub stub;
+ std::unique_ptr<HostStats> stats;
+ message_loop.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind([](std::unique_ptr<HostStats>* stats,
+ MockHostStatsStub* stub) -> void {
+ stats->reset(new HostStats(stub, base::TimeDelta::FromSeconds(1)));
+ },
+ base::Unretained(&stats),
+ base::Unretained(&stub)));
+ message_loop.task_runner()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind([](std::unique_ptr<HostStats>* stats) -> void {
+ stats->reset();
+ },
+ base::Unretained(&stats)),
+ base::TimeDelta::FromSecondsD(2.1));
+ message_loop.task_runner()->PostDelayedTask(
+ FROM_HERE,
+ run_loop.QuitClosure(),
+ base::TimeDelta::FromSecondsD(2.2));
+ run_loop.Run();
+
+ ASSERT_EQ(2U, stub.received().size());
+}
+
+TEST(HostStatsTest, MergeUsage) {
+ base::MessageLoop message_loop;
+ base::RunLoop run_loop;
+ MockHostStatsStub stub;
+ std::unique_ptr<HostStats> stats;
+ message_loop.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind([](std::unique_ptr<HostStats>* stats,
+ MockHostStatsStub* stub) -> void {
+ stats->reset(new HostStats(stub, base::TimeDelta::FromSeconds(1)));
+ },
+ base::Unretained(&stats),
+ base::Unretained(&stub)));
+ message_loop.task_runner()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind([](std::unique_ptr<HostStats>* stats) -> void {
+ ProcessResourceUsage fake_usage;
+ fake_usage.processor_usage = 10000000;
+ fake_usage.working_set_size = SIZE_MAX >> 1;
+ fake_usage.pagefile_size = SIZE_MAX >> 1;
+ static_cast<HostStatsStub*>(stats->get())->OnHostStats(fake_usage);
+ },
+ base::Unretained(&stats)),
+ base::TimeDelta::FromSecondsD(1.1));
+ message_loop.task_runner()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind([](std::unique_ptr<HostStats>* stats) -> void {
+ stats->reset();
+ },
+ base::Unretained(&stats)),
+ base::TimeDelta::FromSecondsD(3.1));
+ message_loop.task_runner()->PostDelayedTask(
+ FROM_HERE,
+ run_loop.QuitClosure(),
+ base::TimeDelta::FromSecondsD(3.2));
+ run_loop.Run();
+
+ ASSERT_EQ(3U, stub.received().size());
+ ASSERT_LT(stub.received()[0].processor_usage, 10000000);
+ ASSERT_LT(stub.received()[0].working_set_size, SIZE_MAX >> 1);
+ ASSERT_LT(stub.received()[0].pagefile_size, SIZE_MAX >> 1);
+ ASSERT_GE(stub.received()[1].processor_usage, 10000000);
+ ASSERT_GE(stub.received()[1].working_set_size, SIZE_MAX >> 1);
+ ASSERT_GE(stub.received()[1].pagefile_size, SIZE_MAX >> 1);
+ ASSERT_GE(stub.received()[2].processor_usage, 10000000);
+ ASSERT_GE(stub.received()[2].working_set_size, SIZE_MAX >> 1);
+ ASSERT_GE(stub.received()[2].pagefile_size, SIZE_MAX >> 1);
+}
+
+} // namespace host
+} // namespace remoting
« remoting/host/host_stats_stub.h ('K') | « remoting/host/host_stats_stub.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698