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.

Signed-off-by: Jonathan Browne <12983479+JBYoshi@users.noreply.github.com>
  • Loading branch information
JBYoshi authored and JonathanWoollett-Light committed Oct 9, 2023
1 parent a9ec9a8 commit 5a6f28d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/vmm/src/vstate/vcpu/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,10 @@ 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);
state.tsc_khz = 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 @@ -912,9 +914,11 @@ 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
state.tsc_khz = 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 @@ -924,8 +928,10 @@ mod tests {
fn test_set_tsc() {
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);
state.tsc_khz = 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 5a6f28d

Please sign in to comment.