mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 13:58:58 -04:00
Refactor the zlib and pthreads tests to appear in the regular tinytest tree structure.
svn:r1141
This commit is contained in:
parent
684c022a21
commit
68d0139f19
@ -1439,20 +1439,3 @@ struct testcase_t signal_testcases[] = {
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
int
|
||||
legacy_main(void)
|
||||
{
|
||||
/* Initalize the event library */
|
||||
global_base = event_init();
|
||||
|
||||
#if defined(_EVENT_HAVE_PTHREADS) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)
|
||||
regress_pthread();
|
||||
#endif
|
||||
|
||||
#if defined(_EVENT_HAVE_LIBZ)
|
||||
regress_zlib();
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,8 @@ extern struct testcase_t dns_testcases[];
|
||||
extern struct testcase_t rpc_testcases[];
|
||||
extern struct testcase_t edgetriggered_testcases[];
|
||||
|
||||
int legacy_main(void);
|
||||
|
||||
void regress_pthread(void);
|
||||
void regress_zlib(void);
|
||||
void regress_threads(void *);
|
||||
void test_bufferevent_zlib(void *);
|
||||
|
||||
/* Helpers to wrap old testcases */
|
||||
extern int pair[2];
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "event-config.h"
|
||||
#include "event2/event.h"
|
||||
#include "event2/event_struct.h"
|
||||
#include "event2/event_compat.h"
|
||||
@ -304,6 +305,11 @@ struct testcase_t bufferevent_testcases[] = {
|
||||
LEGACY(bufferevent, TT_ISOLATED),
|
||||
LEGACY(bufferevent_watermarks, TT_ISOLATED),
|
||||
LEGACY(bufferevent_filters, TT_ISOLATED),
|
||||
#ifdef _EVENT_HAVE_LIBZ
|
||||
LEGACY(bufferevent_zlib, TT_ISOLATED),
|
||||
#else
|
||||
{ "bufferevent_zlib", NULL, TT_SKIP, NULL, NULL },
|
||||
#endif
|
||||
|
||||
END_OF_TESTCASES,
|
||||
};
|
||||
|
@ -66,6 +66,7 @@
|
||||
#include <event2/dns.h>
|
||||
#include <event2/dns_compat.h>
|
||||
|
||||
#include "event-config.h"
|
||||
#include "regress.h"
|
||||
#include "tinytest.h"
|
||||
#include "tinytest_macros.h"
|
||||
@ -208,16 +209,26 @@ const struct testcase_setup_t legacy_setup = {
|
||||
/* ============================================================ */
|
||||
|
||||
|
||||
struct testcase_t thread_testcases[] = {
|
||||
#if defined(_EVENT_HAVE_PTHREADS) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)
|
||||
{ "pthreads", regress_threads, TT_FORK, NULL, NULL, },
|
||||
#else
|
||||
{ "pthreads", NULL, TT_SKIP, NULL, NULL },
|
||||
#endif
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
struct testgroup_t testgroups[] = {
|
||||
{ "main/", legacy_testcases },
|
||||
{ "et/", edgetriggered_testcases },
|
||||
{ "evbuffer/", evbuffer_testcases },
|
||||
{ "signal/", signal_testcases },
|
||||
{ "util/", util_testcases },
|
||||
{ "bufferevent/", bufferevent_testcases },
|
||||
{ "http/", http_testcases },
|
||||
{ "dns/", dns_testcases },
|
||||
{ "rpc/", rpc_testcases },
|
||||
{ "main/", legacy_testcases },
|
||||
{ "et/", edgetriggered_testcases },
|
||||
{ "evbuffer/", evbuffer_testcases },
|
||||
{ "signal/", signal_testcases },
|
||||
{ "util/", util_testcases },
|
||||
{ "bufferevent/", bufferevent_testcases },
|
||||
{ "http/", http_testcases },
|
||||
{ "dns/", dns_testcases },
|
||||
{ "rpc/", rpc_testcases },
|
||||
{ "thread/", thread_testcases },
|
||||
END_OF_GROUPS
|
||||
};
|
||||
|
||||
@ -246,7 +257,6 @@ main(int argc, const char **argv)
|
||||
if (tinytest_main(argc,argv,testgroups))
|
||||
return 1;
|
||||
|
||||
in_legacy_test_wrapper = 0;
|
||||
return legacy_main();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@
|
||||
#include "event2/event.h"
|
||||
#include "event2/event_struct.h"
|
||||
#include "event2/thread.h"
|
||||
|
||||
void regress_pthread(void);
|
||||
#include "regress.h"
|
||||
#include "tinytest_macros.h"
|
||||
|
||||
struct cond_wait {
|
||||
pthread_mutex_t lock;
|
||||
@ -107,8 +107,6 @@ pthread_basic(struct event_base *base)
|
||||
struct timeval tv;
|
||||
int i;
|
||||
|
||||
fprintf(stdout, "Testing basic pthreads support: ");
|
||||
|
||||
for (i = 0; i < NUM_THREADS; ++i)
|
||||
pthread_create(&threads[i], NULL, basic_thread, base);
|
||||
|
||||
@ -124,14 +122,13 @@ pthread_basic(struct event_base *base)
|
||||
pthread_join(threads[i], NULL);
|
||||
|
||||
event_del(&ev);
|
||||
|
||||
fprintf(stdout, "OK\n");
|
||||
}
|
||||
|
||||
void
|
||||
regress_pthread(void)
|
||||
regress_threads(void *arg)
|
||||
{
|
||||
struct event_base *base;
|
||||
(void) arg;
|
||||
|
||||
pthread_mutex_init(&count_lock, NULL);
|
||||
|
||||
@ -139,8 +136,7 @@ regress_pthread(void)
|
||||
|
||||
base = event_base_new();
|
||||
if (evthread_make_base_notifiable(base)<0) {
|
||||
puts("Couldn't make base notifiable!");
|
||||
return;
|
||||
tt_abort_msg("Couldn't make base notifiable!");
|
||||
}
|
||||
|
||||
pthread_basic(base);
|
||||
@ -148,4 +144,6 @@ regress_pthread(void)
|
||||
pthread_mutex_destroy(&count_lock);
|
||||
|
||||
event_base_free(base);
|
||||
end:
|
||||
;
|
||||
}
|
||||
|
@ -47,6 +47,7 @@
|
||||
|
||||
#include <zlib.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "event2/util.h"
|
||||
#include "event2/event.h"
|
||||
@ -54,7 +55,7 @@
|
||||
#include "event2/buffer.h"
|
||||
#include "event2/bufferevent.h"
|
||||
|
||||
void regress_zlib(void);
|
||||
#include "regress.h"
|
||||
|
||||
static int infilter_calls;
|
||||
static int outfilter_calls;
|
||||
@ -228,23 +229,20 @@ errorcb(struct bufferevent *bev, short what, void *arg)
|
||||
errorcb_invoked = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
test_bufferevent_zlib(void)
|
||||
void
|
||||
test_bufferevent_zlib(void *arg)
|
||||
{
|
||||
struct bufferevent *bev1, *bev2, *bev1_orig, *bev2_orig;
|
||||
struct bufferevent *bev1=NULL, *bev2=NULL, *bev1_orig, *bev2_orig;
|
||||
char buffer[8333];
|
||||
z_stream z_input, z_output;
|
||||
int i, pair[2], r;
|
||||
int test_ok;
|
||||
int i, pair[2]={-1,-1}, r;
|
||||
(void)arg;
|
||||
|
||||
infilter_calls = outfilter_calls = readcb_finished = writecb_finished
|
||||
= errorcb_invoked = 0;
|
||||
|
||||
fprintf(stdout, "Testing Zlib Filter: ");
|
||||
|
||||
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
|
||||
fprintf(stderr, "%s: socketpair\n", __func__);
|
||||
exit(1);
|
||||
tt_fail_perror("socketpair");
|
||||
}
|
||||
|
||||
evutil_make_socket_nonblocking(pair[0]);
|
||||
@ -255,19 +253,18 @@ test_bufferevent_zlib(void)
|
||||
|
||||
memset(&z_output, 0, sizeof(z_output));
|
||||
r = deflateInit(&z_output, Z_DEFAULT_COMPRESSION);
|
||||
assert(r == Z_OK);
|
||||
tt_int_op(r, ==, Z_OK);
|
||||
memset(&z_input, 0, sizeof(z_input));
|
||||
r = inflateInit(&z_input);
|
||||
|
||||
/* initialize filters */
|
||||
bev1 = bufferevent_filter_new(bev1, NULL, zlib_output_filter, 0,
|
||||
zlib_deflate_free, &z_output);
|
||||
zlib_deflate_free, &z_output);
|
||||
bev2 = bufferevent_filter_new(bev2, zlib_input_filter,
|
||||
NULL, 0, zlib_inflate_free, &z_input);
|
||||
NULL, 0, zlib_inflate_free, &z_input);
|
||||
bufferevent_setcb(bev1, readcb, writecb, errorcb, NULL);
|
||||
bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL);
|
||||
|
||||
|
||||
bufferevent_disable(bev1, EV_READ);
|
||||
bufferevent_enable(bev1, EV_WRITE);
|
||||
|
||||
@ -285,34 +282,21 @@ test_bufferevent_zlib(void)
|
||||
|
||||
event_dispatch();
|
||||
|
||||
bufferevent_free(bev1);
|
||||
bufferevent_free(bev2);
|
||||
tt_want(infilter_calls);
|
||||
tt_want(outfilter_calls);
|
||||
tt_want(readcb_finished);
|
||||
tt_want(writecb_finished);
|
||||
tt_want(!errorcb_invoked);
|
||||
|
||||
test_ok = 1;
|
||||
end:
|
||||
if (bev1)
|
||||
bufferevent_free(bev1);
|
||||
if (bev2)
|
||||
bufferevent_free(bev2);
|
||||
|
||||
test_ok = infilter_calls &&
|
||||
outfilter_calls &&
|
||||
readcb_finished &&
|
||||
writecb_finished &&
|
||||
!errorcb_invoked;
|
||||
|
||||
if (! test_ok) {
|
||||
fprintf(stdout, "FAILED: %d\n", test_ok);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
close(pair[0]);
|
||||
close(pair[1]);
|
||||
#else
|
||||
CloseHandle((HANDLE)pair[0]);
|
||||
CloseHandle((HANDLE)pair[1]);
|
||||
#endif
|
||||
|
||||
fprintf(stdout, "OK\n");
|
||||
}
|
||||
|
||||
void
|
||||
regress_zlib(void)
|
||||
{
|
||||
test_bufferevent_zlib();
|
||||
if (pair[0] >= 0)
|
||||
EVUTIL_CLOSESOCKET(pair[0]);
|
||||
if (pair[1] >= 0)
|
||||
EVUTIL_CLOSESOCKET(pair[1]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user