summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1997-10-23 15:12:46 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1997-10-23 15:12:46 +0000
commit514cf30bb5bff7af44363b12182d844c15da3e67 (patch)
tree43e6934d99210d49a540bcf7f3b9338fbcd7293d /testsuites
parentAdded console_reserve_resources. (diff)
downloadrtems-514cf30bb5bff7af44363b12182d844c15da3e67.tar.bz2
Added new test for termios style consoles from Eric Norum.
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/libtests/termios/init.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/testsuites/libtests/termios/init.c b/testsuites/libtests/termios/init.c
new file mode 100644
index 0000000000..cea9a04c2f
--- /dev/null
+++ b/testsuites/libtests/termios/init.c
@@ -0,0 +1,141 @@
+/*
+ * RTEMS configuration/initialization
+ *
+ * This program may be distributed and used for any purpose.
+ * I ask only that you:
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ */
+
+#include <bsp.h>
+
+#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_TIMERS 5
+#define CONFIGURE_MAXIMUM_PERIODS 1
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+
+#define CONFIGURE_INIT
+rtems_task Init (rtems_task_argument argument);
+
+#include <confdefs.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <termios.h>
+#include <errno.h>
+#include <string.h>
+
+/*
+ * Test raw (ICANON=0) input
+ */
+static void
+testRawInput (int vmin, int vtime)
+{
+ int i;
+ struct termios old, new;
+ rtems_interval ticksPerSecond, then, now;
+ unsigned int msec;
+ unsigned long count;
+ int nread;
+ unsigned char cbuf[100];
+
+ printf ("*** Raw input VMIN=%d VTIME=%d ***\n", vmin, vtime);
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
+ i = tcgetattr (fileno (stdin), &old);
+ if (i < 0) {
+ printf ("tcgetattr failed: %s\n", strerror (errno));
+ return;
+ }
+ new = old;
+ new.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
+ new.c_cc[VMIN] = vmin;
+ new.c_cc[VTIME] = vtime;
+ i = tcsetattr (fileno (stdin), TCSANOW, &new);
+ if (i < 0) {
+ printf ("tcsetattr failed: %s\n", strerror (errno));
+ return;
+ }
+ do {
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
+ count = 0;
+ for (;;) {
+ nread = read (fileno (stdin), cbuf, sizeof cbuf);
+ if (nread < 0) {
+ printf ("Read error: %s\n", strerror (errno));
+ goto out;
+ }
+ count++;
+ if (nread != 0)
+ break;
+ }
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
+ msec = (now - then) * 1000 / ticksPerSecond;
+ printf ("Count:%-10lu Interval:%3u.%3.3d Char:",
+ count, msec / 1000, msec % 1000);
+ for (i = 0 ; i < nread ; i++)
+ printf (" %2.2x", cbuf[i]);
+ printf ("\n");
+ } while (cbuf[0] != 'q');
+ out:
+ i = tcsetattr (fileno (stdin), TCSANOW, &old);
+ if (i < 0)
+ printf ("tcsetattr failed: %s\n", strerror (errno));
+ printf ("*** End of Raw input VMIN=%d VTIME=%d ***\n", vmin, vtime);
+}
+
+/*
+ * RTEMS Startup Task
+ */
+rtems_task
+Init (rtems_task_argument ignored)
+{
+ int i, j;
+
+ printf( "\n\n*** HELLO WORLD TEST ***\n" );
+ printf( "Hello World\n" );
+ printf( "*** END OF HELLO WORLD TEST ***\n" );
+
+ printf( "\n\ntype 'q' to exit raw input tests\n\n" );
+
+ for (;;) {
+ /*
+ * Test blocking, line-oriented input
+ */
+ do {
+ printf (">>> ");
+ fflush (stdout);
+ i = scanf (" %d", &j);
+ printf ("Return: %d Value: %d\n", i, j);
+ } while (i != 0);
+
+ /*
+ * Consume what scanf rejected
+ */
+ while ((i = getchar ()) != '\n')
+ if (i == EOF)
+ break;
+
+ /*
+ * Test character-oriented input
+ */
+ testRawInput (0, 0);
+ testRawInput (0, 20);
+ testRawInput (5, 0);
+ testRawInput (5, 20);
+ }
+ exit (1);
+}