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