X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fhealth%2Fhealth_check.c;h=0569a418775c98b9c9a5f24aac086be43f1b7786;hp=3eef1104008d0deab00324740d9c8447a1dd07f1;hb=6c71277b0dc97ce8a4ac6b8d359b4b349c04b658;hpb=d74df4226a1b4461c896d51a221afe38e07809a7 diff --git a/tests/regression/tools/health/health_check.c b/tests/regression/tools/health/health_check.c index 3eef11040..0569a4187 100644 --- a/tests/regression/tools/health/health_check.c +++ b/tests/regression/tools/health/health_check.c @@ -16,58 +16,108 @@ */ #include +#include -#include "lttng/lttng.h" +#include -#define HEALTH_CMD_FAIL (1 << 0) -#define HEALTH_APP_MNG_FAIL (1 << 1) -#define HEALTH_APP_REG_FAIL (1 << 2) -#define HEALTH_KERNEL_FAIL (1 << 3) -#define HEALTH_CSMR_FAIL (1 << 4) - -int main(int argc, char *argv[]) +static +int check_component(struct lttng_health *lh, const char *component_name) { - int health = -1; - int status = 0; + const struct lttng_health_thread *thread; + int nr_threads, i, status; - /* Command thread */ - health = lttng_health_check(LTTNG_HEALTH_CMD); - printf("Health check cmd: %d\n", health); + if (lttng_health_query(lh)) { + fprintf(stderr, "Error querying %s health\n", + component_name); + return -1; + } + status = lttng_health_state(lh); + if (!status) { + return status; + } - if (health) { - status |= HEALTH_CMD_FAIL; + nr_threads = lttng_health_get_nr_threads(lh); + if (nr_threads < 0) { + fprintf(stderr, "Error getting number of threads\n"); + return -1; } - /* App manage thread */ - health = lttng_health_check(LTTNG_HEALTH_APP_MANAGE); - printf("Health check app. manage: %d\n", health); + printf("Component \"%s\" is in error.\n", component_name); + for (i = 0; i < nr_threads; i++) { + int thread_state; - if (health) { - status |= HEALTH_APP_MNG_FAIL; - } - /* App registration thread */ - health = lttng_health_check(LTTNG_HEALTH_APP_REG); - printf("Health check app. registration: %d\n", health); + thread = lttng_health_get_thread(lh, i); + if (!thread) { + fprintf(stderr, "Error getting thread %d\n", i); + return -1; + } + thread_state = lttng_health_thread_state(thread); + if (!thread_state) { + continue; + } + printf("Thread \"%s\" is not responding in component \"%s\".\n", + lttng_health_thread_name(thread), + component_name); - if (health) { - status |= HEALTH_APP_REG_FAIL; } + return status; +} - /* Kernel thread */ - health = lttng_health_check(LTTNG_HEALTH_KERNEL); - printf("Health check kernel: %d\n", health); +static +int check_sessiond(void) +{ + struct lttng_health *lh; + int status; - if (health) { - status |= HEALTH_KERNEL_FAIL; + lh = lttng_health_create_sessiond(); + if (!lh) { + perror("lttng_health_create_sessiond"); + return -1; } - /* Consumer thread */ - health = lttng_health_check(LTTNG_HEALTH_CONSUMER); - printf("Health check consumer: %d\n", health); + status = check_component(lh, "sessiond"); + + lttng_health_destroy(lh); + + return status; +} + +static +int check_consumerd(enum lttng_health_consumerd hc) +{ + struct lttng_health *lh; + int status; + static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = { + "ust-consumerd-32", + "ust-consumerd-64", + "kernel-consumerd", + }; - if (health) { - status |= HEALTH_CSMR_FAIL; + lh = lttng_health_create_consumerd(hc); + if (!lh) { + perror("lttng_health_create_consumerd"); + return -1; } + status = check_component(lh, cnames[hc]); + + lttng_health_destroy(lh); + return status; } + + +int main(int argc, char *argv[]) +{ + int status = 0, i; + + status |= check_sessiond(); + for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) { + status |= check_consumerd(i); + } + if (!status) { + exit(EXIT_SUCCESS); + } else { + exit(EXIT_FAILURE); + } +}