You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2008, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <stdio.h>
  28. #include "talk/base/linux.h"
  29. #include "talk/base/fileutils.h"
  30. #include "talk/base/logging.h"
  31. #include "talk/base/gunit.h"
  32. namespace talk_base {
  33. // These tests running on ARM are fairly specific to the output of the tegra2
  34. // ARM processor, and so may fail on other ARM-based systems.
  35. TEST(ProcCpuInfo, GetProcInfo) {
  36. ProcCpuInfo proc_info;
  37. EXPECT_TRUE(proc_info.LoadFromSystem());
  38. int out_cpus = 0;
  39. EXPECT_TRUE(proc_info.GetNumCpus(&out_cpus));
  40. LOG(LS_INFO) << "GetNumCpus: " << out_cpus;
  41. EXPECT_GT(out_cpus, 0);
  42. int out_cpus_phys = 0;
  43. EXPECT_TRUE(proc_info.GetNumPhysicalCpus(&out_cpus_phys));
  44. LOG(LS_INFO) << "GetNumPhysicalCpus: " << out_cpus_phys;
  45. EXPECT_GT(out_cpus_phys, 0);
  46. EXPECT_LE(out_cpus_phys, out_cpus);
  47. int out_family = 0;
  48. EXPECT_TRUE(proc_info.GetCpuFamily(&out_family));
  49. LOG(LS_INFO) << "cpu family: " << out_family;
  50. EXPECT_GE(out_family, 4);
  51. #if defined(__arm__)
  52. std::string out_processor;
  53. EXPECT_TRUE(proc_info.GetSectionStringValue(0, "Processor", &out_processor));
  54. LOG(LS_INFO) << "Processor: " << out_processor;
  55. EXPECT_NE(std::string::npos, out_processor.find("ARM"));
  56. // Most other info, such as model, stepping, vendor, etc.
  57. // is missing on ARM systems.
  58. #else
  59. int out_model = 0;
  60. EXPECT_TRUE(proc_info.GetSectionIntValue(0, "model", &out_model));
  61. LOG(LS_INFO) << "model: " << out_model;
  62. int out_stepping = 0;
  63. EXPECT_TRUE(proc_info.GetSectionIntValue(0, "stepping", &out_stepping));
  64. LOG(LS_INFO) << "stepping: " << out_stepping;
  65. int out_processor = 0;
  66. EXPECT_TRUE(proc_info.GetSectionIntValue(0, "processor", &out_processor));
  67. LOG(LS_INFO) << "processor: " << out_processor;
  68. EXPECT_EQ(0, out_processor);
  69. std::string out_str;
  70. EXPECT_TRUE(proc_info.GetSectionStringValue(0, "vendor_id", &out_str));
  71. LOG(LS_INFO) << "vendor_id: " << out_str;
  72. EXPECT_FALSE(out_str.empty());
  73. #endif
  74. }
  75. TEST(ConfigParser, ParseConfig) {
  76. ConfigParser parser;
  77. MemoryStream *test_stream = new MemoryStream(
  78. "Key1: Value1\n"
  79. "Key2\t: Value2\n"
  80. "Key3:Value3\n"
  81. "\n"
  82. "Key1:Value1\n");
  83. ConfigParser::MapVector key_val_pairs;
  84. parser.Attach(test_stream);
  85. EXPECT_EQ(true, parser.Parse(&key_val_pairs));
  86. EXPECT_EQ(2U, key_val_pairs.size());
  87. EXPECT_EQ("Value1", key_val_pairs[0]["Key1"]);
  88. EXPECT_EQ("Value2", key_val_pairs[0]["Key2"]);
  89. EXPECT_EQ("Value3", key_val_pairs[0]["Key3"]);
  90. EXPECT_EQ("Value1", key_val_pairs[1]["Key1"]);
  91. key_val_pairs.clear();
  92. EXPECT_EQ(true, parser.Open("/proc/cpuinfo"));
  93. EXPECT_EQ(true, parser.Parse(&key_val_pairs));
  94. }
  95. TEST(ReadLinuxLsbRelease, ReturnsSomething) {
  96. std::string str = ReadLinuxLsbRelease();
  97. // ChromeOS don't have lsb_release
  98. // EXPECT_FALSE(str.empty());
  99. }
  100. TEST(ReadLinuxUname, ReturnsSomething) {
  101. std::string str = ReadLinuxUname();
  102. EXPECT_FALSE(str.empty());
  103. }
  104. } // namespace talk_base