source: mainline/uspace/app/tester/float/float1.c

Last change on this file was 508b0df1, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Remove uspace <atomic.h>, use <stdatomic.h> instead

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[b6636dc]1/*
2 * Copyright (c) 2005 Jakub Vana
3 * Copyright (c) 2005 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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.
17 *
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.
28 */
29
[d5c1051]30#include <errno.h>
[b6636dc]31#include <stdio.h>
32#include <stdlib.h>
[582a0b8]33#include <stddef.h>
[508b0df1]34#include <stdatomic.h>
[38d8849]35#include <fibril.h>
36#include <fibril_synch.h>
[b6636dc]37#include <inttypes.h>
38#include "../tester.h"
39
40#define THREADS 150
41#define ATTEMPTS 100
42
43#define E_10E8 UINT32_C(271828182)
44#define PRECISION 100000000
45
[38d8849]46static FIBRIL_SEMAPHORE_INITIALIZE(threads_finished, 0);
[508b0df1]47static atomic_int threads_fault;
[b6636dc]48
[38d8849]49static errno_t e(void *data)
[b6636dc]50{
51 for (unsigned int i = 0; i < ATTEMPTS; i++) {
52 double le = -1;
53 double e = 0;
54 double f = 1;
[a35b458]55
[b6636dc]56 for (double d = 1; e != le; d *= f, f += 1) {
57 le = e;
58 e = e + 1 / d;
59 }
[a35b458]60
[b6636dc]61 if ((uint32_t) (e * PRECISION) != E_10E8) {
[508b0df1]62 atomic_fetch_add(&threads_fault, 1);
[b6636dc]63 break;
64 }
65 }
[a35b458]66
[38d8849]67 fibril_semaphore_up(&threads_finished);
68 return EOK;
[b6636dc]69}
70
71const char *test_float1(void)
72{
[508b0df1]73 int total = 0;
[a35b458]74
[508b0df1]75 atomic_store(&threads_fault, 0);
[38d8849]76 fibril_test_spawn_runners(THREADS);
[a35b458]77
[b6636dc]78 TPRINTF("Creating threads");
79 for (unsigned int i = 0; i < THREADS; i++) {
[38d8849]80 fid_t f = fibril_create(e, NULL);
81 if (!f) {
[b6636dc]82 TPRINTF("\nCould not create thread %u\n", i);
83 break;
84 }
[38d8849]85 fibril_detach(f);
86 fibril_add_ready(f);
[a35b458]87
[b6636dc]88 TPRINTF(".");
89 total++;
90 }
[a35b458]91
[b6636dc]92 TPRINTF("\n");
[a35b458]93
[508b0df1]94 for (int i = 0; i < total; i++) {
95 TPRINTF("Threads left: %d\n", total - i);
[38d8849]96 fibril_semaphore_down(&threads_finished);
[b6636dc]97 }
[a35b458]98
[508b0df1]99 if (atomic_load(&threads_fault) == 0)
[b6636dc]100 return NULL;
[a35b458]101
[b6636dc]102 return "Test failed";
103}
Note: See TracBrowser for help on using the repository browser.