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