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
17 #include <common/payload-view.h>
18 #include <common/payload.h>
19 #include <lttng/kernel-probe-internal.h>
20 #include <lttng/kernel-probe.h>
23 int lttng_opt_quiet
= 1;
24 int lttng_opt_verbose
;
29 static void test_kernel_probe_location_address(void)
31 struct lttng_kernel_probe_location
*location
= NULL
;
32 struct lttng_kernel_probe_location
*location_from_buffer
= NULL
;
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", type
,
48 LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
);
50 status
= lttng_kernel_probe_location_address_get_address(
52 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting address");
53 ok(address
== _address
,
54 "Address is equal. Got %" PRIu64
" expected %" PRIu64
,
57 ok(lttng_kernel_probe_location_serialize(location
, &payload
) > 0,
60 struct lttng_payload_view view
=
61 lttng_payload_view_from_payload(
63 ok(lttng_kernel_probe_location_create_from_payload(
64 &view
, &location_from_buffer
) > 0,
68 type
= lttng_kernel_probe_location_get_type(location_from_buffer
);
69 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
== type
,
70 "Location from buffer type got %d expected %d", type
,
71 LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
);
73 status
= lttng_kernel_probe_location_address_get_address(
74 location_from_buffer
, &_address
);
75 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting address");
76 ok(address
== _address
,
77 "Address from buffer is equal. Got %" PRIu64
81 ok(lttng_kernel_probe_location_is_equal(location
, location_from_buffer
),
82 "serialized and from buffer are equal");
84 lttng_payload_reset(&payload
);
85 lttng_kernel_probe_location_destroy(location
);
86 lttng_kernel_probe_location_destroy(location_from_buffer
);
89 static void test_kernel_probe_location_symbol(void)
91 struct lttng_kernel_probe_location
*location
= NULL
;
92 struct lttng_kernel_probe_location
*location_from_buffer
= NULL
;
93 enum lttng_kernel_probe_location_status status
;
94 enum lttng_kernel_probe_location_type type
;
95 uint64_t offset
= 50, _offset
;
96 const char *symbol
= "Une_bonne", *_symbol
;
97 struct lttng_payload payload
;
99 diag("Testing kernel probe location symbol");
101 lttng_payload_init(&payload
);
103 location
= lttng_kernel_probe_location_symbol_create(symbol
, offset
);
104 ok(location
, "Location object");
106 type
= lttng_kernel_probe_location_get_type(location
);
107 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
== type
,
108 "Location type got %d expected %d", type
,
109 LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
);
111 _symbol
= lttng_kernel_probe_location_symbol_get_name(location
);
112 ok(_symbol
, "Getting symbol name");
113 ok(!strncmp(symbol
, _symbol
, strlen(symbol
)),
114 "Symbol name is equal. Got %s, expected %s", _symbol
,
117 status
= lttng_kernel_probe_location_symbol_get_offset(
119 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting offset");
120 ok(offset
== _offset
,
121 "Offset is equal. Got %" PRIu64
" expected %" PRIu64
,
124 ok(lttng_kernel_probe_location_serialize(location
, &payload
) > 0,
127 struct lttng_payload_view view
=
128 lttng_payload_view_from_payload(
130 ok(lttng_kernel_probe_location_create_from_payload(
131 &view
, &location_from_buffer
) > 0,
135 type
= lttng_kernel_probe_location_get_type(location_from_buffer
);
136 ok(LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
== type
,
137 "Location from buffer type got %d expected %d", type
,
138 LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
);
140 _symbol
= lttng_kernel_probe_location_symbol_get_name(
141 location_from_buffer
);
142 ok(_symbol
, "Getting symbol name");
143 ok(!strncmp(symbol
, _symbol
, strlen(symbol
)),
144 "Symbol name is equal. Got %s, expected %s", _symbol
,
147 status
= lttng_kernel_probe_location_symbol_get_offset(
148 location_from_buffer
, &_offset
);
149 ok(status
== LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
, "Getting offset");
150 ok(offset
== _offset
,
151 "Offset is equal. Got %" PRIu64
" expected %" PRIu64
,
154 ok(lttng_kernel_probe_location_is_equal(location
, location_from_buffer
),
155 "serialized and from buffer are equal");
157 lttng_payload_reset(&payload
);
158 lttng_kernel_probe_location_destroy(location
);
159 lttng_kernel_probe_location_destroy(location_from_buffer
);
162 int main(int argc
, const char *argv
[])
164 plan_tests(NUM_TESTS
);
165 test_kernel_probe_location_address();
166 test_kernel_probe_location_symbol();
167 return exit_status();