Module Name: src Committed By: mgorny Date: Thu Oct 15 17:44:45 UTC 2020
Modified Files: src/distrib/sets/lists/tests: mi src/etc/mtree: NetBSD.dist.tests src/tests/sys: Makefile Added Files: src/tests/sys/x86: Makefile t_convert_xmm_s87.c Log Message: Add tests for process_xmm_to_s87() and process_s87_to_xmm() To generate a diff of this commit: cvs rdiff -u -r1.939 -r1.940 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.180 -r1.181 src/etc/mtree/NetBSD.dist.tests cvs rdiff -u -r1.4 -r1.5 src/tests/sys/Makefile cvs rdiff -u -r0 -r1.1 src/tests/sys/x86/Makefile \ src/tests/sys/x86/t_convert_xmm_s87.c 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/mi diff -u src/distrib/sets/lists/tests/mi:1.939 src/distrib/sets/lists/tests/mi:1.940 --- src/distrib/sets/lists/tests/mi:1.939 Thu Oct 8 19:09:08 2020 +++ src/distrib/sets/lists/tests/mi Thu Oct 15 17:44:44 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.939 2020/10/08 19:09:08 rillig Exp $ +# $NetBSD: mi,v 1.940 2020/10/15 17:44:44 mgorny Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -191,6 +191,7 @@ ./usr/libdata/debug/usr/tests/sys/netatalk tests-sys-debug compattestfile,atf ./usr/libdata/debug/usr/tests/sys/netinet tests-sys-debug compattestfile,atf ./usr/libdata/debug/usr/tests/sys/netinet6 tests-sys-debug compattestfile,atf +./usr/libdata/debug/usr/tests/sys/x86 tests-sys-debug compattestfile,atf ./usr/libdata/debug/usr/tests/syscall tests-obsolete obsolete ./usr/libdata/debug/usr/tests/usr.bin tests-usr.bin-debug compattestfile,atf ./usr/libdata/debug/usr/tests/usr.bin/cpio tests-usr.bin-debug compattestfile,atf @@ -4137,6 +4138,10 @@ ./usr/tests/sys/rc/h_args tests-sys-tests compattestfile,atf ./usr/tests/sys/rc/h_simple tests-sys-tests compattestfile,atf ./usr/tests/sys/rc/t_rc_d_cli tests-sys-tests compattestfile,atf +./usr/tests/sys/x86 tests-sys-tests compattestfile,atf +./usr/tests/sys/x86/Atffile tests-sys-tests compattestfile,atf +./usr/tests/sys/x86/Kyuafile tests-sys-tests compattestfile,atf,kyua +./usr/tests/sys/x86/t_convert_xmm_s87 tests-sys-tests compattestfile,atf ./usr/tests/syscall tests-obsolete obsolete ./usr/tests/syscall/Atffile tests-obsolete obsolete ./usr/tests/syscall/t_access tests-obsolete obsolete Index: src/etc/mtree/NetBSD.dist.tests diff -u src/etc/mtree/NetBSD.dist.tests:1.180 src/etc/mtree/NetBSD.dist.tests:1.181 --- src/etc/mtree/NetBSD.dist.tests:1.180 Wed Sep 30 20:20:53 2020 +++ src/etc/mtree/NetBSD.dist.tests Thu Oct 15 17:44:44 2020 @@ -1,4 +1,4 @@ -# $NetBSD: NetBSD.dist.tests,v 1.180 2020/09/30 20:20:53 roy Exp $ +# $NetBSD: NetBSD.dist.tests,v 1.181 2020/10/15 17:44:44 mgorny Exp $ ./usr/libdata/debug/usr/tests ./usr/libdata/debug/usr/tests/atf @@ -171,6 +171,7 @@ ./usr/libdata/debug/usr/tests/sys/netatalk ./usr/libdata/debug/usr/tests/sys/netinet ./usr/libdata/debug/usr/tests/sys/netinet6 +./usr/libdata/debug/usr/tests/sys/x86 ./usr/libdata/debug/usr/tests/usr.bin ./usr/libdata/debug/usr/tests/usr.bin/cpio ./usr/libdata/debug/usr/tests/usr.bin/id @@ -402,6 +403,7 @@ ./usr/tests/sys/netinet ./usr/tests/sys/netinet6 ./usr/tests/sys/rc +./usr/tests/sys/x86 ./usr/tests/usr.bin ./usr/tests/usr.bin/awk ./usr/tests/usr.bin/basename Index: src/tests/sys/Makefile diff -u src/tests/sys/Makefile:1.4 src/tests/sys/Makefile:1.5 --- src/tests/sys/Makefile:1.4 Tue Jun 30 20:32:11 2020 +++ src/tests/sys/Makefile Thu Oct 15 17:44:44 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2020/06/30 20:32:11 riastradh Exp $ +# $NetBSD: Makefile,v 1.5 2020/10/15 17:44:44 mgorny Exp $ .include <bsd.own.mk> @@ -10,5 +10,8 @@ TESTS_SUBDIRS+= netatalk TESTS_SUBDIRS+= netinet TESTS_SUBDIRS+= netinet6 TESTS_SUBDIRS+= rc +.if ${MACHINE} == amd64 || ${MACHINE} == i386 +TESTS_SUBDIRS+= x86 +.endif .include <bsd.test.mk> Added files: Index: src/tests/sys/x86/Makefile diff -u /dev/null src/tests/sys/x86/Makefile:1.1 --- /dev/null Thu Oct 15 17:44:45 2020 +++ src/tests/sys/x86/Makefile Thu Oct 15 17:44:44 2020 @@ -0,0 +1,11 @@ +# $NetBSD: Makefile,v 1.1 2020/10/15 17:44:44 mgorny Exp $ +# + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/sys/x86 +CPPFLAGS+= -I${NETBSDSRCDIR}/sys + +TESTS_C= t_convert_xmm_s87 + +.include <bsd.test.mk> Index: src/tests/sys/x86/t_convert_xmm_s87.c diff -u /dev/null src/tests/sys/x86/t_convert_xmm_s87.c:1.1 --- /dev/null Thu Oct 15 17:44:45 2020 +++ src/tests/sys/x86/t_convert_xmm_s87.c Thu Oct 15 17:44:44 2020 @@ -0,0 +1,211 @@ +/* $NetBSD: t_convert_xmm_s87.c,v 1.1 2020/10/15 17:44:44 mgorny Exp $ */ + +/*- + * Copyright (c) 2020 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Michał Górny for Moritz Systems Technology Company Sp. z o.o. + * + * 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 <sys/cdefs.h> +__RCSID("$NetBSD: t_convert_xmm_s87.c,v 1.1 2020/10/15 17:44:44 mgorny Exp $"); + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/sysctl.h> +#include <x86/cpu.h> +#include <x86/cpu_extended_state.h> + +#include <stdint.h> +#include <string.h> + +#include <atf-c.h> + +#include "arch/x86/x86/convert_xmm_s87.c" + +static const struct fpaccfx ST_INPUTS[] = { + {{0x8000000000000000, 0x4000}}, /* +2.0 */ + {{0x3f00000000000000, 0x0000}}, /* 1.654785e-4932 */ + {{0x0000000000000000, 0x0000}}, /* +0 */ + {{0x0000000000000000, 0x8000}}, /* -0 */ + {{0x8000000000000000, 0x7fff}}, /* +inf */ + {{0x8000000000000000, 0xffff}}, /* -inf */ + {{0xc000000000000000, 0xffff}}, /* nan */ + {{0x8000000000000000, 0xc000}}, /* -2.0 */ +}; +__CTASSERT(sizeof(*ST_INPUTS) == 16); + +ATF_TC(fsave_fxsave_hw); +ATF_TC_HEAD(fsave_fxsave_hw, tc) +{ + atf_tc_set_md_var(tc, "descr", + "converting between FSAVE/FXSAVE comparing to actual results"); +} + +ATF_TC_BODY(fsave_fxsave_hw, tc) +{ + struct save87 fsave, fsave_conv; + struct fxsave fxsave, fxsave_conv; + int i, j; + + int mib[] = { CTL_MACHDEP, CPU_OSFXSR }; + int has_fxsave; + size_t has_fxsave_size = sizeof(has_fxsave); + if (sysctl(mib, __arraycount(mib), &has_fxsave, &has_fxsave_size, + NULL, 0) == -1 || !has_fxsave) + atf_tc_skip("FXSAVE not supported"); + + for (i = 1; i <= __arraycount(ST_INPUTS); i++) { + unsigned long unused1, unused2; + __asm__ __volatile__( + "finit\n" + ".loadfp:\n\t" + "fldt (%2)\n\t" + "add $0x10, %2\n\t" + "loop .loadfp\n\t" + "fxsave %5\n\t" + "fsave %4\n\t" + : "=b"(unused1), "=c"(unused2) + : "b"(ST_INPUTS), "c"(i), "m"(fsave), "m"(fxsave) + : "st" + ); + + /* Self-assertion for working FSAVE/FXSAVE */ + ATF_REQUIRE_EQ(fsave.s87_cw, fxsave.fx_cw); + ATF_REQUIRE_EQ(fsave.s87_sw, fxsave.fx_sw); + + /* Test process_xmm_to_s87() */ + process_xmm_to_s87(&fxsave, &fsave_conv); + ATF_CHECK_EQ(fsave_conv.s87_cw, fsave.s87_cw); + ATF_CHECK_EQ(fsave_conv.s87_sw, fsave.s87_sw); + ATF_CHECK_EQ(fsave_conv.s87_tw, fsave.s87_tw); + for (j = 0; j < i; j++) { + ATF_CHECK_EQ(fsave_conv.s87_ac[j].f87_exp_sign, + fsave.s87_ac[j].f87_exp_sign); + ATF_CHECK_EQ(fsave_conv.s87_ac[j].f87_mantissa, + fsave.s87_ac[j].f87_mantissa); + } + + /* Test process_s87_to_xmm() */ + process_s87_to_xmm(&fsave, &fxsave_conv); + ATF_CHECK_EQ(fxsave_conv.fx_cw, fxsave.fx_cw); + ATF_CHECK_EQ(fxsave_conv.fx_sw, fxsave.fx_sw); + ATF_CHECK_EQ(fxsave_conv.fx_tw, fxsave.fx_tw); + for (j = 0; j < i; j++) { + ATF_CHECK_EQ(fxsave_conv.fx_87_ac[j].r.f87_exp_sign, + fxsave.fx_87_ac[j].r.f87_exp_sign); + ATF_CHECK_EQ(fxsave_conv.fx_87_ac[j].r.f87_mantissa, + fxsave.fx_87_ac[j].r.f87_mantissa); + } + } +} + +struct s87_xmm_test_vector { + uint16_t sw; + uint16_t tw; + uint8_t tw_abridged; +}; + +struct s87_xmm_test_vector FIXED_TEST_VECTORS[] = { + {0x3800, 0x3fff, 0x80}, + {0x3000, 0x2fff, 0xc0}, + {0x2800, 0x27ff, 0xe0}, + {0x2000, 0x25ff, 0xf0}, + {0x1800, 0x25bf, 0xf8}, + {0x1000, 0x25af, 0xfc}, + {0x0800, 0x25ab, 0xfe}, + {0x0000, 0x25a8, 0xff}, +}; + +ATF_TC(s87_to_xmm); +ATF_TC_HEAD(s87_to_xmm, tc) +{ + atf_tc_set_md_var(tc, "descr", + "converting from FSAVE to FXSAVE using fixed test vectors"); +} + +ATF_TC_BODY(s87_to_xmm, tc) +{ + struct save87 fsave; + struct fxsave fxsave; + int i, j; + + memset(&fsave, 0, sizeof(fsave)); + for (i = 0; i < __arraycount(ST_INPUTS); i++) { + fsave.s87_sw = FIXED_TEST_VECTORS[i].sw; + fsave.s87_tw = FIXED_TEST_VECTORS[i].tw; + for (j = 0; j <= i; j++) + fsave.s87_ac[i - j] = ST_INPUTS[j].r; + + process_s87_to_xmm(&fsave, &fxsave); + ATF_CHECK_EQ(fxsave.fx_sw, FIXED_TEST_VECTORS[i].sw); + ATF_CHECK_EQ(fxsave.fx_tw, FIXED_TEST_VECTORS[i].tw_abridged); + for (j = 0; j < i; j++) { + ATF_CHECK_EQ(fxsave.fx_87_ac[i - j].r.f87_exp_sign, + ST_INPUTS[j].r.f87_exp_sign); + ATF_CHECK_EQ(fxsave.fx_87_ac[i - j].r.f87_mantissa, + ST_INPUTS[j].r.f87_mantissa); + } + } +} + +ATF_TC(xmm_to_s87); +ATF_TC_HEAD(xmm_to_s87, tc) +{ + atf_tc_set_md_var(tc, "descr", + "converting from FSAVE to FXSAVE using fixed test vectors"); +} + +ATF_TC_BODY(xmm_to_s87, tc) +{ + struct save87 fsave; + struct fxsave fxsave; + int i, j; + + memset(&fxsave, 0, sizeof(fxsave)); + for (i = 0; i < __arraycount(ST_INPUTS); i++) { + fxsave.fx_sw = FIXED_TEST_VECTORS[i].sw; + fxsave.fx_tw = FIXED_TEST_VECTORS[i].tw_abridged; + for (j = 0; j <= i; j++) + fxsave.fx_87_ac[i - j] = ST_INPUTS[j]; + + process_xmm_to_s87(&fxsave, &fsave); + ATF_CHECK_EQ(fsave.s87_sw, FIXED_TEST_VECTORS[i].sw); + ATF_CHECK_EQ(fsave.s87_tw, FIXED_TEST_VECTORS[i].tw); + for (j = 0; j < i; j++) { + ATF_CHECK_EQ(fsave.s87_ac[i - j].f87_exp_sign, + ST_INPUTS[j].r.f87_exp_sign); + ATF_CHECK_EQ(fsave.s87_ac[i - j].f87_mantissa, + ST_INPUTS[j].r.f87_mantissa); + } + } +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, fsave_fxsave_hw); + ATF_TP_ADD_TC(tp, s87_to_xmm); + ATF_TP_ADD_TC(tp, xmm_to_s87); + return atf_no_error(); +}