2 * Copyright (c) 2013-2018, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
31 #include "pt_last_ip.h"
38 static struct ptunit_result init(void)
40 struct pt_last_ip last_ip;
42 memset(&last_ip, 0xcd, sizeof(last_ip));
44 pt_last_ip_init(&last_ip);
46 ptu_uint_eq(last_ip.ip, 0ull);
47 ptu_uint_eq(last_ip.have_ip, 0);
48 ptu_uint_eq(last_ip.suppressed, 0);
53 static struct ptunit_result init_null(void)
55 pt_last_ip_init(NULL);
60 static struct ptunit_result status_initial(void)
62 struct pt_last_ip last_ip;
65 pt_last_ip_init(&last_ip);
67 errcode = pt_last_ip_query(NULL, &last_ip);
68 ptu_int_eq(errcode, -pte_noip);
73 static struct ptunit_result status(void)
75 struct pt_last_ip last_ip;
79 last_ip.suppressed = 0;
81 errcode = pt_last_ip_query(NULL, &last_ip);
82 ptu_int_eq(errcode, 0);
87 static struct ptunit_result status_null(void)
91 errcode = pt_last_ip_query(NULL, NULL);
92 ptu_int_eq(errcode, -pte_internal);
97 static struct ptunit_result status_noip(void)
99 struct pt_last_ip last_ip;
103 last_ip.suppressed = 0;
105 errcode = pt_last_ip_query(NULL, &last_ip);
106 ptu_int_eq(errcode, -pte_noip);
111 static struct ptunit_result status_suppressed(void)
113 struct pt_last_ip last_ip;
117 last_ip.suppressed = 1;
119 errcode = pt_last_ip_query(NULL, &last_ip);
120 ptu_int_eq(errcode, -pte_ip_suppressed);
125 static struct ptunit_result query_initial(void)
127 struct pt_last_ip last_ip;
131 pt_last_ip_init(&last_ip);
133 errcode = pt_last_ip_query(&ip, &last_ip);
134 ptu_int_eq(errcode, -pte_noip);
139 static struct ptunit_result query(void)
141 struct pt_last_ip last_ip;
142 uint64_t ip, exp = 42ull;
147 last_ip.suppressed = 0;
149 errcode = pt_last_ip_query(&ip, &last_ip);
150 ptu_int_eq(errcode, 0);
151 ptu_uint_eq(last_ip.ip, exp);
156 static struct ptunit_result query_null(void)
161 errcode = pt_last_ip_query(&ip, NULL);
162 ptu_int_eq(errcode, -pte_internal);
163 ptu_uint_eq(ip, 13ull);
168 static struct ptunit_result query_noip(void)
170 struct pt_last_ip last_ip;
176 last_ip.suppressed = 0;
178 errcode = pt_last_ip_query(&ip, &last_ip);
179 ptu_int_eq(errcode, -pte_noip);
180 ptu_uint_eq(ip, 0ull);
185 static struct ptunit_result query_suppressed(void)
187 struct pt_last_ip last_ip;
193 last_ip.suppressed = 1;
195 errcode = pt_last_ip_query(&ip, &last_ip);
196 ptu_int_eq(errcode, -pte_ip_suppressed);
197 ptu_uint_eq(ip, 0ull);
202 static struct ptunit_result update_ip_suppressed(uint32_t have_ip)
204 struct pt_last_ip last_ip;
205 struct pt_packet_ip packet;
209 last_ip.have_ip = have_ip;
210 last_ip.suppressed = 0;
212 packet.ipc = pt_ipc_suppressed;
215 errcode = pt_last_ip_update_ip(&last_ip, &packet, NULL);
216 ptu_int_eq(errcode, 0);
217 ptu_uint_eq(last_ip.ip, 42ull);
218 ptu_uint_eq(last_ip.have_ip, have_ip);
219 ptu_uint_eq(last_ip.suppressed, 1);
224 static struct ptunit_result update_ip_upd16(uint32_t have_ip)
226 struct pt_last_ip last_ip;
227 struct pt_packet_ip packet;
230 last_ip.ip = 0xff0042ull;
231 last_ip.have_ip = have_ip;
232 last_ip.suppressed = 0;
234 packet.ipc = pt_ipc_update_16;
235 packet.ip = 0xccc013ull;
237 errcode = pt_last_ip_update_ip(&last_ip, &packet, NULL);
238 ptu_int_eq(errcode, 0);
239 ptu_uint_eq(last_ip.ip, 0xffc013ull);
240 ptu_uint_eq(last_ip.have_ip, 1);
241 ptu_uint_eq(last_ip.suppressed, 0);
246 static struct ptunit_result update_ip_upd32(uint32_t have_ip)
248 struct pt_last_ip last_ip;
249 struct pt_packet_ip packet;
252 last_ip.ip = 0xff00000420ull;
253 last_ip.have_ip = have_ip;
254 last_ip.suppressed = 0;
256 packet.ipc = pt_ipc_update_32;
257 packet.ip = 0xcc0000c013ull;
259 errcode = pt_last_ip_update_ip(&last_ip, &packet, NULL);
260 ptu_int_eq(errcode, 0);
261 ptu_uint_eq(last_ip.ip, 0xff0000c013ull);
262 ptu_uint_eq(last_ip.have_ip, 1);
263 ptu_uint_eq(last_ip.suppressed, 0);
268 static struct ptunit_result update_ip_sext48(uint32_t have_ip)
270 struct pt_last_ip last_ip;
271 struct pt_packet_ip packet;
274 last_ip.ip = 0x7fffffffffffffffull;
275 last_ip.have_ip = have_ip;
276 last_ip.suppressed = 0;
278 packet.ipc = pt_ipc_sext_48;
279 packet.ip = 0xff00000000ffull;
281 errcode = pt_last_ip_update_ip(&last_ip, &packet, NULL);
282 ptu_int_eq(errcode, 0);
283 ptu_uint_eq(last_ip.ip, 0xffffff00000000ffull);
284 ptu_uint_eq(last_ip.have_ip, 1);
285 ptu_uint_eq(last_ip.suppressed, 0);
290 static struct ptunit_result update_ip_bad_packet(uint32_t have_ip)
292 struct pt_last_ip last_ip;
293 struct pt_packet_ip packet;
296 last_ip.ip = 0x7fffffffffffffffull;
297 last_ip.have_ip = have_ip;
298 last_ip.suppressed = 0;
300 packet.ipc = (enum pt_ip_compression) 0xff;
303 errcode = pt_last_ip_update_ip(&last_ip, &packet, NULL);
304 ptu_int_eq(errcode, -pte_bad_packet);
305 ptu_uint_eq(last_ip.ip, 0x7fffffffffffffffull);
306 ptu_uint_eq(last_ip.have_ip, have_ip);
307 ptu_uint_eq(last_ip.suppressed, 0);
312 static struct ptunit_result update_ip_null_ip(void)
314 struct pt_packet_ip packet;
317 errcode = pt_last_ip_update_ip(NULL, &packet, NULL);
318 ptu_int_eq(errcode, -pte_internal);
323 static struct ptunit_result update_ip_null_packet(uint32_t have_ip)
325 struct pt_last_ip last_ip;
328 last_ip.ip = 0x7fffffffffffffffull;
329 last_ip.have_ip = have_ip;
330 last_ip.suppressed = 0;
332 errcode = pt_last_ip_update_ip(&last_ip, NULL, NULL);
333 ptu_int_eq(errcode, -pte_internal);
334 ptu_uint_eq(last_ip.ip, 0x7fffffffffffffffull);
335 ptu_uint_eq(last_ip.have_ip, have_ip);
336 ptu_uint_eq(last_ip.suppressed, 0);
341 int main(int argc, char **argv)
343 struct ptunit_suite suite;
345 suite = ptunit_mk_suite(argc, argv);
347 ptu_run(suite, init);
348 ptu_run(suite, init_null);
349 ptu_run(suite, status_initial);
350 ptu_run(suite, status);
351 ptu_run(suite, status_null);
352 ptu_run(suite, status_noip);
353 ptu_run(suite, status_suppressed);
354 ptu_run(suite, query_initial);
355 ptu_run(suite, query);
356 ptu_run(suite, query_null);
357 ptu_run(suite, query_noip);
358 ptu_run(suite, query_suppressed);
359 ptu_run_p(suite, update_ip_suppressed, 0);
360 ptu_run_p(suite, update_ip_suppressed, 1);
361 ptu_run_p(suite, update_ip_upd16, 0);
362 ptu_run_p(suite, update_ip_upd16, 1);
363 ptu_run_p(suite, update_ip_upd32, 0);
364 ptu_run_p(suite, update_ip_upd32, 1);
365 ptu_run_p(suite, update_ip_sext48, 0);
366 ptu_run_p(suite, update_ip_sext48, 1);
367 ptu_run_p(suite, update_ip_bad_packet, 0);
368 ptu_run_p(suite, update_ip_bad_packet, 1);
369 ptu_run(suite, update_ip_null_ip);
370 ptu_run_p(suite, update_ip_null_packet, 0);
371 ptu_run_p(suite, update_ip_null_packet, 1);
373 return ptunit_report(&suite);