| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 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 | /** @addtogroup tester
|
|---|
| 30 | * @brief Test devman service.
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /**
|
|---|
| 34 | * @file
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <inttypes.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <str_error.h>
|
|---|
| 40 | #include <sys/types.h>
|
|---|
| 41 | #include <async.h>
|
|---|
| 42 | #include <devman.h>
|
|---|
| 43 | #include <str.h>
|
|---|
| 44 | #include <async.h>
|
|---|
| 45 | #include <vfs/vfs.h>
|
|---|
| 46 | #include <vfs/vfs_sess.h>
|
|---|
| 47 | #include <sys/stat.h>
|
|---|
| 48 | #include <fcntl.h>
|
|---|
| 49 | #include "../tester.h"
|
|---|
| 50 |
|
|---|
| 51 | #define DEVICE_CLASS "test3"
|
|---|
| 52 |
|
|---|
| 53 | const char *test_devman2(void)
|
|---|
| 54 | {
|
|---|
| 55 | size_t idx = 1;
|
|---|
| 56 | int rc = EOK;
|
|---|
| 57 | const char *err_msg = NULL;
|
|---|
| 58 | char *path = NULL;
|
|---|
| 59 | while (rc == EOK) {
|
|---|
| 60 | rc = asprintf(&path, "/dev/class/%s\\%zu", DEVICE_CLASS, idx);
|
|---|
| 61 | if (rc < 0) {
|
|---|
| 62 | continue;
|
|---|
| 63 | }
|
|---|
| 64 | int fd = open(path, O_RDONLY);
|
|---|
| 65 | if (fd < 0) {
|
|---|
| 66 | TPRINTF("Failed opening `%s': %s.\n",
|
|---|
| 67 | path, str_error(fd));
|
|---|
| 68 | rc = fd;
|
|---|
| 69 | err_msg = "Failed opening file";
|
|---|
| 70 | continue;
|
|---|
| 71 | }
|
|---|
| 72 | async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
|
|---|
| 73 | close(fd);
|
|---|
| 74 | if (sess == NULL) {
|
|---|
| 75 | TPRINTF("Failed opening phone: %s.\n", str_error(errno));
|
|---|
| 76 | rc = errno;
|
|---|
| 77 | err_msg = "Failed opening file descriptor phone";
|
|---|
| 78 | continue;
|
|---|
| 79 | }
|
|---|
| 80 | async_hangup(sess);
|
|---|
| 81 | TPRINTF("Path `%s' okay.\n", path);
|
|---|
| 82 | free(path);
|
|---|
| 83 | idx++;
|
|---|
| 84 | rc = EOK;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | if (path != NULL)
|
|---|
| 88 | free(path);
|
|---|
| 89 |
|
|---|
| 90 | return err_msg;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | /** @}
|
|---|
| 94 | */
|
|---|