Fix some unrelated unit tests when !HAVE_OPENSSL_POLICY_MAPPING.
[wvstreams.git] / wvtestmain.cc
blob9f18ac314f092454138691f8f7244121d80b1387
1 #include "wvtest.h"
2 #include "wvcrash.h"
3 #include "wvstring.h"
4 #include <stdlib.h>
5 #include <stdio.h>
6 #ifdef _WIN32
7 #include <io.h>
8 #include <windows.h>
9 #else
10 #include <unistd.h>
11 #include <fcntl.h>
12 #endif
14 static bool fd_is_valid(int fd)
16 #ifdef _WIN32
17 if ((HANDLE)_get_osfhandle(fd) != INVALID_HANDLE_VALUE) return true;
18 #endif
19 int nfd = dup(fd);
20 if (nfd >= 0)
22 close(nfd);
23 return true;
25 return false;
30 static int fd_count(const char *when)
32 int count = 0;
34 printf("fds open at %s:", when);
36 for (int fd = 0; fd < 1024; fd++)
38 if (fd_is_valid(fd))
40 count++;
41 printf(" %d", fd);
42 fflush(stdout);
45 printf("\n");
47 return count;
51 int main(int argc, char **argv)
53 #ifdef _WIN32
54 setup_console_crash();
55 #endif
57 // test wvtest itself. Not very thorough, but you have to draw the
58 // line somewhere :)
59 WVPASS(true);
60 WVPASS(1);
61 WVFAIL(false);
62 WVFAIL(0);
63 int startfd, endfd;
64 char * const *prefixes = NULL;
66 if (argc > 1)
67 prefixes = argv + 1;
69 startfd = fd_count("start");
70 int ret = WvTest::run_all(prefixes);
72 if (ret == 0) // don't pollute the strace output if we failed anyway
74 endfd = fd_count("end");
76 WVPASS(startfd == endfd);
77 #ifndef _WIN32
78 if (startfd != endfd)
79 system(WvString("ls -l /proc/%s/fd", getpid()));
80 #endif
83 // keep 'make' from aborting if this environment variable is set
84 if (getenv("WVTEST_NO_FAIL"))
85 return 0;
86 else
87 return ret;