source: rtems-libbsd/testsuite/swi01/swi_test.c @ ee6b343

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since ee6b343 was ee6b343, checked in by Christian Mauderer <christian.mauderer@…>, on 05/10/12 at 13:06:10

Provide SWI(9) and TIMEOUT(9)

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <assert.h>
33
34#include <stdio.h>
35#include <unistd.h>
36
37#include <freebsd/machine/rtems-bsd-config.h>
38
39#include <freebsd/sys/types.h>
40#include <freebsd/sys/systm.h>
41
42#include <freebsd/sys/param.h>
43#include <freebsd/sys/bus.h>
44#include <freebsd/sys/interrupt.h>
45
46#define SWI_TEST_THREAD_PRIO (0)
47
48// Time to wait for swi-test-handler
49#define SWI_SLEEP_TIME (100)
50
51enum arg {
52        HANDLER_NOT_VISITED,
53        HANDLER_VISITED,
54};
55
56// The swi handler function, that will be called by all tests.
57void swi_test_handler(void *arg)
58{
59        enum arg* argument = arg;
60
61        printf("This is swi_test_handler.\n");
62
63        *argument = HANDLER_VISITED;
64}
65
66void swi_test_normal_handler()
67{
68        struct intr_event *test_intr_event = NULL;
69        enum arg argument = HANDLER_NOT_VISITED;
70        void *test_ih = NULL;
71        int retval = 0;
72
73        printf("== Create thread and install a functional handler.\n");
74
75        retval = swi_add(&test_intr_event, "swi_test", swi_test_handler, &argument,
76                SWI_TEST_THREAD_PRIO, 0, &test_ih);
77        assert(retval == 0);
78
79        swi_sched(test_ih, 0);
80
81        usleep(SWI_SLEEP_TIME);
82       
83        assert(argument == HANDLER_VISITED);
84}
85
86void swi_test_exclusive_handler()
87{
88        struct intr_event *test_intr_event = NULL;
89        enum arg argument = HANDLER_NOT_VISITED;
90        void *test_ih = NULL;
91        int retval = 0;
92
93        printf("== Create a thread with a exclusive handler.\n");
94
95        retval = swi_add(&test_intr_event, "swi_test", swi_test_handler, &argument,
96                SWI_TEST_THREAD_PRIO, INTR_EXCL, &test_ih);
97        assert(retval == 0);
98
99        swi_sched(test_ih, 0);
100       
101        usleep(SWI_SLEEP_TIME);
102       
103        assert(argument == HANDLER_VISITED);
104}
105
106void swi_test_error_number_of_processes_exceeded()
107{
108        // [EAGAIN] The system-imposed limit on the total number of processes
109        // under execution would be exceeded.  The limit is given by the
110        // sysctl(3) MIB variable KERN_MAXPROC.
111#warning TODO: write test case
112}
113
114void swi_test_error_intr_entropy_set()
115{
116        struct intr_event *test_intr_event = NULL;
117        enum arg argument = HANDLER_NOT_VISITED;
118        void *test_ih = NULL;
119        int retval = 0;
120
121        printf("== Set the INTR_ENTROPY flag.\n");
122
123        retval = swi_add(&test_intr_event, "swi_test", swi_test_handler, &argument,
124                SWI_TEST_THREAD_PRIO, INTR_ENTROPY, &test_ih);
125        assert(retval == EINVAL);
126       
127        usleep(SWI_SLEEP_TIME);
128       
129        assert(argument == HANDLER_NOT_VISITED);
130}
131
132void swi_test_error_point_to_hardware_interrupt_thread()
133{
134        //[EINVAL] The ithdp argument points to a hardware interrupt thread.
135#warning TODO: write test case
136}
137       
138void swi_test_error_name_null()
139{
140        struct intr_event *test_intr_event = NULL;
141        enum arg argument = HANDLER_NOT_VISITED;
142        void *test_ih = NULL;
143        int retval = 0;
144
145        printf("== Set name to NULL.\n");
146
147        retval = swi_add(&test_intr_event, NULL, swi_test_handler, &argument,
148                SWI_TEST_THREAD_PRIO, 0, &test_ih);
149        assert(retval == EINVAL);
150       
151        usleep(SWI_SLEEP_TIME);
152       
153        assert(argument == HANDLER_NOT_VISITED);
154}
155
156void swi_test_error_handler_null()
157{
158        struct intr_event *test_intr_event = NULL;
159        enum arg argument = HANDLER_NOT_VISITED;
160        void *test_ih = NULL;
161        int retval = 0;
162
163        printf("== Set handler to NULL.\n");
164
165        retval = swi_add(&test_intr_event, "swi_test", NULL, &argument,
166                SWI_TEST_THREAD_PRIO, 0, &test_ih);
167        assert(retval == EINVAL);
168       
169        usleep(SWI_SLEEP_TIME);
170       
171        assert(argument == HANDLER_NOT_VISITED);
172}
173
174void swi_test_error_has_allready_exclusive()
175{
176        struct intr_event *test_intr_event = NULL;
177        enum arg argument = HANDLER_NOT_VISITED;
178        void *test_ih1 = NULL;
179        void *test_ih2 = NULL;
180        int retval = 0;
181
182        printf("== Create a thread with a exclusive handler and try to add another handler.\n");
183
184        retval = swi_add(&test_intr_event, "swi_test1", swi_test_handler, &argument,
185                SWI_TEST_THREAD_PRIO, INTR_EXCL, &test_ih1);
186        assert(retval == 0);
187
188        retval = swi_add(&test_intr_event, "swi_test2", swi_test_handler, &argument,
189                SWI_TEST_THREAD_PRIO, 0, &test_ih2);
190        assert(retval == EINVAL);
191       
192        usleep(SWI_SLEEP_TIME);
193       
194        assert(argument == HANDLER_NOT_VISITED);
195}
196
197void swi_test(void)
198{
199        swi_test_normal_handler();
200        swi_test_exclusive_handler();
201        swi_test_error_number_of_processes_exceeded();
202        swi_test_error_intr_entropy_set();
203        swi_test_error_point_to_hardware_interrupt_thread();
204        swi_test_error_name_null();
205        swi_test_error_handler_null();
206        swi_test_error_has_allready_exclusive();
207}
208
Note: See TracBrowser for help on using the repository browser.