1 // Copyright 2022 Google LLC
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_loongarch.h"
16
17 #include "filesystem_for_testing.h"
18 #include "gtest/gtest.h"
19 #include "hwcaps_for_testing.h"
20
21 namespace cpu_features {
22 namespace {
23
TEST(CpuinfoLoongArchvTest,UnknownFromCpuInfo)24 TEST(CpuinfoLoongArchvTest, UnknownFromCpuInfo) {
25 ResetHwcaps();
26 auto& fs = GetEmptyFilesystem();
27 fs.CreateFile("/proc/cpuinfo", R"(
28 system type : generic-loongson-machine
29
30 processor : 0
31 package : 0
32 core : 0
33 CPU Family : Loongson-64bit
34 Model Name : Loongson-3A5000-HV
35 CPU Revision : 0x11
36 FPU Revision : 0x00
37 CPU MHz : 2500.00
38 BogoMIPS : 5000.00
39 TLB Entries : 2112
40 Address Sizes : 48 bits physical, 48 bits virtual
41 ISA : loongarch32 loongarch64
42 Features : cpucfg lam ual fpu lsx lasx crc32 complex crypto lvz lbt_x86 lbt_arm lbt_mips
43 Hardware Watchpoint : yes, iwatch count: 8, dwatch count: 8
44
45 processor : 1
46 package : 0
47 core : 1
48 CPU Family : Loongson-64bit
49 Model Name : Loongson-3A5000-HV
50 CPU Revision : 0x11
51 FPU Revision : 0x00
52 CPU MHz : 2500.00
53 BogoMIPS : 5000.00
54 TLB Entries : 2112
55 Address Sizes : 48 bits physical, 48 bits virtual
56 ISA : loongarch32 loongarch64
57 Features : cpucfg lam ual fpu lsx lasx crc32 complex crypto lvz lbt_x86 lbt_arm lbt_mips
58 Hardware Watchpoint : yes, iwatch count: 8, dwatch count: 8
59
60 processor : 2
61 package : 0
62 core : 2
63 CPU Family : Loongson-64bit
64 Model Name : Loongson-3A5000-HV
65 CPU Revision : 0x11
66 FPU Revision : 0x00
67 CPU MHz : 2500.00
68 BogoMIPS : 5000.00
69 TLB Entries : 2112
70 Address Sizes : 48 bits physical, 48 bits virtual
71 ISA : loongarch32 loongarch64
72 Features : cpucfg lam ual fpu lsx lasx crc32 complex crypto lvz lbt_x86 lbt_arm lbt_mips
73 Hardware Watchpoint : yes, iwatch count: 8, dwatch count: 8
74
75 processor : 3
76 package : 0
77 core : 3
78 CPU Family : Loongson-64bit
79 Model Name : Loongson-3A5000-HV
80 CPU Revision : 0x11
81 FPU Revision : 0x00
82 CPU MHz : 2500.00
83 BogoMIPS : 5000.00
84 TLB Entries : 2112
85 Address Sizes : 48 bits physical, 48 bits virtual
86 ISA : loongarch32 loongarch64
87 Features : cpucfg lam ual fpu lsx lasx crc32 complex crypto lvz lbt_x86 lbt_arm lbt_mips
88 Hardware Watchpoint : yes, iwatch count: 8, dwatch count: 8)");
89 const auto info = GetLoongArchInfo();
90 EXPECT_FALSE(info.features.CPUCFG);
91 EXPECT_TRUE(info.features.LAM);
92 EXPECT_TRUE(info.features.UAL);
93 EXPECT_TRUE(info.features.FPU);
94 EXPECT_TRUE(info.features.LSX);
95 EXPECT_TRUE(info.features.LASX);
96 EXPECT_TRUE(info.features.CRC32);
97 EXPECT_TRUE(info.features.COMPLEX);
98 EXPECT_TRUE(info.features.CRYPTO);
99 EXPECT_TRUE(info.features.LVZ);
100 EXPECT_TRUE(info.features.LBT_X86);
101 EXPECT_TRUE(info.features.LBT_ARM);
102 EXPECT_TRUE(info.features.LBT_MIPS);
103 }
104
TEST(CpuinfoLoongArchvTest,QemuCpuInfo)105 TEST(CpuinfoLoongArchvTest, QemuCpuInfo) {
106 ResetHwcaps();
107 auto& fs = GetEmptyFilesystem();
108 fs.CreateFile("/proc/cpuinfo", R"(
109 system type : generic-loongson-machine
110
111 processor : 0
112 package : 0
113 core : 0
114 CPU Family : Loongson-64bit
115 Model Name : Loongson-3A5000
116 CPU Revision : 0x10
117 FPU Revision : 0x01
118 CPU MHz : 2000.00
119 BogoMIPS : 4000.00
120 TLB Entries : 2112
121 Address Sizes : 48 bits physical, 48 bits virtual
122 ISA : loongarch32 loongarch64
123 Features : cpucfg lam ual fpu crc32
124 Hardware Watchpoint : yes, iwatch count: 0, dwatch count: 0
125
126 processor : 1
127 package : 0
128 core : 1
129 CPU Family : Loongson-64bit
130 Model Name : Loongson-3A5000
131 CPU Revision : 0x10
132 FPU Revision : 0x01
133 CPU MHz : 2000.00
134 BogoMIPS : 4000.00
135 TLB Entries : 2112
136 Address Sizes : 48 bits physical, 48 bits virtual
137 ISA : loongarch32 loongarch64
138 Features : cpucfg lam ual fpu crc32
139 Hardware Watchpoint : yes, iwatch count: 0, dwatch count: 0
140
141 processor : 2
142 package : 0
143 core : 2
144 CPU Family : Loongson-64bit
145 Model Name : Loongson-3A5000
146 CPU Revision : 0x10
147 FPU Revision : 0x01
148 CPU MHz : 2000.00
149 BogoMIPS : 4000.00
150 TLB Entries : 2112
151 Address Sizes : 48 bits physical, 48 bits virtual
152 ISA : loongarch32 loongarch64
153 Features : cpucfg lam ual fpu crc32
154 Hardware Watchpoint : yes, iwatch count: 0, dwatch count: 0
155
156 processor : 3
157 package : 0
158 core : 3
159 CPU Family : Loongson-64bit
160 Model Name : Loongson-3A5000
161 CPU Revision : 0x10
162 FPU Revision : 0x01
163 CPU MHz : 2000.00
164 BogoMIPS : 4000.00
165 TLB Entries : 2112
166 Address Sizes : 48 bits physical, 48 bits virtual
167 ISA : loongarch32 loongarch64
168 Features : cpucfg lam ual fpu crc32
169 Hardware Watchpoint : yes, iwatch count: 0, dwatch count: 0)");
170 const auto info = GetLoongArchInfo();
171 EXPECT_FALSE(info.features.CPUCFG);
172 EXPECT_TRUE(info.features.LAM);
173 EXPECT_TRUE(info.features.UAL);
174 EXPECT_TRUE(info.features.FPU);
175 EXPECT_TRUE(info.features.CRC32);
176 }
177
178 } // namespace
179 } // namespace cpu_features
180