xref: /illumos-gate/usr/src/test/bhyve-tests/tests/vmm/legacy_destruct.c (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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 <sys/stat.h>
22 #include <errno.h>
23 #include <err.h>
24 #include <assert.h>
25 
26 #include <sys/vmm.h>
27 #include <sys/vmm_dev.h>
28 #include <vmmapi.h>
29 
30 #include "common.h"
31 
32 int
33 main(int argc, char *argv[])
34 {
35 	const char *suite_name = basename(argv[0]);
36 	struct vmctx *ctx;
37 
38 	ctx = create_test_vm(suite_name);
39 	if (ctx == NULL) {
40 		errx(EXIT_FAILURE, "could open test VM");
41 	}
42 
43 	/*
44 	 * It would be odd if we had the freshly created VM instance, but it did
45 	 * not appear to exist.
46 	 */
47 	assert(check_instance_usable(suite_name));
48 
49 	vm_close(ctx);
50 
51 	/* Instance should remain, even though we closed it */
52 	if (!check_instance_usable(suite_name)) {
53 		err(EXIT_FAILURE, "instance missing after vm_close()");
54 	}
55 
56 	/*
57 	 * The common destroy_instance() uses the "legacy" destruction mechanism
58 	 * via the vmmctl device.
59 	 */
60 	if (destroy_instance(suite_name) != 0) {
61 		errx(EXIT_FAILURE, "ioctl(VMM_DESTROY_VM) failed");
62 	}
63 
64 	/* Instance should be gone at this point */
65 	if (check_instance_usable(suite_name)) {
66 		err(EXIT_FAILURE, "instance still accessible after destroy");
67 	}
68 
69 	(void) printf("%s\tPASS\n", suite_name);
70 	return (EXIT_SUCCESS);
71 }
72