Marat Dukhan | ac57632 | 2017-05-08 13:08:25 +0000 | [diff] [blame] | 1 | #include <gtest/gtest.h> |
| 2 | |
| 3 | #include <cpuinfo.h> |
| 4 | #include <cpuinfo-mock.h> |
| 5 | |
| 6 | |
| 7 | TEST(PROCESSORS, count) { |
| 8 | ASSERT_EQ(4, cpuinfo_processors_count); |
| 9 | } |
| 10 | |
| 11 | TEST(PROCESSORS, non_null) { |
| 12 | ASSERT_TRUE(cpuinfo_processors); |
| 13 | } |
| 14 | |
| 15 | TEST(PROCESSORS, vendor_qualcomm) { |
| 16 | for (uint32_t i = 0; i < cpuinfo_processors_count; i++) { |
| 17 | ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_processors[i].vendor); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | TEST(PROCESSORS, uarch_krait) { |
| 22 | for (uint32_t i = 0; i < cpuinfo_processors_count; i++) { |
| 23 | ASSERT_EQ(cpuinfo_uarch_krait, cpuinfo_processors[i].uarch); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | TEST(ISA, thumb) { |
| 28 | ASSERT_TRUE(cpuinfo_isa.thumb); |
| 29 | } |
| 30 | |
| 31 | TEST(ISA, thumb2) { |
| 32 | ASSERT_TRUE(cpuinfo_isa.thumb2); |
| 33 | } |
| 34 | |
| 35 | TEST(ISA, thumbee) { |
| 36 | ASSERT_FALSE(cpuinfo_isa.thumbee); |
| 37 | } |
| 38 | |
| 39 | TEST(ISA, jazelle) { |
| 40 | ASSERT_FALSE(cpuinfo_isa.jazelle); |
| 41 | } |
| 42 | |
| 43 | TEST(ISA, armv5e) { |
| 44 | ASSERT_TRUE(cpuinfo_isa.armv5e); |
| 45 | } |
| 46 | |
| 47 | TEST(ISA, armv6) { |
| 48 | ASSERT_TRUE(cpuinfo_isa.armv6); |
| 49 | } |
| 50 | |
| 51 | TEST(ISA, armv6k) { |
| 52 | ASSERT_TRUE(cpuinfo_isa.armv6k); |
| 53 | } |
| 54 | |
| 55 | TEST(ISA, armv7) { |
| 56 | ASSERT_TRUE(cpuinfo_isa.armv7); |
| 57 | } |
| 58 | |
| 59 | TEST(ISA, armv7mp) { |
| 60 | ASSERT_TRUE(cpuinfo_isa.armv7mp); |
| 61 | } |
| 62 | |
| 63 | TEST(ISA, idiv) { |
| 64 | ASSERT_TRUE(cpuinfo_isa.idiv); |
| 65 | } |
| 66 | |
| 67 | TEST(ISA, vfpv2) { |
| 68 | ASSERT_FALSE(cpuinfo_isa.vfpv2); |
| 69 | } |
| 70 | |
| 71 | TEST(ISA, vfpv3) { |
| 72 | ASSERT_TRUE(cpuinfo_isa.vfpv3); |
| 73 | } |
| 74 | |
| 75 | TEST(ISA, d32) { |
| 76 | ASSERT_TRUE(cpuinfo_isa.d32); |
| 77 | } |
| 78 | |
| 79 | TEST(ISA, fp16) { |
| 80 | ASSERT_TRUE(cpuinfo_isa.fp16); |
| 81 | } |
| 82 | |
| 83 | TEST(ISA, fma) { |
| 84 | ASSERT_TRUE(cpuinfo_isa.fma); |
| 85 | } |
| 86 | |
| 87 | TEST(ISA, wmmx) { |
| 88 | ASSERT_FALSE(cpuinfo_isa.wmmx); |
| 89 | } |
| 90 | |
| 91 | TEST(ISA, wmmx2) { |
| 92 | ASSERT_FALSE(cpuinfo_isa.wmmx2); |
| 93 | } |
| 94 | |
| 95 | TEST(ISA, neon) { |
| 96 | ASSERT_TRUE(cpuinfo_isa.neon); |
| 97 | } |
| 98 | |
| 99 | TEST(ISA, aes) { |
| 100 | ASSERT_FALSE(cpuinfo_isa.aes); |
| 101 | } |
| 102 | |
| 103 | TEST(ISA, sha1) { |
| 104 | ASSERT_FALSE(cpuinfo_isa.sha1); |
| 105 | } |
| 106 | |
| 107 | TEST(ISA, sha2) { |
| 108 | ASSERT_FALSE(cpuinfo_isa.sha2); |
| 109 | } |
| 110 | |
| 111 | TEST(ISA, pmull) { |
| 112 | ASSERT_FALSE(cpuinfo_isa.pmull); |
| 113 | } |
| 114 | |
| 115 | TEST(ISA, crc32) { |
| 116 | ASSERT_FALSE(cpuinfo_isa.crc32); |
| 117 | } |
| 118 | |
| 119 | TEST(L1I, count) { |
| 120 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 121 | ASSERT_EQ(4, l1i.count); |
| 122 | } |
| 123 | |
| 124 | TEST(L1I, non_null) { |
| 125 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 126 | ASSERT_TRUE(l1i.instances); |
| 127 | } |
| 128 | |
| 129 | TEST(L1I, size) { |
| 130 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 131 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 132 | ASSERT_EQ(16 * 1024, l1i.instances[k].size); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | TEST(L1I, associativity) { |
| 137 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 138 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 139 | ASSERT_EQ(4, l1i.instances[k].associativity); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | TEST(L1I, sets) { |
| 144 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 145 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 146 | ASSERT_EQ(64, l1i.instances[k].sets); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | TEST(L1I, partitions) { |
| 151 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 152 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 153 | ASSERT_EQ(1, l1i.instances[k].partitions); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | TEST(L1I, line_size) { |
| 158 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 159 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 160 | ASSERT_EQ(64, l1i.instances[k].line_size); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | TEST(L1I, flags) { |
| 165 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 166 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 167 | ASSERT_EQ(0, l1i.instances[k].flags); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | TEST(L1I, processors) { |
| 172 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 173 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 174 | ASSERT_EQ(k, l1i.instances[k].thread_start); |
| 175 | ASSERT_EQ(1, l1i.instances[k].thread_count); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | TEST(L1D, count) { |
| 180 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 181 | ASSERT_EQ(4, l1d.count); |
| 182 | } |
| 183 | |
| 184 | TEST(L1D, non_null) { |
| 185 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 186 | ASSERT_TRUE(l1d.instances); |
| 187 | } |
| 188 | |
| 189 | TEST(L1D, size) { |
| 190 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 191 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 192 | ASSERT_EQ(16 * 1024, l1d.instances[k].size); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | TEST(L1D, associativity) { |
| 197 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 198 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 199 | ASSERT_EQ(4, l1d.instances[k].associativity); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | TEST(L1D, sets) { |
| 204 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 205 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 206 | ASSERT_EQ(64, l1d.instances[k].sets); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | TEST(L1D, partitions) { |
| 211 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 212 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 213 | ASSERT_EQ(1, l1d.instances[k].partitions); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | TEST(L1D, line_size) { |
| 218 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 219 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 220 | ASSERT_EQ(64, l1d.instances[k].line_size); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | TEST(L1D, flags) { |
| 225 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 226 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 227 | ASSERT_EQ(0, l1d.instances[k].flags); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | TEST(L1D, processors) { |
| 232 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 233 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 234 | ASSERT_EQ(k, l1d.instances[k].thread_start); |
| 235 | ASSERT_EQ(1, l1d.instances[k].thread_count); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | TEST(L2, count) { |
| 240 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 241 | ASSERT_EQ(1, l2.count); |
| 242 | } |
| 243 | |
| 244 | TEST(L2, non_null) { |
| 245 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 246 | ASSERT_TRUE(l2.instances); |
| 247 | } |
| 248 | |
| 249 | TEST(L2, size) { |
| 250 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 251 | for (uint32_t k = 0; k < l2.count; k++) { |
| 252 | ASSERT_EQ(2 * 1024 * 1024, l2.instances[k].size); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | TEST(L2, associativity) { |
| 257 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 258 | for (uint32_t k = 0; k < l2.count; k++) { |
| 259 | ASSERT_EQ(8, l2.instances[k].associativity); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | TEST(L2, sets) { |
| 264 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 265 | for (uint32_t k = 0; k < l2.count; k++) { |
| 266 | ASSERT_EQ(2048, l2.instances[k].sets); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | TEST(L2, partitions) { |
| 271 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 272 | for (uint32_t k = 0; k < l2.count; k++) { |
| 273 | ASSERT_EQ(1, l2.instances[k].partitions); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | TEST(L2, line_size) { |
| 278 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 279 | for (uint32_t k = 0; k < l2.count; k++) { |
| 280 | ASSERT_EQ(128, l2.instances[k].line_size); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | TEST(L2, flags) { |
| 285 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 286 | for (uint32_t k = 0; k < l2.count; k++) { |
| 287 | ASSERT_EQ(0, l2.instances[k].flags); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | TEST(L2, processors) { |
| 292 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 293 | for (uint32_t k = 0; k < l2.count; k++) { |
| 294 | ASSERT_EQ(0, l2.instances[k].thread_start); |
| 295 | ASSERT_EQ(4, l2.instances[k].thread_count); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | TEST(L3, none) { |
| 300 | cpuinfo_caches l3 = cpuinfo_get_l3_cache(); |
| 301 | ASSERT_EQ(0, l3.count); |
| 302 | ASSERT_FALSE(l3.instances); |
| 303 | } |
| 304 | |
| 305 | TEST(L4, none) { |
| 306 | cpuinfo_caches l4 = cpuinfo_get_l4_cache(); |
| 307 | ASSERT_EQ(0, l4.count); |
| 308 | ASSERT_FALSE(l4.instances); |
| 309 | } |
| 310 | |
Marat Dukhan | 079ccbd | 2017-08-09 17:00:32 -0700 | [diff] [blame^] | 311 | #include <nexus4.h> |
| 312 | |
Marat Dukhan | ac57632 | 2017-05-08 13:08:25 +0000 | [diff] [blame] | 313 | int main(int argc, char* argv[]) { |
Marat Dukhan | 079ccbd | 2017-08-09 17:00:32 -0700 | [diff] [blame^] | 314 | cpuinfo_mock_filesystem(filesystem); |
Marat Dukhan | ac57632 | 2017-05-08 13:08:25 +0000 | [diff] [blame] | 315 | cpuinfo_initialize(); |
| 316 | ::testing::InitGoogleTest(&argc, argv); |
| 317 | return RUN_ALL_TESTS(); |
| 318 | } |