[compiler-rt] b7a86d0 - [xray][test] Test __xray_typedevent after D43668

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 14:53:26 PDT 2023


Author: Fangrui Song
Date: 2023-06-19T14:53:22-07:00
New Revision: b7a86d03cb49229634419be4ae44df00fadd990d

URL: https://github.com/llvm/llvm-project/commit/b7a86d03cb49229634419be4ae44df00fadd990d
DIFF: https://github.com/llvm/llvm-project/commit/b7a86d03cb49229634419be4ae44df00fadd990d.diff

LOG: [xray][test] Test __xray_typedevent after D43668

Added: 
    compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp b/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp
new file mode 100644
index 0000000000000..20c99557acc48
--- /dev/null
+++ b/compiler-rt/test/xray/TestCases/Posix/typed-event-logging.cpp
@@ -0,0 +1,36 @@
+// RUN: %clangxx_xray %s -o %t
+// RUN: XRAY_OPTIONS=patch_premain=false:verbosity=1 %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: target={{x86_64-.*linux.*}}
+
+#include <assert.h>
+#include <stdio.h>
+#include "xray/xray_interface.h"
+
+[[clang::xray_always_instrument]] void foo() {
+  static constexpr char CustomLogged[] = "hello custom logging!";
+  printf("before calling the custom logging...\n");
+  __xray_typedevent(42, CustomLogged, sizeof(CustomLogged));
+  printf("after calling the custom logging...\n");
+}
+
+static void myprinter(uint16_t type, const void *ptr, size_t size) {
+  assert(type == 42);
+  printf("%.*s\n", static_cast<int>(size), static_cast<const char*>(ptr));
+}
+
+int main() {
+  // CHECK: before calling the custom logging...
+  // CHECK-NEXT: after calling the custom logging...
+  foo();
+  __xray_set_typedevent_handler(myprinter);
+  __xray_patch();
+  // CHECK-NEXT: before calling the custom logging...
+  // CHECK-NEXT: hello custom logging!
+  // CHECK-NEXT: after calling the custom logging...
+  foo();
+  // CHECK-NEXT: before calling the custom logging...
+  // CHECK-NEXT: after calling the custom logging...
+  __xray_remove_typedevent_handler();
+  foo();
+}


        


More information about the llvm-commits mailing list