13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+ #include < linux/version.h>
16
17
#include < signal.h>
17
18
#include < sys/types.h>
18
19
#include < sys/wait.h>
@@ -34,6 +35,17 @@ static int a_probed_function() {
34
35
return an_int;
35
36
}
36
37
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
+
37
49
extern " C" int lib_probed_function ();
38
50
39
51
int call_shared_lib_func () {
@@ -394,3 +406,26 @@ TEST_CASE("test probing running Ruby process in namespaces",
394
406
REQUIRE (std::string (sym.module ).find (pid_root, 1 ) == std::string::npos);
395
407
}
396
408
}
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