libustctl: use direct socket communication
[ust.git] / tests / libustctl_function_tests / libustctl_function_tests.c
CommitLineData
48beefc9
NC
1/* Copyright (C) 2010 Nils Carlson
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
2298f329 18/* Simple function tests for ustctl */
48beefc9
NC
19
20#include <stdio.h>
21#include <unistd.h>
22#include <sys/types.h>
fbae86d6 23#include <sys/wait.h>
6678d7dd 24#include <errno.h>
48beefc9
NC
25
26#include <ust/marker.h>
2298f329 27#include <ust/ustctl.h>
48beefc9
NC
28
29#include "tap.h"
30
2298f329 31static void ustctl_function_tests(pid_t pid)
48beefc9 32{
8b26d56b 33 int result, sock;
48beefc9
NC
34 unsigned int subbuf_size, subbuf_num;
35 unsigned int new_subbuf_size, new_subbuf_num;
36 struct marker_status *marker_status, *ms_ptr;
37 char *old_socket_path, *new_socket_path;
38 char *tmp_ustd_socket = "/tmp/tmp_ustd_socket";
d89b8191 39 char *trace = "auto";
48beefc9
NC
40
41 printf("Connecting to pid %d\n", pid);
42
8b26d56b
NC
43 sock = ustctl_connect_pid(pid);
44 tap_ok(sock > 0, "ustctl_connect_pid");
45
48beefc9 46 /* marker status array functions */
8b26d56b 47 result = ustctl_get_cmsf(sock, &marker_status);
2298f329 48 tap_ok(!result, "ustctl_get_cmsf");
48beefc9
NC
49
50 result = 0;
51 for (ms_ptr = marker_status; ms_ptr->channel; ms_ptr++) {
52 if (!strcmp(ms_ptr->channel, "ust") &&
53 !strcmp(ms_ptr->marker, "bar")) {
54 result = 1;
55 }
56 }
57 tap_ok(result, "Found channel \"ust\", marker \"bar\"");
58
2298f329 59 tap_ok(!ustctl_free_cmsf(marker_status), "ustctl_free_cmsf");
48beefc9
NC
60
61 /* Get and set the socket path */
8b26d56b 62 tap_ok(!ustctl_get_sock_path(sock, &old_socket_path),
2298f329 63 "ustctl_get_sock_path");
48beefc9
NC
64
65 printf("Socket path: %s\n", old_socket_path);
66
8b26d56b 67 tap_ok(!ustctl_set_sock_path(sock, tmp_ustd_socket),
2298f329 68 "ustctl_set_sock_path - set a new path");
48beefc9 69
8b26d56b 70 tap_ok(!ustctl_get_sock_path(sock, &new_socket_path),
2298f329 71 "ustctl_get_sock_path - get the new path");
48beefc9
NC
72
73 tap_ok(!strcmp(new_socket_path, tmp_ustd_socket),
74 "Compare the set path and the retrieved path");
75
76 free(new_socket_path);
77
8b26d56b 78 tap_ok(!ustctl_set_sock_path(sock, old_socket_path),
48beefc9
NC
79 "Reset the socket path");
80
81 free(old_socket_path);
82
83 /* Enable, disable markers */
8b26d56b 84 tap_ok(!ustctl_set_marker_state(sock, trace, "ust", "bar", 1),
2298f329 85 "ustctl_set_marker_state - existing marker ust bar");
48beefc9
NC
86
87 /* Create and allocate a trace */
8b26d56b 88 tap_ok(!ustctl_create_trace(sock, trace), "ustctl_create_trace");
48beefc9 89
8b26d56b 90 tap_ok(!ustctl_alloc_trace(sock, trace), "ustctl_alloc_trace");
48beefc9
NC
91
92 /* Get subbuf size and number */
8b26d56b 93 subbuf_num = ustctl_get_subbuf_num(sock, trace, "ust");
2298f329 94 tap_ok(subbuf_num > 0, "ustctl_get_subbuf_num - %d sub-buffers",
48beefc9
NC
95 subbuf_num);
96
8b26d56b 97 subbuf_size = ustctl_get_subbuf_size(sock, trace, "ust");
2298f329 98 tap_ok(subbuf_size, "ustctl_get_subbuf_size - sub-buffer size is %d",
48beefc9
NC
99 subbuf_size);
100
101 /* Start the trace */
8b26d56b 102 tap_ok(!ustctl_start_trace(sock, trace), "ustctl_start_trace");
48beefc9
NC
103
104
105 /* Stop the trace and destroy it*/
8b26d56b 106 tap_ok(!ustctl_stop_trace(sock, trace), "ustctl_stop_trace");
48beefc9 107
8b26d56b 108 tap_ok(!ustctl_destroy_trace(sock, trace), "ustctl_destroy_trace");
48beefc9
NC
109
110 /* Create a new trace */
8b26d56b 111 tap_ok(!ustctl_create_trace(sock, trace), "ustctl_create_trace - create a new trace");
48beefc9
NC
112
113 printf("Setting new subbufer number and sizes (doubling)\n");
114 new_subbuf_num = 2 * subbuf_num;
115 new_subbuf_size = 2 * subbuf_size;
116
8b26d56b 117 tap_ok(!ustctl_set_subbuf_num(sock, trace, "ust", new_subbuf_num),
2298f329 118 "ustctl_set_subbuf_num");
48beefc9 119
8b26d56b 120 tap_ok(!ustctl_set_subbuf_size(sock, trace, "ust", new_subbuf_size),
2298f329 121 "ustctl_set_subbuf_size");
48beefc9
NC
122
123
124 /* Allocate the new trace */
8b26d56b 125 tap_ok(!ustctl_alloc_trace(sock, trace), "ustctl_alloc_trace - allocate the new trace");
48beefc9
NC
126
127
128 /* Get subbuf size and number and compare with what was set */
8b26d56b 129 subbuf_num = ustctl_get_subbuf_num(sock, trace, "ust");
48beefc9 130
8b26d56b 131 subbuf_size = ustctl_get_subbuf_size(sock, trace, "ust");
48beefc9
NC
132
133 tap_ok(subbuf_num == new_subbuf_num, "Set a new subbuf number, %d == %d",
134 subbuf_num, new_subbuf_num);
135
136
8b26d56b 137 result = ustctl_get_subbuf_size(sock, trace, "ust");
48beefc9
NC
138 tap_ok(subbuf_size == new_subbuf_size, "Set a new subbuf size, %d == %d",
139 subbuf_size, new_subbuf_size);
140
8b26d56b 141 tap_ok(!ustctl_destroy_trace(sock, trace), "ustctl_destroy_trace - without ever starting");
48beefc9 142
bc549f16
NC
143 /*
144 * Activate a non-existent marker, this should be possible as the marker
145 * can be loaded at a later time.
146 */
8b26d56b 147 tap_ok(ustctl_set_marker_state(sock, trace, "ustl", "blar", 1) == 0,
6678d7dd 148 "Enable non-existent marker ustl blar");
48beefc9
NC
149
150 printf("##### Tests that definetly should work are completed #####\n");
151 printf("############## Start expected failure cases ##############\n");
152
8b26d56b 153 tap_ok(ustctl_set_marker_state(sock, trace, "ust","bar", 1),
48beefc9 154 "Enable already enabled marker ust/bar");
8b26d56b 155
bc549f16 156 tap_ok(EEXIST == errno,
6678d7dd 157 "Right error code for enabling an already enabled marker");
48beefc9 158
8b26d56b 159 tap_ok(ustctl_start_trace(sock, trace),
48beefc9
NC
160 "Start a non-existent trace");
161
8b26d56b 162 tap_ok(ustctl_destroy_trace(sock, trace),
48beefc9
NC
163 "Destroy non-existent trace");
164
165 exit(tap_status() ? EXIT_FAILURE : EXIT_SUCCESS);
166
167}
168
fbae86d6 169int main(int argc, char **argv)
48beefc9 170{
fbae86d6 171 int i, status;
48beefc9 172 pid_t parent_pid, child_pid;
48beefc9 173
8b26d56b 174 tap_plan(29);
48beefc9 175
2298f329 176 printf("Function tests for ustctl\n");
48beefc9
NC
177
178 parent_pid = getpid();
179 child_pid = fork();
180 if (child_pid) {
181 for(i=0; i<10; i++) {
182 trace_mark(ust, bar, "str %s", "FOOBAZ");
183 trace_mark(ust, bar2, "number1 %d number2 %d", 53, 9800);
184 usleep(100000);
185 }
186
187 wait(&status);
188 } else {
2298f329 189 ustctl_function_tests(parent_pid);
48beefc9
NC
190 }
191
192 exit(status ? EXIT_FAILURE : EXIT_SUCCESS);
193}
This page took 0.033529 seconds and 4 git commands to generate.