blob: f6815141d2bcee108ef35e4a13a1783fe363460f [file] [log] [blame]
henrike@webrtc.org0e118e72013-07-10 00:45:36 +00001/*
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
28#include <stdio.h>
29#include "talk/base/linux.h"
30#include "talk/base/fileutils.h"
31#include "talk/base/logging.h"
32#include "talk/base/gunit.h"
33
34namespace talk_base {
35
36// These tests running on ARM are fairly specific to the output of the tegra2
37// ARM processor, and so may fail on other ARM-based systems.
38TEST(ProcCpuInfo, GetProcInfo) {
39 ProcCpuInfo proc_info;
40 EXPECT_TRUE(proc_info.LoadFromSystem());
41
42 int out_cpus = 0;
43 EXPECT_TRUE(proc_info.GetNumCpus(&out_cpus));
44 LOG(LS_INFO) << "GetNumCpus: " << out_cpus;
45 EXPECT_GT(out_cpus, 0);
46
47 int out_cpus_phys = 0;
48 EXPECT_TRUE(proc_info.GetNumPhysicalCpus(&out_cpus_phys));
49 LOG(LS_INFO) << "GetNumPhysicalCpus: " << out_cpus_phys;
50 EXPECT_GT(out_cpus_phys, 0);
51 EXPECT_LE(out_cpus_phys, out_cpus);
52
53 int out_family = 0;
54 EXPECT_TRUE(proc_info.GetCpuFamily(&out_family));
55 LOG(LS_INFO) << "cpu family: " << out_family;
56 EXPECT_GE(out_family, 4);
57
58#if defined(__arm__)
59 std::string out_processor;
60 EXPECT_TRUE(proc_info.GetSectionStringValue(0, "Processor", &out_processor));
61 LOG(LS_INFO) << "Processor: " << out_processor;
62 EXPECT_NE(std::string::npos, out_processor.find("ARM"));
63
64 // Most other info, such as model, stepping, vendor, etc.
65 // is missing on ARM systems.
66#else
67 int out_model = 0;
68 EXPECT_TRUE(proc_info.GetSectionIntValue(0, "model", &out_model));
69 LOG(LS_INFO) << "model: " << out_model;
70
71 int out_stepping = 0;
72 EXPECT_TRUE(proc_info.GetSectionIntValue(0, "stepping", &out_stepping));
73 LOG(LS_INFO) << "stepping: " << out_stepping;
74
75 int out_processor = 0;
76 EXPECT_TRUE(proc_info.GetSectionIntValue(0, "processor", &out_processor));
77 LOG(LS_INFO) << "processor: " << out_processor;
78 EXPECT_EQ(0, out_processor);
79
80 std::string out_str;
81 EXPECT_TRUE(proc_info.GetSectionStringValue(0, "vendor_id", &out_str));
82 LOG(LS_INFO) << "vendor_id: " << out_str;
83 EXPECT_FALSE(out_str.empty());
84#endif
85}
86
87TEST(ConfigParser, ParseConfig) {
88 ConfigParser parser;
89 MemoryStream *test_stream = new MemoryStream(
90 "Key1: Value1\n"
91 "Key2\t: Value2\n"
92 "Key3:Value3\n"
93 "\n"
94 "Key1:Value1\n");
95 ConfigParser::MapVector key_val_pairs;
96 parser.Attach(test_stream);
97 EXPECT_EQ(true, parser.Parse(&key_val_pairs));
98 EXPECT_EQ(2U, key_val_pairs.size());
99 EXPECT_EQ("Value1", key_val_pairs[0]["Key1"]);
100 EXPECT_EQ("Value2", key_val_pairs[0]["Key2"]);
101 EXPECT_EQ("Value3", key_val_pairs[0]["Key3"]);
102 EXPECT_EQ("Value1", key_val_pairs[1]["Key1"]);
103 key_val_pairs.clear();
104 EXPECT_EQ(true, parser.Open("/proc/cpuinfo"));
105 EXPECT_EQ(true, parser.Parse(&key_val_pairs));
106}
107
mallinath@webrtc.orgb881d272014-02-03 16:57:16 +0000108#if !defined(GOOGLE_CHROME_BUILD) && !defined(CHROMIUM_BUILD)
109TEST(ReadLinuxLsbRelease, ReturnsSomething) {
110 std::string str = ReadLinuxLsbRelease();
111 // ChromeOS don't have lsb_release
112 // EXPECT_FALSE(str.empty());
113}
114#endif
115
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000116TEST(ReadLinuxUname, ReturnsSomething) {
117 std::string str = ReadLinuxUname();
118 EXPECT_FALSE(str.empty());
119}
120
121} // namespace talk_base