Test health: add test_thread_ok
[lttng-tools.git] / tests / regression / tools / health / health_check.c
CommitLineData
dff9583f
CB
1/*
2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#include <stdio.h>
6c71277b 19#include <stdlib.h>
4d6fd696 20#include <string.h>
dff9583f 21
6c71277b 22#include <lttng/health.h>
dff9583f 23
4d6fd696
MD
24static const char *relayd_path;
25
6c71277b 26static
26401f03
MD
27int check_component(struct lttng_health *lh, const char *component_name,
28 int ok_if_not_running)
dff9583f 29{
6c71277b
MD
30 const struct lttng_health_thread *thread;
31 int nr_threads, i, status;
dff9583f 32
6c71277b 33 if (lttng_health_query(lh)) {
26401f03
MD
34 if (ok_if_not_running) {
35 return 0;
36 }
6c71277b
MD
37 fprintf(stderr, "Error querying %s health\n",
38 component_name);
39 return -1;
40 }
41 status = lttng_health_state(lh);
42 if (!status) {
43 return status;
44 }
dff9583f 45
6c71277b
MD
46 nr_threads = lttng_health_get_nr_threads(lh);
47 if (nr_threads < 0) {
48 fprintf(stderr, "Error getting number of threads\n");
49 return -1;
dff9583f
CB
50 }
51
6c71277b
MD
52 printf("Component \"%s\" is in error.\n", component_name);
53 for (i = 0; i < nr_threads; i++) {
54 int thread_state;
dff9583f 55
6c71277b
MD
56 thread = lttng_health_get_thread(lh, i);
57 if (!thread) {
58 fprintf(stderr, "Error getting thread %d\n", i);
59 return -1;
60 }
61 thread_state = lttng_health_thread_state(thread);
62 if (!thread_state) {
63 continue;
64 }
65 printf("Thread \"%s\" is not responding in component \"%s\".\n",
66 lttng_health_thread_name(thread),
67 component_name);
dff9583f 68
dff9583f 69 }
6c71277b
MD
70 return status;
71}
dff9583f 72
6c71277b
MD
73static
74int check_sessiond(void)
75{
76 struct lttng_health *lh;
77 int status;
dff9583f 78
6c71277b
MD
79 lh = lttng_health_create_sessiond();
80 if (!lh) {
81 perror("lttng_health_create_sessiond");
82 return -1;
dff9583f
CB
83 }
84
26401f03 85 status = check_component(lh, "sessiond", 0);
6c71277b
MD
86
87 lttng_health_destroy(lh);
88
89 return status;
90}
91
92static
93int check_consumerd(enum lttng_health_consumerd hc)
94{
95 struct lttng_health *lh;
96 int status;
97 static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = {
98 "ust-consumerd-32",
99 "ust-consumerd-64",
100 "kernel-consumerd",
101 };
dff9583f 102
6c71277b
MD
103 lh = lttng_health_create_consumerd(hc);
104 if (!lh) {
105 perror("lttng_health_create_consumerd");
106 return -1;
dff9583f
CB
107 }
108
26401f03 109 status = check_component(lh, cnames[hc], 1);
6c71277b
MD
110
111 lttng_health_destroy(lh);
112
dff9583f
CB
113 return status;
114}
6c71277b 115
4d6fd696
MD
116static
117int check_relayd(const char *path)
118{
119 struct lttng_health *lh;
120 int status;
121
122 lh = lttng_health_create_relayd(path);
123 if (!lh) {
124 perror("lttng_health_create_relayd");
125 return -1;
126 }
127
26401f03 128 status = check_component(lh, "relayd", 0);
4d6fd696
MD
129
130 lttng_health_destroy(lh);
131
132 return status;
133}
6c71277b
MD
134
135int main(int argc, char *argv[])
136{
137 int status = 0, i;
138
4d6fd696 139 for (i = 1; i < argc; i++) {
bd38113f
MD
140 size_t relayd_path_arg_len = strlen("--relayd-path=");
141 if (!strncmp(argv[i], "--relayd-path=",
142 relayd_path_arg_len)) {
143 relayd_path = &argv[i][relayd_path_arg_len];
4d6fd696 144 } else {
bd38113f 145 fprintf(stderr, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv[i]);
4d6fd696
MD
146 exit(EXIT_FAILURE);
147 }
148 }
149
6c71277b
MD
150 status |= check_sessiond();
151 for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) {
152 status |= check_consumerd(i);
153 }
4d6fd696
MD
154 if (relayd_path) {
155 status |= check_relayd(relayd_path);
156 }
6c71277b
MD
157 if (!status) {
158 exit(EXIT_SUCCESS);
159 } else {
160 exit(EXIT_FAILURE);
161 }
162}
This page took 0.03807 seconds and 5 git commands to generate.