Skip to content

Commit b7a86d0

Browse files
committed
[xray][test] Test __xray_typedevent after D43668
1 parent 5866935 commit b7a86d0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx_xray %s -o %t
2+
// RUN: XRAY_OPTIONS=patch_premain=false:verbosity=1 %run %t 2>&1 | FileCheck %s
3+
4+
// REQUIRES: target={{x86_64-.*linux.*}}
5+
6+
#include <assert.h>
7+
#include <stdio.h>
8+
#include "xray/xray_interface.h"
9+
10+
[[clang::xray_always_instrument]] void foo() {
11+
static constexpr char CustomLogged[] = "hello custom logging!";
12+
printf("before calling the custom logging...\n");
13+
__xray_typedevent(42, CustomLogged, sizeof(CustomLogged));
14+
printf("after calling the custom logging...\n");
15+
}
16+
17+
static void myprinter(uint16_t type, const void *ptr, size_t size) {
18+
assert(type == 42);
19+
printf("%.*s\n", static_cast<int>(size), static_cast<const char*>(ptr));
20+
}
21+
22+
int main() {
23+
// CHECK: before calling the custom logging...
24+
// CHECK-NEXT: after calling the custom logging...
25+
foo();
26+
__xray_set_typedevent_handler(myprinter);
27+
__xray_patch();
28+
// CHECK-NEXT: before calling the custom logging...
29+
// CHECK-NEXT: hello custom logging!
30+
// CHECK-NEXT: after calling the custom logging...
31+
foo();
32+
// CHECK-NEXT: before calling the custom logging...
33+
// CHECK-NEXT: after calling the custom logging...
34+
__xray_remove_typedevent_handler();
35+
foo();
36+
}

0 commit comments

Comments
 (0)