Skip to content

Commit 50ad6fa

Browse files
committed
usdt: Add test for uprobe refcnt support
1 parent 8287f17 commit 50ad6fa

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/cc/test_usdt_probes.cc

+35
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#include <linux/version.h>
1617
#include <signal.h>
1718
#include <sys/types.h>
1819
#include <sys/wait.h>
@@ -34,6 +35,17 @@ static int a_probed_function() {
3435
return an_int;
3536
}
3637

38+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
39+
FOLLY_SDT_DEFINE_SEMAPHORE(libbcc_test, sample_probe_2)
40+
static int a_probed_function_with_sem() {
41+
int an_int = 23 + getpid();
42+
void *a_pointer = malloc(4);
43+
FOLLY_SDT_WITH_SEMAPHORE(libbcc_test, sample_probe_2, an_int, a_pointer);
44+
free(a_pointer);
45+
return an_int;
46+
}
47+
#endif // linux version >= 4.20
48+
3749
extern "C" int lib_probed_function();
3850

3951
int call_shared_lib_func() {
@@ -394,3 +406,26 @@ TEST_CASE("test probing running Ruby process in namespaces",
394406
REQUIRE(std::string(sym.module).find(pid_root, 1) == std::string::npos);
395407
}
396408
}
409+
410+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)
411+
TEST_CASE("Test uprobe refcnt semaphore activation", "[usdt]") {
412+
ebpf::BPF bpf;
413+
414+
REQUIRE(!FOLLY_SDT_IS_ENABLED(libbcc_test, sample_probe_2));
415+
416+
ebpf::USDT u("/proc/self/exe", "libbcc_test", "sample_probe_2", "on_event");
417+
418+
auto res = bpf.init("int on_event() { return 0; }", {}, {u});
419+
REQUIRE(res.code() == 0);
420+
421+
res = bpf.attach_usdt(u);
422+
REQUIRE(res.code() == 0);
423+
424+
REQUIRE(FOLLY_SDT_IS_ENABLED(libbcc_test, sample_probe_2));
425+
426+
res = bpf.detach_usdt(u);
427+
REQUIRE(res.code() == 0);
428+
429+
REQUIRE(a_probed_function_with_sem() != 0);
430+
}
431+
#endif // linux version >= 4.20

0 commit comments

Comments
 (0)