diff options
author | David Teigland <teigland@redhat.com> | 2009-06-02 12:25:34 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2009-06-02 12:25:34 -0500 |
commit | de35a795c61d339211f00119127a8e31fdab6fc8 (patch) | |
tree | 3442ae93d0af9e1847ec4449d8ef390ee74f309b | |
parent | e2abfa0ae1114805592853549ab812731e939910 (diff) | |
download | dct-stuff-de35a795c61d339211f00119127a8e31fdab6fc8.tar.gz dct-stuff-de35a795c61d339211f00119127a8e31fdab6fc8.tar.xz dct-stuff-de35a795c61d339211f00119127a8e31fdab6fc8.zip |
cpgx: run options, better build
. automate whitetank build stuff
. -i <sec> option to specify how many seconds to run
. -t <sec> option to specify timeout waiting for a dispatch
Signed-off-by: David Teigland <teigland@redhat.com>
-rw-r--r-- | cpgx/Makefile | 6 | ||||
-rw-r--r-- | cpgx/cpgx.c | 67 |
2 files changed, 53 insertions, 20 deletions
diff --git a/cpgx/Makefile b/cpgx/Makefile index 031e842..6a13264 100644 --- a/cpgx/Makefile +++ b/cpgx/Makefile @@ -1,10 +1,10 @@ -ARCHM=$(shell uname -m) - CFLAGS := -Wall -g -ifdef WHITETANK +OPENAIS_CPG := $(wildcard /usr/include/openais/cpg.h) +ifneq ($(strip $(OPENAIS_CPG)),) CFLAGS += -DWHITETANK +ARCHM=$(shell uname -m) ifeq (x86_64,$(ARCHM)) LDFLAGS += -L/usr/lib64/openais else diff --git a/cpgx/cpgx.c b/cpgx/cpgx.c index baa9bea..7d49ce5 100644 --- a/cpgx/cpgx.c +++ b/cpgx/cpgx.c @@ -136,13 +136,18 @@ static int cluster_down; static int opt_leave = 1; static int opt_exit = 1; static int opt_die = 0; -static int got_error = 0; +static int iterations_sec = 0; +static int timeout_sec = 0; static int continue_after_error = 0; static int opt_print_event = 1; static int opt_print_debug = 1; -static time_t prog_begin; +static int got_error = 0; +static time_t parent_begin; +static time_t child_begin; static time_t join_time; static time_t leave_time; +static time_t last_dispatch; +static uint32_t dispatch_count; static int dump_point; static int dump_wrap; static char debug_buf[256]; @@ -152,8 +157,6 @@ static uint8_t our_nodeid; static uint32_t eventid; static uint32_t last_config_eventid; static uint32_t sync_max = DEFAULT_SYNC_MAX; -static uint32_t dispatch_count; -static struct timeval last_dispatch; static int history_len; static struct event *history; static struct dct_config *last_config; @@ -1031,7 +1034,7 @@ static void confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name, int i; dispatch_count++; - gettimeofday(&last_dispatch, NULL); + last_dispatch = time(NULL); memset(&c, 0, sizeof(struct dct_config)); @@ -1266,7 +1269,7 @@ static void deliver_cb(cpg_handle_t handle, const struct cpg_name *group_name, struct dct_header *hd = data; dispatch_count++; - gettimeofday(&last_dispatch, NULL); + last_dispatch = time(NULL); if (len < sizeof(struct dct_header)) { log_error("deliver short message %u", (unsigned int)len); @@ -1475,13 +1478,20 @@ int we_should_die(void) return 0; } +int iterations_done(void) +{ + if (!iterations_sec) + return 0; + if (time(NULL) - parent_begin > iterations_sec) + return 1; + return 0; +} + void loop(void) { void (*workfn) (int ci); void (*deadfn) (int ci); int poll_timeout = 5; /* ms */ - unsigned long ms; - struct timeval now; int rv, i; srandom(time(NULL)); @@ -1490,7 +1500,7 @@ void loop(void) free_nodes_list(); dispatch_count = 0; - gettimeofday(&last_dispatch, NULL); + last_dispatch = time(NULL); sync_wait = 0; sync_done = 0; @@ -1530,10 +1540,8 @@ void loop(void) } } - gettimeofday(&now, NULL); - ms = time_diff_ms(&last_dispatch, &now); - if (ms > 20000) - log_error("no cpg dispatch in %lu ms", ms); + if (timeout_sec && (time(NULL) - last_dispatch > timeout_sec)) + log_error("no cpg dispatch in %d sec", timeout_sec); if (got_error) { fflush(stdout); @@ -1542,6 +1550,9 @@ void loop(void) exit(EXIT_FAILURE); } + if (iterations_done()) + exit(EXIT_SUCCESS); + /* * do things that create events (send messages, leave, exit) */ @@ -1605,6 +1616,8 @@ void print_usage(void) printf(" (kills corosync, restarts with cman_tool join)\n"); printf(" -s <num> sync up to num events, default %d\n", DEFAULT_SYNC_MAX); + printf(" -t <sec> timeout after no dispatch for this many seconds, default 0 (never)\n"); + printf(" -i <sec> run for this many seconds, default 0 (forever)\n"); printf(" -c continue after error\n"); printf("\n"); printf("Output:\n"); @@ -1627,7 +1640,7 @@ int main(int argc, char **argv) int optchar; while (cont) { - optchar = getopt(argc, argv, "H:D:l:e:d:s:ch"); + optchar = getopt(argc, argv, "H:D:l:e:d:s:t:i:ch"); switch (optchar) { case 'H': @@ -1654,6 +1667,14 @@ int main(int argc, char **argv) sync_max = atoi(optarg); break; + case 't': + timeout_sec = atoi(optarg); + break; + + case 'i': + iterations_sec = atoi(optarg); + break; + case 'c': continue_after_error = 1; break; @@ -1668,6 +1689,8 @@ int main(int argc, char **argv) }; } + parent_begin = time(NULL); + srandom(time(NULL)); history_len = HISTORY_EVENTS * sizeof(struct event); @@ -1692,16 +1715,20 @@ int main(int argc, char **argv) memset(dump_buf, 0, sizeof(dump_buf)); dump_point = 0; dump_wrap = 0; - prog_begin = time(NULL); + child_begin = time(NULL); while (1) { loop(); sleep(rand_int(0, 3)); + + if (iterations_done()) + exit(EXIT_SUCCESS); } } /* * parent waits for exit, + * exit 0 is successfully completed all iterations * exit 1 is error; stop to see what went wrong * exit 2 is intentional part of test, keep going */ @@ -1712,14 +1739,20 @@ int main(int argc, char **argv) code = WEXITSTATUS(status); if (code == 1 && !continue_after_error) break; + + if (iterations_done()) { + code = 0; + break; + } } else { printf("not WIFEXITED\n"); + code = 1; break; } sleep(rand_int(0, 3)); } - return 1; + return code; } void dump_save(void) @@ -1750,7 +1783,7 @@ void dump_write(void) return; now = time(NULL); - strftime(begin, sizeof(begin), "%b %d %T", localtime(&prog_begin)); + strftime(begin, sizeof(begin), "%b %d %T", localtime(&child_begin)); strftime(end, sizeof(end), "%b %d %T", localtime(&now)); fprintf(fp, "cpgx %s - %s\n", begin, end); |