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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 884063003: Updated device reporting code to report multiple samples of free RAM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 baseline_offset_periods_ = 0; 118 baseline_offset_periods_ = 0;
119 } 119 }
120 120
121 void set_mock_cpu_usage(double total_cpu_usage, int num_processors) { 121 void set_mock_cpu_usage(double total_cpu_usage, int num_processors) {
122 std::vector<double> usage; 122 std::vector<double> usage;
123 for (int i = 0; i < num_processors; ++i) 123 for (int i = 0; i < num_processors; ++i)
124 usage.push_back(total_cpu_usage / num_processors); 124 usage.push_back(total_cpu_usage / num_processors);
125 125
126 mock_cpu_usage_ = usage; 126 mock_cpu_usage_ = usage;
127 127
128 // Refresh our samples. 128 RefreshSampleResourceUsage();
129 for (int i = 0; i < static_cast<int>(kMaxCPUSamples); ++i) 129 }
130 SampleCPUUsage(); 130
131 void RefreshSampleResourceUsage() {
132 // Refresh our samples. Sample more than kMaxHardwareSamples times to
133 // make sure that the code correctly caps the number of cached samples.
134 for (int i = 0; i < static_cast<int>(kMaxResourceUsageSamples + 1); ++i)
135 SampleResourceUsage();
131 } 136 }
132 137
133 protected: 138 protected:
134 void CheckIdleState() override { 139 void CheckIdleState() override {
135 // This should never be called in testing, as it results in a dbus call. 140 // This should never be called in testing, as it results in a dbus call.
136 ADD_FAILURE(); 141 ADD_FAILURE();
137 } 142 }
138 143
139 // Each time this is called, returns a time that is a fixed increment 144 // Each time this is called, returns a time that is a fixed increment
140 // later than the previous time. 145 // later than the previous time.
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 << expected_info.volume_id(); 788 << expected_info.volume_id();
784 } 789 }
785 790
786 // Now turn off hardware status reporting - should have no data. 791 // Now turn off hardware status reporting - should have no data.
787 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); 792 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
788 GetStatus(); 793 GetStatus();
789 EXPECT_EQ(0, status_.volume_info_size()); 794 EXPECT_EQ(0, status_.volume_info_size());
790 } 795 }
791 796
792 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { 797 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) {
798 status_collector_->RefreshSampleResourceUsage();
793 GetStatus(); 799 GetStatus();
794 EXPECT_TRUE(status_.has_system_ram_free()); 800 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples),
801 status_.system_ram_free().size());
795 EXPECT_TRUE(status_.has_system_ram_total()); 802 EXPECT_TRUE(status_.has_system_ram_total());
796 // No good way to inject specific test values for available system RAM, so 803 // No good way to inject specific test values for available system RAM, so
797 // just make sure it's > 0. 804 // just make sure it's > 0.
798 EXPECT_GT(status_.system_ram_total(), 0); 805 EXPECT_GT(status_.system_ram_total(), 0);
799 } 806 }
800 807
801 TEST_F(DeviceStatusCollectorTest, TestCPUSamples) { 808 TEST_F(DeviceStatusCollectorTest, TestCPUSamples) {
802 // Mock 100% CPU usage and 2 processors. 809 // Mock 100% CPU usage and 2 processors.
803 const int full_cpu_usage = 100; 810 const int full_cpu_usage = 100;
804 status_collector_->set_mock_cpu_usage(full_cpu_usage, 2); 811 status_collector_->set_mock_cpu_usage(full_cpu_usage, 2);
805 GetStatus(); 812 GetStatus();
806 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxCPUSamples), 813 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples),
807 status_.cpu_utilization_pct().size()); 814 status_.cpu_utilization_pct().size());
808 for (const auto utilization : status_.cpu_utilization_pct()) 815 for (const auto utilization : status_.cpu_utilization_pct())
809 EXPECT_EQ(full_cpu_usage, utilization); 816 EXPECT_EQ(full_cpu_usage, utilization);
810 817
811 // Now set CPU usage to 0. 818 // Now set CPU usage to 0.
812 const int idle_cpu_usage = 0; 819 const int idle_cpu_usage = 0;
813 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2); 820 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2);
814 GetStatus(); 821 GetStatus();
815 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxCPUSamples), 822 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples),
816 status_.cpu_utilization_pct().size()); 823 status_.cpu_utilization_pct().size());
817 for (const auto utilization : status_.cpu_utilization_pct()) 824 for (const auto utilization : status_.cpu_utilization_pct())
818 EXPECT_EQ(idle_cpu_usage, utilization); 825 EXPECT_EQ(idle_cpu_usage, utilization);
819 826
820 // Turning off hardware reporting should not report CPU utilization. 827 // Turning off hardware reporting should not report CPU utilization.
821 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); 828 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
822 GetStatus(); 829 GetStatus();
823 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); 830 EXPECT_EQ(0, status_.cpu_utilization_pct().size());
824 } 831 }
825 832
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 found_match = true; 1095 found_match = true;
1089 break; 1096 break;
1090 } 1097 }
1091 } 1098 }
1092 EXPECT_TRUE(found_match) << "No matching state for fake network " 1099 EXPECT_TRUE(found_match) << "No matching state for fake network "
1093 << " (" << state.name << ")"; 1100 << " (" << state.name << ")";
1094 } 1101 }
1095 } 1102 }
1096 1103
1097 } // namespace policy 1104 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698