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