blob: c65ef071c59b25d0c602068a1dd83909ff44c936 [file] [log] [blame]
henrike@webrtc.org47be73b2014-05-13 18:00:26 +00001/*
2 * Copyright 2008 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <stdio.h>
12#include "webrtc/base/linux.h"
13#include "webrtc/base/fileutils.h"
14#include "webrtc/base/logging.h"
15#include "webrtc/base/gunit.h"
16
17namespace rtc {
18
19// These tests running on ARM are fairly specific to the output of the tegra2
20// ARM processor, and so may fail on other ARM-based systems.
21TEST(ProcCpuInfo, GetProcInfo) {
22 ProcCpuInfo proc_info;
23 EXPECT_TRUE(proc_info.LoadFromSystem());
24
25 int out_cpus = 0;
26 EXPECT_TRUE(proc_info.GetNumCpus(&out_cpus));
27 LOG(LS_INFO) << "GetNumCpus: " << out_cpus;
28 EXPECT_GT(out_cpus, 0);
29
30 int out_cpus_phys = 0;
31 EXPECT_TRUE(proc_info.GetNumPhysicalCpus(&out_cpus_phys));
32 LOG(LS_INFO) << "GetNumPhysicalCpus: " << out_cpus_phys;
33 EXPECT_GT(out_cpus_phys, 0);
34 EXPECT_LE(out_cpus_phys, out_cpus);
35
36 int out_family = 0;
37 EXPECT_TRUE(proc_info.GetCpuFamily(&out_family));
38 LOG(LS_INFO) << "cpu family: " << out_family;
39 EXPECT_GE(out_family, 4);
40
41#if defined(__arm__)
42 std::string out_processor;
43 EXPECT_TRUE(proc_info.GetSectionStringValue(0, "Processor", &out_processor));
44 LOG(LS_INFO) << "Processor: " << out_processor;
45 EXPECT_NE(std::string::npos, out_processor.find("ARM"));
46
47 // Most other info, such as model, stepping, vendor, etc.
48 // is missing on ARM systems.
49#else
50 int out_model = 0;
51 EXPECT_TRUE(proc_info.GetSectionIntValue(0, "model", &out_model));
52 LOG(LS_INFO) << "model: " << out_model;
53
54 int out_stepping = 0;
55 EXPECT_TRUE(proc_info.GetSectionIntValue(0, "stepping", &out_stepping));
56 LOG(LS_INFO) << "stepping: " << out_stepping;
57
58 int out_processor = 0;
59 EXPECT_TRUE(proc_info.GetSectionIntValue(0, "processor", &out_processor));
60 LOG(LS_INFO) << "processor: " << out_processor;
61 EXPECT_EQ(0, out_processor);
62
63 std::string out_str;
64 EXPECT_TRUE(proc_info.GetSectionStringValue(0, "vendor_id", &out_str));
65 LOG(LS_INFO) << "vendor_id: " << out_str;
66 EXPECT_FALSE(out_str.empty());
67#endif
68}
69
70TEST(ConfigParser, ParseConfig) {
71 ConfigParser parser;
72 MemoryStream *test_stream = new MemoryStream(
73 "Key1: Value1\n"
74 "Key2\t: Value2\n"
75 "Key3:Value3\n"
76 "\n"
77 "Key1:Value1\n");
78 ConfigParser::MapVector key_val_pairs;
79 parser.Attach(test_stream);
80 EXPECT_EQ(true, parser.Parse(&key_val_pairs));
81 EXPECT_EQ(2U, key_val_pairs.size());
82 EXPECT_EQ("Value1", key_val_pairs[0]["Key1"]);
83 EXPECT_EQ("Value2", key_val_pairs[0]["Key2"]);
84 EXPECT_EQ("Value3", key_val_pairs[0]["Key3"]);
85 EXPECT_EQ("Value1", key_val_pairs[1]["Key1"]);
86 key_val_pairs.clear();
87 EXPECT_EQ(true, parser.Open("/proc/cpuinfo"));
88 EXPECT_EQ(true, parser.Parse(&key_val_pairs));
89}
90
91#if !defined(WEBRTC_CHROMIUM_BUILDs)
92TEST(ReadLinuxLsbRelease, ReturnsSomething) {
93 std::string str = ReadLinuxLsbRelease();
94 // ChromeOS don't have lsb_release
95 // EXPECT_FALSE(str.empty());
96}
97#endif
98
99TEST(ReadLinuxUname, ReturnsSomething) {
100 std::string str = ReadLinuxUname();
101 EXPECT_FALSE(str.empty());
102}
103
104} // namespace rtc