Changeset ffdd2b9 in mainline
- Timestamp:
- 2010-11-26T13:31:59Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3e94678, 46c20c8, bbe7848
- Parents:
- df6b760
- Location:
- uspace
- Files:
-
- 1 added
- 1 deleted
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
rdf6b760 rffdd2b9 46 46 app/tasks \ 47 47 app/tester \ 48 app/test_serial \49 48 app/tetris \ 50 49 app/trace \ -
uspace/app/tester/Makefile
rdf6b760 rffdd2b9 50 50 ipc/connect.c \ 51 51 loop/loop1.c \ 52 mm/malloc1.c 52 mm/malloc1.c \ 53 hw/serial/serial1.c 53 54 54 55 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tester/hw/serial/serial1.c
rdf6b760 rffdd2b9 27 27 */ 28 28 29 /** @addtogroup test _serial30 * @brief test the serial port driver - read from the serial port29 /** @addtogroup tester 30 * @brief Test the serial port driver - loopback test 31 31 * @{ 32 32 */ … … 48 48 #include <str.h> 49 49 #include <ipc/serial_ctl.h> 50 51 #define NAME "test serial" 52 53 54 static void print_usage(void) 50 #include "../../tester.h" 51 52 #define DEFAULT_COUNT 1024 53 #define DEFAULT_SLEEP 100000 54 #define EOT "####> End of transfer <####\n" 55 56 const char *test_serial1(void) 55 57 { 56 printf("Usage: \n test_serial count \n where count is the number of " 57 "characters to be read\n"); 58 } 59 60 int main(int argc, char *argv[]) 61 { 62 if (argc != 2) { 63 printf(NAME ": incorrect number of arguments.\n"); 64 print_usage(); 65 return 0; 66 } 67 68 long int cnt = strtol(argv[1], NULL, 10); 69 70 int res; 71 res = devman_get_phone(DEVMAN_CLIENT, IPC_FLAG_BLOCKING); 58 size_t cnt; 59 60 if (test_argc < 1) 61 cnt = DEFAULT_COUNT; 62 else 63 switch (str_size_t(test_argv[0], NULL, 0, true, &cnt)) { 64 case EOK: 65 break; 66 case EINVAL: 67 return "Invalid argument, unsigned integer expected"; 68 case EOVERFLOW: 69 return "Argument size overflow"; 70 default: 71 return "Unexpected argument error"; 72 } 73 74 int res = devman_get_phone(DEVMAN_CLIENT, IPC_FLAG_BLOCKING); 75 72 76 devman_handle_t handle; 73 74 77 res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle, 75 78 IPC_FLAG_BLOCKING); 76 if (EOK != res) { 77 printf(NAME ": could not get the device handle, errno = %d.\n", 78 -res); 79 return 1; 80 } 81 82 printf(NAME ": trying to read %ld characters from device with handle " 83 "%" PRIun ".\n", cnt, handle); 79 if (res != EOK) 80 return "Could not get serial device handle"; 84 81 85 82 int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING); 86 if (0 > phone) { 87 printf(NAME ": could not connect to the device, errno = %d.\n", 88 -res); 89 devman_hangup_phone(DEVMAN_CLIENT); 90 return 2; 83 if (phone < 0) { 84 devman_hangup_phone(DEVMAN_CLIENT); 85 return "Unable to connect to serial device"; 91 86 } 92 87 93 88 char *buf = (char *) malloc(cnt + 1); 94 if (NULL == buf) { 95 printf(NAME ": failed to allocate the input buffer\n"); 89 if (buf == NULL) { 96 90 ipc_hangup(phone); 97 91 devman_hangup_phone(DEVMAN_CLIENT); 98 return 3; 99 } 100 101 ipcarg_t old_baud, old_par, old_stop, old_word_size; 92 return "Failed to allocate input buffer"; 93 } 94 95 ipcarg_t old_baud; 96 ipcarg_t old_par; 97 ipcarg_t old_stop; 98 ipcarg_t old_word_size; 102 99 103 100 res = ipc_call_sync_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud, 104 101 &old_par, &old_word_size, &old_stop); 105 if (EOK != res) { 106 printf(NAME ": failed to get old communication parameters, " 107 "errno = %d.\n", -res); 108 devman_hangup_phone(DEVMAN_CLIENT); 102 if (res != EOK) { 103 free(buf); 109 104 ipc_hangup(phone); 110 free(buf);111 return 4;105 devman_hangup_phone(DEVMAN_CLIENT); 106 return "Failed to get old serial communication parameters"; 112 107 } 113 108 … … 115 110 SERIAL_NO_PARITY, 8, 1); 116 111 if (EOK != res) { 117 printf(NAME ": failed to set communication parameters, errno = " 118 "%d.\n", -res); 119 devman_hangup_phone(DEVMAN_CLIENT); 112 free(buf); 120 113 ipc_hangup(phone); 121 free(buf); 122 return 4; 123 } 124 125 int total = 0; 126 int read = 0; 114 devman_hangup_phone(DEVMAN_CLIENT); 115 return "Failed to set serial communication parameters"; 116 } 117 118 TPRINTF("Trying to read %zu characters from serial device " 119 "(handle=%" PRIun ")\n", cnt, handle); 120 121 size_t total = 0; 127 122 while (total < cnt) { 128 read = read_dev(phone, buf, cnt - total); 129 if (0 > read) { 130 printf(NAME ": failed read from device, errno = %d.\n", 131 -read); 123 ssize_t read = read_dev(phone, buf, cnt - total); 124 125 if (read < 0) { 132 126 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 133 127 old_par, old_word_size, old_stop); 128 free(buf); 134 129 ipc_hangup(phone); 135 130 devman_hangup_phone(DEVMAN_CLIENT); 131 return "Failed read from serial device"; 132 } 133 134 if ((size_t) read > cnt - total) { 135 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 136 old_par, old_word_size, old_stop); 136 137 free(buf); 137 return 5; 138 } 139 total += read; 140 if (read > 0) { 138 ipc_hangup(phone); 139 devman_hangup_phone(DEVMAN_CLIENT); 140 return "Read more data than expected"; 141 } 142 143 TPRINTF("Read %zd bytes\n", read); 144 145 if (read == 0) 146 usleep(DEFAULT_SLEEP); 147 else { 141 148 buf[read] = 0; 142 printf(buf);149 143 150 /* 144 151 * Write data back to the device to test the opposite 145 152 * direction of data transfer. 146 153 */ 147 write_dev(phone, buf, read); 148 } else { 149 usleep(100000); 150 } 151 } 152 153 const char *the_end = "\n---------\nTHE END\n---------\n"; 154 write_dev(phone, (void *)the_end, str_size(the_end)); 155 156 /* restore original communication settings */ 157 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, 158 old_word_size, old_stop); 154 ssize_t written = write_dev(phone, buf, read); 155 156 if (written < 0) { 157 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 158 old_par, old_word_size, old_stop); 159 free(buf); 160 ipc_hangup(phone); 161 devman_hangup_phone(DEVMAN_CLIENT); 162 return "Failed write to serial device"; 163 } 164 165 if (written != read) { 166 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 167 old_par, old_word_size, old_stop); 168 free(buf); 169 ipc_hangup(phone); 170 devman_hangup_phone(DEVMAN_CLIENT); 171 return "Written less data than read from serial device"; 172 } 173 174 TPRINTF("Written %zd bytes\n", written); 175 } 176 177 total += read; 178 } 179 180 TPRINTF("Trying to write EOT banner to the serial device\n"); 181 182 size_t eot_size = str_size(EOT); 183 ssize_t written = write_dev(phone, (void *) EOT, eot_size); 184 185 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 186 old_par, old_word_size, old_stop); 187 free(buf); 188 ipc_hangup(phone); 159 189 devman_hangup_phone(DEVMAN_CLIENT); 160 ipc_hangup(phone); 161 free(buf); 162 163 return 0; 190 191 if (written < 0) 192 return "Failed to write EOT banner to serial device"; 193 194 if ((size_t) written != eot_size) 195 return "Written less data than the size of the EOT banner " 196 "to serial device"; 197 198 return NULL; 164 199 } 165 200 -
uspace/app/tester/tester.c
rdf6b760 rffdd2b9 64 64 #include "loop/loop1.def" 65 65 #include "mm/malloc1.def" 66 #include "hw/serial/serial1.def" 66 67 {NULL, NULL, NULL, false} 67 68 }; -
uspace/app/tester/tester.h
rdf6b760 rffdd2b9 81 81 extern const char *test_loop1(void); 82 82 extern const char *test_malloc1(void); 83 extern const char *test_serial1(void); 83 84 84 85 extern test_t tests[];
Note:
See TracChangeset
for help on using the changeset viewer.