Changeset 7bdcc45 in mainline for uspace/app/tester
- Timestamp:
- 2010-12-16T16:38:49Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7837101
- Parents:
- 8e58f94 (diff), eb221e5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app/tester
- Files:
-
- 3 added
- 11 edited
- 1 moved
-
Makefile (modified) (2 diffs)
-
hw/serial/serial1.c (moved) (moved from uspace/app/test_serial/test_serial.c ) (4 diffs)
-
hw/serial/serial1.def (added)
-
ipc/ping_pong.c (modified) (1 diff)
-
ipc/register.c (modified) (4 diffs)
-
print/print1.c (modified) (1 diff)
-
print/print2.c (modified) (1 diff)
-
print/print4.c (modified) (2 diffs)
-
print/print5.c (added)
-
print/print5.def (added)
-
stdio/stdio1.c (modified) (1 diff)
-
tester.c (modified) (3 diffs)
-
tester.h (modified) (2 diffs)
-
thread/thread1.c (modified) (2 diffs)
-
vfs/vfs1.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/Makefile
r8e58f94 r7bdcc45 38 38 print/print3.c \ 39 39 print/print4.c \ 40 print/print5.c \ 40 41 console/console1.c \ 41 42 stdio/stdio1.c \ … … 49 50 ipc/connect.c \ 50 51 loop/loop1.c \ 51 mm/malloc1.c 52 mm/malloc1.c \ 53 hw/serial/serial1.c 52 54 53 55 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tester/hw/serial/serial1.c
r8e58f94 r7bdcc45 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 */ … … 35 35 */ 36 36 37 #include <inttypes.h> 37 38 #include <errno.h> 38 39 #include <stdlib.h> … … 47 48 #include <str.h> 48 49 #include <ipc/serial_ctl.h> 49 50 #define NAME "test serial" 51 52 53 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) 54 57 { 55 printf("Usage: \n test_serial count \n where count is the number of " 56 "characters to be read\n"); 57 } 58 59 int main(int argc, char *argv[]) 60 { 61 if (argc != 2) { 62 printf(NAME ": incorrect number of arguments.\n"); 63 print_usage(); 64 return 0; 65 } 66 67 long int cnt = strtol(argv[1], NULL, 10); 68 69 int res; 70 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 71 76 devman_handle_t handle; 72 73 77 res = devman_device_get_handle("/hw/pci0/00:01.0/com1", &handle, 74 78 IPC_FLAG_BLOCKING); 75 if (EOK != res) { 76 printf(NAME ": could not get the device handle, errno = %d.\n", 77 -res); 78 return 1; 79 } 80 81 printf(NAME ": trying to read %d characters from device with handle " 82 "%d.\n", cnt, handle); 79 if (res != EOK) 80 return "Could not get serial device handle"; 83 81 84 82 int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING); 85 if (0 > phone) { 86 printf(NAME ": could not connect to the device, errno = %d.\n", 87 -res); 88 devman_hangup_phone(DEVMAN_CLIENT); 89 return 2; 83 if (phone < 0) { 84 devman_hangup_phone(DEVMAN_CLIENT); 85 return "Unable to connect to serial device"; 90 86 } 91 87 92 88 char *buf = (char *) malloc(cnt + 1); 93 if (NULL == buf) { 94 printf(NAME ": failed to allocate the input buffer\n"); 89 if (buf == NULL) { 95 90 ipc_hangup(phone); 96 91 devman_hangup_phone(DEVMAN_CLIENT); 97 return 3; 98 } 99 100 ipcarg_t old_baud, old_par, old_stop, old_word_size; 92 return "Failed to allocate input buffer"; 93 } 94 95 sysarg_t old_baud; 96 sysarg_t old_par; 97 sysarg_t old_stop; 98 sysarg_t old_word_size; 101 99 102 100 res = ipc_call_sync_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud, 103 101 &old_par, &old_word_size, &old_stop); 104 if (EOK != res) { 105 printf(NAME ": failed to get old communication parameters, " 106 "errno = %d.\n", -res); 107 devman_hangup_phone(DEVMAN_CLIENT); 102 if (res != EOK) { 103 free(buf); 108 104 ipc_hangup(phone); 109 free(buf);110 return 4;105 devman_hangup_phone(DEVMAN_CLIENT); 106 return "Failed to get old serial communication parameters"; 111 107 } 112 108 … … 114 110 SERIAL_NO_PARITY, 8, 1); 115 111 if (EOK != res) { 116 printf(NAME ": failed to set communication parameters, errno = " 117 "%d.\n", -res); 118 devman_hangup_phone(DEVMAN_CLIENT); 112 free(buf); 119 113 ipc_hangup(phone); 120 free(buf); 121 return 4; 122 } 123 124 int total = 0; 125 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; 126 122 while (total < cnt) { 127 read = read_dev(phone, buf, cnt - total); 128 if (0 > read) { 129 printf(NAME ": failed read from device, errno = %d.\n", 130 -read); 123 ssize_t read = read_dev(phone, buf, cnt - total); 124 125 if (read < 0) { 131 126 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 132 127 old_par, old_word_size, old_stop); 128 free(buf); 133 129 ipc_hangup(phone); 134 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); 135 137 free(buf); 136 return 5; 137 } 138 total += read; 139 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 { 140 148 buf[read] = 0; 141 printf(buf);149 142 150 /* 143 151 * Write data back to the device to test the opposite 144 152 * direction of data transfer. 145 153 */ 146 write_dev(phone, buf, read); 147 } else { 148 usleep(100000); 149 } 150 } 151 152 const char *the_end = "\n---------\nTHE END\n---------\n"; 153 write_dev(phone, (void *)the_end, str_size(the_end)); 154 155 /* restore original communication settings */ 156 ipc_call_sync_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, old_par, 157 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); 158 189 devman_hangup_phone(DEVMAN_CLIENT); 159 ipc_hangup(phone); 160 free(buf); 161 162 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; 163 199 } 164 200 -
uspace/app/tester/ipc/ping_pong.c
r8e58f94 r7bdcc45 72 72 } 73 73 74 TPRINTF("OK\nCompleted % llu round trips in %u seconds, %llurt/s.\n",74 TPRINTF("OK\nCompleted %" PRIu64 " round trips in %u seconds, %" PRIu64 " rt/s.\n", 75 75 count, DURATION_SECS, count / DURATION_SECS); 76 76 -
uspace/app/tester/ipc/register.c
r8e58f94 r7bdcc45 27 27 */ 28 28 29 #include <inttypes.h> 29 30 #include <stdio.h> 30 31 #include <unistd.h> … … 41 42 unsigned int i; 42 43 43 TPRINTF("Connected phone % #xaccepting\n", icall->in_phone_hash);44 TPRINTF("Connected phone %" PRIun " accepting\n", icall->in_phone_hash); 44 45 ipc_answer_0(iid, EOK); 45 46 for (i = 0; i < MAX_CONNECTIONS; i++) { … … 55 56 int retval; 56 57 57 switch (IPC_GET_ METHOD(call)) {58 switch (IPC_GET_IMETHOD(call)) { 58 59 case IPC_M_PHONE_HUNGUP: 59 TPRINTF("Phone % #xhung up\n", icall->in_phone_hash);60 TPRINTF("Phone %" PRIun " hung up\n", icall->in_phone_hash); 60 61 retval = 0; 61 62 break; 62 63 case IPC_TEST_METHOD: 63 TPRINTF("Received well known message from % #x: %#x\n",64 TPRINTF("Received well known message from %" PRIun ": %" PRIun "\n", 64 65 icall->in_phone_hash, callid); 65 66 ipc_answer_0(callid, EOK); 66 67 break; 67 68 default: 68 TPRINTF("Received unknown message from % #x: %#x\n",69 TPRINTF("Received unknown message from %" PRIun ": %" PRIun "\n", 69 70 icall->in_phone_hash, callid); 70 71 ipc_answer_0(callid, ENOENT); … … 78 79 async_set_client_connection(client_connection); 79 80 80 ipcarg_t phonead;81 sysarg_t phonead; 81 82 int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead); 82 83 if (res != 0) -
uspace/app/tester/print/print1.c
r8e58f94 r7bdcc45 49 49 TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); 50 50 51 TPRINTF("Testing printf(\"%%s\", NULL):\n");52 TPRINTF("Expected output: \"(NULL)\"\n");53 TPRINTF("Real output: \"%s\"\n\n", NULL);54 55 51 return NULL; 56 52 } -
uspace/app/tester/print/print2.c
r8e58f94 r7bdcc45 33 33 const char *test_print2(void) 34 34 { 35 TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");36 TPRINTF("Expected output: [a] [ b] [c ] [ d] [e ]\n");37 TPRINTF("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');35 TPRINTF("Testing printf(\"%%c\", 'a'):\n"); 36 TPRINTF("Expected output: [a]\n"); 37 TPRINTF("Real output: [%c]\n\n", 'a'); 38 38 39 39 TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n"); -
uspace/app/tester/print/print4.c
r8e58f94 r7bdcc45 45 45 TPRINTF(" "); 46 46 for (index = 0; index < 32; index++) 47 TPRINTF("%lc", (w char_t) ((group << 5) + index));47 TPRINTF("%lc", (wint_t) ((group << 5) + index)); 48 48 49 49 TPRINTF("\n"); … … 57 57 uint8_t index; 58 58 for (index = 0; index < 32; index++) 59 TPRINTF("%lc", (w char_t) ((group << 5) + index));59 TPRINTF("%lc", (wint_t) ((group << 5) + index)); 60 60 61 61 TPRINTF("\n"); -
uspace/app/tester/stdio/stdio1.c
r8e58f94 r7bdcc45 60 60 61 61 buf[cnt] = '\0'; 62 TPRINTF("Read % u bytes, string \"%s\"\n", cnt, buf);62 TPRINTF("Read %zu bytes, string \"%s\"\n", cnt, buf); 63 63 64 64 TPRINTF("Seek to beginning..."); -
uspace/app/tester/tester.c
r8e58f94 r7bdcc45 51 51 #include "print/print3.def" 52 52 #include "print/print4.def" 53 #include "print/print5.def" 53 54 #include "console/console1.def" 54 55 #include "stdio/stdio1.def" … … 63 64 #include "loop/loop1.def" 64 65 #include "mm/malloc1.def" 66 #include "hw/serial/serial1.def" 65 67 {NULL, NULL, NULL, false} 66 68 }; … … 110 112 } 111 113 114 unsigned int _len = (unsigned int) len; 115 if ((_len != len) || (((int) _len) < 0)) { 116 printf("Command length overflow\n"); 117 return; 118 } 119 112 120 for (test = tests; test->name != NULL; test++) 113 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); 121 printf("%-*s %s%s\n", _len, test->name, test->desc, 122 (test->safe ? "" : " (unsafe)")); 114 123 115 printf("%-*s Run all safe tests\n", len, "*");124 printf("%-*s Run all safe tests\n", _len, "*"); 116 125 } 117 126 -
uspace/app/tester/tester.h
r8e58f94 r7bdcc45 68 68 extern const char *test_print3(void); 69 69 extern const char *test_print4(void); 70 extern const char *test_print5(void); 70 71 extern const char *test_console1(void); 71 72 extern const char *test_stdio1(void); … … 80 81 extern const char *test_loop1(void); 81 82 extern const char *test_malloc1(void); 83 extern const char *test_serial1(void); 82 84 83 85 extern test_t tests[]; -
uspace/app/tester/thread/thread1.c
r8e58f94 r7bdcc45 35 35 #include <stdio.h> 36 36 #include <unistd.h> 37 #include <inttypes.h> 37 38 #include "../tester.h" 38 39 … … 74 75 atomic_set(&finish, 0); 75 76 while (atomic_get(&threads_finished) < total) { 76 TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished)); 77 TPRINTF("Threads left: %" PRIua "\n", 78 total - atomic_get(&threads_finished)); 77 79 sleep(1); 78 80 } -
uspace/app/tester/vfs/vfs1.c
r8e58f94 r7bdcc45 105 105 if (cnt < 0) 106 106 return "write() failed"; 107 TPRINTF("Written % d bytes\n", cnt);107 TPRINTF("Written %zd bytes\n", cnt); 108 108 109 109 if (lseek(fd0, 0, SEEK_SET) != 0) … … 116 116 return "read() failed"; 117 117 118 TPRINTF("Read %d bytes: \".*s\"\n", cnt, cnt, buf); 118 int _cnt = (int) cnt; 119 if (_cnt != cnt) { 120 /* Count overflow, just to be sure. */ 121 TPRINTF("Read %zd bytes\n", cnt); 122 } else { 123 TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt, _cnt, buf); 124 } 119 125 } 120 126
Note:
See TracChangeset
for help on using the changeset viewer.
