Skip to content

Commit 5efde6d

Browse files
committed
KVM: selftests: Refactor stable TSC check to use TEST_REQUIRE()
Refactor the nested TSC scaling test's check on a stable system TSC to use TEST_REQUIRE() to do the heavy lifting when the system doesn't have a stable TSC. Using a helper+TEST_REQUIRE() eliminates the need for gotos and a custom message. Cc: Hao Ge <gehao@kylinos.cn> Cc: Vipin Sharma <vipinsh@google.com> Link: https://lore.kernel.org/r/20230406001724.706668-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b9846a6 commit 5efde6d

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,21 @@ static void l1_guest_code(struct vmx_pages *vmx_pages)
116116
GUEST_DONE();
117117
}
118118

119-
static void stable_tsc_check_supported(void)
119+
static bool system_has_stable_tsc(void)
120120
{
121+
bool tsc_is_stable;
121122
FILE *fp;
122123
char buf[4];
123124

124125
fp = fopen("/sys/devices/system/clocksource/clocksource0/current_clocksource", "r");
125126
if (fp == NULL)
126-
goto skip_test;
127+
return false;
127128

128-
if (fgets(buf, sizeof(buf), fp) == NULL)
129-
goto close_fp;
129+
tsc_is_stable = fgets(buf, sizeof(buf), fp) &&
130+
!strncmp(buf, "tsc", sizeof(buf));
130131

131-
if (strncmp(buf, "tsc", sizeof(buf)))
132-
goto close_fp;
133-
134-
fclose(fp);
135-
return;
136-
137-
close_fp:
138132
fclose(fp);
139-
skip_test:
140-
print_skip("Kernel does not use TSC clocksource - assuming that host TSC is not stable");
141-
exit(KSFT_SKIP);
133+
return tsc_is_stable;
142134
}
143135

144136
int main(int argc, char *argv[])
@@ -156,7 +148,7 @@ int main(int argc, char *argv[])
156148

157149
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
158150
TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL));
159-
stable_tsc_check_supported();
151+
TEST_REQUIRE(system_has_stable_tsc());
160152

161153
/*
162154
* We set L1's scale factor to be a random number from 2 to 10.

0 commit comments

Comments
 (0)