API change for lttng_get_readeable_code
[deliverable/lttng-tools.git] / tests / lttng / kernel_all_events_basic.c
CommitLineData
e3fa263d
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;
8c9ae521 36 struct lttng_event event;
d04f4d75 37 char *channel_name = "channel0";
e3fa263d
DG
38 int ret = 0;
39
40 dom.type = LTTNG_DOMAIN_KERNEL;
41
8c9ae521
DG
42 memset(&event, 0, sizeof(struct lttng_event));
43 event.type = LTTNG_EVENT_TRACEPOINT;
44
c60ddab6 45 printf("\nTesting tracing all kernel events:\n");
e3fa263d
DG
46 printf("-----------\n");
47 /* Check if root */
48 if (getuid() != 0) {
49 printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n");
50 return 0;
51 }
52
53 if (argc < 2) {
54 printf("Missing session trace path\n");
55 return 1;
56 }
57
58 printf("Creating tracing session (%s): ", argv[1]);
59 if ((ret = lttng_create_session("test", argv[1])) < 0) {
9a745bc7 60 printf("error creating the session : %s\n", lttng_strerror(ret));
e3fa263d
DG
61 goto create_fail;
62 }
63 PRINT_OK();
64
65 printf("Creating session handle: ");
66 if ((handle = lttng_create_handle("test", &dom)) == NULL) {
9a745bc7 67 printf("error creating handle: %s\n", lttng_strerror(ret));
e3fa263d
DG
68 goto handle_fail;
69 }
70 PRINT_OK();
71
72 printf("Enabling all kernel events: ");
8c9ae521 73 if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) {
9a745bc7 74 printf("error enabling event: %s\n", lttng_strerror(ret));
e3fa263d
DG
75 goto enable_fail;
76 }
77 PRINT_OK();
78
79 printf("Start tracing: ");
80 if ((ret = lttng_start_tracing(handle)) < 0) {
9a745bc7 81 printf("error starting tracing: %s\n", lttng_strerror(ret));
e3fa263d
DG
82 goto start_fail;
83 }
84 PRINT_OK();
85
86 sleep(2);
87
88 printf("Stop tracing: ");
89 if ((ret = lttng_stop_tracing(handle)) < 0) {
9a745bc7 90 printf("error stopping tracing: %s\n", lttng_strerror(ret));
e3fa263d
DG
91 goto stop_fail;
92 }
93 PRINT_OK();
94
95 printf("Destroy tracing session: ");
96 if ((ret = lttng_destroy_session(handle)) < 0) {
9a745bc7 97 printf("error destroying session: %s\n", lttng_strerror(ret));
e3fa263d
DG
98 }
99 PRINT_OK();
100
101 return 0;
102
103create_fail:
104 assert(ret != 0);
105handle_fail:
106 assert(handle != NULL);
107
108stop_fail:
109start_fail:
110enable_fail:
111 lttng_destroy_session(handle);
112 lttng_destroy_handle(handle);
113
114 return 1;
115}
This page took 0.030542 seconds and 5 git commands to generate.