Skip to content

Commit

Permalink
[Test code] Fix THC tolerance tests.
Browse files Browse the repository at this point in the history
In these tests, the tolerance constants all originally rounded to 0,
which meant they weren't testing the correct behavior (everything was
always under the tolerance level). This fixes the tests to properly put
everything over the tolerance threshold.
  • Loading branch information
JBYoshi committed Oct 8, 2023
1 parent c207b8f commit 4d55f2d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/vmm/src/vstate/vcpu/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ mod tests {
// The frequency difference is within tolerance.
let mut state = orig_state.clone();
state.tsc_khz =
Some(state.tsc_khz.unwrap() + TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR / 2);
Some(state.tsc_khz.unwrap() + state.tsc_khz.unwrap() * TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR / 2);
assert!(!vcpu
.is_tsc_scaling_required(state.tsc_khz.unwrap())
.unwrap());
Expand All @@ -913,8 +913,8 @@ mod tests {
// The frequency difference is over the tolerance.
let mut state = orig_state;
state.tsc_khz =
Some(state.tsc_khz.unwrap() + TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2);
assert!(!vcpu
Some(state.tsc_khz.unwrap() + state.tsc_khz.unwrap() * TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2);
assert!(vcpu
.is_tsc_scaling_required(state.tsc_khz.unwrap())
.unwrap());
}
Expand All @@ -925,7 +925,7 @@ mod tests {
let (vm, vcpu, _) = setup_vcpu(0x1000);
let mut state = vcpu.save_state().unwrap();
state.tsc_khz =
Some(state.tsc_khz.unwrap() + TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2);
Some(state.tsc_khz.unwrap() + state.tsc_khz.unwrap() * TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2);

if vm.fd().check_extension(Cap::TscControl) {
assert!(vcpu.set_tsc_khz(state.tsc_khz.unwrap()).is_ok());
Expand Down

0 comments on commit 4d55f2d

Please sign in to comment.