2018-04-04 14:35:50 +00:00
|
|
|
#ifndef ODYSSEY_TEST_H
|
|
|
|
#define ODYSSEY_TEST_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Odyssey.
|
|
|
|
*
|
|
|
|
* Scalable PostgreSQL connection pooler.
|
|
|
|
*/
|
|
|
|
|
2018-06-10 09:40:42 +00:00
|
|
|
#include <string.h>
|
2019-08-08 14:39:13 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <errno.h>
|
2018-06-10 09:40:42 +00:00
|
|
|
|
2018-04-04 14:35:50 +00:00
|
|
|
#define odyssey_test(function) \
|
|
|
|
do { \
|
2019-07-31 09:40:04 +00:00
|
|
|
struct timeval tv_start, tv_stop; \
|
2018-04-04 14:35:50 +00:00
|
|
|
fprintf(stdout, "%s: ", #function); \
|
|
|
|
fflush(stdout); \
|
2019-07-31 09:40:04 +00:00
|
|
|
gettimeofday(&tv_start, NULL); \
|
2018-04-04 14:35:50 +00:00
|
|
|
(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); \
|
2018-04-04 14:35:50 +00:00
|
|
|
} while (0);
|
|
|
|
|
2019-11-24 16:00:00 +00:00
|
|
|
#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);
|
|
|
|
|
2018-04-04 14:35:50 +00:00
|
|
|
#define test(expression) \
|
|
|
|
do { \
|
|
|
|
if (! (expression)) { \
|
2018-06-10 09:40:42 +00:00
|
|
|
fprintf(stdout, "fail (%s:%d) with error \"%s\" (%d) %s\n", \
|
|
|
|
__FILE__, __LINE__, strerror(errno), errno, #expression); \
|
2018-04-04 14:35:50 +00:00
|
|
|
fflush(stdout); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#endif /* ODYSSEY_TEST_H */
|