source: mainline/uspace/app/tester/proc/dummy_task.c@ 25697163

Last change on this file since 25697163 was 102f641, checked in by Matthieu Riolo <matthieu.riolo@…>, 7 years ago

Correcting syntax according to ccheck

  • Property mode set to 100644
File size: 2.8 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 <libc.h>
30#include <async.h>
31#include <errno.h>
32#include <stdlib.h>
33#include <str.h>
34#include <task.h>
35
36#include "../tester.h"
37#include "common.h"
38
39typedef void (*behavior_func_t)(void);
40
41typedef struct {
42 const char *name;
43 task_behavior_t behavior;
44 behavior_func_t func;
45} behavior_item_t;
46
47static const char *err = NULL;
48
49static void dummy_fail(void)
50{
51 task_id_t id = task_get_id();
52 printf("Gonna shoot myself (%" PRIu64 ").\n", id);
53 behavior_func_t func = NULL;
54 func();
55}
56
57static void dummy_bypass(void)
58{
59 __SYSCALL1(SYS_TASK_EXIT, false);
60}
61
62static void dummy_daemon(void)
63{
64 task_retval(EOK);
65 async_manager();
66}
67
68static void dummy_job_fail(void)
69{
70 err = "Intended error";
71}
72
73static void dummy_job_ok(void)
74{
75 err = NULL;
76}
77
78static behavior_item_t behaviors[] = {
79 { STR_FAIL, BEHAVIOR_FAIL, &dummy_fail },
80 { STR_BYPASS, BEHAVIOR_BYPASS, &dummy_bypass },
81 { STR_DAEMON, BEHAVIOR_DAEMON, &dummy_daemon },
82 { STR_JOB_FAIL, BEHAVIOR_JOB_FAIL, &dummy_job_fail },
83 { STR_JOB_OK, BEHAVIOR_JOB_OK, &dummy_job_ok },
84 { NULL, BEHAVIOR_JOB_OK, NULL }
85};
86
87const char *test_proc_dummy_task(void)
88{
89 const char *name = (test_argc == 0) ? STR_JOB_OK : test_argv[0];
90
91 for (behavior_item_t *it = behaviors; it->name != NULL; ++it) {
92 if (str_cmp(name, it->name) != 0) {
93 continue;
94 }
95 it->func();
96 }
97
98 return err;
99}
Note: See TracBrowser for help on using the repository browser.