1*eca53ba6SRoland Levillain // Copyright 2017 Google LLC
2*eca53ba6SRoland Levillain //
3*eca53ba6SRoland Levillain // Licensed under the Apache License, Version 2.0 (the "License");
4*eca53ba6SRoland Levillain // you may not use this file except in compliance with the License.
5*eca53ba6SRoland Levillain // You may obtain a copy of the License at
6*eca53ba6SRoland Levillain //
7*eca53ba6SRoland Levillain // http://www.apache.org/licenses/LICENSE-2.0
8*eca53ba6SRoland Levillain //
9*eca53ba6SRoland Levillain // Unless required by applicable law or agreed to in writing, software
10*eca53ba6SRoland Levillain // distributed under the License is distributed on an "AS IS" BASIS,
11*eca53ba6SRoland Levillain // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*eca53ba6SRoland Levillain // See the License for the specific language governing permissions and
13*eca53ba6SRoland Levillain // limitations under the License.
14*eca53ba6SRoland Levillain
15*eca53ba6SRoland Levillain #include "cpuinfo_mips.h"
16*eca53ba6SRoland Levillain
17*eca53ba6SRoland Levillain #include "filesystem_for_testing.h"
18*eca53ba6SRoland Levillain #include "gtest/gtest.h"
19*eca53ba6SRoland Levillain #include "hwcaps_for_testing.h"
20*eca53ba6SRoland Levillain #include "internal/stack_line_reader.h"
21*eca53ba6SRoland Levillain #include "internal/string_view.h"
22*eca53ba6SRoland Levillain
23*eca53ba6SRoland Levillain namespace cpu_features {
24*eca53ba6SRoland Levillain
25*eca53ba6SRoland Levillain namespace {
26*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,MipsFeaturesEnum)27*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, MipsFeaturesEnum) {
28*eca53ba6SRoland Levillain const char *last_name = GetMipsFeaturesEnumName(MIPS_LAST_);
29*eca53ba6SRoland Levillain EXPECT_STREQ(last_name, "unknown_feature");
30*eca53ba6SRoland Levillain for (int i = static_cast<int>(MIPS_MSA); i != static_cast<int>(MIPS_LAST_); ++i) {
31*eca53ba6SRoland Levillain const auto feature = static_cast<MipsFeaturesEnum>(i);
32*eca53ba6SRoland Levillain const char *name = GetMipsFeaturesEnumName(feature);
33*eca53ba6SRoland Levillain ASSERT_FALSE(name == nullptr);
34*eca53ba6SRoland Levillain EXPECT_STRNE(name, "");
35*eca53ba6SRoland Levillain EXPECT_STRNE(name, last_name);
36*eca53ba6SRoland Levillain }
37*eca53ba6SRoland Levillain }
38*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,FromHardwareCapBoth)39*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, FromHardwareCapBoth) {
40*eca53ba6SRoland Levillain ResetHwcaps();
41*eca53ba6SRoland Levillain SetHardwareCapabilities(MIPS_HWCAP_MSA | MIPS_HWCAP_R6, 0);
42*eca53ba6SRoland Levillain GetEmptyFilesystem(); // disabling /proc/cpuinfo
43*eca53ba6SRoland Levillain const auto info = GetMipsInfo();
44*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.msa);
45*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.eva);
46*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.r6);
47*eca53ba6SRoland Levillain }
48*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,FromHardwareCapOnlyOne)49*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) {
50*eca53ba6SRoland Levillain ResetHwcaps();
51*eca53ba6SRoland Levillain SetHardwareCapabilities(MIPS_HWCAP_MSA, 0);
52*eca53ba6SRoland Levillain GetEmptyFilesystem(); // disabling /proc/cpuinfo
53*eca53ba6SRoland Levillain const auto info = GetMipsInfo();
54*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.msa);
55*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.eva);
56*eca53ba6SRoland Levillain }
57*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,Ci40)58*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, Ci40) {
59*eca53ba6SRoland Levillain ResetHwcaps();
60*eca53ba6SRoland Levillain auto& fs = GetEmptyFilesystem();
61*eca53ba6SRoland Levillain fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0)
62*eca53ba6SRoland Levillain machine : IMG Marduk – Ci40 with cc2520
63*eca53ba6SRoland Levillain processor : 0
64*eca53ba6SRoland Levillain cpu model : MIPS interAptiv (multi) V2.0 FPU V0.0
65*eca53ba6SRoland Levillain BogoMIPS : 363.72
66*eca53ba6SRoland Levillain wait instruction : yes
67*eca53ba6SRoland Levillain microsecond timers : yes
68*eca53ba6SRoland Levillain tlb_entries : 64
69*eca53ba6SRoland Levillain extra interrupt vector : yes
70*eca53ba6SRoland Levillain hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
71*eca53ba6SRoland Levillain isa : mips1 mips2 mips32r1 mips32r2
72*eca53ba6SRoland Levillain ASEs implemented : mips16 dsp mt eva
73*eca53ba6SRoland Levillain shadow register sets : 1
74*eca53ba6SRoland Levillain kscratch registers : 0
75*eca53ba6SRoland Levillain package : 0
76*eca53ba6SRoland Levillain core : 0
77*eca53ba6SRoland Levillain VCED exceptions : not available
78*eca53ba6SRoland Levillain VCEI exceptions : not available
79*eca53ba6SRoland Levillain VPE : 0
80*eca53ba6SRoland Levillain )");
81*eca53ba6SRoland Levillain const auto info = GetMipsInfo();
82*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.msa);
83*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.eva);
84*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.r6);
85*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.mips16);
86*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.mdmx);
87*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.mips3d);
88*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.smart);
89*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.dsp);
90*eca53ba6SRoland Levillain }
91*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,AR7161)92*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, AR7161) {
93*eca53ba6SRoland Levillain ResetHwcaps();
94*eca53ba6SRoland Levillain auto& fs = GetEmptyFilesystem();
95*eca53ba6SRoland Levillain fs.CreateFile("/proc/cpuinfo",
96*eca53ba6SRoland Levillain R"(system type : Atheros AR7161 rev 2
97*eca53ba6SRoland Levillain machine : NETGEAR WNDR3700/WNDR3800/WNDRMAC
98*eca53ba6SRoland Levillain processor : 0
99*eca53ba6SRoland Levillain cpu model : MIPS 24Kc V7.4
100*eca53ba6SRoland Levillain BogoMIPS : 452.19
101*eca53ba6SRoland Levillain wait instruction : yes
102*eca53ba6SRoland Levillain microsecond timers : yes
103*eca53ba6SRoland Levillain tlb_entries : 16
104*eca53ba6SRoland Levillain extra interrupt vector : yes
105*eca53ba6SRoland Levillain hardware watchpoint : yes, count: 4, address/irw mask: [0x0000, 0x0f98, 0x0f78, 0x0df8]
106*eca53ba6SRoland Levillain ASEs implemented : mips16
107*eca53ba6SRoland Levillain shadow register sets : 1
108*eca53ba6SRoland Levillain kscratch registers : 0
109*eca53ba6SRoland Levillain core : 0
110*eca53ba6SRoland Levillain VCED exceptions : not available
111*eca53ba6SRoland Levillain VCEI exceptions : not available
112*eca53ba6SRoland Levillain )");
113*eca53ba6SRoland Levillain const auto info = GetMipsInfo();
114*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.msa);
115*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.eva);
116*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.mips16);
117*eca53ba6SRoland Levillain }
118*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,Goldfish)119*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, Goldfish) {
120*eca53ba6SRoland Levillain ResetHwcaps();
121*eca53ba6SRoland Levillain auto& fs = GetEmptyFilesystem();
122*eca53ba6SRoland Levillain fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish
123*eca53ba6SRoland Levillain Hardware : goldfish
124*eca53ba6SRoland Levillain Revison : 1
125*eca53ba6SRoland Levillain processor : 0
126*eca53ba6SRoland Levillain cpu model : MIPS 24Kc V0.0 FPU V0.0
127*eca53ba6SRoland Levillain BogoMIPS : 1042.02
128*eca53ba6SRoland Levillain wait instruction : yes
129*eca53ba6SRoland Levillain microsecond timers : yes
130*eca53ba6SRoland Levillain tlb_entries : 16
131*eca53ba6SRoland Levillain extra interrupt vector : yes
132*eca53ba6SRoland Levillain hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8]
133*eca53ba6SRoland Levillain ASEs implemented :
134*eca53ba6SRoland Levillain shadow register sets : 1
135*eca53ba6SRoland Levillain core : 0
136*eca53ba6SRoland Levillain VCED exceptions : not available
137*eca53ba6SRoland Levillain VCEI exceptions : not available
138*eca53ba6SRoland Levillain )");
139*eca53ba6SRoland Levillain const auto info = GetMipsInfo();
140*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.msa);
141*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.eva);
142*eca53ba6SRoland Levillain }
143*eca53ba6SRoland Levillain
TEST(CpuinfoMipsTest,BCM1250)144*eca53ba6SRoland Levillain TEST(CpuinfoMipsTest, BCM1250) {
145*eca53ba6SRoland Levillain ResetHwcaps();
146*eca53ba6SRoland Levillain auto& fs = GetEmptyFilesystem();
147*eca53ba6SRoland Levillain fs.CreateFile("/proc/cpuinfo", R"(system type : SiByte BCM91250A (SWARM)
148*eca53ba6SRoland Levillain processor : 0
149*eca53ba6SRoland Levillain cpu model : SiByte SB1 V0.2 FPU V0.2
150*eca53ba6SRoland Levillain BogoMIPS : 532.48
151*eca53ba6SRoland Levillain wait instruction : no
152*eca53ba6SRoland Levillain microsecond timers : yes
153*eca53ba6SRoland Levillain tlb_entries : 64
154*eca53ba6SRoland Levillain extra interrupt vector : yes
155*eca53ba6SRoland Levillain hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8]
156*eca53ba6SRoland Levillain isa : mips1 mips2 mips3 mips4 mips5 mips32r1 mips32r2 mips64r1 mips64r2
157*eca53ba6SRoland Levillain ASEs implemented : mdmx mips3d
158*eca53ba6SRoland Levillain shadow register sets : 1
159*eca53ba6SRoland Levillain kscratch registers : 0
160*eca53ba6SRoland Levillain package : 0
161*eca53ba6SRoland Levillain core : 0
162*eca53ba6SRoland Levillain VCED exceptions : not available
163*eca53ba6SRoland Levillain VCEI exceptions : not available
164*eca53ba6SRoland Levillain )");
165*eca53ba6SRoland Levillain const auto info = GetMipsInfo();
166*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.msa);
167*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.eva);
168*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.mips16);
169*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.mdmx);
170*eca53ba6SRoland Levillain EXPECT_TRUE(info.features.mips3d);
171*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.smart);
172*eca53ba6SRoland Levillain EXPECT_FALSE(info.features.dsp);
173*eca53ba6SRoland Levillain }
174*eca53ba6SRoland Levillain
175*eca53ba6SRoland Levillain } // namespace
176*eca53ba6SRoland Levillain } // namespace cpu_features
177