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
18 #include <common/payload-view.h>
19 #include <common/payload.h>
20 #include <lttng/kernel-probe-internal.h>
21 #include <lttng/kernel-probe.h>
24 int lttng_opt_quiet
= 1;
25 int lttng_opt_verbose
;
30 static void test_kernel_probe_location_address(void)
32 struct lttng_kernel_probe_location
*location
= NULL
;
33 struct lttng_kernel_probe_location
*location_from_buffer
= NULL
;
34 enum lttng_kernel_probe_location_status status
;
35 enum lttng_kernel_probe_location_type type
;
36 uint64_t address
= 50, _address
;
37 struct lttng_payload payload
;
39 diag("Testing kernel probe location address");
41 lttng_payload_init(&payload
);
43 location
= lttng_kernel_probe_location_address_create(address
);
44 ok(location
, "Location object");
46 type
= lttng_kernel_probe_location_get_type(location
);
47 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
== type
,
48 "Location type got %d expected %d", type
,
49 LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
);
51 status
= lttng_kernel_probe_location_address_get_address(
53 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting address");
54 ok(address
== _address
,
55 "Address is equal. Got %" PRIu64
" expected %" PRIu64
,
58 ok(lttng_kernel_probe_location_serialize(location
, &payload
) > 0,
61 struct lttng_payload_view view
=
62 lttng_payload_view_from_payload(
64 ok(lttng_kernel_probe_location_create_from_payload(
65 &view
, &location_from_buffer
) > 0,
69 type
= lttng_kernel_probe_location_get_type(location_from_buffer
);
70 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
== type
,
71 "Location from buffer type got %d expected %d", type
,
72 LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
);
74 status
= lttng_kernel_probe_location_address_get_address(
75 location_from_buffer
, &_address
);
76 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting address");
77 ok(address
== _address
,
78 "Address from buffer is equal. Got %" PRIu64
82 ok(lttng_kernel_probe_location_is_equal(location
, location_from_buffer
),
83 "serialized and from buffer are equal");
85 lttng_payload_reset(&payload
);
86 lttng_kernel_probe_location_destroy(location
);
87 lttng_kernel_probe_location_destroy(location_from_buffer
);
90 static void test_kernel_probe_location_symbol(void)
92 struct lttng_kernel_probe_location
*location
= NULL
;
93 struct lttng_kernel_probe_location
*location_from_buffer
= NULL
;
94 enum lttng_kernel_probe_location_status status
;
95 enum lttng_kernel_probe_location_type type
;
96 uint64_t offset
= 50, _offset
;
97 const char *symbol
= "Une_bonne", *_symbol
;
98 struct lttng_payload payload
;
100 diag("Testing kernel probe location symbol");
102 lttng_payload_init(&payload
);
104 location
= lttng_kernel_probe_location_symbol_create(symbol
, offset
);
105 ok(location
, "Location object");
107 type
= lttng_kernel_probe_location_get_type(location
);
108 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
== type
,
109 "Location type got %d expected %d", type
,
110 LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
);
112 _symbol
= lttng_kernel_probe_location_symbol_get_name(location
);
113 ok(_symbol
, "Getting symbol name");
114 ok(!strncmp(symbol
, _symbol
, strlen(symbol
)),
115 "Symbol name is equal. Got %s, expected %s", _symbol
,
118 status
= lttng_kernel_probe_location_symbol_get_offset(
120 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting offset");
121 ok(offset
== _offset
,
122 "Offset is equal. Got %" PRIu64
" expected %" PRIu64
,
125 ok(lttng_kernel_probe_location_serialize(location
, &payload
) > 0,
128 struct lttng_payload_view view
=
129 lttng_payload_view_from_payload(
131 ok(lttng_kernel_probe_location_create_from_payload(
132 &view
, &location_from_buffer
) > 0,
136 type
= lttng_kernel_probe_location_get_type(location_from_buffer
);
137 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
== type
,
138 "Location from buffer type got %d expected %d", type
,
139 LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
);
141 _symbol
= lttng_kernel_probe_location_symbol_get_name(
142 location_from_buffer
);
143 ok(_symbol
, "Getting symbol name");
144 ok(!strncmp(symbol
, _symbol
, strlen(symbol
)),
145 "Symbol name is equal. Got %s, expected %s", _symbol
,
148 status
= lttng_kernel_probe_location_symbol_get_offset(
149 location_from_buffer
, &_offset
);
150 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting offset");
151 ok(offset
== _offset
,
152 "Offset is equal. Got %" PRIu64
" expected %" PRIu64
,
155 ok(lttng_kernel_probe_location_is_equal(location
, location_from_buffer
),
156 "serialized and from buffer are equal");
158 lttng_payload_reset(&payload
);
159 lttng_kernel_probe_location_destroy(location
);
160 lttng_kernel_probe_location_destroy(location_from_buffer
);
163 int main(int argc
, const char *argv
[])
165 plan_tests(NUM_TESTS
);
166 test_kernel_probe_location_address();
167 test_kernel_probe_location_symbol();
168 return exit_status();