Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 1 | #include <gtest/gtest.h> |
| 2 | |
| 3 | #include <cpuinfo.h> |
| 4 | #include <cpuinfo-mock.h> |
| 5 | |
| 6 | |
| 7 | TEST(PROCESSORS, count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 8 | ASSERT_EQ(4, cpuinfo_get_processors_count()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 9 | } |
| 10 | |
| 11 | TEST(PROCESSORS, non_null) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 12 | ASSERT_TRUE(cpuinfo_get_processors()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 13 | } |
| 14 | |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 15 | TEST(PROCESSORS, smt_id) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 16 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 17 | ASSERT_EQ(0, cpuinfo_get_processor(i)->smt_id); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 18 | } |
| 19 | } |
| 20 | |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 21 | TEST(PROCESSORS, core) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 22 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 23 | ASSERT_EQ(cpuinfo_get_core(i), cpuinfo_get_processor(i)->core); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | |
| 27 | TEST(PROCESSORS, package) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 28 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 29 | ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_processor(i)->package); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
Marat Dukhan | 846c178 | 2017-09-13 09:47:26 -0700 | [diff] [blame] | 33 | TEST(PROCESSORS, linux_id) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 34 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 35 | ASSERT_EQ(i, cpuinfo_get_processor(i)->linux_id); |
Marat Dukhan | 846c178 | 2017-09-13 09:47:26 -0700 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 39 | TEST(PROCESSORS, l1i) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 40 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 41 | ASSERT_EQ(cpuinfo_get_l1i_cache(i), cpuinfo_get_processor(i)->cache.l1i); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | TEST(PROCESSORS, l1d) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 46 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 47 | ASSERT_EQ(cpuinfo_get_l1d_cache(i), cpuinfo_get_processor(i)->cache.l1d); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | TEST(PROCESSORS, l2) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 52 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 53 | ASSERT_EQ(cpuinfo_get_l2_cache(0), cpuinfo_get_processor(i)->cache.l2); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | TEST(PROCESSORS, l3) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 58 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 59 | ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l3); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | TEST(PROCESSORS, l4) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 64 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 65 | ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l4); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Marat Dukhan | 7073e83 | 2017-09-24 22:23:55 -0700 | [diff] [blame] | 69 | TEST(CORES, count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 70 | ASSERT_EQ(4, cpuinfo_get_cores_count()); |
Marat Dukhan | 7073e83 | 2017-09-24 22:23:55 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 73 | TEST(CORES, non_null) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 74 | ASSERT_TRUE(cpuinfo_get_cores()); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Marat Dukhan | 7073e83 | 2017-09-24 22:23:55 -0700 | [diff] [blame] | 77 | TEST(CORES, processor_start) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 78 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 79 | ASSERT_EQ(i, cpuinfo_get_core(i)->processor_start); |
Marat Dukhan | 7073e83 | 2017-09-24 22:23:55 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | TEST(CORES, processor_count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 84 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 85 | ASSERT_EQ(1, cpuinfo_get_core(i)->processor_count); |
Marat Dukhan | 7073e83 | 2017-09-24 22:23:55 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 89 | TEST(CORES, core_id) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 90 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 91 | ASSERT_EQ(i, cpuinfo_get_core(i)->core_id); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | TEST(CORES, package) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 96 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 97 | ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_core(i)->package); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | TEST(CORES, vendor) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 102 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 103 | ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_core(i)->vendor); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
| 107 | TEST(CORES, uarch) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 108 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 109 | ASSERT_EQ(cpuinfo_uarch_krait, cpuinfo_get_core(i)->uarch); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
| 113 | TEST(CORES, midr) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 114 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 115 | ASSERT_EQ(UINT32_C(0x513F06F1), cpuinfo_get_core(i)->midr); |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 119 | TEST(PACKAGES, count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 120 | ASSERT_EQ(1, cpuinfo_get_packages_count()); |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | TEST(PACKAGES, name) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 124 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 125 | ASSERT_EQ("Qualcomm APQ8084", |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 126 | std::string(cpuinfo_get_package(i)->name, |
| 127 | strnlen(cpuinfo_get_package(i)->name, CPUINFO_PACKAGE_NAME_MAX))); |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | TEST(PACKAGES, processor_start) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 132 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 133 | ASSERT_EQ(0, cpuinfo_get_package(i)->processor_start); |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | TEST(PACKAGES, processor_count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 138 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 139 | ASSERT_EQ(4, cpuinfo_get_package(i)->processor_count); |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
| 143 | TEST(PACKAGES, core_start) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 144 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 145 | ASSERT_EQ(0, cpuinfo_get_package(i)->core_start); |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | TEST(PACKAGES, core_count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 150 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 151 | ASSERT_EQ(4, cpuinfo_get_package(i)->core_count); |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 155 | TEST(ISA, thumb) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 156 | ASSERT_TRUE(cpuinfo_has_arm_thumb()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | TEST(ISA, thumb2) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 160 | ASSERT_TRUE(cpuinfo_has_arm_thumb2()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | TEST(ISA, armv5e) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 164 | ASSERT_TRUE(cpuinfo_has_arm_v5e()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | TEST(ISA, armv6) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 168 | ASSERT_TRUE(cpuinfo_has_arm_v6()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | TEST(ISA, armv6k) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 172 | ASSERT_TRUE(cpuinfo_has_arm_v6k()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | TEST(ISA, armv7) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 176 | ASSERT_TRUE(cpuinfo_has_arm_v7()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | TEST(ISA, armv7mp) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 180 | ASSERT_TRUE(cpuinfo_has_arm_v7mp()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | TEST(ISA, idiv) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 184 | ASSERT_TRUE(cpuinfo_has_arm_idiv()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | TEST(ISA, vfpv2) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 188 | ASSERT_FALSE(cpuinfo_has_arm_vfpv2()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | TEST(ISA, vfpv3) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 192 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 195 | TEST(ISA, vfpv3_d32) { |
| 196 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3_d32()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 199 | TEST(ISA, vfpv3_fp16) { |
| 200 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 203 | TEST(ISA, vfpv3_fp16_d32) { |
| 204 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16_d32()); |
| 205 | } |
| 206 | |
| 207 | TEST(ISA, vfpv4) { |
| 208 | ASSERT_TRUE(cpuinfo_has_arm_vfpv4()); |
| 209 | } |
| 210 | |
| 211 | TEST(ISA, vfpv4_d32) { |
| 212 | ASSERT_TRUE(cpuinfo_has_arm_vfpv4_d32()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | TEST(ISA, wmmx) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 216 | ASSERT_FALSE(cpuinfo_has_arm_wmmx()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | TEST(ISA, wmmx2) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 220 | ASSERT_FALSE(cpuinfo_has_arm_wmmx2()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | TEST(ISA, neon) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 224 | ASSERT_TRUE(cpuinfo_has_arm_neon()); |
| 225 | } |
| 226 | |
| 227 | TEST(ISA, neon_fp16) { |
| 228 | ASSERT_TRUE(cpuinfo_has_arm_neon_fp16()); |
| 229 | } |
| 230 | |
| 231 | TEST(ISA, neon_fma) { |
| 232 | ASSERT_TRUE(cpuinfo_has_arm_neon_fma()); |
| 233 | } |
| 234 | |
| 235 | TEST(ISA, atomics) { |
| 236 | ASSERT_FALSE(cpuinfo_has_arm_atomics()); |
| 237 | } |
| 238 | |
| 239 | TEST(ISA, neon_rdm) { |
| 240 | ASSERT_FALSE(cpuinfo_has_arm_neon_rdm()); |
| 241 | } |
| 242 | |
| 243 | TEST(ISA, fp16_arith) { |
| 244 | ASSERT_FALSE(cpuinfo_has_arm_fp16_arith()); |
| 245 | } |
| 246 | |
| 247 | TEST(ISA, jscvt) { |
| 248 | ASSERT_FALSE(cpuinfo_has_arm_jscvt()); |
| 249 | } |
| 250 | |
| 251 | TEST(ISA, fcma) { |
| 252 | ASSERT_FALSE(cpuinfo_has_arm_fcma()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST(ISA, aes) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 256 | ASSERT_FALSE(cpuinfo_has_arm_aes()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | TEST(ISA, sha1) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 260 | ASSERT_FALSE(cpuinfo_has_arm_sha1()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | TEST(ISA, sha2) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 264 | ASSERT_FALSE(cpuinfo_has_arm_sha2()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | TEST(ISA, pmull) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 268 | ASSERT_FALSE(cpuinfo_has_arm_pmull()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | TEST(ISA, crc32) { |
Marat Dukhan | eb3025f | 2017-09-26 12:57:41 -0700 | [diff] [blame] | 272 | ASSERT_FALSE(cpuinfo_has_arm_crc32()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | TEST(L1I, count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 276 | ASSERT_EQ(4, cpuinfo_get_l1i_caches_count()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | TEST(L1I, non_null) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 280 | ASSERT_TRUE(cpuinfo_get_l1i_caches()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | TEST(L1I, size) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 284 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 285 | ASSERT_EQ(16 * 1024, cpuinfo_get_l1i_cache(i)->size); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
| 289 | TEST(L1I, associativity) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 290 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 291 | ASSERT_EQ(4, cpuinfo_get_l1i_cache(i)->associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | TEST(L1I, sets) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 296 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 297 | ASSERT_EQ(cpuinfo_get_l1i_cache(i)->size, |
| 298 | cpuinfo_get_l1i_cache(i)->sets * cpuinfo_get_l1i_cache(i)->line_size * cpuinfo_get_l1i_cache(i)->partitions * cpuinfo_get_l1i_cache(i)->associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | TEST(L1I, partitions) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 303 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 304 | ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->partitions); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
| 308 | TEST(L1I, line_size) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 309 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 310 | ASSERT_EQ(64, cpuinfo_get_l1i_cache(i)->line_size); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | TEST(L1I, flags) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 315 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 316 | ASSERT_EQ(0, cpuinfo_get_l1i_cache(i)->flags); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | TEST(L1I, processors) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 321 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 322 | ASSERT_EQ(i, cpuinfo_get_l1i_cache(i)->processor_start); |
| 323 | ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->processor_count); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | TEST(L1D, count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 328 | ASSERT_EQ(4, cpuinfo_get_l1d_caches_count()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | TEST(L1D, non_null) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 332 | ASSERT_TRUE(cpuinfo_get_l1d_caches()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | TEST(L1D, size) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 336 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 337 | ASSERT_EQ(16 * 1024, cpuinfo_get_l1d_cache(i)->size); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | TEST(L1D, associativity) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 342 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 343 | ASSERT_EQ(4, cpuinfo_get_l1d_cache(i)->associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
| 347 | TEST(L1D, sets) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 348 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 349 | ASSERT_EQ(cpuinfo_get_l1d_cache(i)->size, |
| 350 | cpuinfo_get_l1d_cache(i)->sets * cpuinfo_get_l1d_cache(i)->line_size * cpuinfo_get_l1d_cache(i)->partitions * cpuinfo_get_l1d_cache(i)->associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | TEST(L1D, partitions) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 355 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 356 | ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->partitions); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | TEST(L1D, line_size) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 361 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 362 | ASSERT_EQ(64, cpuinfo_get_l1d_cache(i)->line_size); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | TEST(L1D, flags) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 367 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 368 | ASSERT_EQ(0, cpuinfo_get_l1d_cache(i)->flags); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| 372 | TEST(L1D, processors) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 373 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 374 | ASSERT_EQ(i, cpuinfo_get_l1d_cache(i)->processor_start); |
| 375 | ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->processor_count); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | TEST(L2, count) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 380 | ASSERT_EQ(1, cpuinfo_get_l2_caches_count()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | TEST(L2, non_null) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 384 | ASSERT_TRUE(cpuinfo_get_l2_caches()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | TEST(L2, size) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 388 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 389 | ASSERT_EQ(2 * 1024 * 1024, cpuinfo_get_l2_cache(i)->size); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
| 393 | TEST(L2, associativity) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 394 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 395 | ASSERT_EQ(8, cpuinfo_get_l2_cache(i)->associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | TEST(L2, sets) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 400 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 401 | ASSERT_EQ(cpuinfo_get_l2_cache(i)->size, |
| 402 | cpuinfo_get_l2_cache(i)->sets * cpuinfo_get_l2_cache(i)->line_size * cpuinfo_get_l2_cache(i)->partitions * cpuinfo_get_l2_cache(i)->associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | TEST(L2, partitions) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 407 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 408 | ASSERT_EQ(1, cpuinfo_get_l2_cache(i)->partitions); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | TEST(L2, line_size) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 413 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 414 | ASSERT_EQ(128, cpuinfo_get_l2_cache(i)->line_size); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
| 418 | TEST(L2, flags) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 419 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 420 | ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->flags); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
| 424 | TEST(L2, processors) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 425 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 426 | ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->processor_start); |
| 427 | ASSERT_EQ(4, cpuinfo_get_l2_cache(i)->processor_count); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | TEST(L3, none) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 432 | ASSERT_EQ(0, cpuinfo_get_l3_caches_count()); |
| 433 | ASSERT_FALSE(cpuinfo_get_l3_caches()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | TEST(L4, none) { |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 437 | ASSERT_EQ(0, cpuinfo_get_l4_caches_count()); |
| 438 | ASSERT_FALSE(cpuinfo_get_l4_caches()); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | #include <nexus6.h> |
| 442 | |
| 443 | int main(int argc, char* argv[]) { |
Marat Dukhan | 63a7a6b | 2017-11-29 15:11:56 -0800 | [diff] [blame^] | 444 | #if CPUINFO_ARCH_ARM |
| 445 | cpuinfo_set_hwcap(UINT32_C(0x0007B0D7)); |
| 446 | #endif |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 447 | cpuinfo_mock_filesystem(filesystem); |
Marat Dukhan | 5659d29 | 2017-09-12 23:21:03 -0700 | [diff] [blame] | 448 | #ifdef __ANDROID__ |
| 449 | cpuinfo_mock_android_properties(properties); |
| 450 | #endif |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 451 | cpuinfo_initialize(); |
| 452 | ::testing::InitGoogleTest(&argc, argv); |
| 453 | return RUN_ALL_TESTS(); |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 454 | } |