xref: /illumos-gate/usr/src/test/bhyve-tests/tests/kdev/vrtc_ops.c (revision a1d41cf940fc4cda50098ad61e6a78b19c7483cd)
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 2023 Oxide Computer Company
14  */
15 
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <strings.h>
20 #include <libgen.h>
21 #include <assert.h>
22 
23 #include <sys/types.h>
24 #include <sys/sysmacros.h>
25 #include <sys/debug.h>
26 #include <sys/vmm.h>
27 #include <sys/vmm_dev.h>
28 #include <vmmapi.h>
29 
30 #include "in_guest.h"
31 #include "test_defs.h"
32 
33 
34 int
35 main(int argc, char *argv[])
36 {
37 	const char *test_suite_name = basename(argv[0]);
38 	struct vmctx *ctx = NULL;
39 	int err;
40 
41 	ctx = test_initialize(test_suite_name);
42 
43 	err = test_setup_vcpu(ctx, 0, MEM_LOC_PAYLOAD, MEM_LOC_STACK);
44 	if (err != 0) {
45 		test_fail_errno(err, "Could not initialize vcpu0");
46 	}
47 
48 	timespec_t ts = { 0 };
49 	err = vm_rtc_settime(ctx, &ts);
50 	if (err != 0) {
51 		test_fail_errno(err, "Could zero out RTC time");
52 	}
53 
54 	struct vm_entry ventry = { 0 };
55 	struct vm_exit vexit = { 0 };
56 
57 	do {
58 		const enum vm_exit_kind kind =
59 		    test_run_vcpu(ctx, 0, &ventry, &vexit);
60 		switch (kind) {
61 		case VEK_REENTR:
62 			break;
63 		case VEK_TEST_PASS:
64 			test_pass();
65 			break;
66 		case VEK_TEST_FAIL:
67 			test_fail();
68 			break;
69 		case VEK_TEST_MSG:
70 			test_msg_print(ctx);
71 			break;
72 		default:
73 			test_fail_vmexit(&vexit);
74 			break;
75 		}
76 	} while (true);
77 }
78