[haiku-commits] r35990 - haiku/trunk/src/tests/add-ons/kernel/drivers/tty

  • From: revol@xxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 28 Mar 2010 21:17:30 +0200 (CEST)

Author: mmu_man
Date: 2010-03-28 21:17:30 +0200 (Sun, 28 Mar 2010)
New Revision: 35990
Changeset: http://dev.haiku-os.org/changeset/35990/haiku

Modified:
   haiku/trunk/src/tests/add-ons/kernel/drivers/tty/Jamfile
   haiku/trunk/src/tests/add-ons/kernel/drivers/tty/tty-test.cpp
Log:
Fix build.
Add test for ioctl(FIONREAD). Doesn't work much yet though.


Modified: haiku/trunk/src/tests/add-ons/kernel/drivers/tty/Jamfile
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/drivers/tty/Jamfile    2010-03-28 
19:14:33 UTC (rev 35989)
+++ haiku/trunk/src/tests/add-ons/kernel/drivers/tty/Jamfile    2010-03-28 
19:17:30 UTC (rev 35990)
@@ -2,5 +2,5 @@
 
 UsePrivateHeaders [ FDirName kernel ] ;
 
-SimpleTest tty-test : tty-test.cpp : libroot.so ;
+SimpleTest tty-test : tty-test.cpp : libroot.so $(TARGET_LIBSTDC++) ;
 

Modified: haiku/trunk/src/tests/add-ons/kernel/drivers/tty/tty-test.cpp
===================================================================
--- haiku/trunk/src/tests/add-ons/kernel/drivers/tty/tty-test.cpp       
2010-03-28 19:14:33 UTC (rev 35989)
+++ haiku/trunk/src/tests/add-ons/kernel/drivers/tty/tty-test.cpp       
2010-03-28 19:17:30 UTC (rev 35990)
@@ -8,10 +8,12 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/ioctl.h>
 #include <sys/select.h>
 
 #include <OS.h>
@@ -145,7 +147,7 @@
 
        int Select(bigtime_t timeout = -1)
        {
-               int count = max(max(fReadSet.Count(), fWriteSet.Count()),
+               int count = max_c(max_c(fReadSet.Count(), fWriteSet.Count()),
                        fErrorSet.Count());
                fd_set *readSet = (fReadSet.Count() > 0 ? &fReadSet : NULL);
                fd_set *writeSet = (fWriteSet.Count() > 0 ? &fWriteSet : NULL);
@@ -401,7 +403,8 @@
 
        char path[32];
        sprintf(path, "/dev/%ct/r%x", (master ? 'p' : 't'), index);
-       int fd = open(path, O_RDWR);
+       // we do not want the slave to be our controlling tty
+       int fd = open(path, O_RDWR | (master ? 0 : O_NOCTTY));
 
        if (fd < 0) {
                fprintf(stderr, "Failed to open tty `%s': %s\n", path, 
strerror(errno));
@@ -801,8 +804,91 @@
        bool    fUnblock;
 };
 
+// TestIoctlFIONRead
+class TestIoctlFIONRead : public TestCase {
+public:
+       TestIoctlFIONRead(bool master)
+               : fMaster(-1),
+                 fSlave(-1),
+                 fTestMaster(master)
+       {
+               printf("TestIoctlFIONRead(%d)\n", master);
+       }
 
 
+protected:
+       virtual ~TestIoctlFIONRead()
+       {
+               close_tty(fMaster);
+               close_tty(fSlave);
+       }
+
+       virtual void Test()
+       {
+               fMaster = open_tty(0, true);
+               fSlave = open_tty(0, false);
+               
+               int fd = (fTestMaster ? fMaster : fSlave);
+               status_t err;
+               int toRead = -1;
+
+               errno = 0;
+               err = ioctl(fd, FIONREAD, NULL);
+               CHK(err == -1);
+printf("e: %s\n", strerror(errno));
+               // should be CHK(errno == EINVAL); !!
+               CHK(errno == EFAULT);
+
+               errno = 0;
+               err = ioctl(fd, FIONREAD, (void *)1);
+               CHK(err == -1);
+printf("e: %s\n", strerror(errno));
+               CHK(errno == EFAULT);
+
+               errno = 0;
+
+               err = ioctl(fd, FIONREAD, &toRead);
+printf("e: %s\n", strerror(errno));
+               //CHK(err == 0);
+               //CHK(toRead == 0);
+
+               WriteDontFail((fTestMaster ? fSlave : fMaster), 1);
+
+               errno = 0;
+
+               err = ioctl(fd, FIONREAD, &toRead);
+printf("e: %d\n", err);
+               CHK(err == 0);
+               CHK(toRead == 1);
+
+               WriteUntilBlock((fTestMaster ? fSlave : fMaster));
+
+               err = ioctl(fd, FIONREAD, &toRead);
+               CHK(err == 0);
+               CHK(toRead > 1);
+
+               close_tty((fTestMaster ? fSlave : fMaster));
+
+               err = ioctl(fd, FIONREAD, &toRead);
+               CHK(err == 0);
+               CHK(toRead > 1);
+
+               ReadDontFail(fd, toRead);
+
+               err = ioctl(fd, FIONREAD, &toRead);
+               CHK(err == 0);
+               CHK(toRead == 0);
+
+       }
+
+private:
+       int             fMaster;
+       int             fSlave;
+       bool    fTestMaster;
+};
+
+
+
 // #pragma mark -
 
 int
@@ -843,5 +929,8 @@
        RUN_TEST(new TestSelectNotifyAfterPending(true,  true,  false));
        RUN_TEST(new TestSelectNotifyAfterPending(true,  true,  true));
 
+       RUN_TEST(new TestIoctlFIONRead(true));
+       //RUN_TEST(new TestIoctlFIONRead(false));
+
        return 0;
 }


Other related posts:

  • » [haiku-commits] r35990 - haiku/trunk/src/tests/add-ons/kernel/drivers/tty - revol