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