1 use *;
2
3 #[test]
genuine_intel()4 fn genuine_intel() {
5 let vf = VendorInfo {
6 ebx: 1970169159,
7 edx: 1231384169,
8 ecx: 1818588270,
9 };
10 assert!(vf.as_string() == "GenuineIntel");
11 }
12
13 #[test]
feature_info()14 fn feature_info() {
15 let finfo = FeatureInfo {
16 eax: 198313,
17 ebx: 34605056,
18 edx_ecx: FeatureInfoFlags {
19 bits: 2109399999 | 3219913727 << 32,
20 },
21 };
22
23 assert!(finfo.model_id() == 10);
24 assert!(finfo.extended_model_id() == 3);
25 assert!(finfo.stepping_id() == 9);
26 assert!(finfo.extended_family_id() == 0);
27 assert!(finfo.family_id() == 6);
28 assert!(finfo.stepping_id() == 9);
29 assert!(finfo.brand_index() == 0);
30
31 assert!(finfo.edx_ecx.contains(FeatureInfoFlags::SSE2));
32 assert!(finfo.edx_ecx.contains(FeatureInfoFlags::SSE41));
33 }
34
35 #[test]
cache_info()36 fn cache_info() {
37 let cinfos = CacheInfoIter {
38 current: 1,
39 eax: 1979931137,
40 ebx: 15774463,
41 ecx: 0,
42 edx: 13238272,
43 };
44 for (idx, cache) in cinfos.enumerate() {
45 match idx {
46 0 => assert!(cache.num == 0xff),
47 1 => assert!(cache.num == 0x5a),
48 2 => assert!(cache.num == 0xb2),
49 3 => assert!(cache.num == 0x03),
50 4 => assert!(cache.num == 0xf0),
51 5 => assert!(cache.num == 0xca),
52 6 => assert!(cache.num == 0x76),
53 _ => unreachable!(),
54 }
55 }
56 }
57
58 #[test]
cache_parameters()59 fn cache_parameters() {
60 let caches: [CacheParameter; 4] = [
61 CacheParameter {
62 eax: 469778721,
63 ebx: 29360191,
64 ecx: 63,
65 edx: 0,
66 },
67 CacheParameter {
68 eax: 469778722,
69 ebx: 29360191,
70 ecx: 63,
71 edx: 0,
72 },
73 CacheParameter {
74 eax: 469778755,
75 ebx: 29360191,
76 ecx: 511,
77 edx: 0,
78 },
79 CacheParameter {
80 eax: 470008163,
81 ebx: 46137407,
82 ecx: 4095,
83 edx: 6,
84 },
85 ];
86
87 for (idx, cache) in caches.into_iter().enumerate() {
88 match idx {
89 0 => {
90 assert!(cache.cache_type() == CacheType::DATA);
91 assert!(cache.level() == 1);
92 assert!(cache.is_self_initializing());
93 assert!(!cache.is_fully_associative());
94 assert!(cache.max_cores_for_cache() == 2);
95 assert!(cache.max_cores_for_package() == 8);
96 assert!(cache.coherency_line_size() == 64);
97 assert!(cache.physical_line_partitions() == 1);
98 assert!(cache.associativity() == 8);
99 assert!(!cache.is_write_back_invalidate());
100 assert!(!cache.is_inclusive());
101 assert!(!cache.has_complex_indexing());
102 assert!(cache.sets() == 64);
103 }
104 1 => {
105 assert!(cache.cache_type() == CacheType::INSTRUCTION);
106 assert!(cache.level() == 1);
107 assert!(cache.is_self_initializing());
108 assert!(!cache.is_fully_associative());
109 assert!(cache.max_cores_for_cache() == 2);
110 assert!(cache.max_cores_for_package() == 8);
111 assert!(cache.coherency_line_size() == 64);
112 assert!(cache.physical_line_partitions() == 1);
113 assert!(cache.associativity() == 8);
114 assert!(!cache.is_write_back_invalidate());
115 assert!(!cache.is_inclusive());
116 assert!(!cache.has_complex_indexing());
117 assert!(cache.sets() == 64);
118 }
119 2 => {
120 assert!(cache.cache_type() == CacheType::UNIFIED);
121 assert!(cache.level() == 2);
122 assert!(cache.is_self_initializing());
123 assert!(!cache.is_fully_associative());
124 assert!(cache.max_cores_for_cache() == 2);
125 assert!(cache.max_cores_for_package() == 8);
126 assert!(cache.coherency_line_size() == 64);
127 assert!(cache.physical_line_partitions() == 1);
128 assert!(cache.associativity() == 8);
129 assert!(!cache.is_write_back_invalidate());
130 assert!(!cache.is_inclusive());
131 assert!(!cache.has_complex_indexing());
132 assert!(cache.sets() == 512);
133 }
134 3 => {
135 assert!(cache.cache_type() == CacheType::UNIFIED);
136 assert!(cache.level() == 3);
137 assert!(cache.is_self_initializing());
138 assert!(!cache.is_fully_associative());
139 assert!(cache.max_cores_for_cache() == 16);
140 assert!(cache.max_cores_for_package() == 8);
141 assert!(cache.coherency_line_size() == 64);
142 assert!(cache.physical_line_partitions() == 1);
143 assert!(cache.associativity() == 12);
144 assert!(!cache.is_write_back_invalidate());
145 assert!(cache.is_inclusive());
146 assert!(cache.has_complex_indexing());
147 assert!(cache.sets() == 4096);
148 }
149 _ => unreachable!(),
150 }
151 }
152 }
153
154 #[test]
monitor_mwait_features()155 fn monitor_mwait_features() {
156 let mmfeatures = MonitorMwaitInfo {
157 eax: 64,
158 ebx: 64,
159 ecx: 3,
160 edx: 135456,
161 };
162 assert!(mmfeatures.smallest_monitor_line() == 64);
163 assert!(mmfeatures.largest_monitor_line() == 64);
164 assert!(mmfeatures.extensions_supported());
165 assert!(mmfeatures.interrupts_as_break_event());
166 assert!(mmfeatures.supported_c0_states() == 0);
167 assert!(mmfeatures.supported_c1_states() == 2);
168 assert!(mmfeatures.supported_c2_states() == 1);
169 assert!(mmfeatures.supported_c3_states() == 1);
170 assert!(mmfeatures.supported_c4_states() == 2);
171 assert!(mmfeatures.supported_c5_states() == 0);
172 assert!(mmfeatures.supported_c6_states() == 0);
173 assert!(mmfeatures.supported_c7_states() == 0);
174 }
175
176 #[test]
thermal_power_features()177 fn thermal_power_features() {
178 let tpfeatures = ThermalPowerInfo {
179 eax: ThermalPowerFeaturesEax { bits: 119 },
180 ebx: 2,
181 ecx: ThermalPowerFeaturesEcx { bits: 9 },
182 edx: 0,
183 };
184
185 assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::DTS));
186 assert!(
187 tpfeatures
188 .eax
189 .contains(ThermalPowerFeaturesEax::TURBO_BOOST)
190 );
191 assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::ARAT));
192 assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::PLN));
193 assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::ECMD));
194 assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::PTM));
195
196 assert!(
197 tpfeatures
198 .ecx
199 .contains(ThermalPowerFeaturesEcx::HW_COORD_FEEDBACK)
200 );
201 assert!(
202 tpfeatures
203 .ecx
204 .contains(ThermalPowerFeaturesEcx::ENERGY_BIAS_PREF)
205 );
206
207 assert!(tpfeatures.dts_irq_threshold() == 0x2);
208 let tpfeatures = ThermalPowerInfo {
209 eax: ThermalPowerFeaturesEax::DTS
210 | ThermalPowerFeaturesEax::TURBO_BOOST
211 | ThermalPowerFeaturesEax::ARAT
212 | ThermalPowerFeaturesEax::PLN
213 | ThermalPowerFeaturesEax::ECMD
214 | ThermalPowerFeaturesEax::PTM
215 | ThermalPowerFeaturesEax::HWP
216 | ThermalPowerFeaturesEax::HWP_NOTIFICATION
217 | ThermalPowerFeaturesEax::HWP_ACTIVITY_WINDOW
218 | ThermalPowerFeaturesEax::HWP_ENERGY_PERFORMANCE_PREFERENCE
219 | ThermalPowerFeaturesEax::HDC,
220 ebx: 2,
221 ecx: ThermalPowerFeaturesEcx::HW_COORD_FEEDBACK | ThermalPowerFeaturesEcx::ENERGY_BIAS_PREF,
222 edx: 0,
223 };
224
225 assert!(tpfeatures.has_dts());
226 assert!(!tpfeatures.has_turbo_boost3());
227 assert!(tpfeatures.has_turbo_boost());
228 assert!(tpfeatures.has_arat());
229 assert!(tpfeatures.has_pln());
230 assert!(tpfeatures.has_ecmd());
231 assert!(tpfeatures.has_ptm());
232 assert!(tpfeatures.has_hwp());
233 assert!(tpfeatures.has_hwp_notification());
234 assert!(tpfeatures.has_hwp_activity_window());
235 assert!(tpfeatures.has_hwp_energy_performance_preference());
236 assert!(!tpfeatures.has_hwp_package_level_request());
237 assert!(tpfeatures.has_hdc());
238 assert!(tpfeatures.has_hw_coord_feedback());
239 assert!(tpfeatures.has_energy_bias_pref());
240 assert!(tpfeatures.dts_irq_threshold() == 0x2);
241 }
242
243 #[test]
extended_features()244 fn extended_features() {
245 let tpfeatures = ExtendedFeatures {
246 eax: 0,
247 ebx: ExtendedFeaturesEbx { bits: 641 },
248 ecx: ExtendedFeaturesEcx { bits: 0 },
249 edx: 0,
250 };
251 assert!(tpfeatures.eax == 0);
252 assert!(tpfeatures.has_fsgsbase());
253 assert!(!tpfeatures.has_tsc_adjust_msr());
254 assert!(!tpfeatures.has_bmi1());
255 assert!(!tpfeatures.has_hle());
256 assert!(!tpfeatures.has_avx2());
257 assert!(tpfeatures.has_smep());
258 assert!(!tpfeatures.has_bmi2());
259 assert!(tpfeatures.has_rep_movsb_stosb());
260 assert!(!tpfeatures.has_invpcid());
261 assert!(!tpfeatures.has_rtm());
262 assert!(!tpfeatures.has_rdtm());
263 assert!(!tpfeatures.has_fpu_cs_ds_deprecated());
264
265 let tpfeatures2 = ExtendedFeatures {
266 eax: 0,
267 ebx: ExtendedFeaturesEbx::FSGSBASE
268 | ExtendedFeaturesEbx::ADJUST_MSR
269 | ExtendedFeaturesEbx::BMI1
270 | ExtendedFeaturesEbx::AVX2
271 | ExtendedFeaturesEbx::SMEP
272 | ExtendedFeaturesEbx::BMI2
273 | ExtendedFeaturesEbx::REP_MOVSB_STOSB
274 | ExtendedFeaturesEbx::INVPCID
275 | ExtendedFeaturesEbx::DEPRECATE_FPU_CS_DS
276 | ExtendedFeaturesEbx::MPX
277 | ExtendedFeaturesEbx::RDSEED
278 | ExtendedFeaturesEbx::ADX
279 | ExtendedFeaturesEbx::SMAP
280 | ExtendedFeaturesEbx::CLFLUSHOPT
281 | ExtendedFeaturesEbx::PROCESSOR_TRACE,
282 ecx: ExtendedFeaturesEcx { bits: 0 },
283 edx: 201326592,
284 };
285
286 assert!(tpfeatures2.has_fsgsbase());
287 assert!(tpfeatures2.has_tsc_adjust_msr());
288 assert!(tpfeatures2.has_bmi1());
289 assert!(tpfeatures2.has_avx2());
290 assert!(tpfeatures2.has_smep());
291 assert!(tpfeatures2.has_bmi2());
292 assert!(tpfeatures2.has_rep_movsb_stosb());
293 assert!(tpfeatures2.has_invpcid());
294 assert!(tpfeatures2.has_fpu_cs_ds_deprecated());
295 assert!(tpfeatures2.has_mpx());
296 assert!(tpfeatures2.has_rdseed());
297 assert!(tpfeatures2.has_adx());
298 assert!(tpfeatures2.has_smap());
299 assert!(tpfeatures2.has_clflushopt());
300 assert!(tpfeatures2.has_processor_trace());
301 }
302
303 #[test]
direct_cache_access_info()304 fn direct_cache_access_info() {
305 let dca = DirectCacheAccessInfo { eax: 0x1 };
306 assert!(dca.get_dca_cap_value() == 0x1);
307 }
308
309 #[test]
performance_monitoring_info()310 fn performance_monitoring_info() {
311 let pm = PerformanceMonitoringInfo {
312 eax: 120587267,
313 ebx: PerformanceMonitoringFeaturesEbx { bits: 0 },
314 ecx: 0,
315 edx: 1539,
316 };
317
318 assert!(pm.version_id() == 3);
319 assert!(pm.number_of_counters() == 4);
320 assert!(pm.counter_bit_width() == 48);
321 assert!(pm.ebx_length() == 7);
322 assert!(pm.fixed_function_counters() == 3);
323 assert!(pm.fixed_function_counters_bit_width() == 48);
324
325 assert!(
326 !pm.ebx
327 .contains(PerformanceMonitoringFeaturesEbx::CORE_CYC_EV_UNAVAILABLE)
328 );
329 assert!(
330 !pm.ebx
331 .contains(PerformanceMonitoringFeaturesEbx::INST_RET_EV_UNAVAILABLE)
332 );
333 assert!(
334 !pm.ebx
335 .contains(PerformanceMonitoringFeaturesEbx::REF_CYC_EV_UNAVAILABLE)
336 );
337 assert!(
338 !pm.ebx
339 .contains(PerformanceMonitoringFeaturesEbx::CACHE_REF_EV_UNAVAILABLE)
340 );
341 assert!(
342 !pm.ebx
343 .contains(PerformanceMonitoringFeaturesEbx::LL_CACHE_MISS_EV_UNAVAILABLE)
344 );
345 assert!(
346 !pm.ebx
347 .contains(PerformanceMonitoringFeaturesEbx::BRANCH_INST_RET_EV_UNAVAILABLE)
348 );
349 assert!(
350 !pm.ebx
351 .contains(PerformanceMonitoringFeaturesEbx::BRANCH_MISPRED_EV_UNAVAILABLE)
352 );
353 }
354
355 #[cfg(test)]
356 #[test]
extended_topology_info()357 fn extended_topology_info() {
358 let l1 = ExtendedTopologyLevel {
359 eax: 1,
360 ebx: 2,
361 ecx: 256,
362 edx: 3,
363 };
364 let l2 = ExtendedTopologyLevel {
365 eax: 4,
366 ebx: 4,
367 ecx: 513,
368 edx: 3,
369 };
370
371 assert!(l1.processors() == 2);
372 assert!(l1.level_number() == 0);
373 assert!(l1.level_type() == TopologyType::SMT);
374 assert!(l1.x2apic_id() == 3);
375 assert!(l1.shift_right_for_next_apic_id() == 1);
376
377 assert!(l2.processors() == 4);
378 assert!(l2.level_number() == 1);
379 assert!(l2.level_type() == TopologyType::CORE);
380 assert!(l2.x2apic_id() == 3);
381 assert!(l2.shift_right_for_next_apic_id() == 4);
382 }
383
384 #[test]
extended_state_info()385 fn extended_state_info() {
386 let es = ExtendedStateInfo {
387 eax: ExtendedStateInfoXCR0Flags { bits: 7 },
388 ebx: 832,
389 ecx: 832,
390 edx: 0,
391 eax1: 1,
392 ebx1: 0,
393 ecx1: ExtendedStateInfoXSSFlags { bits: 0 },
394 edx1: 0,
395 };
396
397 assert!(es.xsave_area_size_enabled_features() == 832);
398 assert!(es.xsave_area_size_supported_features() == 832);
399 assert!(es.has_xsaveopt());
400 }
401
402 #[test]
extended_state_info3()403 fn extended_state_info3() {
404 /*let cpuid = CpuId::new();
405 cpuid.get_extended_state_info().map(|info| {
406 println!("{:?}", info);
407 use std::vec::Vec;
408 let es: Vec<ExtendedState> = info.iter().collect();
409 println!("{:?}", es);
410 });*/
411
412 let esi = ExtendedStateInfo {
413 eax: ExtendedStateInfoXCR0Flags::LEGACY_X87
414 | ExtendedStateInfoXCR0Flags::SSE128
415 | ExtendedStateInfoXCR0Flags::AVX256
416 | ExtendedStateInfoXCR0Flags::MPX_BNDREGS
417 | ExtendedStateInfoXCR0Flags::MPX_BNDCSR
418 | ExtendedStateInfoXCR0Flags::AVX512_OPMASK
419 | ExtendedStateInfoXCR0Flags::AVX512_ZMM_HI256
420 | ExtendedStateInfoXCR0Flags::AVX512_ZMM_HI16
421 | ExtendedStateInfoXCR0Flags::PKRU,
422 ebx: 2688,
423 ecx: 2696,
424 edx: 0,
425 eax1: 15,
426 ebx1: 2560,
427 ecx1: ExtendedStateInfoXSSFlags::PT,
428 edx1: 0,
429 };
430
431 assert!(esi.xcr0_supports_legacy_x87());
432 assert!(esi.xcr0_supports_sse_128());
433 assert!(esi.xcr0_supports_avx_256());
434 assert!(esi.xcr0_supports_mpx_bndregs());
435 assert!(esi.xcr0_supports_mpx_bndcsr());
436 assert!(esi.xcr0_supports_avx512_opmask());
437 assert!(esi.xcr0_supports_avx512_zmm_hi256());
438 assert!(esi.xcr0_supports_avx512_zmm_hi16());
439 assert!(esi.xcr0_supports_pkru());
440 assert!(esi.ia32_xss_supports_pt());
441 assert!(!esi.ia32_xss_supports_hdc());
442
443 assert!(esi.xsave_area_size_enabled_features() == 2688);
444 assert!(esi.xsave_area_size_supported_features() == 2696);
445
446 assert!(esi.has_xsaveopt());
447 assert!(esi.has_xsavec());
448 assert!(esi.has_xgetbv());
449 assert!(esi.has_xsaves_xrstors());
450 assert!(esi.xsave_size() == 2560);
451
452 let es = [
453 ExtendedState {
454 subleaf: 2,
455 eax: 256,
456 ebx: 576,
457 ecx: 0,
458 },
459 ExtendedState {
460 subleaf: 3,
461 eax: 64,
462 ebx: 960,
463 ecx: 0,
464 },
465 ExtendedState {
466 subleaf: 4,
467 eax: 64,
468 ebx: 1024,
469 ecx: 0,
470 },
471 ExtendedState {
472 subleaf: 5,
473 eax: 64,
474 ebx: 1088,
475 ecx: 0,
476 },
477 ExtendedState {
478 subleaf: 6,
479 eax: 512,
480 ebx: 1152,
481 ecx: 0,
482 },
483 ExtendedState {
484 subleaf: 7,
485 eax: 1024,
486 ebx: 1664,
487 ecx: 0,
488 },
489 ExtendedState {
490 subleaf: 8,
491 eax: 128,
492 ebx: 0,
493 ecx: 1,
494 },
495 ExtendedState {
496 subleaf: 9,
497 eax: 8,
498 ebx: 2688,
499 ecx: 0,
500 },
501 ];
502
503 let e = &es[0];
504 assert!(e.subleaf == 2);
505 assert!(e.size() == 256);
506 assert!(e.offset() == 576);
507 assert!(e.is_in_xcr0());
508 assert!(!e.is_in_ia32_xss());
509 assert!(!e.is_compacted_format());
510
511 let e = &es[1];
512 assert!(e.subleaf == 3);
513 assert!(e.size() == 64);
514 assert!(e.offset() == 960);
515 assert!(e.is_in_xcr0());
516 assert!(!e.is_in_ia32_xss());
517 assert!(!e.is_compacted_format());
518
519 let e = &es[2];
520 assert!(e.subleaf == 4);
521 assert!(e.size() == 64);
522 assert!(e.offset() == 1024);
523 assert!(e.is_in_xcr0());
524 assert!(!e.is_in_ia32_xss());
525 assert!(!e.is_compacted_format());
526
527 let e = &es[3];
528 assert!(e.subleaf == 5);
529 assert!(e.size() == 64);
530 assert!(e.offset() == 1088);
531 assert!(e.is_in_xcr0());
532 assert!(!e.is_in_ia32_xss());
533 assert!(!e.is_compacted_format());
534
535 let e = &es[4];
536 assert!(e.subleaf == 6);
537 assert!(e.size() == 512);
538 assert!(e.offset() == 1152);
539 assert!(e.is_in_xcr0());
540 assert!(!e.is_in_ia32_xss());
541 assert!(!e.is_compacted_format());
542
543 let e = &es[5];
544 assert!(e.subleaf == 7);
545 assert!(e.size() == 1024);
546 assert!(e.offset() == 1664);
547 assert!(e.is_in_xcr0());
548 assert!(!e.is_in_ia32_xss());
549 assert!(!e.is_compacted_format());
550
551 let e = &es[6];
552 assert!(e.subleaf == 8);
553 assert!(e.size() == 128);
554 assert!(e.offset() == 0);
555 assert!(!e.is_in_xcr0());
556 assert!(e.is_in_ia32_xss());
557 assert!(!e.is_compacted_format());
558
559 let e = &es[7];
560 assert!(e.subleaf == 9);
561 assert!(e.size() == 8);
562 assert!(e.offset() == 2688);
563 assert!(e.is_in_xcr0());
564 assert!(!e.is_in_ia32_xss());
565 assert!(!e.is_compacted_format());
566 }
567
568 #[test]
extended_state_info2()569 fn extended_state_info2() {
570 let es = ExtendedStateInfo {
571 eax: ExtendedStateInfoXCR0Flags { bits: 31 },
572 ebx: 1088,
573 ecx: 1088,
574 edx: 0,
575 eax1: 15,
576 ebx1: 960,
577 ecx1: ExtendedStateInfoXSSFlags { bits: 256 },
578 edx1: 0,
579 };
580
581 assert!(es.xcr0_supports_legacy_x87());
582 assert!(es.xcr0_supports_sse_128());
583 assert!(es.xcr0_supports_avx_256());
584 assert!(es.xcr0_supports_mpx_bndregs());
585 assert!(es.xcr0_supports_mpx_bndcsr());
586 assert!(!es.xcr0_supports_avx512_opmask());
587 assert!(!es.xcr0_supports_pkru());
588 assert!(es.ia32_xss_supports_pt());
589
590 assert!(es.xsave_area_size_enabled_features() == 0x440);
591 assert!(es.xsave_area_size_supported_features() == 0x440);
592
593 assert!(es.has_xsaveopt());
594 assert!(es.has_xsavec());
595 assert!(es.has_xgetbv());
596 assert!(es.has_xsaves_xrstors());
597 assert!(es.xsave_size() == 0x3c0);
598
599 let esiter: [ExtendedState; 3] = [
600 ExtendedState {
601 subleaf: 2,
602 eax: 256,
603 ebx: 576,
604 ecx: 0,
605 },
606 ExtendedState {
607 subleaf: 3,
608 eax: 64,
609 ebx: 960,
610 ecx: 0,
611 },
612 ExtendedState {
613 subleaf: 4,
614 eax: 64,
615 ebx: 1024,
616 ecx: 0,
617 },
618 ];
619
620 let e = &esiter[0];
621 assert!(e.subleaf == 2);
622 assert!(e.size() == 256);
623 assert!(e.offset() == 576);
624 assert!(e.is_in_xcr0());
625 assert!(!e.is_in_ia32_xss());
626
627 let e = &esiter[1];
628 assert!(e.subleaf == 3);
629 assert!(e.size() == 64);
630 assert!(e.offset() == 960);
631 assert!(e.is_in_xcr0());
632 assert!(!e.is_in_ia32_xss());
633
634 let e = &esiter[2];
635 assert!(e.subleaf == 4);
636 assert!(e.size() == 64);
637 assert!(e.offset() == 1024);
638 assert!(e.is_in_xcr0());
639 assert!(!e.is_in_ia32_xss());
640 }
641
642 #[test]
quality_of_service_info()643 fn quality_of_service_info() {
644 let qos = RdtMonitoringInfo { ebx: 832, edx: 0 };
645
646 assert!(qos.rmid_range() == 832);
647 assert!(!qos.has_l3_monitoring());
648 }
649
650 #[test]
extended_functions()651 fn extended_functions() {
652 let ef = ExtendedFunctionInfo {
653 max_eax_value: 8,
654 data: [
655 CpuIdResult {
656 eax: 2147483656,
657 ebx: 0,
658 ecx: 0,
659 edx: 0,
660 },
661 CpuIdResult {
662 eax: 0,
663 ebx: 0,
664 ecx: 1,
665 edx: 672139264,
666 },
667 CpuIdResult {
668 eax: 538976288,
669 ebx: 1226842144,
670 ecx: 1818588270,
671 edx: 539578920,
672 },
673 CpuIdResult {
674 eax: 1701998403,
675 ebx: 692933672,
676 ecx: 758475040,
677 edx: 926102323,
678 },
679 CpuIdResult {
680 eax: 1346576469,
681 ebx: 541073493,
682 ecx: 808988209,
683 edx: 8013895,
684 },
685 CpuIdResult {
686 eax: 0,
687 ebx: 0,
688 ecx: 0,
689 edx: 0,
690 },
691 CpuIdResult {
692 eax: 0,
693 ebx: 0,
694 ecx: 16801856,
695 edx: 0,
696 },
697 CpuIdResult {
698 eax: 0,
699 ebx: 0,
700 ecx: 0,
701 edx: 256,
702 },
703 CpuIdResult {
704 eax: 12324,
705 ebx: 0,
706 ecx: 0,
707 edx: 0,
708 },
709 ],
710 };
711
712 assert_eq!(
713 ef.processor_brand_string().unwrap(),
714 " Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz"
715 );
716 assert!(ef.has_lahf_sahf());
717 assert!(!ef.has_lzcnt());
718 assert!(!ef.has_prefetchw());
719 assert!(ef.has_syscall_sysret());
720 assert!(ef.has_execute_disable());
721 assert!(!ef.has_1gib_pages());
722 assert!(ef.has_rdtscp());
723 assert!(ef.has_64bit_mode());
724 assert!(ef.has_invariant_tsc());
725
726 assert!(ef.extended_signature().unwrap() == 0x0);
727 assert!(ef.cache_line_size().unwrap() == 64);
728 assert!(ef.l2_associativity().unwrap() == L2Associativity::EightWay);
729 assert!(ef.cache_size().unwrap() == 256);
730 assert!(ef.physical_address_bits().unwrap() == 36);
731 assert!(ef.linear_address_bits().unwrap() == 48);
732 }
733
734 #[cfg(test)]
735 #[test]
sgx_test()736 fn sgx_test() {
737 let sgx = SgxInfo {
738 eax: 1,
739 ebx: 0,
740 ecx: 0,
741 edx: 9247,
742 eax1: 54,
743 ebx1: 0,
744 ecx1: 31,
745 edx1: 0,
746 };
747
748 assert!(sgx.max_enclave_size_64bit() == 0x24);
749 assert!(sgx.max_enclave_size_non_64bit() == 0x1f);
750 assert!(sgx.has_sgx1());
751 assert!(!sgx.has_sgx2());
752 assert!(sgx.miscselect() == 0x0);
753 assert!(sgx.secs_attributes() == (0x0000000000000036, 0x000000000000001f));
754 }
755
756 #[cfg(test)]
757 #[test]
readme_test()758 fn readme_test() {
759 // let cpuid = CpuId::new();
760 //
761 // match cpuid.get_vendor_info() {
762 // Some(vf) => assert!(vf.as_string() == "GenuineIntel"),
763 // None => ()
764 // }
765 //
766 // let has_sse = match cpuid.get_feature_info() {
767 // Some(finfo) => finfo.has_sse(),
768 // None => false
769 // };
770 //
771 // if has_sse {
772 // println!("CPU supports SSE!");
773 // }
774 //
775 // match cpuid.get_cache_parameters() {
776 // Some(cparams) => {
777 // for cache in cparams {
778 // let size = cache.associativity() * cache.physical_line_partitions() * cache.coherency_line_size() * cache.sets();
779 // println!("L{}-Cache size is {}", cache.level(), size);
780 // }
781 // },
782 // None => println!("No cache parameter information available"),
783 // }
784 //
785 }
786
787 /*
788 extern crate serde_json;
789
790 #[cfg(test)]
791 #[test]
792 fn test_serializability() {
793 #[derive(Debug, Default, Serialize, Deserialize)]
794 struct SerializeDeserializeTest {
795 _x1: CpuId,
796 _x2: CpuIdResult,
797 _x3: VendorInfo,
798 _x4: CacheInfoIter,
799 _x5: CacheInfo,
800 _x6: ProcessorSerial,
801 _x7: FeatureInfo,
802 _x8: CacheParametersIter,
803 _x9: CacheParameter,
804 _x10: MonitorMwaitInfo,
805 _x11: ThermalPowerInfo,
806 _x12: ExtendedFeatures,
807 _x13: DirectCacheAccessInfo,
808 _x14: PerformanceMonitoringInfo,
809 _x15: ExtendedTopologyIter,
810 _x16: ExtendedTopologyLevel,
811 _x17: ExtendedStateInfo,
812 _x18: ExtendedStateIter,
813 _x19: ExtendedState,
814 _x20: RdtAllocationInfo,
815 _x21: RdtMonitoringInfo,
816 _x22: L3CatInfo,
817 _x23: L2CatInfo,
818 _x24: ProcessorTraceInfo,
819 _x25: ProcessorTraceIter,
820 _x26: ProcessorTrace,
821 _x27: TscInfo,
822 _x28: ProcessorFrequencyInfo,
823 _x29: SoCVendorInfo,
824 _x30: SoCVendorAttributesIter,
825 _x31: SoCVendorBrand,
826 _x32: ExtendedFunctionInfo,
827 _x33: MemBwAllocationInfo,
828 _x34: L3MonitoringInfo,
829 _x35: SgxSectionInfo,
830 _x36: EpcSection,
831 _x37: SgxInfo,
832 _x38: SgxSectionIter,
833 _x39: DatInfo,
834 _x40: DatIter,
835 _x41: DatType,
836 }
837
838 let st: SerializeDeserializeTest = Default::default();
839 let test = serde_json::to_string(&st).unwrap();
840 let _st: SerializeDeserializeTest = serde_json::from_str(&test).unwrap();
841 }*/
842