summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/lib
diff options
context:
space:
mode:
authorAndrew Jones <drjones@redhat.com>2020-03-13 16:56:44 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2020-03-16 17:59:07 +0100
commit94c4b76b88d40f9062dc32ff2fff551ae1791c1e (patch)
tree74487c65682932b2d52df3e1ec5de6684d1a01d8 /tools/testing/selftests/kvm/lib
parentbeca54702dc694970dd9727dde59cf5f56c4dbd8 (diff)
KVM: selftests: Introduce steal-time test
The steal-time test confirms what is reported to the guest as stolen time is consistent with the run_delay reported for the VCPU thread on the host. Both x86_64 and AArch64 have the concept of steal/stolen time so this test is introduced for both architectures. While adding the test we ensure .gitignore has all tests listed (it was missing s390x/resets) and that the Makefile has all tests listed in alphabetical order (not really necessary, but it almost was already...). We also extend the common API with a new num-guest- pages call and a new timespec call. Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/lib')
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c7
-rw-r--r--tools/testing/selftests/kvm/lib/test_util.c15
2 files changed, 22 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index e26917ba25bc..35bd42370c21 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1769,3 +1769,10 @@ vm_num_guest_pages(enum vm_guest_mode mode, unsigned int num_host_pages)
return vm_calc_num_pages(num_host_pages, getpageshift(),
vm_guest_mode_params[mode].page_shift, false);
}
+
+unsigned int vm_calc_num_guest_pages(enum vm_guest_mode mode, size_t size)
+{
+ unsigned int n;
+ n = DIV_ROUND_UP(size, vm_guest_mode_params[mode].page_size);
+ return vm_adjust_num_guest_pages(mode, n);
+}
diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
index 26fb3d73dc74..ee12c4b9ae05 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -71,6 +71,21 @@ struct timespec timespec_diff(struct timespec start, struct timespec end)
return temp;
}
+struct timespec timespec_add_ns(struct timespec ts, int64_t ns)
+{
+ struct timespec res;
+
+ res.tv_sec = ts.tv_sec;
+ res.tv_nsec = ts.tv_nsec + ns;
+
+ if (res.tv_nsec > 1000000000UL) {
+ res.tv_sec += 1;
+ res.tv_nsec -= 1000000000UL;
+ }
+
+ return res;
+}
+
void print_skip(const char *fmt, ...)
{
va_list ap;