2 * Unit tests for the kernel probe location API.
4 * Copyright (C) 2020 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
6 * SPDX-License-Identifier: LGPL-2.1-only
10 #include <common/payload-view.hpp>
11 #include <common/payload.hpp>
13 #include <lttng/kernel-probe-internal.hpp>
14 #include <lttng/kernel-probe.h>
23 int lttng_opt_quiet
= 1;
24 int lttng_opt_verbose
;
29 static void test_kernel_probe_location_address()
31 struct lttng_kernel_probe_location
*location
= nullptr;
32 struct lttng_kernel_probe_location
*location_from_buffer
= nullptr;
33 enum lttng_kernel_probe_location_status status
;
34 enum lttng_kernel_probe_location_type type
;
35 uint64_t address
= 50, _address
;
36 struct lttng_payload payload
;
38 diag("Testing kernel probe location address");
40 lttng_payload_init(&payload
);
42 location
= lttng_kernel_probe_location_address_create(address
);
43 ok(location
, "Location object");
45 type
= lttng_kernel_probe_location_get_type(location
);
46 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
== type
,
47 "Location type got %d expected %d",
49 LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
);
51 status
= lttng_kernel_probe_location_address_get_address(location
, &_address
);
52 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting address");
53 ok(address
== _address
,
54 "Address is equal. Got %" PRIu64
" expected %" PRIu64
,
58 ok(lttng_kernel_probe_location_serialize(location
, &payload
) > 0, "Serializing");
60 struct lttng_payload_view view
= lttng_payload_view_from_payload(&payload
, 0, -1);
61 ok(lttng_kernel_probe_location_create_from_payload(&view
, &location_from_buffer
) >
66 type
= lttng_kernel_probe_location_get_type(location_from_buffer
);
67 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
== type
,
68 "Location from buffer type got %d expected %d",
70 LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
);
72 status
= lttng_kernel_probe_location_address_get_address(location_from_buffer
, &_address
);
73 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting address");
74 ok(address
== _address
,
75 "Address from buffer is equal. Got %" PRIu64
" expected %" PRIu64
,
79 ok(lttng_kernel_probe_location_is_equal(location
, location_from_buffer
),
80 "serialized and from buffer are equal");
82 lttng_payload_reset(&payload
);
83 lttng_kernel_probe_location_destroy(location
);
84 lttng_kernel_probe_location_destroy(location_from_buffer
);
87 static void test_kernel_probe_location_symbol()
89 struct lttng_kernel_probe_location
*location
= nullptr;
90 struct lttng_kernel_probe_location
*location_from_buffer
= nullptr;
91 enum lttng_kernel_probe_location_status status
;
92 enum lttng_kernel_probe_location_type type
;
93 uint64_t offset
= 50, _offset
;
94 const char *symbol
= "Une_bonne", *_symbol
;
95 struct lttng_payload payload
;
97 diag("Testing kernel probe location symbol");
99 lttng_payload_init(&payload
);
101 location
= lttng_kernel_probe_location_symbol_create(symbol
, offset
);
102 ok(location
, "Location object");
104 type
= lttng_kernel_probe_location_get_type(location
);
105 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
== type
,
106 "Location type got %d expected %d",
108 LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
);
110 _symbol
= lttng_kernel_probe_location_symbol_get_name(location
);
111 ok(_symbol
, "Getting symbol name");
112 ok(!strncmp(symbol
, _symbol
, strlen(symbol
)),
113 "Symbol name is equal. Got %s, expected %s",
117 status
= lttng_kernel_probe_location_symbol_get_offset(location
, &_offset
);
118 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting offset");
119 ok(offset
== _offset
, "Offset is equal. Got %" PRIu64
" expected %" PRIu64
, _offset
, offset
);
121 ok(lttng_kernel_probe_location_serialize(location
, &payload
) > 0, "Serializing");
123 struct lttng_payload_view view
= lttng_payload_view_from_payload(&payload
, 0, -1);
124 ok(lttng_kernel_probe_location_create_from_payload(&view
, &location_from_buffer
) >
129 type
= lttng_kernel_probe_location_get_type(location_from_buffer
);
130 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
== type
,
131 "Location from buffer type got %d expected %d",
133 LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
);
135 _symbol
= lttng_kernel_probe_location_symbol_get_name(location_from_buffer
);
136 ok(_symbol
, "Getting symbol name");
137 ok(!strncmp(symbol
, _symbol
, strlen(symbol
)),
138 "Symbol name is equal. Got %s, expected %s",
142 status
= lttng_kernel_probe_location_symbol_get_offset(location_from_buffer
, &_offset
);
143 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting offset");
144 ok(offset
== _offset
, "Offset is equal. Got %" PRIu64
" expected %" PRIu64
, _offset
, offset
);
146 ok(lttng_kernel_probe_location_is_equal(location
, location_from_buffer
),
147 "serialized and from buffer are equal");
149 lttng_payload_reset(&payload
);
150 lttng_kernel_probe_location_destroy(location
);
151 lttng_kernel_probe_location_destroy(location_from_buffer
);
156 plan_tests(NUM_TESTS
);
157 test_kernel_probe_location_address();
158 test_kernel_probe_location_symbol();
159 return exit_status();