1 /* Copyright (C) 2010 Nils Carlson
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.
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.
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
18 /* Simple function tests for ustcmd */
22 #include <sys/types.h>
24 #include <ust/marker.h>
25 #include <ust/ustcmd.h>
29 static void ustcmd_function_tests(pid_t pid
)
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";
38 printf("Connecting to pid %d\n", pid
);
40 /* marker status array functions */
41 result
= ustcmd_get_cmsf(&marker_status
, pid
);
42 tap_ok(!result
, "ustcmd_get_cmsf");
45 for (ms_ptr
= marker_status
; ms_ptr
->channel
; ms_ptr
++) {
46 if (!strcmp(ms_ptr
->channel
, "ust") &&
47 !strcmp(ms_ptr
->marker
, "bar")) {
51 tap_ok(result
, "Found channel \"ust\", marker \"bar\"");
53 tap_ok(!ustcmd_free_cmsf(marker_status
), "ustcmd_free_cmsf");
55 /* Get and set the socket path */
56 tap_ok(!ustcmd_get_sock_path(&old_socket_path
, pid
),
57 "ustcmd_get_sock_path");
59 printf("Socket path: %s\n", old_socket_path
);
61 tap_ok(!ustcmd_set_sock_path(tmp_ustd_socket
, pid
),
62 "ustcmd_set_sock_path - set a new path");
64 tap_ok(!ustcmd_get_sock_path(&new_socket_path
, pid
),
65 "ustcmd_get_sock_path - get the new path");
67 tap_ok(!strcmp(new_socket_path
, tmp_ustd_socket
),
68 "Compare the set path and the retrieved path");
70 free(new_socket_path
);
72 tap_ok(!ustcmd_set_sock_path(old_socket_path
, pid
),
73 "Reset the socket path");
75 free(old_socket_path
);
77 /* Enable, disable markers */
78 tap_ok(!ustcmd_set_marker_state("ust", "bar", 1, pid
),
79 "ustcmd_set_marker_state - existing marker ust bar");
81 /* Create and allocate a trace */
82 tap_ok(!ustcmd_create_trace(pid
), "ustcmd_create_trace");
84 tap_ok(!ustcmd_alloc_trace(pid
), "ustcmd_alloc_trace");
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",
91 subbuf_size
= ustcmd_get_subbuf_size("ust", pid
);
92 tap_ok(subbuf_size
, "ustcmd_get_subbuf_size - sub-buffer size is %d",
96 tap_ok(!ustcmd_start_trace(pid
), "ustcmd_start_trace");
99 /* Stop the trace and destroy it*/
100 tap_ok(!ustcmd_stop_trace(pid
), "ustcmd_stop_trace");
102 tap_ok(!ustcmd_destroy_trace(pid
), "ustcmd_destroy_trace");
104 /* Create a new trace */
105 tap_ok(!ustcmd_create_trace(pid
), "ustcmd_create_trace - create a new trace");
107 printf("Setting new subbufer number and sizes (doubling)\n");
108 new_subbuf_num
= 2 * subbuf_num
;
109 new_subbuf_size
= 2 * subbuf_size
;
111 tap_ok(!ustcmd_set_subbuf_num("ust", new_subbuf_num
, pid
),
112 "ustcmd_set_subbuf_num");
114 tap_ok(!ustcmd_set_subbuf_size("ust", new_subbuf_size
, pid
),
115 "ustcmd_set_subbuf_size");
118 /* Allocate the new trace */
119 tap_ok(!ustcmd_alloc_trace(pid
), "ustcmd_alloc_trace - allocate the new trace");
122 /* Get subbuf size and number and compare with what was set */
123 subbuf_num
= ustcmd_get_subbuf_num("ust", pid
);
125 subbuf_size
= ustcmd_get_subbuf_size("ust", pid
);
127 tap_ok(subbuf_num
== new_subbuf_num
, "Set a new subbuf number, %d == %d",
128 subbuf_num
, new_subbuf_num
);
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
);
135 tap_ok(!ustcmd_destroy_trace(pid
), "ustcmd_destroy_trace - without ever starting");
138 printf("##### Tests that definetly should work are completed #####\n");
139 printf("############## Start expected failure cases ##############\n");
141 tap_ok(ustcmd_set_marker_state("ust","bar", 1, pid
),
142 "Enable already enabled marker ust/bar");
144 tap_ok(ustcmd_set_marker_state("ustl", "blar", 1, pid
),
145 "Enable non-existent marker ustl blar");
147 tap_ok(ustcmd_start_trace(pid
),
148 "Start a non-existent trace");
150 tap_ok(ustcmd_destroy_trace(pid
),
151 "Destroy non-existent trace");
153 exit(tap_status() ? EXIT_FAILURE
: EXIT_SUCCESS
);
160 int i
, status
, pipefd
[2];
161 pid_t parent_pid
, child_pid
;
166 printf("Function tests for ustcmd\n");
168 parent_pid
= getpid();
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);
179 ustcmd_function_tests(parent_pid
);
182 exit(status
? EXIT_FAILURE
: EXIT_SUCCESS
);
This page took 0.033318 seconds and 4 git commands to generate.