2 * Copyright (c) 2005 Jakub Vana
3 * Copyright (c) 2005 Jakub Jermar
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - 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.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <stdatomic.h>
36 #include <fibril_synch.h>
38 #include "../tester.h"
43 #define E_10E8 UINT32_C(271828182)
44 #define PRECISION 100000000
46 static FIBRIL_SEMAPHORE_INITIALIZE(threads_finished
, 0);
47 static atomic_int threads_fault
;
49 static errno_t
e(void *data
)
51 for (unsigned int i
= 0; i
< ATTEMPTS
; i
++) {
56 for (double d
= 1; e
!= le
; d
*= f
, f
+= 1) {
61 if ((uint32_t) (e
* PRECISION
) != E_10E8
) {
62 atomic_fetch_add(&threads_fault
, 1);
67 fibril_semaphore_up(&threads_finished
);
71 const char *test_float1(void)
75 atomic_store(&threads_fault
, 0);
76 fibril_test_spawn_runners(THREADS
);
78 TPRINTF("Creating threads");
79 for (unsigned int i
= 0; i
< THREADS
; i
++) {
80 fid_t f
= fibril_create(e
, NULL
);
82 TPRINTF("\nCould not create thread %u\n", i
);
94 for (int i
= 0; i
< total
; i
++) {
95 TPRINTF("Threads left: %d\n", total
- i
);
96 fibril_semaphore_down(&threads_finished
);
99 if (atomic_load(&threads_fault
) == 0)
102 return "Test failed";