Rev 2260 | Rev 2283 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2260 | Rev 2265 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Jan Hudecek |
2 | * Copyright (c) 2007 Jan Hudecek |
3 | * Copyright (c) 2005 Jakub Jermar |
3 | * Copyright (c) 2005 Jakub Jermar |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include <print.h> |
30 | #include <print.h> |
31 | 31 | ||
32 | #include <test.h> |
32 | #include <test.h> |
33 | #include <ddi/tasklet.h> |
33 | #include <proc/tasklet.h> |
34 | #include <synch/waitq.h> |
34 | #include <synch/waitq.h> |
35 | 35 | ||
36 | #include <arch/types.h> |
36 | #include <arch/types.h> |
37 | 37 | ||
38 | static void func(void *data) |
38 | static void func(void *data) |
39 | { |
39 | { |
40 | printf("%s", data); |
40 | printf("%s", data); |
41 | } |
41 | } |
42 | 42 | ||
43 | char * test_tasklet1(bool quiet) |
43 | char * test_tasklet1(bool quiet) |
44 | { |
44 | { |
45 | waitq_t wq; |
45 | waitq_t wq; |
46 | waitq_initialize(&wq); |
46 | waitq_initialize(&wq); |
47 | tasklet_descriptor_t *tasklet_desc; |
47 | tasklet_descriptor_t *tasklet_desc; |
48 | 48 | ||
49 | //before we start we need to register a tasklet |
49 | //before we start we need to register a tasklet |
50 | if (!quiet) |
50 | if (!quiet) |
51 | printf("Registering tasklet..."); |
51 | printf("Registering tasklet..."); |
52 | if (!quiet) |
52 | if (!quiet) |
53 | tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n"); |
53 | tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n"); |
54 | else |
54 | else |
55 | tasklet_desc=tasklet_register(&func, ""); |
55 | tasklet_desc=tasklet_register(&func, ""); |
56 | if (!quiet) |
56 | if (!quiet) |
57 | printf("Done!\n"); |
57 | printf("Done!\n"); |
58 | 58 | ||
59 | //first we'll try disabling the tasklet |
59 | //first we'll try disabling the tasklet |
60 | if (!quiet) |
60 | if (!quiet) |
61 | printf("Disabling tasklet..."); |
61 | printf("Disabling tasklet..."); |
62 | tasklet_disable(tasklet_desc); |
62 | tasklet_disable(tasklet_desc); |
63 | if (!quiet) |
63 | if (!quiet) |
64 | printf("Done!\n"); |
64 | printf("Done!\n"); |
65 | 65 | ||
66 | //we'll schedule the disabled tasklet |
66 | //we'll schedule the disabled tasklet |
67 | if (!quiet) |
67 | if (!quiet) |
68 | printf("Scheduling tasklet..."); |
68 | printf("Scheduling tasklet..."); |
69 | tasklet_schedule(tasklet_desc); |
69 | tasklet_schedule(tasklet_desc); |
70 | if (!quiet) |
70 | if (!quiet) |
71 | printf("Done!\n"); |
71 | printf("Done!\n"); |
72 | 72 | ||
73 | //and we'll wait if it gets called. It shouldn't however because it's disabled |
73 | //and we'll wait if it gets called. It shouldn't however because it's disabled |
74 | if (!quiet) |
74 | if (!quiet) |
75 | printf("Waiting 5s..."); |
75 | printf("Waiting 5s..."); |
76 | waitq_sleep_timeout(&wq,(uint32_t) 5000000,0); |
76 | waitq_sleep_timeout(&wq,(uint32_t) 5000000,0); |
77 | if (!quiet) |
77 | if (!quiet) |
78 | printf("Done!\n"); |
78 | printf("Done!\n"); |
79 | 79 | ||
80 | //then we'll try to enable it |
80 | //then we'll try to enable it |
81 | if (!quiet) |
81 | if (!quiet) |
82 | printf("Enabling tasklet..."); |
82 | printf("Enabling tasklet..."); |
83 | tasklet_enable(tasklet_desc); |
83 | tasklet_enable(tasklet_desc); |
84 | if (!quiet) |
84 | if (!quiet) |
85 | printf("Done!\n"); |
85 | printf("Done!\n"); |
86 | 86 | ||
87 | //and wait if it gets called this time. It should beacause it's enabled |
87 | //and wait if it gets called this time. It should beacause it's enabled |
88 | if (!quiet) |
88 | if (!quiet) |
89 | printf("Waiting 5s..."); |
89 | printf("Waiting 5s..."); |
90 | waitq_sleep_timeout(&wq,(uint32_t) 5000000,0); |
90 | waitq_sleep_timeout(&wq,(uint32_t) 5000000,0); |
91 | if (!quiet) |
91 | if (!quiet) |
92 | printf("Done!\n"); |
92 | printf("Done!\n"); |
93 | 93 | ||
94 | //finally we'll free the tasklet structure |
94 | //finally we'll free the tasklet structure |
95 | if (!quiet) |
95 | if (!quiet) |
96 | printf("Freeing..."); |
96 | printf("Freeing..."); |
97 | tasklet_free(tasklet_desc); |
97 | tasklet_free(tasklet_desc); |
98 | if (!quiet) |
98 | if (!quiet) |
99 | printf("Done!\n"); |
99 | printf("Done!\n"); |
100 | 100 | ||
101 | 101 | ||
102 | return NULL; |
102 | return NULL; |
103 | } |
103 | } |
104 | 104 |