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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "remoting/host/host_stats.h"
6
7 #include <stdint.h>
8
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/location.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
15 #include "base/time/time.h"
16 #include "remoting/base/process_resource_usage.h"
17 #include "remoting/host/host_stats_stub.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace remoting {
21 namespace host {
22
23 namespace {
24
25 class MockHostStatsStub : public HostStatsStub {
26 public:
27 MockHostStatsStub() = default;
28 ~MockHostStatsStub() = default;
29
30 void OnHostStats(const ProcessResourceUsage& usage) override {
31 received_.push_back(usage);
32 }
33
34 const std::vector<ProcessResourceUsage>& received() const {
35 return received_;
36 }
37
38 void Clear() {
39 received_.clear();
40 }
41
42 private:
43 std::vector<ProcessResourceUsage> received_;
44 };
45
46 } // namespace
47
48 TEST(HostStatsTest, ReportUsage) {
49 base::MessageLoop message_loop;
50 base::RunLoop run_loop;
51 MockHostStatsStub stub;
52 std::unique_ptr<HostStats> stats;
53 message_loop.task_runner()->PostTask(
54 FROM_HERE,
55 base::Bind([](std::unique_ptr<HostStats>* stats,
56 MockHostStatsStub* stub) -> void {
57 stats->reset(new HostStats(stub, base::TimeDelta::FromSeconds(1)));
58 },
59 base::Unretained(&stats),
60 base::Unretained(&stub)));
61 message_loop.task_runner()->PostDelayedTask(
62 FROM_HERE,
63 base::Bind([](std::unique_ptr<HostStats>* stats) -> void {
64 stats->reset();
65 },
66 base::Unretained(&stats)),
67 base::TimeDelta::FromSecondsD(2.1));
68 message_loop.task_runner()->PostDelayedTask(
69 FROM_HERE,
70 run_loop.QuitClosure(),
71 base::TimeDelta::FromSecondsD(2.2));
72 run_loop.Run();
73
74 ASSERT_EQ(2U, stub.received().size());
75 }
76
77 TEST(HostStatsTest, MergeUsage) {
78 base::MessageLoop message_loop;
79 base::RunLoop run_loop;
80 MockHostStatsStub stub;
81 std::unique_ptr<HostStats> stats;
82 message_loop.task_runner()->PostTask(
83 FROM_HERE,
84 base::Bind([](std::unique_ptr<HostStats>* stats,
85 MockHostStatsStub* stub) -> void {
86 stats->reset(new HostStats(stub, base::TimeDelta::FromSeconds(1)));
87 },
88 base::Unretained(&stats),
89 base::Unretained(&stub)));
90 message_loop.task_runner()->PostDelayedTask(
91 FROM_HERE,
92 base::Bind([](std::unique_ptr<HostStats>* stats) -> void {
93 ProcessResourceUsage fake_usage;
94 fake_usage.processor_usage = 10000000;
95 fake_usage.working_set_size = SIZE_MAX >> 1;
96 fake_usage.pagefile_size = SIZE_MAX >> 1;
97 static_cast<HostStatsStub*>(stats->get())->OnHostStats(fake_usage);
98 },
99 base::Unretained(&stats)),
100 base::TimeDelta::FromSecondsD(1.1));
101 message_loop.task_runner()->PostDelayedTask(
102 FROM_HERE,
103 base::Bind([](std::unique_ptr<HostStats>* stats) -> void {
104 stats->reset();
105 },
106 base::Unretained(&stats)),
107 base::TimeDelta::FromSecondsD(3.1));
108 message_loop.task_runner()->PostDelayedTask(
109 FROM_HERE,
110 run_loop.QuitClosure(),
111 base::TimeDelta::FromSecondsD(3.2));
112 run_loop.Run();
113
114 ASSERT_EQ(3U, stub.received().size());
115 ASSERT_LT(stub.received()[0].processor_usage, 10000000);
116 ASSERT_LT(stub.received()[0].working_set_size, SIZE_MAX >> 1);
117 ASSERT_LT(stub.received()[0].pagefile_size, SIZE_MAX >> 1);
118 ASSERT_GE(stub.received()[1].processor_usage, 10000000);
119 ASSERT_GE(stub.received()[1].working_set_size, SIZE_MAX >> 1);
120 ASSERT_GE(stub.received()[1].pagefile_size, SIZE_MAX >> 1);
121 ASSERT_GE(stub.received()[2].processor_usage, 10000000);
122 ASSERT_GE(stub.received()[2].working_set_size, SIZE_MAX >> 1);
123 ASSERT_GE(stub.received()[2].pagefile_size, SIZE_MAX >> 1);
124 }
125
126 } // namespace host
127 } // namespace remoting
OLDNEW
« 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