Skip to content

Commit 5a6f28d

Browse files
JBYoshiJonathanWoollett-Light
authored andcommitted
[Test code] Fix THC tolerance tests
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 <[email protected]>
1 parent a9ec9a8 commit 5a6f28d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/vmm/src/vstate/vcpu/x86_64.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,10 @@ mod tests {
902902
{
903903
// The frequency difference is within tolerance.
904904
let mut state = orig_state.clone();
905-
state.tsc_khz =
906-
Some(state.tsc_khz.unwrap() + TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR / 2);
905+
state.tsc_khz = Some(
906+
state.tsc_khz.unwrap()
907+
+ state.tsc_khz.unwrap() * TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR / 2,
908+
);
907909
assert!(!vcpu
908910
.is_tsc_scaling_required(state.tsc_khz.unwrap())
909911
.unwrap());
@@ -912,9 +914,11 @@ mod tests {
912914
{
913915
// The frequency difference is over the tolerance.
914916
let mut state = orig_state;
915-
state.tsc_khz =
916-
Some(state.tsc_khz.unwrap() + TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2);
917-
assert!(!vcpu
917+
state.tsc_khz = Some(
918+
state.tsc_khz.unwrap()
919+
+ state.tsc_khz.unwrap() * TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2,
920+
);
921+
assert!(vcpu
918922
.is_tsc_scaling_required(state.tsc_khz.unwrap())
919923
.unwrap());
920924
}
@@ -924,8 +928,10 @@ mod tests {
924928
fn test_set_tsc() {
925929
let (vm, vcpu, _) = setup_vcpu(0x1000);
926930
let mut state = vcpu.save_state().unwrap();
927-
state.tsc_khz =
928-
Some(state.tsc_khz.unwrap() + TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2);
931+
state.tsc_khz = Some(
932+
state.tsc_khz.unwrap()
933+
+ state.tsc_khz.unwrap() * TSC_KHZ_TOL_NUMERATOR / TSC_KHZ_TOL_DENOMINATOR * 2,
934+
);
929935

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

0 commit comments

Comments
 (0)