Module Name:    src
Committed By:   maxv
Date:           Sun Dec 23 13:35:02 UTC 2018

Modified Files:
        src/distrib/sets/lists/tests: md.amd64
        src/tests/lib: Makefile
Added Files:
        src/tests/lib/libnvmm: Makefile h_mem_assist.c h_mem_assist_asm.S
            t_mem_assist.sh

Log Message:
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/distrib/sets/lists/tests/md.amd64
cvs rdiff -u -r1.30 -r1.31 src/tests/lib/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libnvmm/Makefile \
    src/tests/lib/libnvmm/h_mem_assist.c \
    src/tests/lib/libnvmm/h_mem_assist_asm.S \
    src/tests/lib/libnvmm/t_mem_assist.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/md.amd64
diff -u src/distrib/sets/lists/tests/md.amd64:1.3 src/distrib/sets/lists/tests/md.amd64:1.4
--- src/distrib/sets/lists/tests/md.amd64:1.3	Sun Apr  2 01:49:52 2017
+++ src/distrib/sets/lists/tests/md.amd64	Sun Dec 23 13:35:02 2018
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.3 2017/04/02 01:49:52 kamil Exp $
+# $NetBSD: md.amd64,v 1.4 2018/12/23 13:35:02 maxv Exp $
 ./usr/tests/kernel/arch/x86/Atffile		tests-obsolete	obsolete
 ./usr/tests/kernel/arch/x86/Kyuafile		tests-obsolete	obsolete
 ./usr/tests/kernel/arch/x86/t_ptrace_wait	tests-obsolete	obsolete
@@ -7,3 +7,7 @@
 ./usr/tests/kernel/arch/x86/t_ptrace_wait6	tests-obsolete	obsolete
 ./usr/tests/kernel/arch/x86/t_ptrace_waitid	tests-obsolete	obsolete
 ./usr/tests/kernel/arch/x86/t_ptrace_waitpid	tests-obsolete	obsolete
+./usr/tests/lib/libnvmm/Atffile			tests-lib-tests	compattestfile,atf
+./usr/tests/lib/libnvmm/Kyuafile		tests-lib-tests	compattestfile,atf,kyua
+./usr/tests/lib/libnvmm/h_mem_assist		tests-lib-tests	compattestfile,atf
+./usr/tests/lib/libnvmm/t_mem_assist		tests-lib-tests	compattestfile,atf

Index: src/tests/lib/Makefile
diff -u src/tests/lib/Makefile:1.30 src/tests/lib/Makefile:1.31
--- src/tests/lib/Makefile:1.30	Thu Nov 23 02:40:01 2017
+++ src/tests/lib/Makefile	Sun Dec 23 13:35:02 2018
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.30 2017/11/23 02:40:01 kre Exp $
+# $NetBSD: Makefile,v 1.31 2018/12/23 13:35:02 maxv Exp $
 
 .include <bsd.own.mk>
 
 TESTS_SUBDIRS=	csu libbluetooth libc libcrypt libcurses libexecinfo \
-		libm libobjc libposix libppath libprop libpthread \
+		libm libnvmm libobjc libposix libppath libprop libpthread \
 		librefuse librt libtre libusbhid libutil \
 		semaphore
 

Added files:

Index: src/tests/lib/libnvmm/Makefile
diff -u /dev/null src/tests/lib/libnvmm/Makefile:1.1
--- /dev/null	Sun Dec 23 13:35:02 2018
+++ src/tests/lib/libnvmm/Makefile	Sun Dec 23 13:35:02 2018
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.1 2018/12/23 13:35:02 maxv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+TESTSDIR=	${TESTSBASE}/lib/libnvmm
+
+COPTS+=	-Wall
+LDADD+=	-lnvmm
+
+.if ${MACHINE} == "amd64"
+# Mem Assist
+TESTS_SH=		t_mem_assist
+PROGS=			h_mem_assist
+SRCS.h_mem_assist=	h_mem_assist.c h_mem_assist_asm.S
+.endif
+
+.include <bsd.test.mk>
Index: src/tests/lib/libnvmm/h_mem_assist.c
diff -u /dev/null src/tests/lib/libnvmm/h_mem_assist.c:1.1
--- /dev/null	Sun Dec 23 13:35:02 2018
+++ src/tests/lib/libnvmm/h_mem_assist.c	Sun Dec 23 13:35:02 2018
@@ -0,0 +1,328 @@
+/*
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maxime Villard.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <err.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <machine/segments.h>
+#include <machine/psl.h>
+#include <machine/pte.h>
+#include <x86/specialreg.h>
+
+#include <nvmm.h>
+
+#define PAGE_SIZE 4096
+
+static uint8_t mmiobuf[PAGE_SIZE];
+static uint8_t *instbuf;
+
+static void
+init_seg(struct nvmm_x64_state_seg *seg, int type, int sel)
+{
+	seg->selector = sel;
+	seg->attrib.type = type;
+	seg->attrib.dpl = 0;
+	seg->attrib.p = 1;
+	seg->attrib.avl = 1;
+	seg->attrib.lng = 1;
+	seg->attrib.def32 = 0;
+	seg->attrib.gran = 1;
+	seg->limit = 0xFFFFFFFF;
+	seg->base = 0x00000000;
+}
+
+static void
+reset_machine(struct nvmm_machine *mach)
+{
+	struct nvmm_x64_state state;
+
+	memset(&state, 0, sizeof(state));
+
+	/* Default. */
+	state.gprs[NVMM_X64_GPR_RFLAGS] = PSL_MBO;
+	init_seg(&state.segs[NVMM_X64_SEG_CS], SDT_MEMERA, GSEL(GCODE_SEL, SEL_KPL));
+	init_seg(&state.segs[NVMM_X64_SEG_SS], SDT_MEMRWA, GSEL(GDATA_SEL, SEL_KPL));
+	init_seg(&state.segs[NVMM_X64_SEG_DS], SDT_MEMRWA, GSEL(GDATA_SEL, SEL_KPL));
+	init_seg(&state.segs[NVMM_X64_SEG_ES], SDT_MEMRWA, GSEL(GDATA_SEL, SEL_KPL));
+	init_seg(&state.segs[NVMM_X64_SEG_FS], SDT_MEMRWA, GSEL(GDATA_SEL, SEL_KPL));
+	init_seg(&state.segs[NVMM_X64_SEG_GS], SDT_MEMRWA, GSEL(GDATA_SEL, SEL_KPL));
+
+	/* Blank. */
+	init_seg(&state.segs[NVMM_X64_SEG_GDT], 0, 0x0000);
+	init_seg(&state.segs[NVMM_X64_SEG_IDT], 0, 0x0000);
+	init_seg(&state.segs[NVMM_X64_SEG_LDT], 0, 0x0000);
+	init_seg(&state.segs[NVMM_X64_SEG_TR], 0, 0x0000);
+
+	/* Protected mode enabled. */
+	state.crs[NVMM_X64_CR_CR0] = CR0_PG|CR0_PE|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM;
+
+	/* 64bit mode enabled. */
+	state.crs[NVMM_X64_CR_CR4] = CR4_PAE;
+	state.msrs[NVMM_X64_MSR_EFER] = EFER_LME | EFER_SCE | EFER_LMA;
+
+	/* Stolen from x86/pmap.c */
+#define	PATENTRY(n, type)	(type << ((n) * 8))
+#define	PAT_UC		0x0ULL
+#define	PAT_WC		0x1ULL
+#define	PAT_WT		0x4ULL
+#define	PAT_WP		0x5ULL
+#define	PAT_WB		0x6ULL
+#define	PAT_UCMINUS	0x7ULL
+	state.msrs[NVMM_X64_MSR_PAT] =
+	    PATENTRY(0, PAT_WB) | PATENTRY(1, PAT_WT) |
+	    PATENTRY(2, PAT_UCMINUS) | PATENTRY(3, PAT_UC) |
+	    PATENTRY(4, PAT_WB) | PATENTRY(5, PAT_WT) |
+	    PATENTRY(6, PAT_UCMINUS) | PATENTRY(7, PAT_UC);
+
+	/* Page tables. */
+	state.crs[NVMM_X64_CR_CR3] = 0x3000;
+
+	state.gprs[NVMM_X64_GPR_RIP] = 0x2000;
+
+	if (nvmm_vcpu_setstate(mach, 0, &state, NVMM_X64_STATE_ALL) == -1)
+		err(errno, "nvmm_vcpu_setstate");
+}
+
+static void
+map_pages(struct nvmm_machine *mach)
+{
+	pt_entry_t *L4, *L3, *L2, *L1;
+
+	instbuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
+	    -1, 0);
+	if (instbuf == MAP_FAILED)
+		err(errno, "mmap");
+
+	if (nvmm_hva_map(mach, (uintptr_t)instbuf, PAGE_SIZE) == -1)
+		err(errno, "nvmm_hva_map");
+	if (nvmm_gpa_map(mach, (uintptr_t)instbuf, 0x2000, PAGE_SIZE, 0) == -1)
+		err(errno, "nvmm_gpa_map");
+
+	L4 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
+	    -1, 0);
+	if (L4 == MAP_FAILED)
+		err(errno, "mmap");
+	L3 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
+	    -1, 0);
+	if (L3 == MAP_FAILED)
+		err(errno, "mmap");
+	L2 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
+	    -1, 0);
+	if (L2 == MAP_FAILED)
+		err(errno, "mmap");
+	L1 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
+	    -1, 0);
+	if (L1 == MAP_FAILED)
+		err(errno, "mmap");
+
+	if (nvmm_hva_map(mach, (uintptr_t)L4, PAGE_SIZE) == -1)
+		err(errno, "nvmm_hva_map");
+	if (nvmm_hva_map(mach, (uintptr_t)L3, PAGE_SIZE) == -1)
+		err(errno, "nvmm_hva_map");
+	if (nvmm_hva_map(mach, (uintptr_t)L2, PAGE_SIZE) == -1)
+		err(errno, "nvmm_hva_map");
+	if (nvmm_hva_map(mach, (uintptr_t)L1, PAGE_SIZE) == -1)
+		err(errno, "nvmm_hva_map");
+
+	if (nvmm_gpa_map(mach, (uintptr_t)L4, 0x3000, PAGE_SIZE, 0) == -1)
+		err(errno, "nvmm_gpa_map");
+	if (nvmm_gpa_map(mach, (uintptr_t)L3, 0x4000, PAGE_SIZE, 0) == -1)
+		err(errno, "nvmm_gpa_map");
+	if (nvmm_gpa_map(mach, (uintptr_t)L2, 0x5000, PAGE_SIZE, 0) == -1)
+		err(errno, "nvmm_gpa_map");
+	if (nvmm_gpa_map(mach, (uintptr_t)L1, 0x6000, PAGE_SIZE, 0) == -1)
+		err(errno, "nvmm_gpa_map");
+
+	memset(L4, 0, PAGE_SIZE);
+	memset(L3, 0, PAGE_SIZE);
+	memset(L2, 0, PAGE_SIZE);
+	memset(L1, 0, PAGE_SIZE);
+
+	L4[0] = PG_V | PG_RW | 0x4000;
+	L3[0] = PG_V | PG_RW | 0x5000;
+	L2[0] = PG_V | PG_RW | 0x6000;
+	L1[0x2000 / PAGE_SIZE] = PG_V | PG_RW | 0x2000;
+	L1[0x1000 / PAGE_SIZE] = PG_V | PG_RW | 0x1000;
+}
+
+/* -------------------------------------------------------------------------- */
+
+static void
+mem_callback(struct nvmm_mem *mem)
+{
+	size_t off;
+
+	if (mem->gpa < 0x1000 || mem->gpa + mem->size > 0x1000 + PAGE_SIZE) {
+		printf("Out of page\n");
+		exit(-1);
+	}
+
+	off = mem->gpa - 0x1000;
+
+	printf("-> gpa = %p\n", (void *)mem->gpa);
+
+	if (mem->write) {
+		memcpy(mmiobuf + off, mem->data, mem->size);
+	} else {
+		memcpy(mem->data, mmiobuf + off, mem->size);
+	}
+}
+static int
+handle_memory(struct nvmm_machine *mach, struct nvmm_exit *exit)
+{
+	int ret;
+
+	ret = nvmm_assist_mem(mach, 0, exit, mem_callback);
+	if (ret == -1) {
+		err(errno, "nvmm_assist_mem");
+	}
+
+	return 0;
+}
+
+static void
+run_machine(struct nvmm_machine *mach)
+{
+	struct nvmm_exit exit;
+
+	while (1) {
+		if (nvmm_vcpu_run(mach, 0, &exit) == -1)
+			err(errno, "nvmm_vcpu_run");
+
+		switch (exit.reason) {
+		case NVMM_EXIT_NONE:
+			break;
+
+		case NVMM_EXIT_MSR:
+			/* Stop here. */
+			return;
+
+		case NVMM_EXIT_MEMORY:
+			handle_memory(mach, &exit);
+			break;
+
+		case NVMM_EXIT_SHUTDOWN:
+			printf("Shutting down!\n");
+			return;
+
+		default:
+			printf("Invalid!\n");
+			return;
+		}
+	}
+}
+
+/* -------------------------------------------------------------------------- */
+
+struct test {
+	const char *name;
+	uint8_t *code_begin;
+	uint8_t *code_end;
+	uint64_t wanted;
+};
+
+static void
+run_test(struct nvmm_machine *mach, struct test *test)
+{
+	uint64_t *res;
+	size_t size;
+
+	size = (size_t)test->code_end - (size_t)test->code_begin;
+
+	reset_machine(mach);
+
+	memset(mmiobuf, 0, PAGE_SIZE);
+	memcpy(instbuf, test->code_begin, size);
+
+	run_machine(mach);
+
+	res = (uint64_t *)mmiobuf;
+	if (*res == test->wanted) {
+		printf("Test '%s' passed\n", test->name);
+	} else {
+		printf("Test '%s' failed, wanted 0x%lx, got 0x%lx\n", test->name,
+		    test->wanted, *res);
+	}
+}
+
+/* -------------------------------------------------------------------------- */
+
+extern uint8_t test1_begin, test1_end;
+extern uint8_t test2_begin, test2_end;
+extern uint8_t test3_begin, test3_end;
+extern uint8_t test4_begin, test4_end;
+extern uint8_t test5_begin, test5_end;
+extern uint8_t test6_begin, test6_end;
+extern uint8_t test7_begin, test7_end;
+extern uint8_t test8_begin, test8_end;
+
+struct test tests[] = {
+	{ "test1 - MOV", &test1_begin, &test1_end, 0x3004 },
+	{ "test2 - OR",  &test2_begin, &test2_end, 0x14FF },
+	{ "test3 - AND", &test3_begin, &test3_end, 0x1FC0 },
+	{ "test4 - XOR", &test4_begin, &test4_end, 0x10CF },
+	{ "test5 - Address Sizes", &test5_begin, &test5_end, 0x1F00 },
+	{ "test6 - DMO", &test6_begin, &test6_end, 0xFFAB },
+	{ "test7 - STOS", &test7_begin, &test7_end, 0x00123456 },
+	{ "test8 - LODS", &test8_begin, &test8_end, 0x12345678 },
+	{ NULL, NULL, NULL, -1 }
+};
+
+/*
+ * 0x1000: MMIO address, unmapped
+ * 0x2000: Instructions, mapped
+ * 0x3000: L4
+ * 0x4000: L3
+ * 0x5000: L2
+ * 0x6000: L1
+ */
+int main(int argc, char *argv[])
+{
+	struct nvmm_machine mach;
+	size_t i;
+
+	if (nvmm_machine_create(&mach) == -1)
+		err(errno, "nvmm_machine_create");
+	if (nvmm_vcpu_create(&mach, 0) == -1)
+		err(errno, "nvmm_vcpu_create");
+	map_pages(&mach);
+
+	for (i = 0; tests[i].name != NULL; i++) {
+		run_test(&mach, &tests[i]);
+	}
+
+	return 0;
+}
Index: src/tests/lib/libnvmm/h_mem_assist_asm.S
diff -u /dev/null src/tests/lib/libnvmm/h_mem_assist_asm.S:1.1
--- /dev/null	Sun Dec 23 13:35:02 2018
+++ src/tests/lib/libnvmm/h_mem_assist_asm.S	Sun Dec 23 13:35:02 2018
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maxime Villard.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+	.globl	test1_begin, test1_end
+	.globl	test2_begin, test2_end
+	.globl	test3_begin, test3_end
+	.globl	test4_begin, test4_end
+	.globl	test5_begin, test5_end
+	.globl	test6_begin, test6_end
+	.globl	test7_begin, test7_end
+	.globl	test8_begin, test8_end
+	.text
+	.code64
+
+#define TEST_END	\
+	movq	$0xFFFFFFFFFFFFFFFF,%rcx;	\
+	rdmsr	;
+
+	.align	64
+test1_begin:
+	movq	$0x1000,%rax
+	movq	$0x1000,%rbp
+
+	movq	$0x1000,(%rax)
+
+	movq	$1,%r11
+	movq	$0x2000,(%rax,%r11,8)
+
+	movq	(%rbp),%r8
+	movq	8(%rbp),%rbx
+	addq	%rbx,%r8
+	movq	%r8,(%rbp)
+	movb	$4,(%rbp)
+
+	TEST_END
+test1_end:
+
+	.align	64
+test2_begin:
+	movq	$0x1000,%rax
+
+	movq	$0x1000,(%rax)
+	movq	$0x00FF,%rbx
+	orb	%bl,(%rax)
+	movq	$0x0400,%rcx
+	orw	%cx,(%rax)
+
+	TEST_END
+test2_end:
+
+	.align	64
+test3_begin:
+	movq	$0x1000,%rax
+
+	movq	$0x1FFF,(%rax)
+	movq	$0x1FF0,%rbx
+	andq	%rbx,(%rax)
+	movq	$0x10C1,%rcx
+	andb	%cl,(%rax)
+
+	TEST_END
+test3_end:
+
+	.align	64
+test4_begin:
+	movq	$0x1000,%rax
+
+	movq	$0x1FFF,(%rax)
+	movq	$0x1FF0,%rbx
+	xorq	%rbx,(%rax)
+	movq	$0x10C0,%rcx
+	xorw	%cx,(%rax)
+
+	TEST_END
+test4_end:
+
+	.align	64
+test5_begin:
+	movq	$0xFFFFFFFF00001000,%rax
+
+	movq	$0x1FFF,(%eax)
+	movb	$0,(%eax,%ebx,1)
+
+	TEST_END
+test5_end:
+
+	.align	64
+test6_begin:
+	movq	$0xFFA0,%rax
+	movabs	%rax,0x1000
+
+	movabs	0x1000,%al
+	orb	$0x0B,%al
+	movabs	%al,0x1000
+
+	TEST_END
+test6_end:
+
+	.align	64
+test7_begin:
+	movq	$0x56,%rax
+
+	movq	$1,%rcx
+	movq	$0x1000,%rdi
+	rep	stosb
+
+	movq	$0x1234,%rax
+	stosw
+
+	TEST_END
+test7_end:
+
+	.align	64
+test8_begin:
+	movq	$0x1008,%rsi
+	movq	$0x12345678,(%rsi)
+
+	movq	$0x1000,%rdi
+
+	lodsw
+	movw	%ax,(%rdi)
+	addq	$2,%rdi
+
+	lodsb
+	movb	%al,(%rdi)
+	addq	$1,%rdi
+
+	lodsb
+	movb	%al,(%rdi)
+	addq	$2,%rdi
+
+	TEST_END
+test8_end:
Index: src/tests/lib/libnvmm/t_mem_assist.sh
diff -u /dev/null src/tests/lib/libnvmm/t_mem_assist.sh:1.1
--- /dev/null	Sun Dec 23 13:35:02 2018
+++ src/tests/lib/libnvmm/t_mem_assist.sh	Sun Dec 23 13:35:02 2018
@@ -0,0 +1,50 @@
+#	$NetBSD: t_mem_assist.sh,v 1.1 2018/12/23 13:35:02 maxv Exp $
+#
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case mem_assist
+mem_assist_head()
+{
+	atf_set "descr" "Check the Mem Assist provided in libnvmm"
+}
+
+mem_assist_body()
+{
+	$(atf_get_srcdir)/h_mem_assist
+
+	exitcode=$?
+
+	if [ $exitcode -eq 6 ] ; then
+		atf_skip "NVMM driver not loaded"
+	elif [ $exitcode -ne 0 ] ; then
+		atf_fail "Mem Assist failed with errno $exitcode"
+	fi
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case mem_assist
+}

Reply via email to