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