From: Marko Kreen Date: Mon, 25 Jan 2016 10:53:22 +0000 (+0200) Subject: test: make asynctest.c compile again X-Git-Tag: pgbouncer_1_7_1~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=136eeb4aa8b44ed9428233498e65e0df7b36da9e;p=pgbouncer test: make asynctest.c compile again --- diff --git a/test/Makefile b/test/Makefile index 0b3e2e8..55c132c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,12 +1,7 @@ -#PGINC = -I$(shell pg_config --includedir) -#PGLIB = -L$(shell pg_config --libdir) -#CPPFLAGS += -I../include -I../lib $(PGINC) -#LDFLAGS += $(PGLIB) -#LIBS := -lpq $(LIBS) -#ifeq ($(PORTNAME),win32) -#CPPFLAGS += -I../win32 -#endif +PG_CPPFLAGS = -I$(shell pg_config --includedir) +PG_LIBS = -lpq +PG_LDFLAGS = -L$(shell pg_config --libdir) USUAL_DIR = ../lib @@ -24,7 +19,11 @@ hba_test_SOURCES = hba_test.c ../src/hba.c ../src/util.c hba_test_EMBED_LIBUSUAL = 1 EXTRA_PROGRAMS = asynctest +asynctest_CPPFLAGS = -I../include $(PG_CPPFLAGS) +asynctest_LDFLAGS = $(PG_LDFLAGS) +asynctest_LDADD = $(PG_LIBS) asynctest_SOURCES = asynctest.c +asynctest_EMBED_LIBUSUAL = 1 AM_FEATURES = libusual diff --git a/test/asynctest.c b/test/asynctest.c index 74b2204..38f1d8a 100644 --- a/test/asynctest.c +++ b/test/asynctest.c @@ -6,30 +6,28 @@ * - variable-size query */ -#include "system.h" - #ifdef WIN32 #undef strerror #undef main #endif -#include -#include -#include - -static void log_error(const char *, ...); -static void log_debug(const char *, ...); -static void fatal(const char *fmt, ...); -static void fatal_noexit(const char *fmt, ...); +#include +#include +#include +#include +#include +#include +#include +#include -#include "list.h" +#include static char *simple_query = "select 1"; typedef void (*libev_cb_f)(int sock, short flags, void *arg); typedef struct DbConn { - List head; + struct List head; const char *connstr; struct event ev; PGconn *con; @@ -60,30 +58,10 @@ static int per_conn_queries = 1; static STATLIST(idle_list); static STATLIST(active_list); -static usec_t _time_cache = 0; - /* * utility functions */ -static usec_t get_time_usec(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (usec_t)tv.tv_sec * USEC + tv.tv_usec; -} - -static usec_t get_cached_time(void) -{ - if (!_time_cache) - _time_cache = get_time_usec(); - return _time_cache; -} -static void reset_time_cache(void) -{ - _time_cache = 0; -} - /* fill mem with random junk */ static void init_bulk_data(void) { @@ -107,68 +85,19 @@ static DbConn *new_db(const char *connstr) static void set_idle(DbConn *db) { Assert(item_in_list(&db->head, &active_list.head)); - statlist_remove(&db->head, &active_list); - statlist_append(&db->head, &idle_list); + statlist_remove(&active_list, &db->head); + statlist_append(&idle_list, &db->head); log_debug("%p: set_idle", db); } static void set_active(DbConn *db) { Assert(item_in_list(&db->head, &idle_list.head)); - statlist_remove(&db->head, &idle_list); - statlist_append(&db->head, &active_list); + statlist_remove(&idle_list, &db->head); + statlist_append(&active_list, &db->head); log_debug("%p: set_active", db); } -static void fatal_perror(const char *err) -{ - log_error("%s: %s", err, strerror(errno)); - exit(1); -} - -static void fatal_noexit(const char *fmt, ...) -{ - va_list ap; - char buf[1024]; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - printf("FATAL: %s\n", buf); -} - -static void fatal(const char *fmt, ...) -{ - va_list ap; - char buf[1024]; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - printf("FATAL: %s\n", buf); - exit(1); -} - -static void log_debug(const char *fmt, ...) -{ - va_list ap; - char buf[1024]; - if (verbose == 0) - return; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - printf("dbg: %s\n", buf); -} - -static void log_error(const char *fmt, ...) -{ - va_list ap; - char buf[1024]; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - printf("ERR: %s\n", buf); -} - static void wait_event(DbConn *db, short ev, libev_cb_f fn) { event_set(&db->ev, PQsocket(db->con), ev, fn, db); @@ -406,7 +335,7 @@ static void launch_connect(DbConn *db) static void handle_idle(void) { DbConn *db; - List *item, *tmp; + struct List *item, *tmp; int allow_connects = 100000; int allow_queries = 100000; static usec_t startup_time = 0; @@ -588,7 +517,7 @@ int main(int argc, char *argv[]) for (i = 0; i < numcon; i++) { db = new_db(cstr); - statlist_append(&db->head, &idle_list); + statlist_append(&idle_list, &db->head); } event_init();