summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@chromium.org>2018-07-26 14:44:50 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-07-31 16:37:06 -0700
commit658357638c2fdd95525dd555c86078ecaed47458 (patch)
tree4ce39a88cb1c2d63415035e2add719dcd6c21ca9 /tests
parentc017a764d7237432f805d3b3f8f1ce7f5fdae107 (diff)
downloadcrosvm-658357638c2fdd95525dd555c86078ecaed47458.tar
crosvm-658357638c2fdd95525dd555c86078ecaed47458.tar.gz
crosvm-658357638c2fdd95525dd555c86078ecaed47458.tar.bz2
crosvm-658357638c2fdd95525dd555c86078ecaed47458.tar.lz
crosvm-658357638c2fdd95525dd555c86078ecaed47458.tar.xz
crosvm-658357638c2fdd95525dd555c86078ecaed47458.tar.zst
crosvm-658357638c2fdd95525dd555c86078ecaed47458.zip
plugin: allow retrieving list of supported MSRs
Add crossvm plugin API to allow fetching list of supported MSRs.

BUG=b:111083877
TEST=cargo test -p kvm; cargo test --features=plugin

Change-Id: I178c7bc33d606bef10422faac6bb9afb3fe0a014
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1152229
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/plugin_msr_index_list.c49
-rw-r--r--tests/plugins.rs5
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/plugin_msr_index_list.c b/tests/plugin_msr_index_list.c
new file mode 100644
index 0000000..0a940ae
--- /dev/null
+++ b/tests/plugin_msr_index_list.c
@@ -0,0 +1,49 @@
+/*
+ * 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;
+    }
+
+    uint32_t msr_indices[256];
+    int n_entries;
+    ret = crosvm_get_msr_index_list(crosvm, 1, msr_indices, &n_entries);
+    if (ret >= 0) {
+        fprintf(stderr,
+                "expected crosvm_get_msr_index_list to fail with E2BIG\n");
+        return 1;
+    }
+
+
+    memset(msr_indices, 0, sizeof(msr_indices));
+    ret = crosvm_get_msr_index_list(crosvm, 256, msr_indices, &n_entries);
+    if (ret < 0) {
+        fprintf(stderr,
+                "unexpected failure of crosvm_get_msr_index_list: %d\n", ret);
+        return 1;
+    }
+
+    if (n_entries <= 1) {
+        fprintf(stderr,
+                "unexpected number of supported msr entries: %d\n",
+                n_entries);
+        return 1;
+    }
+
+    return 0;
+}
diff --git a/tests/plugins.rs b/tests/plugins.rs
index c760875..7d2d8ff 100644
--- a/tests/plugins.rs
+++ b/tests/plugins.rs
@@ -242,6 +242,11 @@ fn test_supported_cpuid() {
 }
 
 #[test]
+fn test_msr_index_list() {
+    test_plugin(include_str!("plugin_msr_index_list.c"));
+}
+
+#[test]
 fn test_vm_state_manipulation() {
     test_plugin(include_str!("plugin_vm_state.c"));
 }