mirror of
https://github.com/torvalds/linux.git
synced 2026-04-22 08:44:02 -04:00
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>
99 lines
1.8 KiB
C
99 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* tools/testing/selftests/kvm/lib/test_util.c
|
|
*
|
|
* Copyright (C) 2020, Google LLC.
|
|
*/
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <limits.h>
|
|
#include <assert.h>
|
|
#include "test_util.h"
|
|
|
|
/*
|
|
* Parses "[0-9]+[kmgt]?".
|
|
*/
|
|
size_t parse_size(const char *size)
|
|
{
|
|
size_t base;
|
|
char *scale;
|
|
int shift = 0;
|
|
|
|
TEST_ASSERT(size && isdigit(size[0]), "Need at least one digit in '%s'", size);
|
|
|
|
base = strtoull(size, &scale, 0);
|
|
|
|
TEST_ASSERT(base != ULLONG_MAX, "Overflow parsing size!");
|
|
|
|
switch (tolower(*scale)) {
|
|
case 't':
|
|
shift = 40;
|
|
break;
|
|
case 'g':
|
|
shift = 30;
|
|
break;
|
|
case 'm':
|
|
shift = 20;
|
|
break;
|
|
case 'k':
|
|
shift = 10;
|
|
break;
|
|
case 'b':
|
|
case '\0':
|
|
shift = 0;
|
|
break;
|
|
default:
|
|
TEST_ASSERT(false, "Unknown size letter %c", *scale);
|
|
}
|
|
|
|
TEST_ASSERT((base << shift) >> shift == base, "Overflow scaling size!");
|
|
|
|
return base << shift;
|
|
}
|
|
|
|
int64_t timespec_to_ns(struct timespec ts)
|
|
{
|
|
return (int64_t)ts.tv_nsec + 1000000000LL * (int64_t)ts.tv_sec;
|
|
}
|
|
|
|
struct timespec timespec_diff(struct timespec start, struct timespec end)
|
|
{
|
|
struct timespec temp;
|
|
|
|
if ((end.tv_nsec - start.tv_nsec) < 0) {
|
|
temp.tv_sec = end.tv_sec - start.tv_sec - 1;
|
|
temp.tv_nsec = 1000000000LL + end.tv_nsec - start.tv_nsec;
|
|
} else {
|
|
temp.tv_sec = end.tv_sec - start.tv_sec;
|
|
temp.tv_nsec = end.tv_nsec - start.tv_nsec;
|
|
}
|
|
|
|
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;
|
|
|
|
assert(fmt);
|
|
va_start(ap, fmt);
|
|
vprintf(fmt, ap);
|
|
va_end(ap);
|
|
puts(", skipping test");
|
|
}
|