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

Side by Side Diff: base/sys_info_unittest.cc

Issue 23588009: Parse /etc/lsb-release only once on ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 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 | Annotate | Revision Log
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 "base/environment.h"
5 #include "base/file_util.h" 6 #include "base/file_util.h"
6 #include "base/sys_info.h" 7 #include "base/sys_info.h"
7 #include "base/threading/platform_thread.h" 8 #include "base/threading/platform_thread.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
10 11
11 typedef PlatformTest SysInfoTest; 12 typedef PlatformTest SysInfoTest;
12 using base::FilePath; 13 using base::FilePath;
13 14
14 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 15 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
(...skipping 15 matching lines...) Expand all
30 } 31 }
31 32
32 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { 33 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
33 // We aren't actually testing that it's correct, just that it's sane. 34 // We aren't actually testing that it's correct, just that it's sane.
34 FilePath tmp_path; 35 FilePath tmp_path;
35 ASSERT_TRUE(file_util::GetTempDir(&tmp_path)); 36 ASSERT_TRUE(file_util::GetTempDir(&tmp_path));
36 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) 37 EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0)
37 << tmp_path.value(); 38 << tmp_path.value();
38 } 39 }
39 40
40 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 41 #if defined(OS_WIN) || defined(OS_MACOSX)
41 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) { 42 TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
42 int32 os_major_version = -1; 43 int32 os_major_version = -1;
43 int32 os_minor_version = -1; 44 int32 os_minor_version = -1;
44 int32 os_bugfix_version = -1; 45 int32 os_bugfix_version = -1;
45 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, 46 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
46 &os_minor_version, 47 &os_minor_version,
47 &os_bugfix_version); 48 &os_bugfix_version);
48 EXPECT_GT(os_major_version, -1); 49 EXPECT_GT(os_major_version, -1);
49 EXPECT_GT(os_minor_version, -1); 50 EXPECT_GT(os_minor_version, -1);
50 EXPECT_GT(os_bugfix_version, -1); 51 EXPECT_GT(os_bugfix_version, -1);
51 } 52 }
52 #endif 53 #endif
53 54
54 TEST_F(SysInfoTest, Uptime) { 55 TEST_F(SysInfoTest, Uptime) {
55 int64 up_time_1 = base::SysInfo::Uptime(); 56 int64 up_time_1 = base::SysInfo::Uptime();
56 // UpTime() is implemented internally using TimeTicks::Now(), which documents 57 // UpTime() is implemented internally using TimeTicks::Now(), which documents
57 // system resolution as being 1-15ms. Sleep a little longer than that. 58 // system resolution as being 1-15ms. Sleep a little longer than that.
58 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); 59 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
59 int64 up_time_2 = base::SysInfo::Uptime(); 60 int64 up_time_2 = base::SysInfo::Uptime();
60 EXPECT_GT(up_time_1, 0); 61 EXPECT_GT(up_time_1, 0);
61 EXPECT_GT(up_time_2, up_time_1); 62 EXPECT_GT(up_time_2, up_time_1);
62 } 63 }
63 64
64 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
66
65 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { 67 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) {
66 int32 os_major_version = -1; 68 int32 os_major_version = -1;
67 int32 os_minor_version = -1; 69 int32 os_minor_version = -1;
68 int32 os_bugfix_version = -1; 70 int32 os_bugfix_version = -1;
69 std::string lsb_release("FOO=1234123.34.5\n"); 71 const char* kLsbRelease =
70 lsb_release.append(base::SysInfo::GetLinuxStandardBaseVersionKey()); 72 "FOO=1234123.34.5\n"
71 lsb_release.append("=1.2.3.4\n"); 73 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n";
72 base::SysInfo::ParseLsbRelease(lsb_release, 74 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, 0);
73 &os_major_version, 75 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
74 &os_minor_version, 76 &os_minor_version,
75 &os_bugfix_version); 77 &os_bugfix_version);
76 EXPECT_EQ(1, os_major_version); 78 EXPECT_EQ(1, os_major_version);
77 EXPECT_EQ(2, os_minor_version); 79 EXPECT_EQ(2, os_minor_version);
78 EXPECT_EQ(3, os_bugfix_version); 80 EXPECT_EQ(3, os_bugfix_version);
79 } 81 }
80 82
81 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { 83 TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) {
82 int32 os_major_version = -1; 84 int32 os_major_version = -1;
83 int32 os_minor_version = -1; 85 int32 os_minor_version = -1;
84 int32 os_bugfix_version = -1; 86 int32 os_bugfix_version = -1;
85 std::string lsb_release(base::SysInfo::GetLinuxStandardBaseVersionKey()); 87 const char* kLsbRelease =
86 lsb_release.append("=1.2.3.4\n"); 88 "CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
87 lsb_release.append("FOO=1234123.34.5\n"); 89 "FOO=1234123.34.5\n";
88 base::SysInfo::ParseLsbRelease(lsb_release, 90 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, 0);
89 &os_major_version, 91 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
90 &os_minor_version, 92 &os_minor_version,
91 &os_bugfix_version); 93 &os_bugfix_version);
92 EXPECT_EQ(1, os_major_version); 94 EXPECT_EQ(1, os_major_version);
93 EXPECT_EQ(2, os_minor_version); 95 EXPECT_EQ(2, os_minor_version);
94 EXPECT_EQ(3, os_bugfix_version); 96 EXPECT_EQ(3, os_bugfix_version);
95 } 97 }
96 98
97 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { 99 TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) {
98 int32 os_major_version = -1; 100 int32 os_major_version = -1;
99 int32 os_minor_version = -1; 101 int32 os_minor_version = -1;
100 int32 os_bugfix_version = -1; 102 int32 os_bugfix_version = -1;
101 std::string lsb_release("FOO=1234123.34.5\n"); 103 const char* kLsbRelease = "FOO=1234123.34.5\n";
102 base::SysInfo::ParseLsbRelease(lsb_release, 104 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, 0);
103 &os_major_version, 105 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
104 &os_minor_version, 106 &os_minor_version,
105 &os_bugfix_version); 107 &os_bugfix_version);
106 EXPECT_EQ(-1, os_major_version); 108 EXPECT_EQ(0, os_major_version);
107 EXPECT_EQ(-1, os_minor_version); 109 EXPECT_EQ(0, os_minor_version);
108 EXPECT_EQ(-1, os_bugfix_version); 110 EXPECT_EQ(0, os_bugfix_version);
111 }
112
113 TEST_F(SysInfoTest, GoogleChromeOSLsbReleaseTime) {
114 const char* kLsbRelease = "CHROMEOS_RELEASE_VERSION=1.2.3.4";
115 double lsb_release_time = 12345;
116 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, lsb_release_time);
117 base::Time parsed_lsb_release_time = base::SysInfo::GetLsbReleaseTime();
118 EXPECT_EQ(lsb_release_time, parsed_lsb_release_time.ToDoubleT());
109 } 119 }
110 120
111 #endif // OS_CHROMEOS 121 #endif // OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698