Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2421 | mencl | 1 | /* |
2 | * Copyright (c) 2005 Jakub Vana |
||
3 | * Copyright (c) 2005 Jakub Jermar |
||
4 | * Copyright (c) 2007 Vojtech Mencl |
||
5 | * All rights reserved. |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions |
||
9 | * are met: |
||
10 | * |
||
11 | * - Redistributions of source code must retain the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer. |
||
13 | * - Redistributions in binary form must reproduce the above copyright |
||
14 | * notice, this list of conditions and the following disclaimer in the |
||
15 | * documentation and/or other materials provided with the distribution. |
||
16 | * - The name of the author may not be used to endorse or promote products |
||
17 | * derived from this software without specific prior written permission. |
||
18 | * |
||
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
29 | */ |
||
30 | |||
31 | #include <print.h> |
||
32 | #include <debug.h> |
||
33 | |||
34 | #include <test.h> |
||
35 | #include <atomic.h> |
||
36 | #include <proc/thread.h> |
||
37 | |||
38 | #include <arch.h> |
||
39 | |||
40 | #define THREADS 5 |
||
41 | #define RUN_TIME 10 |
||
42 | |||
43 | static atomic_t finish; |
||
44 | static atomic_t threads_finished; |
||
45 | static atomic_t run_time; |
||
46 | static bool sh_quiet; |
||
47 | |||
48 | static void timeouttest(void *data) |
||
49 | { |
||
50 | unsigned int tmp; |
||
51 | thread_detach(THREAD); |
||
52 | |||
53 | while (atomic_get(&finish)) { |
||
54 | tmp = atomic_get(&run_time) + 10000; |
||
55 | if (!sh_quiet) |
||
56 | printf("%llu sleeps %u mikrosec\n", THREAD->tid, tmp); |
||
57 | atomic_set(&run_time, tmp + 10000); |
||
58 | thread_usleep(atomic_get(&run_time)); |
||
59 | if (atomic_get(&run_time) > 300000) |
||
60 | atomic_set(&run_time,10000); |
||
61 | } |
||
62 | atomic_inc(&threads_finished); |
||
63 | } |
||
64 | |||
65 | char * test_timeout1(bool quiet) |
||
66 | { |
||
67 | unsigned int i, total = 0; |
||
68 | sh_quiet = quiet; |
||
69 | |||
70 | atomic_set(&finish, 1); |
||
71 | atomic_set(&threads_finished, 0); |
||
72 | atomic_set(&run_time, 10000); |
||
73 | |||
74 | for (i = 0; i < THREADS; i++) { |
||
75 | thread_t *t; |
||
76 | if (!(t = thread_create(timeouttest, NULL, TASK, 0, "timeouttest", false))) { |
||
77 | if (!quiet) |
||
78 | printf("Could not create thread %d\n", i); |
||
79 | break; |
||
80 | } |
||
81 | thread_ready(t); |
||
82 | total++; |
||
83 | } |
||
84 | |||
85 | if (!quiet) |
||
86 | printf("Running threads for %d seconds...\n",RUN_TIME); |
||
87 | thread_sleep(RUN_TIME); |
||
88 | |||
89 | atomic_set(&finish, 0); |
||
90 | while (atomic_get(&threads_finished) < total) { |
||
91 | if (!quiet) |
||
92 | printf("Threads left: %d\n", total - atomic_get(&threads_finished)); |
||
93 | thread_sleep(1); |
||
94 | } |
||
95 | |||
96 | return NULL; |
||
97 | } |