source: mainline/uspace/app/tester/proc/task_wait.c@ 55fe220

Last change on this file since 55fe220 was 62273d1, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

taskman: Implement simple task exit monitoring

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Copyright (c) 2015 Michal Koutny
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <async.h>
30#include <errno.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <task.h>
34
35#include "../tester.h"
36#include "common.h"
37
38#define DUMMY_TASK "/root/app/tester"
39#define DUMMY_TASK_ARG "proc_dummy_task"
40
41#define S(x) #x
42#define S_(x) S(x)
43#define S__LINE__ S_(__LINE__)
44
45#define TASSERT(expr) \
46 do { \
47 if (!(expr)) \
48 return "Failed " #expr " " __FILE__ ":" S__LINE__ ; \
49 } while (0)
50
51static int dummy_task_spawn(task_id_t *task_id, task_wait_t *wait,
52 const char *behavior)
53{
54 return task_spawnl(task_id, wait,
55 DUMMY_TASK, DUMMY_TASK, DUMMY_TASK_ARG, behavior,
56 NULL);
57}
58
59const char *test_proc_task_wait(void)
60{
61 const char *err = NULL;
62
63 int rc;
64 task_id_t tid;
65 task_wait_t wait;
66 int retval;
67 task_exit_t texit;
68
69 TPRINTF("11 match\n");
70
71 task_wait_set(&wait, TASK_WAIT_EXIT);
72 rc = dummy_task_spawn(&tid, &wait, STR_FAIL);
73 TASSERT(rc == EOK);
74
75 TPRINTF("waiting...");
76 rc = task_wait(&wait, &texit, &retval);
77 TPRINTF("done.\n");
78 TASSERT(rc == EOK);
79 TASSERT(texit == TASK_EXIT_UNEXPECTED);
80 TPRINTF("OK\n");
81 /* ---- */
82
83 TPRINTF("12 lost wait\n");
84
85 task_wait_set(&wait, TASK_WAIT_RETVAL);
86 rc = dummy_task_spawn(&tid, &wait, STR_FAIL);
87 TASSERT(rc == EOK);
88
89 TPRINTF("waiting...");
90 rc = task_wait(&wait, &texit, &retval);
91 TPRINTF("done.\n");
92 TASSERT(rc == EINVAL);
93 TPRINTF("OK\n");
94 /* ---- */
95
96 TPRINTF("13 partial match\n");
97
98 task_wait_set(&wait, TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
99 rc = dummy_task_spawn(&tid, &wait, STR_BYPASS);
100 TASSERT(rc == EOK);
101
102 TPRINTF("waiting...");
103 rc = task_wait(&wait, &texit, &retval);
104 TPRINTF("done.\n");
105 TASSERT(rc == EOK);
106 TASSERT(texit == TASK_EXIT_UNEXPECTED);
107 /* retval is undefined */
108 TPRINTF("OK\n");
109 /* ---- */
110
111 TPRINTF("21 ignore retval\n");
112
113 task_wait_set(&wait, TASK_WAIT_EXIT);
114 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
115 TASSERT(rc == EOK);
116
117 TPRINTF("waiting...");
118 rc = task_wait(&wait, &texit, &retval);
119 TPRINTF("done.\n");
120 TASSERT(rc == EOK);
121 TASSERT(texit == TASK_EXIT_NORMAL);
122 /* retval is unknown */
123 TPRINTF("OK\n");
124 /* ---- */
125
126 TPRINTF("22 good match\n");
127
128 task_wait_set(&wait, TASK_WAIT_RETVAL);
129 rc = dummy_task_spawn(&tid, &wait, STR_DAEMON);
130 TASSERT(rc == EOK);
131
132 TPRINTF("waiting...");
133 rc = task_wait(&wait, &texit, &retval);
134 TPRINTF("done.\n");
135 TASSERT(rc == EOK);
136 /* exit is not expected */
137 TASSERT(retval == EOK);
138 task_kill(tid); /* Terminate daemon */
139 TPRINTF("OK\n");
140 /* ---- */
141
142 TPRINTF("23 partial match (non-exited task)\n");
143
144 // TODO should update wait for synchronized exit waiting
145 task_wait_set(&wait, TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
146 rc = dummy_task_spawn(&tid, &wait, STR_DAEMON);
147 TASSERT(rc == EOK);
148
149 TPRINTF("waiting...");
150 rc = task_wait(&wait, &texit, &retval);
151 TPRINTF("done.\n");
152 TASSERT(rc == EOK);
153 /* exit is not expected */
154 TASSERT(retval == EOK);
155 task_kill(tid); /* Terminate daemon */
156 TPRINTF("OK\n");
157 /* ---- */
158
159 TPRINTF("31 on exit return\n");
160
161 task_wait_set(&wait, TASK_WAIT_EXIT);
162 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
163 TASSERT(rc == EOK);
164
165 TPRINTF("waiting...");
166 rc = task_wait(&wait, &texit, &retval);
167 TPRINTF("done.\n");
168 TASSERT(rc == EOK);
169 TASSERT(texit == TASK_EXIT_NORMAL);
170 /* retval is unknown */
171 TPRINTF("OK\n");
172 /* ---- */
173
174
175 TPRINTF("32 keep retval until exit\n");
176
177 task_wait_set(&wait, TASK_WAIT_RETVAL);
178 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
179 TASSERT(rc == EOK);
180
181 TPRINTF("waiting...");
182 rc = task_wait(&wait, &texit, &retval);
183 TPRINTF("done.\n");
184 TASSERT(rc == EOK);
185 /* exit is unknown */
186 TASSERT(retval == EOK);
187 /* check task already exited */
188 rc = task_kill(tid);
189 TASSERT(rc == ENOENT);
190 TPRINTF("OK\n");
191 /* ---- */
192
193 TPRINTF("33 double good match\n");
194
195 task_wait_set(&wait, TASK_WAIT_RETVAL | TASK_WAIT_EXIT);
196 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
197 TASSERT(rc == EOK);
198
199 TPRINTF("waiting...");
200 rc = task_wait(&wait, &texit, &retval);
201 TPRINTF("done.\n");
202 TASSERT(rc == EOK);
203 TASSERT(texit == TASK_EXIT_NORMAL);
204 TASSERT(retval == EOK);
205 TPRINTF("OK\n");
206 /* ---- */
207
208 TPRINTF("All task waiting tests finished");
209
210
211
212 return err;
213}
Note: See TracBrowser for help on using the repository browser.