wvtestmain.cc

00001 #include "wvtest.h"
00002 #include "wvstring.h"
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #ifdef _WIN32
00006 #include <io.h>
00007 #include <windows.h>
00008 #else
00009 #include <unistd.h>
00010 #include <fcntl.h>
00011 #endif
00012 
00013 static bool fd_is_valid(int fd)
00014 {
00015 #ifdef _WIN32
00016     if ((HANDLE)_get_osfhandle(fd) != INVALID_HANDLE_VALUE) return true;
00017 #endif    
00018     int nfd = dup(fd);
00019     if (nfd >= 0)
00020     {
00021         close(nfd);
00022         return true;
00023     }
00024     return false;
00025 
00026 }
00027 
00028 
00029 static int fd_count(const char *when)
00030 {
00031     int count = 0;
00032     
00033     printf("fds open at %s:", when);
00034     
00035     for (int fd = 0; fd < 1024; fd++)
00036     {
00037         if (fd_is_valid(fd))
00038         {
00039             count++;
00040             printf(" %d", fd);
00041             fflush(stdout);
00042         }
00043     }
00044     printf("\n");
00045     
00046     return count;
00047 }
00048 
00049 
00050 int main(int argc, char **argv)
00051 {
00052     // test wvtest itself.  Not very thorough, but you have to draw the
00053     // line somewhere :)
00054     WVPASS(true);
00055     WVPASS(1);
00056     WVFAIL(false);
00057     WVFAIL(0);
00058     int startfd, endfd;
00059     char * const *prefixes = NULL;
00060     
00061     if (argc > 1)
00062         prefixes = argv + 1;
00063     
00064     startfd = fd_count("start");
00065     int ret = WvTest::run_all(prefixes);
00066     endfd = fd_count("end");
00067     
00068     WVPASS(startfd == endfd);
00069 #ifndef _WIN32
00070     if (startfd != endfd)
00071         system(WvString("ls -l /proc/%s/fd", getpid()));
00072 #endif    
00073     
00074     // keep 'make' from aborting if this environment variable is set
00075     if (getenv("WVTEST_NO_FAIL"))
00076         return 0;
00077     else
00078         return ret;
00079 }

Generated on Mon Feb 5 10:54:30 2007 for WvStreams by  doxygen 1.5.1