1 /* $NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved.");
32 __RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $");
35 * This is adapted from part of csw/cstest of the MPD implementation by
36 * the University of Arizona CS department (http://www.cs.arizona.edu/sr/)
37 * which is in the public domain:
39 * "The MPD system is in the public domain and you may use and distribute it
40 * as you wish. We ask that you retain credits referencing the University
41 * of Arizona and that you identify any changes you make.
43 * We can't provide a warranty with MPD; it's up to you to determine its
44 * suitability and reliability for your needs. We would like to hear of
45 * any problems you encounter but we cannot promise a timely correction."
47 * It was changed to use pthread_create() and sched_yield() instead of
48 * the internal MPD context switching primitives by Ignatios Souvatzis
65 static void recurse(void);
67 int recursion_depth
= 0;
68 pthread_mutex_t recursion_depth_lock
;
73 double *q
= (double *)p
;
79 x
= sin ((y
= cos (x
+ y
+ .4)) - (z
= cos (x
+ z
+ .6)));
80 PTHREAD_REQUIRE(sched_yield());
85 mul3(double x
, double y
, double z
)
87 PTHREAD_REQUIRE(sched_yield());
98 d
= mul3(mul3(2., 3., 5.), mul3(7., 11., 13.), mul3(17., 19., 23.));
99 ATF_REQUIRE_EQ(d
, 223092870.);
101 PTHREAD_REQUIRE(pthread_mutex_lock(&recursion_depth_lock
));
102 rc
= recursion_depth
++;
103 PTHREAD_REQUIRE(pthread_mutex_unlock(&recursion_depth_lock
));
117 pthread_create(&s2
, 0, bar
, 0);
118 sleep(20); /* XXX must be long enough for our slowest machine */
124 atf_tc_set_md_var(tc
, "descr",
125 "Checks that thread context switches will leave the "
126 "floating point computations unharmed");
130 double stirseed
[] = { 1.7, 3.2, 2.4 };
133 printf("Testing threaded floating point computations...\n");
135 PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock
, 0));
137 pthread_create(&s5
, 0, stir
, stirseed
);
140 atf_tc_fail("exiting from main");
145 ATF_TP_ADD_TC(tp
, fpu
);
147 return atf_no_error();