odyssey/test/odyssey_test.h

55 lines
1.4 KiB
C
Raw Normal View History

#ifndef ODYSSEY_TEST_H
#define ODYSSEY_TEST_H
/*
* Odyssey.
*
* Scalable PostgreSQL connection pooler.
*/
#include <string.h>
2019-08-08 14:39:13 +00:00
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#define odyssey_test(function) \
do { \
2019-07-31 09:40:04 +00:00
struct timeval tv_start, tv_stop; \
fprintf(stdout, "%s: ", #function); \
fflush(stdout); \
2019-07-31 09:40:04 +00:00
gettimeofday(&tv_start, NULL); \
(function)(); \
2019-07-31 09:40:04 +00:00
gettimeofday(&tv_stop, NULL); \
2019-08-08 14:39:13 +00:00
fprintf(stdout, "ok (%ld ms)\n", \
(tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000); \
} while (0);
#define odyssey_shell_test(file) \
do { \
struct timeval tv_start, tv_stop; \
fprintf(stdout, "%s: ", file); \
fflush(stdout); \
gettimeofday(&tv_start, NULL); \
int rc = system("/bin/bash ./" file ".sh"); \
if (rc != 0) { \
fprintf(stdout, "fail with status (%d)\n", WEXITSTATUS(rc)); \
fflush(stdout); \
abort(); \
} \
gettimeofday(&tv_stop, NULL); \
fprintf(stdout, "ok (%ld ms)\n", \
(tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000); \
} while (0);
#define test(expression) \
do { \
if (! (expression)) { \
fprintf(stdout, "fail (%s:%d) with error \"%s\" (%d) %s\n", \
__FILE__, __LINE__, strerror(errno), errno, #expression); \
fflush(stdout); \
abort(); \
} \
} while (0);
#endif /* ODYSSEY_TEST_H */