blob: fbec04d593112b9f6ff018971fe5d7a952fbcc91 [file] [log] [blame]
Guillaume Chatelet439d3712018-02-01 10:03:09 +01001// Copyright 2017 Google Inc.
2//
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
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
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.
14
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"
20
21#include "gtest/gtest.h"
22
23namespace cpu_features {
24
25namespace {
26
27void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
28
Guillaume Chatelet5911e962019-01-22 11:00:48 +010029TEST(CpuinfoMipsTest, FromHardwareCapBoth) {
30 SetHardwareCapabilities(MIPS_HWCAP_MSA | MIPS_HWCAP_R6, 0);
31 GetEmptyFilesystem(); // disabling /proc/cpuinfo
32 const auto info = GetMipsInfo();
33 EXPECT_TRUE(info.features.msa);
34 EXPECT_FALSE(info.features.eva);
35 EXPECT_TRUE(info.features.r6);
36}
37
Guillaume Chatelet439d3712018-02-01 10:03:09 +010038TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) {
39 SetHardwareCapabilities(MIPS_HWCAP_MSA, 0);
40 GetEmptyFilesystem(); // disabling /proc/cpuinfo
41 const auto info = GetMipsInfo();
42 EXPECT_TRUE(info.features.msa);
43 EXPECT_FALSE(info.features.eva);
44}
45
46TEST(CpuinfoMipsTest, Ci40) {
47 DisableHardwareCapabilities();
48 auto& fs = GetEmptyFilesystem();
49 fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0)
50machine : IMG Marduk Ci40 with cc2520
51processor : 0
52cpu model : MIPS interAptiv (multi) V2.0 FPU V0.0
53BogoMIPS : 363.72
54wait instruction : yes
55microsecond timers : yes
56tlb_entries : 64
57extra interrupt vector : yes
58hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
59isa : mips1 mips2 mips32r1 mips32r2
60ASEs implemented : mips16 dsp mt eva
61shadow register sets : 1
62kscratch registers : 0
63package : 0
64core : 0
65VCED exceptions : not available
66VCEI exceptions : not available
67VPE : 0
68)");
69 const auto info = GetMipsInfo();
70 EXPECT_FALSE(info.features.msa);
71 EXPECT_TRUE(info.features.eva);
72}
73
74TEST(CpuinfoMipsTest, AR7161) {
75 DisableHardwareCapabilities();
76 auto& fs = GetEmptyFilesystem();
77 fs.CreateFile("/proc/cpuinfo",
78 R"(system type : Atheros AR7161 rev 2
79machine : NETGEAR WNDR3700/WNDR3800/WNDRMAC
80processor : 0
81cpu model : MIPS 24Kc V7.4
82BogoMIPS : 452.19
83wait instruction : yes
84microsecond timers : yes
85tlb_entries : 16
86extra interrupt vector : yes
87hardware watchpoint : yes, count: 4, address/irw mask: [0x0000, 0x0f98, 0x0f78, 0x0df8]
88ASEs implemented : mips16
89shadow register sets : 1
90kscratch registers : 0
91core : 0
92VCED exceptions : not available
93VCEI exceptions : not available
94)");
95 const auto info = GetMipsInfo();
96 EXPECT_FALSE(info.features.msa);
97 EXPECT_FALSE(info.features.eva);
98}
99
100TEST(CpuinfoMipsTest, Goldfish) {
101 DisableHardwareCapabilities();
102 auto& fs = GetEmptyFilesystem();
103 fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish
104Hardware : goldfish
105Revison : 1
106processor : 0
107cpu model : MIPS 24Kc V0.0 FPU V0.0
108BogoMIPS : 1042.02
109wait instruction : yes
110microsecond timers : yes
111tlb_entries : 16
112extra interrupt vector : yes
113hardware watchpoint : yes, count: 1, address/irw mask: [0x0ff8]
114ASEs implemented :
115shadow register sets : 1
116core : 0
117VCED exceptions : not available
118VCEI exceptions : not available
119)");
120 const auto info = GetMipsInfo();
121 EXPECT_FALSE(info.features.msa);
122 EXPECT_FALSE(info.features.eva);
123}
124
125} // namespace
126} // namespace cpu_features