summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-02-06 22:28:36 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-12 22:42:40 -0800
commitdadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd (patch)
tree038c55ce2ceac80b5a5af7518257a2c5b5497738 /tests
parent1d4a70029c849b7aff178dd1e4a00feb7a5c483b (diff)
downloadcrosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.tar
crosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.tar.gz
crosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.tar.bz2
crosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.tar.lz
crosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.tar.xz
crosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.tar.zst
crosvm-dadb7625ea382b0372ec8be9fcae8f0aa3f0b6fd.zip
allow plugin to query for KVM extensions
The guest may need to check for KVM extensions before blindly using
them.

TEST=cargo test --features plugin; cargo test -p kvm; ./build_test
BUG=chromium:800626

Change-Id: If87b928753cd71adeabac4fc7732c3fce7265834
Reviewed-on: https://chromium-review.googlesource.com/906008
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/plugin_extensions.c53
-rw-r--r--tests/plugins.rs5
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/plugin_extensions.c b/tests/plugin_extensions.c
new file mode 100644
index 0000000..4e3ea87
--- /dev/null
+++ b/tests/plugin_extensions.c
@@ -0,0 +1,53 @@
+/*
+ * 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 <fcntl.h>
+#include <linux/memfd.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <time.h>
+#include <unistd.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;
+    }
+
+    bool supported;
+    ret = crosvm_check_extension(crosvm, KVM_CAP_IRQCHIP, &supported);
+    if (ret) {
+        fprintf(stderr, "failed to check for KVM extension: %d\n", ret);
+        return 1;
+    }
+    if (!supported) {
+        fprintf(stderr, "expected KVM extension to be supported\n");
+        return 1;
+    }
+
+    // Assume s390 extensions aren't supported because we shouldn't be running on one.
+    ret = crosvm_check_extension(crosvm, KVM_CAP_S390_PSW, &supported);
+    if (ret) {
+        fprintf(stderr, "failed to check for KVM extension: %d\n", ret);
+        return 1;
+    }
+    if (supported) {
+        fprintf(stderr, "unexpected KVM extension is supported\n");
+        return 1;
+    }
+
+    return 0;
+}
diff --git a/tests/plugins.rs b/tests/plugins.rs
index 54c4b7d..67383fc 100644
--- a/tests/plugins.rs
+++ b/tests/plugins.rs
@@ -226,6 +226,11 @@ fn test_irqfd() {
 }
 
 #[test]
+fn test_extensions() {
+    test_plugin(include_str!("plugin_extensions.c"));
+}
+
+#[test]
 fn test_debugregs() {
     let mini_plugin = MiniPlugin {
         assembly_src: "org 0x1000