00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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