[PATCH 2/2] kvm: add tests for KVM_SET_CPUID2 and KVM_GET_SUPPORTED_CPUID ioctl

Pierre Marsais pierre.marsais at lse.epita.fr
Sat Jun 23 00:10:14 UTC 2018


* tests/ioctl_kvm_run.c (main): Add tests for cpuid related ioctl

Signed-off-by: Pierre Marsais <pierre.marsais at lse.epita.fr>
---
 tests/ioctl_kvm_run.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/ioctl_kvm_run.c b/tests/ioctl_kvm_run.c
index e1bef579..55319fd5 100644
--- a/tests/ioctl_kvm_run.c
+++ b/tests/ioctl_kvm_run.c
@@ -253,6 +253,34 @@ main(void)
 	if (run == MAP_FAILED)
 		perror_msg_and_fail("mmap vcpu");
 
+	/*
+	 * cpuid_nent should be KVM_MAX_CPUID_ENTRIES, however it is not defined
+	 * in public headers.
+	 */
+	size_t cpuid_nent = 80;
+	struct kvm_cpuid2 *cpuid = malloc(sizeof(*cpuid) +
+					  cpuid_nent * sizeof(*cpuid->entries));
+	cpuid->nent = cpuid_nent;
+
+	KVM_IOCTL(kvm, KVM_GET_SUPPORTED_CPUID, cpuid);
+	printf("ioctl(%d<%s>, KVM_GET_SUPPORTED_CPUID, {nent=%d, entries=[",
+	       kvm, dev, cpuid->nent);
+	if (cpuid->nent)
+		printf("...");
+	printf("]}) = 0\n");
+
+	struct kvm_cpuid2 cpuid_tmp = { .nent = 0 };
+	KVM_IOCTL(vcpu_fd, KVM_SET_CPUID2, &cpuid_tmp);
+	printf("ioctl(%d<%s>, KVM_SET_CPUID2, {nent=%d, entries=[]}) = 0\n",
+	       vcpu_fd, vcpu_dev, cpuid_tmp.nent);
+	KVM_IOCTL(vcpu_fd, KVM_SET_CPUID2, cpuid);
+	printf("ioctl(%d<%s>, KVM_SET_CPUID2, {nent=%d, entries=[",
+	       vcpu_fd, vcpu_dev, cpuid->nent);
+	if (cpuid->nent)
+		printf("...");
+	printf("]}) = 0\n");
+	free(cpuid);
+
 	run_kvm(vcpu_fd, run, mmap_size, mem);
 
 	puts("+++ exited with 0 +++");
-- 
2.17.1



More information about the Strace-devel mailing list