virtchar1.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00037 #include <inttypes.h>
00038 #include <errno.h>
00039 #include <str_error.h>
00040 #include <sys/types.h>
00041 #include <async.h>
00042 #include <device/char_dev.h>
00043 #include <str.h>
00044 #include <vfs/vfs.h>
00045 #include <sys/stat.h>
00046 #include <fcntl.h>
00047 #include "../../tester.h"
00048 
00049 #define DEVICE_PATH_NORMAL "/dev/devices/\\virt\\null\\a"
00050 #define DEVICE_PATH_CLASSES "/dev/class/virt-null\\1"
00051 #define BUFFER_SIZE 64
00052 
00053 static const char *test_virtchar1_internal(const char *path)
00054 {
00055         TPRINTF("Opening `%s'...\n", path);
00056         int fd = open(path, O_RDONLY);
00057         if (fd < 0) {
00058                 TPRINTF("   ...error: %s\n", str_error(fd));
00059                 if (fd == ENOENT) {
00060                         TPRINTF("   (error was ENOENT: " \
00061                             "have you compiled test drivers?)\n");
00062                 }
00063                 return "Failed opening devman driver device for reading";
00064         }
00065         
00066         TPRINTF("   ...file handle %d\n", fd);
00067 
00068         TPRINTF(" Asking for phone...\n");
00069         int phone = fd_phone(fd);
00070         if (phone < 0) {
00071                 close(fd);
00072                 TPRINTF("   ...error: %s\n", str_error(phone));
00073                 return "Failed to get phone to device";
00074         }
00075         TPRINTF("   ...phone is %d\n", phone);
00076         
00077         TPRINTF(" Will try to read...\n");
00078         size_t i;
00079         char buffer[BUFFER_SIZE];
00080         char_dev_read(phone, buffer, BUFFER_SIZE);
00081         TPRINTF(" ...verifying that we read zeroes only...\n");
00082         for (i = 0; i < BUFFER_SIZE; i++) {
00083                 if (buffer[i] != 0) {
00084                         return "Not all bytes are zeroes";
00085                 }
00086         }
00087         TPRINTF("   ...data read okay\n");
00088         
00089         /* Clean-up. */
00090         TPRINTF(" Closing phones and file descriptors\n");
00091         async_hangup(phone);
00092         close(fd);
00093         
00094         return NULL;
00095 }
00096 
00097 const char *test_virtchar1(void)
00098 {;
00099         const char *res;
00100 
00101         res = test_virtchar1_internal(DEVICE_PATH_NORMAL);
00102         if (res != NULL) {
00103                 return res;
00104         }
00105 
00106         res = test_virtchar1_internal(DEVICE_PATH_CLASSES);
00107         if (res != NULL) {
00108                 return res;
00109         }
00110 
00111         return NULL;
00112 }
00113 

Generated on Thu Jun 2 07:45:43 2011 for HelenOS/USB by  doxygen 1.4.7