Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/sys/x86 Add tests for process_xmm_to_s87() and process...



details:   https://anonhg.NetBSD.org/src/rev/0d6159077bd1
branches:  trunk
changeset: 955885:0d6159077bd1
user:      mgorny <mgorny%NetBSD.org@localhost>
date:      Thu Oct 15 17:44:44 2020 +0000

description:
Add tests for process_xmm_to_s87() and process_s87_to_xmm()

diffstat:

 distrib/sets/lists/tests/mi       |    7 +-
 etc/mtree/NetBSD.dist.tests       |    4 +-
 tests/sys/Makefile                |    5 +-
 tests/sys/x86/Makefile            |   11 +
 tests/sys/x86/t_convert_xmm_s87.c |  211 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 235 insertions(+), 3 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 10d248798dc1 -r 0d6159077bd1 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Oct 15 17:43:30 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Oct 15 17:44:44 2020 +0000
@@ -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
diff -r 10d248798dc1 -r 0d6159077bd1 etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests       Thu Oct 15 17:43:30 2020 +0000
+++ b/etc/mtree/NetBSD.dist.tests       Thu Oct 15 17:44:44 2020 +0000
@@ -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
diff -r 10d248798dc1 -r 0d6159077bd1 tests/sys/Makefile
--- a/tests/sys/Makefile        Thu Oct 15 17:43:30 2020 +0000
+++ b/tests/sys/Makefile        Thu Oct 15 17:44:44 2020 +0000
@@ -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+=        netinet
 TESTS_SUBDIRS+=        netinet6
 TESTS_SUBDIRS+=        rc
+.if ${MACHINE} == amd64 || ${MACHINE} == i386
+TESTS_SUBDIRS+=        x86
+.endif
 
 .include <bsd.test.mk>
diff -r 10d248798dc1 -r 0d6159077bd1 tests/sys/x86/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sys/x86/Makefile    Thu Oct 15 17:44:44 2020 +0000
@@ -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>
diff -r 10d248798dc1 -r 0d6159077bd1 tests/sys/x86/t_convert_xmm_s87.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sys/x86/t_convert_xmm_s87.c Thu Oct 15 17:44:44 2020 +0000
@@ -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();


Home | Main Index | Thread Index | Old Index