source: mainline/uspace/drv/test1/test1.c@ 1b2981aa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1b2981aa was 1b2981aa, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Add test1 virtual device

The test1 expose bug (deadlock) in devman.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
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/** @file
30 */
31
32#include <assert.h>
33#include <stdio.h>
34#include <errno.h>
35#include <str_error.h>
36#include <driver.h>
37
38#define NAME "test1"
39
40static int add_device(device_t *dev);
41
42static driver_ops_t driver_ops = {
43 .add_device = &add_device
44};
45
46static driver_t the_driver = {
47 .name = NAME,
48 .driver_ops = &driver_ops
49};
50
51/** Callback when new device is passed to this driver.
52 * This function is the body of the test: it shall register new child
53 * (named `clone') that shall be driven by the same task. When the clone
54 * is added, it registers another child (named `child') that is also driven
55 * by this task. The conditions ensure that we do not recurse indefinitely.
56 * When successful, the device tree shall contain following fragment:
57 *
58 * /virtual/test1
59 * /virtual/test1/clone
60 * /virtual/test1/clone/child
61 *
62 * and devman shall not deadlock.
63 *
64 *
65 * @param dev New device.
66 * @return Error code reporting success of the operation.
67 */
68static int add_device(device_t *dev)
69{
70 int rc;
71 printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
72 dev->name, (int) dev->handle);
73
74 if (dev->parent == NULL) {
75 printf(NAME ": cloning myself ;-).\n");
76 rc = child_device_register_wrapper(dev, "clone",
77 "virtual&test1", 10);
78 if (rc != EOK) {
79 printf(NAME ": failed to register clone (%s).\n",
80 str_error(rc));
81 }
82 } else if (str_cmp(dev->name, "clone") == 0) {
83 printf(NAME ": registering child device run by the same task.\n");
84 rc = child_device_register_wrapper(dev, "child",
85 "virtual&test1&child", 10);
86 if (rc != EOK) {
87 printf(NAME ": failed to register child (%s).\n",
88 str_error(rc));
89 }
90 }
91
92 printf(NAME ": device `%s' accepted.\n", dev->name);
93
94 return EOK;
95}
96
97int main(int argc, char *argv[])
98{
99 printf(NAME ": HelenOS test1 virtual device driver\n");
100 return driver_main(&the_driver);
101}
102
103
Note: See TracBrowser for help on using the repository browser.