-
Notifications
You must be signed in to change notification settings - Fork 15
/
wvtestmain.cc
98 lines (81 loc) · 1.75 KB
/
wvtestmain.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "wvtest.h"
#include "wvcrash.h"
#include "wvstring.h"
#include <stdlib.h>
#include <stdio.h>
#ifdef _WIN32
#include <io.h>
#include <windows.h>
#else
#include <unistd.h>
#include <fcntl.h>
#endif
static bool fd_is_valid(int fd)
{
#ifdef _WIN32
if ((HANDLE)_get_osfhandle(fd) != INVALID_HANDLE_VALUE) return true;
#endif
int nfd = dup(fd);
if (nfd >= 0)
{
close(nfd);
return true;
}
return false;
}
#ifdef MACOS
#include <netdb.h>
#endif
static int fd_count(const char *when)
{
int count = 0;
#ifdef MACOS
// MacOS leaks a fd as soon as it activates the resolver. So let's
// make sure the resolver has been activated before we first count fds.
gethostbyname("localhost");
#endif
printf("fds open at %s:", when);
for (int fd = 0; fd < 1024; fd++)
{
if (fd_is_valid(fd))
{
count++;
printf(" %d", fd);
fflush(stdout);
}
}
printf("\n");
return count;
}
int main(int argc, char **argv)
{
#ifdef _WIN32
setup_console_crash();
#endif
// test wvtest itself. Not very thorough, but you have to draw the
// line somewhere :)
WVPASS(true);
WVPASS(1);
WVFAIL(false);
WVFAIL(0);
int startfd, endfd;
char * const *prefixes = NULL;
if (argc > 1)
prefixes = argv + 1;
startfd = fd_count("start");
int ret = WvTest::run_all(prefixes);
if (ret == 0) // don't pollute the strace output if we failed anyway
{
endfd = fd_count("end");
WVPASS(startfd == endfd);
#ifndef _WIN32
if (startfd != endfd)
system(WvString("ls -l /proc/%s/fd", getpid()));
#endif
}
// keep 'make' from aborting if this environment variable is set
if (getenv("WVTEST_NO_FAIL"))
return 0;
else
return ret;
}