Home | History | Annotate | Download | only in base
      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
      3 // found in the LICENSE file.
      4 
      5 #include "base/file_util.h"
      6 #include "base/sys_info.h"
      7 #include "base/threading/platform_thread.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 #include "testing/platform_test.h"
     10 
     11 typedef PlatformTest SysInfoTest;
     12 using base::FilePath;
     13 
     14 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
     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 
     21 TEST_F(SysInfoTest, NumProcs) {
     22   // We aren't actually testing that it's correct, just that it's sane.
     23   EXPECT_GE(base::SysInfo::NumberOfProcessors(), 1);
     24 }
     25 
     26 TEST_F(SysInfoTest, AmountOfMem) {
     27   // We aren't actually testing that it's correct, just that it's sane.
     28   EXPECT_GT(base::SysInfo::AmountOfPhysicalMemory(), 0);
     29   EXPECT_GT(base::SysInfo::AmountOfPhysicalMemoryMB(), 0);
     30 }
     31 
     32 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
     33   // We aren't actually testing that it's correct, just that it's sane.
     34   FilePath tmp_path;
     35   ASSERT_TRUE(file_util::GetTempDir(&tmp_path));
     36   EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0)
     37             << tmp_path.value();
     38 }
     39 
     40 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
     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 }
     52 #endif
     53 
     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 
     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);
     76   EXPECT_EQ(1, os_major_version);
     77   EXPECT_EQ(2, os_minor_version);
     78   EXPECT_EQ(3, os_bugfix_version);
     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);
     92   EXPECT_EQ(1, os_major_version);
     93   EXPECT_EQ(2, os_minor_version);
     94   EXPECT_EQ(3, os_bugfix_version);
     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);
    106   EXPECT_EQ(-1, os_major_version);
    107   EXPECT_EQ(-1, os_minor_version);
    108   EXPECT_EQ(-1, os_bugfix_version);
    109 }
    110 
    111 #endif  // OS_CHROMEOS
    112