Index: uspace/app/test_serial/test_serial.c
===================================================================
--- uspace/app/test_serial/test_serial.c	(revision f6584584155369fb64be36eb3432e8a2081ac094)
+++ uspace/app/test_serial/test_serial.c	(revision ba95e8f41817124410b7cfa7c805434f83686dff)
@@ -28,5 +28,5 @@
 
 /** @addtogroup test_serial
- * @brief	test the serial port driver 
+ * @brief	test the serial port driver - read from the serial port
  * @{
  */ 
@@ -35,144 +35,22 @@
  */
 
+#include <errno.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <ipc/ipc.h>
 #include <sys/types.h>
-#include <atomic.h>
-#include <ipc/devmap.h>
 #include <async.h>
 #include <ipc/services.h>
-#include <ipc/serial.h>
-#include <as.h>
-#include <sysinfo.h>
-#include <errno.h>
-
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-
-#include <string.h>
-
-#define NAME 		"test serial"
-
-/*
-static int device_get_handle(const char *name, dev_handle_t *handle);
-static void print_usage();
-static void move_shutters(const char * serial_dev_name, char room, char cmd);
-static char getcmd(bool wnd, bool up);
-static bool is_com_dev(const char *dev_name);
-
-static int device_get_handle(const char *name, dev_handle_t *handle)
-{
-	int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
-	if (phone < 0)
-		return phone;
-	
-	ipc_call_t answer;
-	aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, &answer);
-	
-	ipcarg_t retval = ipc_data_write_start(phone, name, str_length(name) + 1); 
-
-	if (retval != EOK) {
-		async_wait_for(req, NULL);
-		ipc_hangup(phone);
-		return retval;
-	}
-
-	async_wait_for(req, &retval);
-
-	if (handle != NULL)
-		*handle = -1;
-	
-	if (retval == EOK) {
-		if (handle != NULL)
-			*handle = (dev_handle_t) IPC_GET_ARG1(answer);
-	}
-	
-	ipc_hangup(phone);
-	return retval;
-}
-
-static void print_usage()
-{
-	printf("Usage: \n test_serial comN count \n where 'comN' is a serial port and count is a number of characters to be read\n");	
-}
-
-
-// The name of a serial device must be between 'com0' and 'com9'.
-static bool is_com_dev(const char *dev_name) 
-{
-	if (str_length(dev_name) != 4) {
-		return false;
-	}
-	
-	if (str_cmp("com0", dev_name) > 0) {
-		return false;
-	}
-	
-	if (str_cmp(dev_name, "com9") > 0) {
-		return false;
-	}
-	
-	return true;
-}
-
-
-int main(int argc, char *argv[])
-{
-	if (argc != 3) {
-		printf(NAME ": incorrect number of arguments.\n");
-		print_usage();
-		return 0;		
-	}	
-
-	
-	const char *serial_dev_name = argv[1];
-	long int cnt = strtol(argv[2], NULL, 10);
-	
-	if (!is_com_dev(serial_dev_name)) {
-		printf(NAME ": the first argument is not correct.\n");
-		print_usage();
-		return 0;	
-	}
-	
-	dev_handle_t serial_dev_handle = -1;
-	
-	if (device_get_handle(serial_dev_name, &serial_dev_handle) !=  EOK) {
-		printf(NAME ": could not get the handle of %s.\n", serial_dev_name);
-		return;
-	}
-	
-	printf(NAME ": got the handle of %s.\n", serial_dev_name);
-	
-	int dev_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CONNECT_TO_DEVICE, serial_dev_handle);
-	if(dev_phone < 0) {
-		printf(NAME ": could not connect to %s device.\n", serial_dev_name);
-		return;
-	}
-	
-	printf("The application will read %d characters from %s: \n", cnt, serial_dev_name);
-	
-	int i, c;
-	for (i = 0; i < cnt; i++) {
-		async_req_0_1(dev_phone, SERIAL_GETCHAR, &c);
-		printf("%c", (char)c);
-	}
-	
-	return 0;
-}*/
-
-
 #include <ipc/devman.h>
 #include <devman.h>
 #include <device/char.h>
 
+#define NAME 		"test serial"
+
 
 static void print_usage()
 {
-	printf("Usage: \n test_serial count \n where count is a number of characters to be read\n");	
+	printf("Usage: \n test_serial count \n where count is the number of characters to be read\n");	
 }
-
 
 int main(int argc, char *argv[])
@@ -195,5 +73,5 @@
 	}
 	
-	printf(NAME ": device handle is %d.\n", handle);	
+	printf(NAME ": trying to read %d characters from device with handle %d.\n", cnt, handle);	
 	
 	int phone;
@@ -212,17 +90,27 @@
 	}
 	
-	int read = read_dev(phone, buf, cnt);
-	if (0 > read) {
-		printf(NAME ": failed read from device, errno = %d.\n", -read);
-		ipc_hangup(phone);
-		devman_hangup_phone(DEVMAN_CLIENT);
-		return 4;
+	int total = 0;
+	int read = 0;
+	while (total < cnt) {		
+		read = read_dev(phone, buf, cnt - total);
+		if (0 > read) {
+			printf(NAME ": failed read from device, errno = %d.\n", -read);
+			ipc_hangup(phone);
+			devman_hangup_phone(DEVMAN_CLIENT);
+			free(buf);
+			return 4;
+		}		
+		total += read;
+		if (read > 0) {			
+			buf[read] = 0;
+			printf(buf);		
+		} else {	
+			usleep(100000);			
+		}	
 	}
-	
-	buf[cnt+1] = 0;
-	printf(NAME ": read data: '%s'.", buf);
 	
 	devman_hangup_phone(DEVMAN_CLIENT);
 	ipc_hangup(phone);
+	free(buf);
 	
 	return 0;
