xref: /illumos-gate/usr/src/test/bhyve-tests/tests/viona/interface_version.c (revision dd72704bd9e794056c558153663c739e2012d721)
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 
22 #include <sys/viona_io.h>
23 
24 #define	VIONA_DEV	"/dev/viona"
25 
26 int
27 main(int argc, char *argv[])
28 {
29 	const char *suite_name = basename(argv[0]);
30 
31 	int ctl_fd = open(VIONA_DEV, O_EXCL | O_RDWR);
32 	if (ctl_fd < 0) {
33 		perror("could not open viona device");
34 		return (EXIT_FAILURE);
35 	}
36 
37 	int version = ioctl(ctl_fd, VNA_IOC_VERSION, 0);
38 	if (version < 0) {
39 		perror("VNA_IOC_VERSION ioctl failed");
40 		return (EXIT_FAILURE);
41 	}
42 	if (version != VIONA_CURRENT_INTERFACE_VERSION) {
43 		(void) fprintf(stderr, "kernel version %d != expected %d\n",
44 		    version, VIONA_CURRENT_INTERFACE_VERSION);
45 		return (EXIT_FAILURE);
46 	}
47 
48 	(void) close(ctl_fd);
49 	(void) printf("%s\tPASS\n", suite_name);
50 	return (0);
51 }
52