OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <utime.h> | 5 #include <utime.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include <base/file_util.h> | 10 #include <base/file_util.h> |
11 #include <base/stringprintf.h> | 11 #include <base/stringprintf.h> |
12 #include <gtest/gtest.h> | 12 #include <gtest/gtest.h> |
13 | 13 |
14 #include "counter_mock.h" | 14 #include "counter_mock.h" |
15 #include "metrics_daemon.h" | 15 #include "metrics_daemon.h" |
16 #include "metrics_library_mock.h" | 16 #include "metrics_library_mock.h" |
17 | 17 |
18 using base::Time; | 18 using base::Time; |
19 using base::TimeTicks; | 19 using base::TimeTicks; |
20 using chromeos_metrics::FrequencyCounter; | 20 using chromeos_metrics::FrequencyCounter; |
21 using chromeos_metrics::FrequencyCounterMock; | 21 using chromeos_metrics::FrequencyCounterMock; |
22 using chromeos_metrics::TaggedCounterMock; | 22 using chromeos_metrics::TaggedCounterMock; |
23 using chromeos_metrics::TaggedCounterReporter; | 23 using chromeos_metrics::TaggedCounterReporter; |
24 using chromeos_metrics::TaggedCounterReporterMock; | 24 using chromeos_metrics::TaggedCounterReporterMock; |
25 using std::string; | 25 using std::string; |
26 using std::vector; | 26 using std::vector; |
27 using ::testing::_; | 27 using ::testing::_; |
28 using ::testing::Return; | 28 using ::testing::Return; |
29 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
30 using ::testing::AtLeast; | |
30 | 31 |
31 static const int kSecondsPerDay = 24 * 60 * 60; | 32 static const int kSecondsPerDay = 24 * 60 * 60; |
32 | 33 |
33 static const char kTestDir[] = "test"; | 34 static const char kTestDir[] = "test"; |
34 static const char kLastFile[] = "test/last"; | 35 static const char kLastFile[] = "test/last"; |
35 static const char kCurrentFile[] = "test/current"; | 36 static const char kCurrentFile[] = "test/current"; |
36 static const char kFakeDiskStatsPath[] = "fake-disk-stats"; | 37 static const char kFakeDiskStatsPath[] = "fake-disk-stats"; |
37 static const char kFakeDiskStatsFormat[] = | 38 static const char kFakeDiskStatsFormat[] = |
38 " 1793 1788 %d 105580 " | 39 " 1793 1788 %d 105580 " |
39 " 196 175 %d 30290 " | 40 " 196 175 %d 30290 " |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 EXPECT_CALL(metrics_lib_, | 572 EXPECT_CALL(metrics_lib_, |
572 SendToUMA(_, (kFakeReadSectors[1] - kFakeReadSectors[0]) / 30, | 573 SendToUMA(_, (kFakeReadSectors[1] - kFakeReadSectors[0]) / 30, |
573 _, _, _)); | 574 _, _, _)); |
574 EXPECT_CALL(metrics_lib_, | 575 EXPECT_CALL(metrics_lib_, |
575 SendToUMA(_, (kFakeWriteSectors[1] - kFakeWriteSectors[0]) / 30, | 576 SendToUMA(_, (kFakeWriteSectors[1] - kFakeWriteSectors[0]) / 30, |
576 _, _, _)); | 577 _, _, _)); |
577 daemon_.DiskStatsCallback(); | 578 daemon_.DiskStatsCallback(); |
578 EXPECT_TRUE(ds_state != daemon_.diskstats_state_); | 579 EXPECT_TRUE(ds_state != daemon_.diskstats_state_); |
579 } | 580 } |
580 | 581 |
582 TEST_F(MetricsDaemonTest, ProcessMeminfo) { | |
583 const char* meminfo = "\ | |
584 MemTotal: 2000000 kB\n\ | |
585 MemFree: 1000000 kB\n\ | |
586 Buffers: 10492 kB\n\ | |
587 Cached: 213652 kB\n\ | |
588 SwapCached: 0 kB\n\ | |
589 Active: 133400 kB\n\ | |
590 Inactive: 183396 kB\n\ | |
591 Active(anon): 92984 kB\n\ | |
592 Inactive(anon): 58860 kB\n\ | |
593 Active(file): 40416 kB\n\ | |
594 Inactive(file): 124536 kB\n\ | |
595 Unevictable: 0 kB\n\ | |
596 Mlocked: 0 kB\n\ | |
597 SwapTotal: 0 kB\n\ | |
598 SwapFree: 0 kB\n\ | |
599 Dirty: 40 kB\n\ | |
600 Writeback: 0 kB\n\ | |
601 AnonPages: 92652 kB\n\ | |
602 Mapped: 59716 kB\n\ | |
603 Shmem: 59196 kB\n\ | |
604 Slab: 16656 kB\n\ | |
605 SReclaimable: 6132 kB\n\ | |
606 SUnreclaim: 10524 kB\n\ | |
607 KernelStack: 1648 kB\n\ | |
608 PageTables: 2780 kB\n\ | |
609 NFS_Unstable: 0 kB\n\ | |
610 Bounce: 0 kB\n\ | |
611 WritebackTmp: 0 kB\n\ | |
612 CommitLimit: 970656 kB\n\ | |
613 Committed_AS: 1260528 kB\n\ | |
kmixter1
2011/04/08 23:04:05
Might be nice to check at least one of these numbe
Luigi Semenzato
2011/04/11 16:28:26
I added a check that one number is parsed correctl
| |
614 VmallocTotal: 122880 kB\n\ | |
615 VmallocUsed: 12144 kB\n\ | |
616 VmallocChunk: 103824 kB\n\ | |
617 DirectMap4k: 9636 kB\n\ | |
618 DirectMap2M: 1955840 kB\n\ | |
619 "; | |
620 EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, _, 100)) | |
621 .Times(AtLeast(1)); | |
622 EXPECT_CALL(metrics_lib_, SendToUMA(_, _, _, _, _)) | |
623 .Times(AtLeast(1)); | |
624 EXPECT_TRUE(daemon_.ProcessMeminfo(meminfo)); | |
625 } | |
626 | |
627 TEST_F(MetricsDaemonTest, ProcessMeminfo2) { | |
628 const char* meminfo = "\ | |
629 MemTotal: 2000000 kB\n\ | |
630 MemFree: 1000000 kB\n\ | |
631 "; | |
632 /* Not enough fields */ | |
633 EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, _, 100)) | |
634 .Times(AtLeast(1)); | |
635 EXPECT_FALSE(daemon_.ProcessMeminfo(meminfo)); | |
636 } | |
637 | |
581 int main(int argc, char** argv) { | 638 int main(int argc, char** argv) { |
582 testing::InitGoogleTest(&argc, argv); | 639 testing::InitGoogleTest(&argc, argv); |
583 return RUN_ALL_TESTS(); | 640 return RUN_ALL_TESTS(); |
584 } | 641 } |
OLD | NEW |