diff --git a/legacy/evil/src/bin/Makefile.am b/legacy/evil/src/bin/Makefile.am index ec3a4bb023..50446d3aa6 100644 --- a/legacy/evil/src/bin/Makefile.am +++ b/legacy/evil/src/bin/Makefile.am @@ -10,7 +10,7 @@ AM_CPPFLAGS = \ AM_CFLAGS = @win32_cflags@ -bin_PROGRAMS = evil_suite test_pipe test_evil +bin_PROGRAMS = evil_suite test_evil evil_suite_SOURCES = \ evil_suite.c \ @@ -36,10 +36,6 @@ endif evil_suite_LDADD = $(top_builddir)/src/lib/libevil.la $(top_builddir)/src/lib/dlfcn/libdl.la -lm evil_suite_LDFLAGS = -Wl,--enable-auto-import -test_pipe_SOURCES = test_pipe.c -test_pipe_LDADD = $(top_builddir)/src/lib/libevil.la -test_pipe_LDFLAGS = -Wl,--enable-auto-import - test_evil_SOURCES = test_evil.c test_evil_LDADD = $(top_builddir)/src/lib/libevil.la test_evil_LDFLAGS = -Wl,--enable-auto-import @@ -51,4 +47,5 @@ evil_test_environment.h \ evil_test_link.h \ evil_test_memcpy.h \ evil_test_mkstemp.h \ +evil_test_pipe.h \ evil_test_realpath.h diff --git a/legacy/evil/src/bin/test_pipe.c b/legacy/evil/src/bin/evil_test_pipe.c similarity index 52% rename from legacy/evil/src/bin/test_pipe.c rename to legacy/evil/src/bin/evil_test_pipe.c index 932079530d..575b46ff78 100644 --- a/legacy/evil/src/bin/test_pipe.c +++ b/legacy/evil/src/bin/evil_test_pipe.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include #include @@ -5,7 +9,10 @@ # include # undef WIN32_LEAN_AND_MEAN -#include "Evil.h" +#include + +#include "evil_suite.h" + #define FDREAD 0 #define FDWRITE 1 @@ -17,7 +24,7 @@ typedef struct } data; -DWORD WINAPI +static DWORD WINAPI thread (void *param) { data *d; @@ -31,19 +38,15 @@ thread (void *param) return 0; } -int -main (int argc, char *argv[]) +int test_pipe_test(void) { - int sockets[2]; - int ret; - fd_set rfds; + int sockets[2]; struct timeval t; - data *d; - DWORD thread_id; - HANDLE h; - - if (!evil_sockets_init()) - return EXIT_FAILURE; + fd_set rfds; + int ret; + data *d; + DWORD thread_id; + HANDLE h; FD_ZERO(&rfds); @@ -51,50 +54,74 @@ main (int argc, char *argv[]) t.tv_usec = 0; if (pipe(sockets) < 0) - { - printf ("can not create sockets\n"); - evil_sockets_shutdown(); - return EXIT_FAILURE; - } + return 0; FD_SET(sockets[FDREAD], &rfds); + fcntl(sockets[FDREAD], F_SETFL, O_NONBLOCK); + d = (data *)malloc(sizeof (data)); + if (!d) + return 0; + d->val = 14; d->fd_write = sockets[FDWRITE]; - printf (" pointer sent........: %p\n", d); h = CreateThread(NULL, 0, thread, d, 0, &thread_id); + if (!h) ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t); - if (ret < 0) return -1; + if (ret < 0) + goto free_d; - if (ret == 0) { - printf ("temps expire\n"); - } + if (ret == 0) + goto close_h; if (ret > 0) { - data *d; - int len; - int j = 0; void *buf[1]; + data *d2 = NULL; + int len; while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0) { if (len == sizeof(buf)) { - d = buf[0]; - printf (" pointer received....: %p\n", d); - j = d->val; - printf (" value (should be 14) : %d\n", j); + d2 = (data *)buf[0]; + break; } } + if (d2 && (d2->val == d->val)) + ret = 1; + else + ret = 0; } - CloseHandle (h); + CloseHandle(h); + free(d); - evil_sockets_shutdown(); + return 1; - return EXIT_SUCCESS; + close_h: + CloseHandle(h); + free_d: + free(d); + return 0; +} + +static int +test_pipe_run(suite *s) +{ + int res; + + res = test_pipe_test(); + + return res; +} + +int +test_pipe(suite *s) +{ + + return test_pipe_run(s); } diff --git a/legacy/evil/src/bin/evil_test_pipe.h b/legacy/evil/src/bin/evil_test_pipe.h new file mode 100644 index 0000000000..ff8041f716 --- /dev/null +++ b/legacy/evil/src/bin/evil_test_pipe.h @@ -0,0 +1,8 @@ +#ifndef __EVIL_TEST_PIPE_H__ +#define __EVIL_TEST_PIPE_H__ + + +int test_pipe(suite *s); + + +#endif /* __EVIL_TEST_PIPE_H__ */