summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuodong Xu <guodong.xu@linaro.org>2012-08-13 16:35:26 +0800
committerGuodong Xu <guodong.xu@linaro.org>2012-08-13 16:35:26 +0800
commit514fe01053e2d05646213951b4140a4fb6e62efb (patch)
treec5a0d6c44cb97fee8ebf2b67fe69b33f367e5b04
parent1083863bc2bcf8460ca7131577423430c6e91d14 (diff)
Update redtty_test as a tool for STM dummy driver
-rw-r--r--README11
-rw-r--r--redirect_ttyprintk.c70
2 files changed, 79 insertions, 2 deletions
diff --git a/README b/README
index 3182df3..9ad3b23 100644
--- a/README
+++ b/README
@@ -30,6 +30,17 @@ How to Build:
. to test param_array.c
- make EXTRA_DEBUG_MSG=yes async_test
. to test async_veri.c
+ - make EXTRA_DEBUG_MSG=yes redtty_test
+ . to test redirect_ttyprintk.c
+
+4. redtty_test is a useful tool to assist STM Dummy driver testing. It uses
+ /dev/ttyprintk as the message output channel for STM Dummy device. When
+ enabled (./redtty_test on), all message to STM Dummy driver will be
+ redirect to /dev/ttyprintk, who will then write these message to kernel log.
+ And user can view these messages using kernel log tool, such as dmesg.
+
+Usage: please run ./redtty_test with no args:
+$ ./redtty_test
################################################################################
How to use:
diff --git a/redirect_ttyprintk.c b/redirect_ttyprintk.c
index e27554a..2862807 100644
--- a/redirect_ttyprintk.c
+++ b/redirect_ttyprintk.c
@@ -11,10 +11,12 @@
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <string.h>
#include "test_commands.h"
#define N_TRACESINK 23 /* Trace data routing for MIPI P1149.7 */
+#define N_TTY 0
/* Open /dev/ttyprintk, and attach N_TRACESINK line discipline to it.
* Input:
@@ -31,7 +33,10 @@ int redirect_ttyprintk(void)
fd = open("/dev/ttyprintk", O_WRONLY | O_NOCTTY);
if (fd == -1) {
- TDBG("Failed to open /dev/ttyprintk.\n");
+ printf("Failed to open /dev/ttyprintk.\n");
+ printf("Please check whether /dev/ttyprink exists.\n");
+ printf("If not, please rebuild kernel with "
+ "CONFIG_TTY_PRINTK=y\n");
return -1;
}
@@ -49,9 +54,70 @@ int redirect_ttyprintk(void)
return fd;
}
-/* To check underlining STM device is dummy driver?
+/* Open /dev/ttyprintk, and attach N_TTY line discipline to it.
+ * Input:
+ * none
+ * Return:
+ * -1: Failure, otherwise
+ * fd: file discriptor of /dev/ttyprintk
*/
+int restore_ttyprintk(void)
+{
+ int fd;
+ int ldisc;
+ int ret;
+
+ fd = open("/dev/ttyprintk", O_WRONLY | O_NOCTTY);
+ if (fd == -1) {
+ printf("Failed to open /dev/ttyprintk.\n");
+ printf("Please check whether /dev/ttyprink exists.\n");
+ printf("If not, please rebuild kernel with "
+ "CONFIG_TTY_PRINTK=y\n");
+ return -1;
+ }
+
+ /* N_TTY line discipline will be attached to
+ * the ttyprintk serial port, /dev/ttyprintk
+ */
+ ldisc = N_TTY;
+ ret = ioctl(fd, TIOCSETD, &ldisc);
+ if (ret == -1) {
+ TDBG("Failed to attach N_TTY to /dev/ttyprintk.\n");
+ close(fd);
+ return ret;
+ }
+
+ return fd;
+}
#ifdef REDTTY_TEST_STUB
+extern FILE *stdin;
+
+/* main(), entry point */
+int main(int argc, char** argv)
+{
+ int fd_ttyprintk = -1;
+ char buf[10];
+
+ /* Attach N_TRACESINK to /dev/ttyprink */
+ fd_ttyprintk = redirect_ttyprintk();
+ if (fd_ttyprintk == -1) {
+ printf("Error: failed to open and redirect "
+ "/dev/ttyprintk\n");
+ return -1;
+ }
+ TDBG("Succeed to attach N_TRACESINK to /dev/ttyprintk.\n");
+
+ /* wait for some user input */
+ printf("You can start to test now. And type in any string to quit.\n");
+ fgets(buf, 10, stdin);
+
+ /* close ttyprintk */
+ if (fd_ttyprintk != -1)
+ close(fd_ttyprintk);
+
+ /* return */
+ return 0;
+}
#endif