Add two basic tests for UST global domain
[lttng-tools.git] / tests / lttng / ust_global_event_basic.c
CommitLineData
69c0b621
DG
1/*
2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#define _GNU_SOURCE
20#include <assert.h>
21#include <errno.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <unistd.h>
26#include <time.h>
27
28#include <lttng/lttng.h>
29
30#include "../utils.h"
31
32int main(int argc, char **argv)
33{
34 struct lttng_handle *handle = NULL;
35 struct lttng_domain dom;
36 struct lttng_channel channel;
37 struct lttng_event ev1, ev2, ev3;
38
39 int ret = 0;
40
41 char *session_name = "ust_event_basic";
42
43 dom.type = LTTNG_DOMAIN_UST;
44
45 strcpy(channel.name, "mychan");
46 channel.attr.overwrite = 0;
47 channel.attr.subbuf_size = 4096;
48 channel.attr.num_subbuf = 4;
49 channel.attr.switch_timer_interval = 0;
50 channel.attr.read_timer_interval = 200;
51 channel.attr.output = LTTNG_EVENT_MMAP;
52
53 strcpy(ev1.name, "tp1");
54 ev1.type = LTTNG_EVENT_TRACEPOINT;
55
56 strcpy(ev2.name, "ev2");
57 ev2.type = LTTNG_EVENT_TRACEPOINT;
58
59 strcpy(ev3.name, "ev3");
60 ev3.type = LTTNG_EVENT_TRACEPOINT;
61
62 printf("\nTesting tracing UST events:\n");
63 printf("-----------\n");
64
65 if (argc < 2) {
66 printf("Missing session trace path\n");
67 return 1;
68 }
69
70 printf("Creating tracing session (%s): ", argv[1]);
71 if ((ret = lttng_create_session(session_name, argv[1])) < 0) {
72 printf("error creating the session : %s\n", lttng_strerror(ret));
73 goto create_fail;
74 }
75 PRINT_OK();
76
77 printf("Creating session handle: ");
78 if ((handle = lttng_create_handle(session_name, &dom)) == NULL) {
79 printf("error creating handle: %s\n", lttng_strerror(ret));
80 goto handle_fail;
81 }
82 PRINT_OK();
83
84 printf("Enabling %s UST channel: ", channel.name);
85 if ((ret = lttng_enable_channel(handle, &channel)) < 0) {
86 printf("error enable channel: %s\n", lttng_strerror(ret));
87 goto enable_fail;
88 }
89 PRINT_OK();
90
91 printf("Enabling %s UST event: ", ev1.name);
92 if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) {
93 printf("error enabling event: %s\n", lttng_strerror(ret));
94 goto enable_fail;
95 }
96 PRINT_OK();
97
98 printf("Enabling %s UST event: ", ev2.name);
99 if ((ret = lttng_enable_event(handle, &ev2, channel.name)) < 0) {
100 printf("error enabling event: %s\n", lttng_strerror(ret));
101 goto enable_fail;
102 }
103 PRINT_OK();
104
105 printf("Enabling %s UST event: ", ev3.name);
106 if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) {
107 printf("error enabling event: %s\n", lttng_strerror(ret));
108 goto enable_fail;
109 }
110 PRINT_OK();
111
112 printf("Disabling %s UST event: ", ev1.name);
113 if ((ret = lttng_disable_event(handle, ev1.name, channel.name)) < 0) {
114 printf("error enabling event: %s\n", lttng_strerror(ret));
115 goto enable_fail;
116 }
117 PRINT_OK();
118
119 printf("Disabling %s UST event: ", ev3.name);
120 if ((ret = lttng_disable_event(handle, ev3.name, channel.name)) < 0) {
121 printf("error enabling event: %s\n", lttng_strerror(ret));
122 goto enable_fail;
123 }
124 PRINT_OK();
125
126 printf("Renabling %s UST event: ", ev1.name);
127 if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) {
128 printf("error enabling event: %s\n", lttng_strerror(ret));
129 goto enable_fail;
130 }
131 PRINT_OK();
132
133 printf("Renabling %s UST event: ", ev3.name);
134 if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) {
135 printf("error enabling event: %s\n", lttng_strerror(ret));
136 goto enable_fail;
137 }
138 PRINT_OK();
139
140 printf("Start tracing: ");
141 if ((ret = lttng_start_tracing(session_name)) < 0) {
142 printf("error starting tracing: %s\n", lttng_strerror(ret));
143 goto start_fail;
144 }
145 PRINT_OK();
146
147 sleep(2);
148
149 printf("Stop tracing: ");
150 if ((ret = lttng_stop_tracing(session_name)) < 0) {
151 printf("error stopping tracing: %s\n", lttng_strerror(ret));
152 goto stop_fail;
153 }
154 PRINT_OK();
155
156 printf("Destroy tracing session: ");
157 if ((ret = lttng_destroy_session(session_name)) < 0) {
158 printf("error destroying session: %s\n", lttng_strerror(ret));
159 }
160 PRINT_OK();
161
162 return 0;
163
164create_fail:
165 assert(ret != 0);
166handle_fail:
167 assert(handle != NULL);
168
169stop_fail:
170start_fail:
171enable_fail:
172 lttng_destroy_session(session_name);
173 lttng_destroy_handle(handle);
174
175 return 1;
176}
This page took 0.041737 seconds and 4 git commands to generate.