diff options
author | Colton Lewis <coltonlewis@google.com> | 2022-11-07 21:22:05 +0300 |
---|---|---|
committer | Sean Christopherson <seanjc@google.com> | 2022-11-16 21:09:19 +0300 |
commit | b31f21a7e97eee501db86714868d84377e68e4df (patch) | |
tree | 35e3a382bde5ef7b5f8e4e7a29866ec6f83ddd36 /tools/testing/selftests/kvm/include/test_util.h | |
parent | d886724ea81c6a4dc5e37d4ee09287a31ab8335e (diff) | |
download | linux-b31f21a7e97eee501db86714868d84377e68e4df.tar.xz |
KVM: selftests: implement random number generator for guest code
Implement random number generator for guest code to randomize parts
of the test, making it less predictable and a more accurate reflection
of reality.
The random number generator chosen is the Park-Miller Linear
Congruential Generator, a fancy name for a basic and well-understood
random number generator entirely sufficient for this purpose.
Signed-off-by: Colton Lewis <coltonlewis@google.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20221107182208.479157-2-coltonlewis@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/include/test_util.h')
-rw-r--r-- | tools/testing/selftests/kvm/include/test_util.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 3be98e81189a..80d6416f3012 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -77,6 +77,13 @@ struct timespec timespec_sub(struct timespec ts1, struct timespec ts2); struct timespec timespec_elapsed(struct timespec start); struct timespec timespec_div(struct timespec ts, int divisor); +struct guest_random_state { + uint32_t seed; +}; + +struct guest_random_state new_guest_random_state(uint32_t seed); +uint32_t guest_random_u32(struct guest_random_state *state); + enum vm_mem_backing_src_type { VM_MEM_SRC_ANONYMOUS, VM_MEM_SRC_ANONYMOUS_THP, |