1 // Copyright 2017 Google Inc.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "cpuinfo_mips.h"
16 #include "filesystem_for_testing.h"
17 #include "hwcaps_for_testing.h"
18 #include "internal/stack_line_reader.h"
19 #include "internal/string_view.h"
21 #include "gtest/gtest.h"
23 namespace cpu_features {
27 void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
29 TEST(CpuinfoMipsTest, FromHardwareCapBoth) {
30 SetHardwareCapabilities(MIPS_HWCAP_EVA | MIPS_HWCAP_MSA, 0);
31 GetEmptyFilesystem(); // disabling /proc/cpuinfo
32 const auto info = GetMipsInfo();
33 EXPECT_TRUE(info.features.msa);
34 EXPECT_TRUE(info.features.eva);
37 TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) {
38 SetHardwareCapabilities(MIPS_HWCAP_MSA, 0);
39 GetEmptyFilesystem(); // disabling /proc/cpuinfo
40 const auto info = GetMipsInfo();
41 EXPECT_TRUE(info.features.msa);
42 EXPECT_FALSE(info.features.eva);
45 TEST(CpuinfoMipsTest, Ci40) {
46 DisableHardwareCapabilities();
47 auto& fs = GetEmptyFilesystem();
48 fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0)
49 machine : IMG Marduk – Ci40 with cc2520
51 cpu model : MIPS interAptiv (multi) V2.0 FPU V0.0
53 wait instruction : yes
54 microsecond timers : yes
56 extra interrupt vector : yes
57 hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
58 isa : mips1 mips2 mips32r1 mips32r2
59 ASEs implemented : mips16 dsp mt eva
60 shadow register sets : 1
61 kscratch registers : 0
64 VCED exceptions : not available
65 VCEI exceptions : not available
68 const auto info = GetMipsInfo();
69 EXPECT_FALSE(info.features.msa);
70 EXPECT_TRUE(info.features.eva);
73 TEST(CpuinfoMipsTest, AR7161) {
74 DisableHardwareCapabilities();
75 auto& fs = GetEmptyFilesystem();
76 fs.CreateFile("/proc/cpuinfo",
77 R"(system type : Atheros AR7161 rev 2
78 machine : NETGEAR WNDR3700/WNDR3800/WNDRMAC
80 cpu model : MIPS 24Kc V7.4
82 wait instruction : yes
83 microsecond timers : yes
85 extra interrupt vector : yes
86 hardware watchpoint : yes, count: 4, address/irw mask: [0x0000, 0x0f98, 0x0f78, 0x0df8]
87 ASEs implemented : mips16
88 shadow register sets : 1
89 kscratch registers : 0
91 VCED exceptions : not available
92 VCEI exceptions : not available
94 const auto info = GetMipsInfo();
95 EXPECT_FALSE(info.features.msa);
96 EXPECT_FALSE(info.features.eva);
99 TEST(CpuinfoMipsTest, Goldfish) {
100 DisableHardwareCapabilities();
101 auto& fs = GetEmptyFilesystem();
102 fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish
106 cpu model : MIPS 24Kc V0.0 FPU V0.0
108 wait instruction : yes
109 microsecond timers : yes
111 extra interrupt vector : yes
112 hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8]
114 shadow register sets : 1
116 VCED exceptions : not available
117 VCEI exceptions : not available
119 const auto info = GetMipsInfo();
120 EXPECT_FALSE(info.features.msa);
121 EXPECT_FALSE(info.features.eva);
125 } // namespace cpu_features