Add trivial termios tests.

...and fix the bugs.

Also explain why we can't support separate input and output speeds
without an ABI change. Luckily no-one is likely to need that anyway,
and they can always work around it by using `struct termios2` directly
themselves.

Bug: http://b/69816452
Test: ran tests
Change-Id: Ie08499a198bb6a20d7e5e2f5ff74a60bd53e97e1
diff --git a/libc/include/bits/termios_inlines.h b/libc/include/bits/termios_inlines.h
index d49167e..5f7cc42 100644
--- a/libc/include/bits/termios_inlines.h
+++ b/libc/include/bits/termios_inlines.h
@@ -42,6 +42,9 @@
 
 __BEGIN_DECLS
 
+// Supporting separate input and output speeds would require an ABI
+// change for `struct termios`.
+
 static __inline speed_t cfgetspeed(const struct termios* s) {
   return __BIONIC_CAST(static_cast, speed_t, s->c_cflag & CBAUD);
 }
@@ -60,10 +63,16 @@
   s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
   s->c_cflag &= ~(CSIZE|PARENB);
   s->c_cflag |= CS8;
+  s->c_cc[VMIN] = 1;
+  s->c_cc[VTIME] = 0;
 }
 
 __BIONIC_TERMIOS_INLINE int cfsetspeed(struct termios* s, speed_t speed) {
-  // TODO: check 'speed' is valid.
+  // CBAUD is 0x100f, and every matching bit pattern has a Bxxx constant.
+  if ((speed & ~CBAUD) != 0) {
+    errno = EINVAL;
+    return -1;
+  }
   s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
   return 0;
 }