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
RevLine 
[70d28e8]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
[62273d1]69 TPRINTF("11 match\n");
[70d28e8]70
71 task_wait_set(&wait, TASK_WAIT_EXIT);
72 rc = dummy_task_spawn(&tid, &wait, STR_FAIL);
73 TASSERT(rc == EOK);
74
[62273d1]75 TPRINTF("waiting...");
[70d28e8]76 rc = task_wait(&wait, &texit, &retval);
[62273d1]77 TPRINTF("done.\n");
[70d28e8]78 TASSERT(rc == EOK);
79 TASSERT(texit == TASK_EXIT_UNEXPECTED);
[62273d1]80 TPRINTF("OK\n");
[70d28e8]81 /* ---- */
82
[62273d1]83 TPRINTF("12 lost wait\n");
[70d28e8]84
85 task_wait_set(&wait, TASK_WAIT_RETVAL);
86 rc = dummy_task_spawn(&tid, &wait, STR_FAIL);
87 TASSERT(rc == EOK);
88
[62273d1]89 TPRINTF("waiting...");
[70d28e8]90 rc = task_wait(&wait, &texit, &retval);
[62273d1]91 TPRINTF("done.\n");
[70d28e8]92 TASSERT(rc == EINVAL);
[62273d1]93 TPRINTF("OK\n");
[70d28e8]94 /* ---- */
95
[62273d1]96 TPRINTF("13 partial match\n");
[70d28e8]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
[62273d1]102 TPRINTF("waiting...");
[70d28e8]103 rc = task_wait(&wait, &texit, &retval);
[62273d1]104 TPRINTF("done.\n");
[70d28e8]105 TASSERT(rc == EOK);
106 TASSERT(texit == TASK_EXIT_UNEXPECTED);
107 /* retval is undefined */
[62273d1]108 TPRINTF("OK\n");
[70d28e8]109 /* ---- */
110
[62273d1]111 TPRINTF("21 ignore retval\n");
[70d28e8]112
113 task_wait_set(&wait, TASK_WAIT_EXIT);
114 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
115 TASSERT(rc == EOK);
116
[62273d1]117 TPRINTF("waiting...");
[70d28e8]118 rc = task_wait(&wait, &texit, &retval);
[62273d1]119 TPRINTF("done.\n");
[70d28e8]120 TASSERT(rc == EOK);
121 TASSERT(texit == TASK_EXIT_NORMAL);
122 /* retval is unknown */
[62273d1]123 TPRINTF("OK\n");
[70d28e8]124 /* ---- */
125
[62273d1]126 TPRINTF("22 good match\n");
[70d28e8]127
128 task_wait_set(&wait, TASK_WAIT_RETVAL);
129 rc = dummy_task_spawn(&tid, &wait, STR_DAEMON);
130 TASSERT(rc == EOK);
131
[62273d1]132 TPRINTF("waiting...");
[70d28e8]133 rc = task_wait(&wait, &texit, &retval);
[62273d1]134 TPRINTF("done.\n");
[70d28e8]135 TASSERT(rc == EOK);
136 /* exit is not expected */
137 TASSERT(retval == EOK);
138 task_kill(tid); /* Terminate daemon */
[62273d1]139 TPRINTF("OK\n");
[70d28e8]140 /* ---- */
141
[62273d1]142 TPRINTF("23 partial match (non-exited task)\n");
[70d28e8]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
[62273d1]149 TPRINTF("waiting...");
[70d28e8]150 rc = task_wait(&wait, &texit, &retval);
[62273d1]151 TPRINTF("done.\n");
[70d28e8]152 TASSERT(rc == EOK);
153 /* exit is not expected */
154 TASSERT(retval == EOK);
155 task_kill(tid); /* Terminate daemon */
[62273d1]156 TPRINTF("OK\n");
[70d28e8]157 /* ---- */
158
[62273d1]159 TPRINTF("31 on exit return\n");
[70d28e8]160
161 task_wait_set(&wait, TASK_WAIT_EXIT);
162 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
163 TASSERT(rc == EOK);
164
[62273d1]165 TPRINTF("waiting...");
[70d28e8]166 rc = task_wait(&wait, &texit, &retval);
[62273d1]167 TPRINTF("done.\n");
[70d28e8]168 TASSERT(rc == EOK);
169 TASSERT(texit == TASK_EXIT_NORMAL);
170 /* retval is unknown */
[62273d1]171 TPRINTF("OK\n");
[70d28e8]172 /* ---- */
173
174
[62273d1]175 TPRINTF("32 keep retval until exit\n");
[70d28e8]176
177 task_wait_set(&wait, TASK_WAIT_RETVAL);
178 rc = dummy_task_spawn(&tid, &wait, STR_JOB_OK);
179 TASSERT(rc == EOK);
180
[62273d1]181 TPRINTF("waiting...");
[70d28e8]182 rc = task_wait(&wait, &texit, &retval);
[62273d1]183 TPRINTF("done.\n");
[70d28e8]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);
[62273d1]190 TPRINTF("OK\n");
[70d28e8]191 /* ---- */
192
[62273d1]193 TPRINTF("33 double good match\n");
[70d28e8]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
[62273d1]199 TPRINTF("waiting...");
[70d28e8]200 rc = task_wait(&wait, &texit, &retval);
[62273d1]201 TPRINTF("done.\n");
[70d28e8]202 TASSERT(rc == EOK);
203 TASSERT(texit == TASK_EXIT_NORMAL);
204 TASSERT(retval == EOK);
[62273d1]205 TPRINTF("OK\n");
[70d28e8]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.