xref: /illumos-gate/usr/src/test/bhyve-tests/tests/vmm/interface_version.c (revision 8c0b080c8ed055a259d8cd26b9f005211c6a9753)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2022 Oxide Computer Company
14  */
15 
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <fcntl.h>
20 #include <libgen.h>
21 #include <err.h>
22 
23 #include <sys/vmm.h>
24 #include <sys/vmm_dev.h>
25 #include <vmmapi.h>
26 
27 #include "common.h"
28 
29 int
30 main(int argc, char *argv[])
31 {
32 	const char *suite_name = basename(argv[0]);
33 
34 	int ctl_fd = open(VMM_CTL_DEV, O_EXCL | O_RDWR);
35 	if (ctl_fd < 0) {
36 		perror("could not open vmmctl device");
37 	}
38 
39 	int version = ioctl(ctl_fd, VMM_INTERFACE_VERSION, 0);
40 	if (version < 0) {
41 		perror("VMM_INTERFACE_VERSION ioctl failed");
42 	}
43 	if (version != VMM_CURRENT_INTERFACE_VERSION) {
44 		(void) fprintf(stderr, "kernel version %d != expected %d\n",
45 		    version, VMM_CURRENT_INTERFACE_VERSION);
46 		return (EXIT_FAILURE);
47 	}
48 	(void) close(ctl_fd);
49 
50 	/* Query the version via an instance fd as well */
51 	struct vmctx *ctx = create_test_vm(suite_name);
52 	if (ctx == NULL) {
53 		err(EXIT_FAILURE, "could not open test VM");
54 	}
55 	version = ioctl(vm_get_device_fd(ctx), VMM_INTERFACE_VERSION, 0);
56 	if (version < 0) {
57 		err(EXIT_FAILURE,
58 		    "VMM_INTERFACE_VERSION ioctl failed on vmm fd");
59 	}
60 	if (version != VMM_CURRENT_INTERFACE_VERSION) {
61 		errx(EXIT_FAILURE, "kernel version %d != expected %d",
62 		    version, VMM_CURRENT_INTERFACE_VERSION);
63 	}
64 	vm_destroy(ctx);
65 
66 	(void) printf("%s\tPASS\n", suite_name);
67 	return (0);
68 }
69