Subversion Repositories HelenOS

Rev

Rev 2265 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2260 hudecek 1
/*
2
 * Copyright (c) 2007 Jan Hudecek
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
 
30
#include <print.h>
31
 
32
#include <test.h>
33
#include <ddi/tasklet.h>
34
#include <synch/waitq.h>
35
 
36
#include <arch/types.h>
37
 
38
static void func(void *data)
39
{
40
    printf("%s", data);
41
}
42
 
43
char * test_tasklet1(bool quiet)
44
{
45
    waitq_t wq;
46
    waitq_initialize(&wq);
47
    tasklet_descriptor_t *tasklet_desc;
48
 
49
    //before we start we need to register a tasklet
50
    if (!quiet)
51
        printf("Registering tasklet...");
52
    if (!quiet)
53
        tasklet_desc=tasklet_register(&func, "\nTasklet called and received data\n");
54
    else
55
        tasklet_desc=tasklet_register(&func, "");
56
    if (!quiet)
57
        printf("Done!\n");
58
 
59
    //first we'll try disabling the tasklet
60
    if (!quiet)
61
        printf("Disabling tasklet...");
62
    tasklet_disable(tasklet_desc);
63
    if (!quiet)
64
        printf("Done!\n");
65
 
66
    //we'll schedule the disabled tasklet
67
    if (!quiet)
68
        printf("Scheduling tasklet...");
69
    tasklet_schedule(tasklet_desc);
70
    if (!quiet)
71
        printf("Done!\n");
72
 
73
    //and we'll wait if it gets called. It shouldn't however because it's disabled
74
    if (!quiet)
75
        printf("Waiting 5s...");
76
    waitq_sleep_timeout(&wq,(uint32_t) 5000000,0);
77
    if (!quiet)
78
        printf("Done!\n");
79
 
80
    //then we'll try to enable it
81
    if (!quiet)
82
        printf("Enabling tasklet...");
83
    tasklet_enable(tasklet_desc);
84
    if (!quiet)
85
        printf("Done!\n");
86
 
87
    //and wait if it gets called this time. It should beacause it's enabled
88
    if (!quiet)
89
        printf("Waiting 5s...");
90
    waitq_sleep_timeout(&wq,(uint32_t) 5000000,0);
91
    if (!quiet)
92
        printf("Done!\n");
93
 
94
    //finally we'll free the tasklet structure
95
    if (!quiet)
96
        printf("Freeing...");
97
    tasklet_free(tasklet_desc);
98
    if (!quiet)
99
        printf("Done!\n");
100
 
101
 
102
    return NULL;
103
}