nileshagrawal@chromium.org | a049e95 | 2012-07-11 08:24:43 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
deanm@chromium.org | ee45e8f | 2008-09-18 21:34:24 +0900 | [diff] [blame] | 5 | #include "base/file_util.h" |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 6 | #include "base/sys_info.h" |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 7 | #include "base/threading/platform_thread.h" |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 8 | #include "testing/gtest/include/gtest/gtest.h" |
jeremy@chromium.org | 0d8eba7 | 2008-12-03 04:20:15 +0900 | [diff] [blame] | 9 | #include "testing/platform_test.h" |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 10 | |
mark@chromium.org | 3b2ec6f | 2008-09-26 05:33:42 +0900 | [diff] [blame] | 11 | typedef PlatformTest SysInfoTest; |
brettw@chromium.org | 82bcf51 | 2013-02-17 14:07:23 +0900 | [diff] [blame] | 12 | using base::FilePath; |
mark@chromium.org | 3b2ec6f | 2008-09-26 05:33:42 +0900 | [diff] [blame] | 13 | |
nileshagrawal@chromium.org | a049e95 | 2012-07-11 08:24:43 +0900 | [diff] [blame] | 14 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
robert.nagy@gmail.com | 2172a22 | 2011-10-25 08:47:26 +0900 | [diff] [blame] | 15 | TEST_F(SysInfoTest, MaxSharedMemorySize) { |
| 16 | // We aren't actually testing that it's correct, just that it's sane. |
| 17 | EXPECT_GT(base::SysInfo::MaxSharedMemorySize(), 0u); |
| 18 | } |
| 19 | #endif |
| 20 | |
mark@chromium.org | 3b2ec6f | 2008-09-26 05:33:42 +0900 | [diff] [blame] | 21 | TEST_F(SysInfoTest, NumProcs) { |
deanm@chromium.org | 42a34eb | 2008-09-17 19:09:39 +0900 | [diff] [blame] | 22 | // We aren't actually testing that it's correct, just that it's sane. |
| 23 | EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1); |
| 24 | } |
deanm@chromium.org | 319f044 | 2008-09-17 22:10:45 +0900 | [diff] [blame] | 25 | |
mark@chromium.org | 3b2ec6f | 2008-09-26 05:33:42 +0900 | [diff] [blame] | 26 | TEST_F(SysInfoTest, AmountOfMem) { |
deanm@chromium.org | 319f044 | 2008-09-17 22:10:45 +0900 | [diff] [blame] | 27 | // We aren't actually testing that it's correct, just that it's sane. |
| 28 | EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0); |
deanm@chromium.org | ee45e8f | 2008-09-18 21:34:24 +0900 | [diff] [blame] | 29 | EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0); |
| 30 | } |
| 31 | |
mark@chromium.org | 3b2ec6f | 2008-09-26 05:33:42 +0900 | [diff] [blame] | 32 | TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { |
deanm@chromium.org | ee45e8f | 2008-09-18 21:34:24 +0900 | [diff] [blame] | 33 | // We aren't actually testing that it's correct, just that it's sane. |
phajdan.jr@chromium.org | c800858 | 2009-09-15 04:36:31 +0900 | [diff] [blame] | 34 | FilePath tmp_path; |
deanm@chromium.org | ee45e8f | 2008-09-18 21:34:24 +0900 | [diff] [blame] | 35 | ASSERT_TRUE(file_util::GetTempDir(&tmp_path)); |
tony@chromium.org | 1e25e00 | 2009-10-14 09:41:56 +0900 | [diff] [blame] | 36 | EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0) |
phajdan.jr@chromium.org | c800858 | 2009-09-15 04:36:31 +0900 | [diff] [blame] | 37 | << tmp_path.value(); |
deanm@chromium.org | 319f044 | 2008-09-17 22:10:45 +0900 | [diff] [blame] | 38 | } |
mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame] | 39 | |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 40 | #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
jeremy@chromium.org | 7730edb | 2009-02-25 01:37:13 +0900 | [diff] [blame] | 41 | TEST_F(SysInfoTest, OperatingSystemVersionNumbers) { |
| 42 | int32 os_major_version = -1; |
| 43 | int32 os_minor_version = -1; |
| 44 | int32 os_bugfix_version = -1; |
| 45 | base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 46 | &os_minor_version, |
| 47 | &os_bugfix_version); |
| 48 | EXPECT_GT(os_major_version, -1); |
| 49 | EXPECT_GT(os_minor_version, -1); |
| 50 | EXPECT_GT(os_bugfix_version, -1); |
| 51 | } |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 52 | #endif |
| 53 | |
jeremy@chromium.org | de658ed | 2012-10-29 10:04:09 +0900 | [diff] [blame] | 54 | TEST_F(SysInfoTest, Uptime) { |
| 55 | int64 up_time_1 = base::SysInfo::Uptime(); |
| 56 | // UpTime() is implemented internally using TimeTicks::Now(), which documents |
| 57 | // system resolution as being 1-15ms. Sleep a little longer than that. |
| 58 | base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
| 59 | int64 up_time_2 = base::SysInfo::Uptime(); |
| 60 | EXPECT_GT(up_time_1, 0); |
| 61 | EXPECT_GT(up_time_2, up_time_1); |
| 62 | } |
| 63 | |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 64 | #if defined(OS_CHROMEOS) |
| 65 | TEST_F(SysInfoTest, GoogleChromeOSVersionNumbers) { |
| 66 | int32 os_major_version = -1; |
| 67 | int32 os_minor_version = -1; |
| 68 | int32 os_bugfix_version = -1; |
| 69 | std::string lsb_release("FOO=1234123.34.5\n"); |
| 70 | lsb_release.append(base::SysInfo::GetLinuxStandardBaseVersionKey()); |
| 71 | lsb_release.append("=1.2.3.4\n"); |
| 72 | base::SysInfo::ParseLsbRelease(lsb_release, |
| 73 | &os_major_version, |
| 74 | &os_minor_version, |
| 75 | &os_bugfix_version); |
rkc@chromium.org | d9ab606 | 2011-10-03 15:22:12 +0900 | [diff] [blame] | 76 | EXPECT_EQ(1, os_major_version); |
| 77 | EXPECT_EQ(2, os_minor_version); |
| 78 | EXPECT_EQ(3, os_bugfix_version); |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | TEST_F(SysInfoTest, GoogleChromeOSVersionNumbersFirst) { |
| 82 | int32 os_major_version = -1; |
| 83 | int32 os_minor_version = -1; |
| 84 | int32 os_bugfix_version = -1; |
| 85 | std::string lsb_release(base::SysInfo::GetLinuxStandardBaseVersionKey()); |
| 86 | lsb_release.append("=1.2.3.4\n"); |
| 87 | lsb_release.append("FOO=1234123.34.5\n"); |
| 88 | base::SysInfo::ParseLsbRelease(lsb_release, |
| 89 | &os_major_version, |
| 90 | &os_minor_version, |
| 91 | &os_bugfix_version); |
rkc@chromium.org | d9ab606 | 2011-10-03 15:22:12 +0900 | [diff] [blame] | 92 | EXPECT_EQ(1, os_major_version); |
| 93 | EXPECT_EQ(2, os_minor_version); |
| 94 | EXPECT_EQ(3, os_bugfix_version); |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | TEST_F(SysInfoTest, GoogleChromeOSNoVersionNumbers) { |
| 98 | int32 os_major_version = -1; |
| 99 | int32 os_minor_version = -1; |
| 100 | int32 os_bugfix_version = -1; |
| 101 | std::string lsb_release("FOO=1234123.34.5\n"); |
| 102 | base::SysInfo::ParseLsbRelease(lsb_release, |
| 103 | &os_major_version, |
| 104 | &os_minor_version, |
| 105 | &os_bugfix_version); |
cmasone@google.com | a672b9c | 2009-12-09 10:55:04 +0900 | [diff] [blame] | 106 | EXPECT_EQ(-1, os_major_version); |
| 107 | EXPECT_EQ(-1, os_minor_version); |
| 108 | EXPECT_EQ(-1, os_bugfix_version); |
evan@chromium.org | 54b7210 | 2009-07-22 09:35:18 +0900 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | #endif // OS_CHROMEOS |