X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/demo.git/blobdiff_plain/2b8f7981309972066d053338947a46b5c3cbfac2..7041368a7f3cfe306eebb8a7bb96e3125a367830:/src/wvtest/c/wvtestmain.c diff --git a/src/wvtest/c/wvtestmain.c b/src/wvtest/c/wvtestmain.c new file mode 100644 index 0000000..446e5ba --- /dev/null +++ b/src/wvtest/c/wvtestmain.c @@ -0,0 +1,100 @@ +/* + * WvTest: + * Copyright (C) 1997-2009 Net Integration Technologies, Inc. + * Licensed under the GNU Library General Public License, version 2. + * See the included file named LICENSE for license information. + */ +#include "wvtest.h" +#ifdef HAVE_WVCRASH +# include "wvcrash.h" +#endif +#include +#include +#ifdef _WIN32 +#include +#include +#else +#include +#include +#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; + +} + + +static int fd_count(const char *when) +{ + int count = 0; + int fd; + printf("fds open at %s:", when); + + for (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) +{ + char buf[200]; +#if defined(_WIN32) && defined(HAVE_WVCRASH) + 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 + if (0) + { + endfd = fd_count("end"); + + WVPASS(startfd == endfd); +#ifndef _WIN32 + if (startfd != endfd) + { + sprintf(buf, "ls -l /proc/%d/fd", getpid()); + system(buf); + } +#endif + } + + // keep 'make' from aborting if this environment variable is set + if (getenv("WVTEST_NO_FAIL")) + return 0; + else + return ret; +}