diff options
author | Dmitry Torokhov <dtor@chromium.org> | 2018-02-26 15:17:53 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-02-28 21:30:20 -0800 |
commit | 9786573e07992d43bfd5304ca7490a35aca2c61f (patch) | |
tree | f1082dcd1d1121ccdaf850251384825e1baab6f3 /tests/plugin_supported_cpuid.c | |
parent | d1c761354f5d2583763704c8f9a8a7dd61d1dbb7 (diff) | |
download | crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.tar crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.tar.gz crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.tar.bz2 crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.tar.lz crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.tar.xz crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.tar.zst crosvm-9786573e07992d43bfd5304ca7490a35aca2c61f.zip |
allow plugin to query KVM for supported/emulated CPUIDs
This plumbs calls to KVM_GET_SUPPORTED_CPUID and KVM_GET_EMULATED_CPUID to be available to plugins. TEST=cargo test --features plugin; cargo test -p kvm BUG=chromium:800626 Change-Id: I98879599b5f970c6c2720772658689a505d8abe1 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/938674 Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'tests/plugin_supported_cpuid.c')
-rw-r--r-- | tests/plugin_supported_cpuid.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/plugin_supported_cpuid.c b/tests/plugin_supported_cpuid.c new file mode 100644 index 0000000..0acb134 --- /dev/null +++ b/tests/plugin_supported_cpuid.c @@ -0,0 +1,67 @@ +/* + * Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "crosvm.h" + +int main(int argc, char** argv) { + struct crosvm *crosvm; + int ret = crosvm_connect(&crosvm); + if (ret) { + fprintf(stderr, "failed to connect to crosvm: %d\n", ret); + return 1; + } + + struct kvm_cpuid_entry2 cpuids[100]; + int n_entries; + ret = crosvm_get_supported_cpuid(crosvm, 1, cpuids, &n_entries); + if (ret >= 0) { + fprintf(stderr, + "expected crosvm_get_supported_cpuids to fail with E2BIG\n"); + return 1; + } + + ret = crosvm_get_supported_cpuid(crosvm, 100, cpuids, &n_entries); + if (ret < 0) { + fprintf(stderr, + "unexpected failure of crosvm_get_supported_cpuids: %d\n", ret); + return 1; + } + + if (n_entries <= 1) { + fprintf(stderr, + "unexpected number of supported cpuid entries: %d\n", + n_entries); + return 1; + } + + ret = crosvm_get_emulated_cpuid(crosvm, 1, cpuids, &n_entries); + if (ret >= 0) { + fprintf(stderr, + "expected crosvm_get_emulated_cpuids to fail with E2BIG\n"); + return 1; + } + + ret = crosvm_get_emulated_cpuid(crosvm, 100, cpuids, &n_entries); + if (ret < 0) { + fprintf(stderr, + "unexpected failure of crosvm_get_emulated_cpuid: %d\n", ret); + return 1; + } + + if (n_entries < 1) { + fprintf(stderr, + "unexpected number of emulated cpuid entries: %d\n", n_entries); + return 1; + } + + return 0; +} |