summaryrefslogtreecommitdiff
path: root/usr/src/test/bhyve-tests
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/test/bhyve-tests')
-rw-r--r--usr/src/test/bhyve-tests/runfiles/default.run3
-rw-r--r--usr/src/test/bhyve-tests/tests/common/common.c (renamed from usr/src/test/bhyve-tests/tests/vmm/common.c)0
-rw-r--r--usr/src/test/bhyve-tests/tests/common/common.h (renamed from usr/src/test/bhyve-tests/tests/vmm/common.h)0
-rw-r--r--usr/src/test/bhyve-tests/tests/common/in_guest.c11
-rw-r--r--usr/src/test/bhyve-tests/tests/common/in_guest.h2
-rw-r--r--usr/src/test/bhyve-tests/tests/inst_emul/Makefile2
-rw-r--r--usr/src/test/bhyve-tests/tests/inst_emul/page_dirty.c79
-rw-r--r--usr/src/test/bhyve-tests/tests/vmm/Makefile7
8 files changed, 94 insertions, 10 deletions
diff --git a/usr/src/test/bhyve-tests/runfiles/default.run b/usr/src/test/bhyve-tests/runfiles/default.run
index f424652655..93101811a5 100644
--- a/usr/src/test/bhyve-tests/runfiles/default.run
+++ b/usr/src/test/bhyve-tests/runfiles/default.run
@@ -57,7 +57,8 @@ tests = [
'rdmsr',
'wrmsr',
'triple_fault',
- 'exit_paging'
+ 'exit_paging',
+ 'page_dirty'
]
[/opt/bhyve-tests/tests/viona]
diff --git a/usr/src/test/bhyve-tests/tests/vmm/common.c b/usr/src/test/bhyve-tests/tests/common/common.c
index ca34dc8cb2..ca34dc8cb2 100644
--- a/usr/src/test/bhyve-tests/tests/vmm/common.c
+++ b/usr/src/test/bhyve-tests/tests/common/common.c
diff --git a/usr/src/test/bhyve-tests/tests/vmm/common.h b/usr/src/test/bhyve-tests/tests/common/common.h
index a1147395ef..a1147395ef 100644
--- a/usr/src/test/bhyve-tests/tests/vmm/common.h
+++ b/usr/src/test/bhyve-tests/tests/common/common.h
diff --git a/usr/src/test/bhyve-tests/tests/common/in_guest.c b/usr/src/test/bhyve-tests/tests/common/in_guest.c
index 7d27cf194d..42df592bc8 100644
--- a/usr/src/test/bhyve-tests/tests/common/in_guest.c
+++ b/usr/src/test/bhyve-tests/tests/common/in_guest.c
@@ -123,7 +123,7 @@ populate_desc_tables(struct vmctx *ctx)
}
-static void
+void
test_cleanup(bool is_failure)
{
if (test_vmctx != NULL) {
@@ -144,6 +144,7 @@ test_cleanup(bool is_failure)
if (!is_failure || !keep_on_fail) {
vm_destroy(test_vmctx);
}
+ test_name = NULL;
test_vmctx = NULL;
}
}
@@ -309,6 +310,12 @@ load_payload(struct vmctx *ctx)
struct vmctx *
test_initialize(const char *tname)
{
+ return (test_initialize_flags(tname, 0));
+}
+
+struct vmctx *
+test_initialize_flags(const char *tname, uint64_t create_flags)
+{
char vm_name[VM_MAX_NAMELEN];
int err;
struct vmctx *ctx;
@@ -320,7 +327,7 @@ test_initialize(const char *tname)
(void) snprintf(vm_name, sizeof (vm_name), "bhyve-test-%s-%d",
test_name, getpid());
- err = vm_create(vm_name, 0);
+ err = vm_create(vm_name, create_flags);
if (err != 0) {
test_fail_errno(err, "Could not create VM");
}
diff --git a/usr/src/test/bhyve-tests/tests/common/in_guest.h b/usr/src/test/bhyve-tests/tests/common/in_guest.h
index 8d6e04a6da..fdacd6f540 100644
--- a/usr/src/test/bhyve-tests/tests/common/in_guest.h
+++ b/usr/src/test/bhyve-tests/tests/common/in_guest.h
@@ -19,6 +19,8 @@
#include "payload_common.h"
struct vmctx *test_initialize(const char *);
+struct vmctx *test_initialize_flags(const char *, uint64_t);
+void test_cleanup(bool);
void test_fail_errno(int err, const char *msg);
void test_fail_msg(const char *fmt, ...);
void test_fail_vmexit(const struct vm_exit *vexit);
diff --git a/usr/src/test/bhyve-tests/tests/inst_emul/Makefile b/usr/src/test/bhyve-tests/tests/inst_emul/Makefile
index f01a9c3bee..88f4d17119 100644
--- a/usr/src/test/bhyve-tests/tests/inst_emul/Makefile
+++ b/usr/src/test/bhyve-tests/tests/inst_emul/Makefile
@@ -32,7 +32,7 @@ CPAYLOADS = cpuid
PAYLOADS = $(PROG)
include ../Makefile.in_guest
-COMMON_OBJS = in_guest.o
+COMMON_OBJS = in_guest.o common.o
CLEANFILES = $(COMMON_OBJS) $(PAYLOAD_CLEANFILES) payload_utils.o
CLOBBERFILES = $(PROG)
diff --git a/usr/src/test/bhyve-tests/tests/inst_emul/page_dirty.c b/usr/src/test/bhyve-tests/tests/inst_emul/page_dirty.c
index 2e3a06bf47..36b9721701 100644
--- a/usr/src/test/bhyve-tests/tests/inst_emul/page_dirty.c
+++ b/usr/src/test/bhyve-tests/tests/inst_emul/page_dirty.c
@@ -29,6 +29,7 @@
#include <sys/vmm_dev.h>
#include <vmmapi.h>
+#include "common.h"
#include "in_guest.h"
#define PAGE_SZ 4096
@@ -70,6 +71,73 @@ count_dirty_pages(const uint8_t *bitmap)
return (count);
}
+void
+check_supported(const char *test_suite_name)
+{
+ char name[VM_MAX_NAMELEN];
+ int err;
+
+ name_test_vm(test_suite_name, name);
+
+ err = vm_create(name, VCF_TRACK_DIRTY);
+ if (err == 0) {
+ /*
+ * We created the VM successfully, so we know that dirty page
+ * tracking is supported.
+ */
+ err = destroy_instance(test_suite_name);
+ if (err != 0) {
+ (void) fprintf(stderr,
+ "Could not destroy VM: %s\n", strerror(errno));
+ (void) printf("FAIL %s\n", test_suite_name);
+ exit(EXIT_FAILURE);
+ }
+ } else if (errno == ENOTSUP) {
+ (void) printf(
+ "Skipping test: dirty page tracking not supported\n");
+ (void) printf("PASS %s\n", test_suite_name);
+ exit(EXIT_SUCCESS);
+ } else {
+ /*
+ * Ignore any other errors, they'll be caught by subsequent
+ * test routines.
+ */
+ }
+}
+
+void
+test_dirty_tracking_disabled(const char *test_suite_name)
+{
+ struct vmctx *ctx = NULL;
+ int err;
+
+ uint8_t dirty_bitmap[DIRTY_BITMAP_SZ] = { 0 };
+ struct vmm_dirty_tracker track = {
+ .vdt_start_gpa = 0,
+ .vdt_len = MEM_TOTAL_SZ,
+ .vdt_pfns = (void *)dirty_bitmap,
+ };
+
+ /* Create VM without VCF_TRACK_DIRTY flag */
+ ctx = test_initialize_flags(test_suite_name, 0);
+
+ err = test_setup_vcpu(ctx, 0, MEM_LOC_PAYLOAD, MEM_LOC_STACK);
+ if (err != 0) {
+ test_fail_errno(err, "Could not initialize vcpu0");
+ }
+
+ /* Try to query for dirty pages */
+ err = ioctl(vm_get_device_fd(ctx), VM_TRACK_DIRTY_PAGES, &track);
+ if (err == 0) {
+ test_fail_msg("VM_TRACK_DIRTY_PAGES succeeded unexpectedly\n");
+ } else if (errno != EPERM) {
+ test_fail_errno(errno,
+ "VM_TRACK_DIRTY_PAGES failed with unexpected error");
+ }
+
+ test_cleanup(false);
+}
+
int
main(int argc, char *argv[])
{
@@ -77,12 +145,13 @@ main(int argc, char *argv[])
struct vmctx *ctx = NULL;
int err;
- ctx = test_initialize(test_suite_name);
+ /* Skip test if CPU doesn't support HW A/D tracking */
+ check_supported(test_suite_name);
+
+ /* Test for expected error with dirty tracking disabled */
+ test_dirty_tracking_disabled(test_suite_name);
- /* Until #14251 is fixed, warn the user of the test requirement */
- (void) fprintf(stderr,
- "Ensure that 'gpt_track_dirty' is set to 1 via mdb -kw\n"
- "The reasoning is described in illumos #14251\n");
+ ctx = test_initialize_flags(test_suite_name, VCF_TRACK_DIRTY);
err = test_setup_vcpu(ctx, 0, MEM_LOC_PAYLOAD, MEM_LOC_STACK);
if (err != 0) {
diff --git a/usr/src/test/bhyve-tests/tests/vmm/Makefile b/usr/src/test/bhyve-tests/tests/vmm/Makefile
index 8f7f2d9624..e557aa2407 100644
--- a/usr/src/test/bhyve-tests/tests/vmm/Makefile
+++ b/usr/src/test/bhyve-tests/tests/vmm/Makefile
@@ -44,7 +44,8 @@ CPPFLAGS = -I$(COMPAT)/bhyve -I$(CONTRIB)/bhyve \
-I$(COMPAT)/bhyve/amd64 -I$(CONTRIB)/bhyve/amd64 \
$(CPPFLAGS.master) \
-I$(SRC)/uts/intel/io/vmm \
- -I$(SRC)/uts/intel
+ -I$(SRC)/uts/intel \
+ -I../common
$(PROG) := LDLIBS += -lvmmapi
all: $(PROG)
@@ -66,6 +67,10 @@ $(TESTDIR):
$(TESTDIR)/%: %
$(INS.file)
+%.o: ../common/%.c
+ $(COMPILE.c) -o $@ $^
+ $(POST_PROCESS)
+
%: %.o
$(LINK.c) -o $@ $< $(COMMON_OBJS) $(LDLIBS)
$(POST_PROCESS)