use crate::{CpuId, CpuIdResult};
use phf::phf_map;
static CPUID_VALUE_MAP: phf::Map<u64, CpuIdResult> = phf_map! {
0x00000000_00000000u64 => CpuIdResult { eax: 0x00000016, ebx: 0x756e6547, ecx: 0x6c65746e, edx: 0x49656e69 },
0x00000001_00000000u64 => CpuIdResult { eax: 0x00050657, ebx: 0xc7400800, ecx: 0x7ffefbff, edx: 0xbfebfbff },
0x00000002_00000000u64 => CpuIdResult { eax: 0x76036301, ebx: 0x00f0b5ff, ecx: 0x00000000, edx: 0x00c30000 },
0x00000003_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000004_00000000u64 => CpuIdResult { eax: 0x7c004121, ebx: 0x01c0003f, ecx: 0x0000003f, edx: 0x00000000 },
0x00000004_00000001u64 => CpuIdResult { eax: 0x7c004122, ebx: 0x01c0003f, ecx: 0x0000003f, edx: 0x00000000 },
0x00000004_00000002u64 => CpuIdResult { eax: 0x7c004143, ebx: 0x03c0003f, ecx: 0x000003ff, edx: 0x00000000 },
0x00000004_00000003u64 => CpuIdResult { eax: 0x7c0fc163, ebx: 0x0280003f, ecx: 0x0000cfff, edx: 0x00000005 },
0x00000005_00000000u64 => CpuIdResult { eax: 0x00000040, ebx: 0x00000040, ecx: 0x00000003, edx: 0x00002020 },
0x00000006_00000000u64 => CpuIdResult { eax: 0x00000077, ebx: 0x00000002, ecx: 0x00000009, edx: 0x00000000 },
0x00000007_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0xd39ff7eb, ecx: 0x00000818, edx: 0xbc000400 },
0x00000007_00000001u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000008_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000009_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000000a_00000000u64 => CpuIdResult { eax: 0x07300404, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000603 },
0x0000000b_00000000u64 => CpuIdResult { eax: 0x00000001, ebx: 0x00000002, ecx: 0x00000100, edx: 0x000000c7 },
0x0000000b_00000001u64 => CpuIdResult { eax: 0x00000006, ebx: 0x00000030, ecx: 0x00000201, edx: 0x000000c7 },
0x0000000c_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000000u64 => CpuIdResult { eax: 0x000002ff, ebx: 0x00000a88, ecx: 0x00000a88, edx: 0x00000000 },
0x0000000d_00000001u64 => CpuIdResult { eax: 0x0000000f, ebx: 0x00000a08, ecx: 0x00000100, edx: 0x00000000 },
0x0000000d_00000002u64 => CpuIdResult { eax: 0x00000100, ebx: 0x00000240, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000003u64 => CpuIdResult { eax: 0x00000040, ebx: 0x000003c0, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000004u64 => CpuIdResult { eax: 0x00000040, ebx: 0x00000400, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000005u64 => CpuIdResult { eax: 0x00000040, ebx: 0x00000440, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000006u64 => CpuIdResult { eax: 0x00000200, ebx: 0x00000480, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000007u64 => CpuIdResult { eax: 0x00000400, ebx: 0x00000680, ecx: 0x00000000, edx: 0x00000000 },
0x0000000d_00000008u64 => CpuIdResult { eax: 0x00000080, ebx: 0x00000000, ecx: 0x00000001, edx: 0x00000000 },
0x0000000d_00000009u64 => CpuIdResult { eax: 0x00000008, ebx: 0x00000a80, ecx: 0x00000000, edx: 0x00000000 },
0x0000000e_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x0000000f_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x000000cf, ecx: 0x00000000, edx: 0x00000002 },
0x0000000f_00000001u64 => CpuIdResult { eax: 0x00000000, ebx: 0x0001a000, ecx: 0x000000cf, edx: 0x00000007 },
0x00000010_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x0000000a, ecx: 0x00000000, edx: 0x00000000 },
0x00000010_00000001u64 => CpuIdResult { eax: 0x0000000a, ebx: 0x00000600, ecx: 0x00000004, edx: 0x0000000f },
0x00000010_00000003u64 => CpuIdResult { eax: 0x00000059, ebx: 0x00000000, ecx: 0x00000004, edx: 0x00000007 },
0x00000011_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000012_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000013_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x00000014_00000000u64 => CpuIdResult { eax: 0x00000001, ebx: 0x0000000f, ecx: 0x00000007, edx: 0x00000000 },
0x00000014_00000001u64 => CpuIdResult { eax: 0x02490002, ebx: 0x003f3fff, ecx: 0x00000000, edx: 0x00000000 },
0x00000015_00000000u64 => CpuIdResult { eax: 0x00000002, ebx: 0x000000a8, ecx: 0x00000000, edx: 0x00000000 },
0x00000016_00000000u64 => CpuIdResult { eax: 0x00000834, ebx: 0x00000e74, ecx: 0x00000064, edx: 0x00000000 },
0x20000000_00000000u64 => CpuIdResult { eax: 0x00000834, ebx: 0x00000e74, ecx: 0x00000064, edx: 0x00000000 },
0x80000000_00000000u64 => CpuIdResult { eax: 0x80000008, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80000001_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000121, edx: 0x2c100800 },
0x80000002_00000000u64 => CpuIdResult { eax: 0x65746e49, ebx: 0x2952286c, ecx: 0x6f655820, edx: 0x2952286e },
0x80000003_00000000u64 => CpuIdResult { eax: 0x6c6f4720, ebx: 0x32362064, ecx: 0x43203235, edx: 0x40205550 },
0x80000004_00000000u64 => CpuIdResult { eax: 0x312e3220, ebx: 0x7a484730, ecx: 0x00000000, edx: 0x00000000 },
0x80000005_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80000006_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x01006040, edx: 0x00000000 },
0x80000007_00000000u64 => CpuIdResult { eax: 0x00000000, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000100 },
0x80000008_00000000u64 => CpuIdResult { eax: 0x0000302e, ebx: 0x00000000, ecx: 0x00000000, edx: 0x00000000 },
0x80860000_00000000u64 => CpuIdResult { eax: 0x00000834, ebx: 0x00000e74, ecx: 0x00000064, edx: 0x00000000 },
0xc0000000_00000000u64 => CpuIdResult { eax: 0x00000834, ebx: 0x00000e74, ecx: 0x00000064, edx: 0x00000000 },
};
fn cpuid_reader(eax: u32, ecx: u32) -> CpuIdResult {
let key = (eax as u64) << u32::BITS | ecx as u64;
CPUID_VALUE_MAP[&key]
}
#[test]
fn vendor_check() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let v = cpuid.get_vendor_info().expect("Need to find vendor info");
assert_eq!(v.as_str(), "GenuineIntel");
}
#[test]
fn version_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let f = cpuid.get_feature_info().expect("Need to find feature info");
assert_eq!(f.base_family_id(), 6);
assert_eq!(f.base_model_id(), 5);
assert_eq!(f.stepping_id(), 7);
assert_eq!(f.extended_family_id(), 0);
assert_eq!(f.extended_model_id(), 5);
assert_eq!(f.family_id(), 6);
assert_eq!(f.model_id(), 85);
assert_eq!(f.max_logical_processor_ids(), 64);
assert_eq!(f.initial_local_apic_id(), 199); assert_eq!(f.cflush_cache_line_size(), 0x8);
assert_eq!(f.brand_index(), 0x0);
assert!(f.has_fpu());
assert!(f.has_vme());
assert!(f.has_de());
assert!(f.has_pse());
assert!(f.has_tsc());
assert!(f.has_msr());
assert!(f.has_pae());
assert!(f.has_mce());
assert!(f.has_cmpxchg8b());
assert!(f.has_apic());
assert!(f.has_sysenter_sysexit());
assert!(f.has_mtrr());
assert!(f.has_pge());
assert!(f.has_mca());
assert!(f.has_cmov());
assert!(f.has_pat());
assert!(f.has_pse36());
assert!(!f.has_psn());
assert!(f.has_clflush());
assert!(f.has_ds());
assert!(f.has_acpi());
assert!(f.has_mmx());
assert!(f.has_fxsave_fxstor());
assert!(f.has_sse());
assert!(f.has_sse2());
assert!(f.has_ss());
assert!(f.has_htt());
assert!(f.has_tm());
assert!(f.has_pbe());
assert!(f.has_sse3());
assert!(f.has_pclmulqdq());
assert!(f.has_ds_area());
assert!(f.has_monitor_mwait());
assert!(f.has_cpl());
assert!(f.has_vmx());
assert!(f.has_smx());
assert!(f.has_eist());
assert!(f.has_tm2());
assert!(f.has_ssse3());
assert!(!f.has_cnxtid());
assert!(f.has_fma());
assert!(f.has_cmpxchg16b());
assert!(f.has_pdcm());
assert!(f.has_pcid());
assert!(f.has_dca());
assert!(f.has_sse41());
assert!(f.has_sse42());
assert!(f.has_x2apic());
assert!(f.has_movbe());
assert!(f.has_popcnt());
assert!(f.has_tsc_deadline());
assert!(f.has_aesni());
assert!(f.has_xsave());
assert!(f.has_oxsave());
assert!(f.has_avx());
assert!(f.has_f16c());
assert!(f.has_rdrand());
assert!(!f.has_hypervisor());
}
#[test]
fn cache_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let ci = cpuid.get_cache_info().expect("Leaf is supported");
for (idx, cache) in ci.enumerate() {
match idx {
0 => assert_eq!(cache.num, 0xff),
1 => assert_eq!(cache.num, 0x63),
2 => assert_eq!(cache.num, 0xb5),
3 => assert_eq!(cache.num, 0x03),
4 => assert_eq!(cache.num, 0xf0),
5 => assert_eq!(cache.num, 0x76),
6 => assert_eq!(cache.num, 0xc3),
_ => unreachable!(),
}
}
}
#[test]
fn processor_serial() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let psn = cpuid.get_processor_serial().expect("Leaf is supported");
assert_eq!(psn.serial_lower(), 0x0);
assert_eq!(psn.serial_middle(), 0x0);
}
#[test]
fn monitor_mwait() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mw = cpuid.get_monitor_mwait_info().expect("Leaf is supported");
assert_eq!(mw.largest_monitor_line(), 64);
assert_eq!(mw.smallest_monitor_line(), 64);
assert!(mw.interrupts_as_break_event());
assert!(mw.extensions_supported());
assert_eq!(mw.supported_c0_states(), 0x0);
assert_eq!(mw.supported_c1_states(), 0x2);
assert_eq!(mw.supported_c2_states(), 0x0);
assert_eq!(mw.supported_c3_states(), 0x2);
assert_eq!(mw.supported_c4_states(), 0x0);
assert_eq!(mw.supported_c5_states(), 0x0);
assert_eq!(mw.supported_c6_states(), 0x0);
assert_eq!(mw.supported_c7_states(), 0x0);
}
#[test]
fn thermal_power() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mw = cpuid.get_thermal_power_info().expect("Leaf is supported");
assert!(mw.has_dts());
assert!(mw.has_turbo_boost());
assert!(mw.has_arat());
assert!(mw.has_pln());
assert!(mw.has_ecmd());
assert!(mw.has_ptm());
assert!(!mw.has_hwp());
assert!(!mw.has_hwp_notification());
assert!(!mw.has_hwp_activity_window());
assert!(!mw.has_hwp_energy_performance_preference());
assert!(!mw.has_hwp_package_level_request());
assert!(!mw.has_hdc());
assert!(!mw.has_turbo_boost3());
assert!(!mw.has_hwp_capabilities());
assert!(!mw.has_hwp_peci_override());
assert!(!mw.has_flexible_hwp());
assert!(!mw.has_hwp_fast_access_mode());
assert!(mw.has_hw_coord_feedback());
assert!(!mw.has_ignore_idle_processor_hwp_request());
assert_eq!(mw.dts_irq_threshold(), 0x2);
assert!(mw.has_energy_bias_pref());
}
#[test]
fn extended_features() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_extended_feature_info()
.expect("Leaf is supported");
assert!(e.has_fsgsbase());
assert!(e.has_tsc_adjust_msr());
assert!(!e.has_sgx());
assert!(e.has_bmi1());
assert!(!e.has_hle());
assert!(e.has_avx2());
assert!(e.has_fdp());
assert!(e.has_smep());
assert!(e.has_bmi2());
assert!(e.has_rep_movsb_stosb());
assert!(e.has_invpcid());
assert!(!e.has_rtm());
assert!(e.has_rdtm());
assert!(e.has_fpu_cs_ds_deprecated());
assert!(e.has_mpx());
assert!(e.has_rdta());
assert!(e.has_avx512f());
assert!(e.has_avx512dq());
assert!(e.has_rdseed());
assert!(e.has_adx());
assert!(e.has_smap());
assert!(!e.has_avx512_ifma());
assert!(e.has_clflushopt());
assert!(e.has_clwb());
assert!(e.has_processor_trace());
assert!(!e.has_avx512pf());
assert!(!e.has_avx512er());
assert!(e.has_avx512cd());
assert!(!e.has_sha());
assert!(e.has_avx512bw());
assert!(e.has_avx512vl());
assert!(!e.has_prefetchwt1());
assert!(!e.has_umip());
assert!(e.has_pku());
assert!(e.has_ospke());
assert!(e.has_avx512vnni());
assert!(!e.has_rdpid());
assert!(!e.has_sgx_lc());
assert_eq!(e.mawau_value(), 0x0);
}
#[test]
fn direct_cache_access() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let dca = cpuid.get_direct_cache_access_info().expect("Leaf exists");
assert_eq!(dca.get_dca_cap_value(), 0x0);
}
#[test]
fn perfmon_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let pm = cpuid
.get_performance_monitoring_info()
.expect("Leaf exists");
assert_eq!(pm.version_id(), 0x4);
assert_eq!(pm.number_of_counters(), 0x4);
assert_eq!(pm.counter_bit_width(), 0x30);
assert_eq!(pm.ebx_length(), 0x7);
assert!(!pm.is_core_cyc_ev_unavailable());
assert!(!pm.is_inst_ret_ev_unavailable());
assert!(!pm.is_ref_cycle_ev_unavailable());
assert!(!pm.is_cache_ref_ev_unavailable());
assert!(!pm.is_ll_cache_miss_ev_unavailable());
assert!(!pm.is_branch_inst_ret_ev_unavailable());
assert!(!pm.is_branch_midpred_ev_unavailable());
assert_eq!(pm.fixed_function_counters(), 0x3);
assert_eq!(pm.fixed_function_counters_bit_width(), 0x30);
assert!(!pm.has_any_thread_deprecation());
}
#[test]
fn extended_topology_info() {
use crate::TopologyType;
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let mut e = cpuid
.get_extended_topology_info()
.expect("Leaf is supported");
let t = e.next().expect("Have level 0");
assert_eq!(t.x2apic_id(), 199); assert_eq!(t.level_number(), 0);
assert_eq!(t.level_type(), TopologyType::SMT);
assert_eq!(t.shift_right_for_next_apic_id(), 0x1);
assert_eq!(t.processors(), 2);
let t = e.next().expect("Have level 1");
assert_eq!(t.level_number(), 1);
assert_eq!(t.level_type(), TopologyType::Core);
assert_eq!(t.shift_right_for_next_apic_id(), 0x6);
assert_eq!(t.processors(), 48);
assert_eq!(t.x2apic_id(), 199); }
#[test]
fn extended_state_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_extended_state_info().expect("Leaf is supported");
assert!(e.xcr0_supports_legacy_x87());
assert!(e.xcr0_supports_sse_128());
assert!(e.xcr0_supports_avx_256());
assert!(e.xcr0_supports_mpx_bndregs());
assert!(e.xcr0_supports_mpx_bndcsr());
assert!(e.xcr0_supports_avx512_opmask());
assert!(e.xcr0_supports_avx512_zmm_hi256());
assert!(e.xcr0_supports_avx512_zmm_hi16());
assert!(e.ia32_xss_supports_pt());
assert!(e.xcr0_supports_pkru());
assert!(!e.ia32_xss_supports_hdc());
assert_eq!(e.xsave_area_size_enabled_features(), 2696);
assert_eq!(e.xsave_area_size_supported_features(), 2696);
assert!(e.has_xsaveopt());
assert!(e.has_xsavec());
assert!(e.has_xgetbv());
assert!(e.has_xsaves_xrstors());
assert_eq!(e.xsave_size(), 2568);
let mut e = e.iter();
let ee = e.next().expect("Has level 2");
assert_eq!(ee.size(), 256);
assert_eq!(ee.offset(), 576);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 3");
assert_eq!(ee.size(), 64);
assert_eq!(ee.offset(), 960);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 4");
assert_eq!(ee.size(), 64);
assert_eq!(ee.offset(), 1024);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 5");
assert_eq!(ee.size(), 64);
assert_eq!(ee.offset(), 1088);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 6");
assert_eq!(ee.size(), 512);
assert_eq!(ee.offset(), 1152);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 7");
assert_eq!(ee.size(), 1024);
assert_eq!(ee.offset(), 1664);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 8");
assert_eq!(ee.size(), 128);
assert_eq!(ee.offset(), 0);
assert!(!ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
let ee = e.next().expect("Has level 9");
assert_eq!(ee.size(), 8);
assert_eq!(ee.offset(), 2688);
assert!(ee.is_in_xcr0());
assert!(!ee.is_compacted_format());
}
#[test]
fn rdt_monitoring_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_rdt_monitoring_info().expect("Leaf is supported");
assert_eq!(e.rmid_range(), 207);
assert!(e.has_l3_monitoring());
let l3m = e.l3_monitoring().expect("Leaf is available");
assert_eq!(l3m.conversion_factor(), 106496);
assert_eq!(l3m.maximum_rmid_range(), 207);
assert!(l3m.has_occupancy_monitoring());
assert!(l3m.has_total_bandwidth_monitoring());
assert!(l3m.has_local_bandwidth_monitoring());
}
#[test]
fn rdt_allocation_info() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_rdt_allocation_info().expect("Leaf is supported");
assert!(e.has_l3_cat());
assert!(!e.has_l2_cat());
assert!(e.has_memory_bandwidth_allocation());
assert!(e.l2_cat().is_none());
let l3c = e.l3_cat().expect("Leaf is available");
assert_eq!(l3c.capacity_mask_length(), 0xb);
assert_eq!(l3c.isolation_bitmap(), 0x00000600);
assert_eq!(l3c.highest_cos(), 15);
assert!(l3c.has_code_data_prioritization());
let mba = e.memory_bandwidth_allocation().expect("Leaf is available");
assert_eq!(mba.max_hba_throttling(), 90);
assert!(mba.has_linear_response_delay());
assert_eq!(mba.highest_cos(), 0x7);
}
#[test]
fn sgx_test() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
assert!(cpuid.get_sgx_info().is_none());
}
#[test]
fn processor_trace() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let pt = cpuid.get_processor_trace_info().expect("Leaf is available");
assert!(pt.has_rtit_cr3_match());
assert!(pt.has_configurable_psb_and_cycle_accurate_mode());
assert!(pt.has_ip_tracestop_filtering());
assert!(pt.has_mtc_timing_packet_coefi_suppression());
assert!(!pt.has_ptwrite());
assert!(!pt.has_power_event_trace());
assert!(pt.has_topa());
assert!(pt.has_topa_maximum_entries());
assert!(pt.has_single_range_output_scheme());
assert!(!pt.has_trace_transport_subsystem());
assert!(!pt.has_lip_with_cs_base());
assert_eq!(pt.configurable_address_ranges(), 2);
assert_eq!(pt.supported_mtc_period_encodings(), 585);
assert_eq!(pt.supported_cycle_threshold_value_encodings(), 16383);
assert_eq!(pt.supported_psb_frequency_encodings(), 63);
}
#[test]
fn tsc() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid.get_tsc_info().expect("Leaf is available");
assert_eq!(e.denominator(), 2);
assert_eq!(e.numerator(), 168);
assert_eq!(e.nominal_frequency(), 0x0);
assert_eq!(e.tsc_frequency(), None);
}
#[test]
fn processor_frequency() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_processor_frequency_info()
.expect("Leaf is supported");
assert_eq!(e.processor_base_frequency(), 2100);
assert_eq!(e.processor_max_frequency(), 3700);
assert_eq!(e.bus_frequency(), 100);
}
#[test]
fn extended_processor_and_feature_identifiers() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_extended_processor_and_feature_identifiers()
.expect("Leaf is supported");
assert_eq!(e.pkg_type(), 0x0); assert_eq!(e.brand_id(), 0x0);
assert!(e.has_lahf_sahf());
assert!(!e.has_cmp_legacy());
assert!(!e.has_svm());
assert!(!e.has_ext_apic_space());
assert!(!e.has_alt_mov_cr8());
assert!(e.has_lzcnt());
assert!(!e.has_sse4a());
assert!(!e.has_misaligned_sse_mode());
assert!(e.has_prefetchw());
assert!(!e.has_osvw());
assert!(!e.has_ibs());
assert!(!e.has_xop());
assert!(!e.has_skinit());
assert!(!e.has_wdt());
assert!(!e.has_lwp());
assert!(!e.has_fma4());
assert!(!e.has_tbm());
assert!(!e.has_topology_extensions());
assert!(!e.has_perf_cntr_extensions());
assert!(!e.has_nb_perf_cntr_extensions());
assert!(!e.has_data_access_bkpt_extension());
assert!(!e.has_perf_tsc());
assert!(!e.has_perf_cntr_llc_extensions());
assert!(!e.has_monitorx_mwaitx());
assert!(!e.has_addr_mask_extension());
assert!(e.has_syscall_sysret());
assert!(e.has_execute_disable());
assert!(!e.has_mmx_extensions());
assert!(!e.has_fast_fxsave_fxstor());
assert!(e.has_1gib_pages());
assert!(e.has_rdtscp());
assert!(e.has_64bit_mode());
assert!(!e.has_amd_3dnow_extensions());
assert!(!e.has_3dnow());
}
#[test]
fn brand_string() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_processor_brand_string()
.expect("Leaf is supported");
assert_eq!(e.as_str(), "Intel(R) Xeon(R) Gold 6252 CPU @ 2.10GHz");
}
#[test]
fn l1_tlb_cache() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
assert!(cpuid.get_l1_cache_and_tlb_info().is_none());
}
#[test]
fn l2_l3_tlb_cache() {
use crate::Associativity;
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_l2_l3_cache_and_tlb_info()
.expect("Leaf is supported");
assert_eq!(e.itlb_2m_4m_associativity(), Associativity::Disabled);
assert_eq!(e.itlb_2m_4m_size(), 0);
assert_eq!(e.dtlb_2m_4m_associativity(), Associativity::Disabled);
assert_eq!(e.dtlb_2m_4m_size(), 0);
assert_eq!(e.itlb_4k_size(), 0);
assert_eq!(e.itlb_4k_associativity(), Associativity::Disabled);
assert_eq!(e.dtlb_4k_size(), 0);
assert_eq!(e.dtlb_4k_associativity(), Associativity::Disabled);
assert_eq!(e.l2cache_line_size(), 64);
assert_eq!(e.l2cache_lines_per_tag(), 0);
assert_eq!(e.l2cache_associativity(), Associativity::NWay(8));
assert_eq!(e.l2cache_size(), 256);
assert_eq!(e.l3cache_line_size(), 0);
assert_eq!(e.l3cache_lines_per_tag(), 0);
assert_eq!(e.l3cache_associativity(), Associativity::Disabled);
assert_eq!(e.l3cache_size(), 0);
}
#[test]
fn apm() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_advanced_power_mgmt_info()
.expect("Leaf is supported");
assert!(!e.has_mca_overflow_recovery());
assert!(!e.has_succor());
assert!(!e.has_hwa());
assert_eq!(e.cpu_pwr_sample_time_ratio(), 0x0);
assert!(!e.has_ts());
assert!(!e.has_freq_id_ctrl());
assert!(!e.has_volt_id_ctrl());
assert!(!e.has_thermtrip());
assert!(!e.has_tm());
assert!(!e.has_100mhz_steps());
assert!(!e.has_hw_pstate());
assert!(e.has_invariant_tsc()); assert!(!e.has_cpb());
assert!(!e.has_ro_effective_freq_iface());
assert!(!e.has_feedback_iface());
assert!(!e.has_power_reporting_iface());
}
#[test]
fn processor_capcity_features() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
let e = cpuid
.get_processor_capacity_feature_info()
.expect("Leaf is supported");
assert_eq!(e.physical_address_bits(), 46);
assert_eq!(e.linear_address_bits(), 48);
assert_eq!(e.guest_physical_address_bits(), 0);
assert!(!e.has_cl_zero());
assert!(!e.has_inst_ret_cntr_msr());
assert!(!e.has_restore_fp_error_ptrs());
assert!(!e.has_invlpgb());
assert!(!e.has_rdpru());
assert!(!e.has_mcommit());
assert!(!e.has_wbnoinvd());
assert!(!e.has_int_wbinvd());
assert!(!e.has_unsupported_efer_lmsle());
assert!(!e.has_invlpgb_nested());
assert_eq!(e.invlpgb_max_pages(), 0x0);
assert_eq!(e.maximum_logical_processors(), 1); assert_eq!(e.num_phys_threads(), 1); assert_eq!(e.apic_id_size(), 0);
assert_eq!(e.perf_tsc_size(), 40); assert_eq!(e.max_rdpru_id(), 0);
}
#[test]
fn remaining_unsupported_leafs() {
let cpuid = CpuId::with_cpuid_fn(cpuid_reader);
assert!(cpuid.get_deterministic_address_translation_info().is_none());
assert!(cpuid.get_soc_vendor_info().is_none());
assert!(cpuid.get_extended_topology_info_v2().is_none());
assert!(cpuid.get_tlb_1gb_page_info().is_none());
assert!(cpuid.get_performance_optimization_info().is_none());
assert!(cpuid.get_processor_topology_info().is_none());
assert!(cpuid.get_memory_encryption_info().is_none());
}