Add missing string.h include in libustctl_function_tests
[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>
1c330d13 25#include <string.h>
48beefc9
NC
26
27#include <ust/marker.h>
2298f329 28#include <ust/ustctl.h>
48beefc9
NC
29
30#include "tap.h"
31
2298f329 32static void ustctl_function_tests(pid_t pid)
48beefc9 33{
8b26d56b 34 int result, sock;
48beefc9
NC
35 unsigned int subbuf_size, subbuf_num;
36 unsigned int new_subbuf_size, new_subbuf_num;
b521931e 37 struct ust_marker_status *marker_status, *ms_ptr;
48beefc9
NC
38 char *old_socket_path, *new_socket_path;
39 char *tmp_ustd_socket = "/tmp/tmp_ustd_socket";
d89b8191 40 char *trace = "auto";
48beefc9
NC
41
42 printf("Connecting to pid %d\n", pid);
43
8b26d56b
NC
44 sock = ustctl_connect_pid(pid);
45 tap_ok(sock > 0, "ustctl_connect_pid");
46
48beefc9 47 /* marker status array functions */
8b26d56b 48 result = ustctl_get_cmsf(sock, &marker_status);
2298f329 49 tap_ok(!result, "ustctl_get_cmsf");
48beefc9
NC
50
51 result = 0;
52 for (ms_ptr = marker_status; ms_ptr->channel; ms_ptr++) {
53 if (!strcmp(ms_ptr->channel, "ust") &&
b521931e 54 !strcmp(ms_ptr->ust_marker, "bar")) {
48beefc9
NC
55 result = 1;
56 }
57 }
58 tap_ok(result, "Found channel \"ust\", marker \"bar\"");
59
2298f329 60 tap_ok(!ustctl_free_cmsf(marker_status), "ustctl_free_cmsf");
48beefc9
NC
61
62 /* Get and set the socket path */
8b26d56b 63 tap_ok(!ustctl_get_sock_path(sock, &old_socket_path),
2298f329 64 "ustctl_get_sock_path");
48beefc9
NC
65
66 printf("Socket path: %s\n", old_socket_path);
67
8b26d56b 68 tap_ok(!ustctl_set_sock_path(sock, tmp_ustd_socket),
2298f329 69 "ustctl_set_sock_path - set a new path");
48beefc9 70
8b26d56b 71 tap_ok(!ustctl_get_sock_path(sock, &new_socket_path),
2298f329 72 "ustctl_get_sock_path - get the new path");
48beefc9
NC
73
74 tap_ok(!strcmp(new_socket_path, tmp_ustd_socket),
75 "Compare the set path and the retrieved path");
76
77 free(new_socket_path);
78
8b26d56b 79 tap_ok(!ustctl_set_sock_path(sock, old_socket_path),
48beefc9
NC
80 "Reset the socket path");
81
82 free(old_socket_path);
83
84 /* Enable, disable markers */
b521931e
MD
85 tap_ok(!ustctl_set_ust_marker_state(sock, trace, "ust", "bar", 1),
86 "ustctl_set_ust_marker_state - existing marker ust bar");
48beefc9
NC
87
88 /* Create and allocate a trace */
8b26d56b 89 tap_ok(!ustctl_create_trace(sock, trace), "ustctl_create_trace");
48beefc9 90
8b26d56b 91 tap_ok(!ustctl_alloc_trace(sock, trace), "ustctl_alloc_trace");
48beefc9
NC
92
93 /* Get subbuf size and number */
8b26d56b 94 subbuf_num = ustctl_get_subbuf_num(sock, trace, "ust");
2298f329 95 tap_ok(subbuf_num > 0, "ustctl_get_subbuf_num - %d sub-buffers",
48beefc9
NC
96 subbuf_num);
97
8b26d56b 98 subbuf_size = ustctl_get_subbuf_size(sock, trace, "ust");
2298f329 99 tap_ok(subbuf_size, "ustctl_get_subbuf_size - sub-buffer size is %d",
48beefc9
NC
100 subbuf_size);
101
102 /* Start the trace */
8b26d56b 103 tap_ok(!ustctl_start_trace(sock, trace), "ustctl_start_trace");
48beefc9
NC
104
105
106 /* Stop the trace and destroy it*/
8b26d56b 107 tap_ok(!ustctl_stop_trace(sock, trace), "ustctl_stop_trace");
48beefc9 108
8b26d56b 109 tap_ok(!ustctl_destroy_trace(sock, trace), "ustctl_destroy_trace");
48beefc9
NC
110
111 /* Create a new trace */
8b26d56b 112 tap_ok(!ustctl_create_trace(sock, trace), "ustctl_create_trace - create a new trace");
48beefc9
NC
113
114 printf("Setting new subbufer number and sizes (doubling)\n");
115 new_subbuf_num = 2 * subbuf_num;
116 new_subbuf_size = 2 * subbuf_size;
117
8b26d56b 118 tap_ok(!ustctl_set_subbuf_num(sock, trace, "ust", new_subbuf_num),
2298f329 119 "ustctl_set_subbuf_num");
48beefc9 120
8b26d56b 121 tap_ok(!ustctl_set_subbuf_size(sock, trace, "ust", new_subbuf_size),
2298f329 122 "ustctl_set_subbuf_size");
48beefc9
NC
123
124
125 /* Allocate the new trace */
8b26d56b 126 tap_ok(!ustctl_alloc_trace(sock, trace), "ustctl_alloc_trace - allocate the new trace");
48beefc9
NC
127
128
129 /* Get subbuf size and number and compare with what was set */
8b26d56b 130 subbuf_num = ustctl_get_subbuf_num(sock, trace, "ust");
48beefc9 131
8b26d56b 132 subbuf_size = ustctl_get_subbuf_size(sock, trace, "ust");
48beefc9
NC
133
134 tap_ok(subbuf_num == new_subbuf_num, "Set a new subbuf number, %d == %d",
135 subbuf_num, new_subbuf_num);
136
137
8b26d56b 138 result = ustctl_get_subbuf_size(sock, trace, "ust");
48beefc9
NC
139 tap_ok(subbuf_size == new_subbuf_size, "Set a new subbuf size, %d == %d",
140 subbuf_size, new_subbuf_size);
141
8b26d56b 142 tap_ok(!ustctl_destroy_trace(sock, trace), "ustctl_destroy_trace - without ever starting");
48beefc9 143
bc549f16
NC
144 /*
145 * Activate a non-existent marker, this should be possible as the marker
146 * can be loaded at a later time.
147 */
b521931e 148 tap_ok(ustctl_set_ust_marker_state(sock, trace, "ustl", "blar", 1) == 0,
6678d7dd 149 "Enable non-existent marker ustl blar");
48beefc9
NC
150
151 printf("##### Tests that definetly should work are completed #####\n");
152 printf("############## Start expected failure cases ##############\n");
153
b521931e 154 tap_ok(ustctl_set_ust_marker_state(sock, trace, "ust","bar", 1),
48beefc9 155 "Enable already enabled marker ust/bar");
8b26d56b 156
bc549f16 157 tap_ok(EEXIST == errno,
6678d7dd 158 "Right error code for enabling an already enabled marker");
48beefc9 159
8b26d56b 160 tap_ok(ustctl_start_trace(sock, trace),
48beefc9
NC
161 "Start a non-existent trace");
162
8b26d56b 163 tap_ok(ustctl_destroy_trace(sock, trace),
48beefc9
NC
164 "Destroy non-existent trace");
165
166 exit(tap_status() ? EXIT_FAILURE : EXIT_SUCCESS);
167
168}
169
fbae86d6 170int main(int argc, char **argv)
48beefc9 171{
fbae86d6 172 int i, status;
48beefc9 173 pid_t parent_pid, child_pid;
48beefc9 174
8b26d56b 175 tap_plan(29);
48beefc9 176
2298f329 177 printf("Function tests for ustctl\n");
48beefc9
NC
178
179 parent_pid = getpid();
180 child_pid = fork();
181 if (child_pid) {
182 for(i=0; i<10; i++) {
686debc3
MD
183 ust_marker(bar, "str %s", "FOOBAZ");
184 ust_marker(bar2, "number1 %d number2 %d", 53, 9800);
48beefc9
NC
185 usleep(100000);
186 }
187
188 wait(&status);
189 } else {
2298f329 190 ustctl_function_tests(parent_pid);
48beefc9
NC
191 }
192
193 exit(status ? EXIT_FAILURE : EXIT_SUCCESS);
194}
This page took 0.035677 seconds and 4 git commands to generate.