summaryrefslogtreecommitdiff
path: root/test/xray
diff options
context:
space:
mode:
Diffstat (limited to 'test/xray')
-rw-r--r--test/xray/CMakeLists.txt6
-rw-r--r--test/xray/TestCases/Linux/arg1-logger.cc43
-rw-r--r--test/xray/TestCases/Linux/argv0-log-file-name.cc2
-rw-r--r--test/xray/TestCases/Linux/fdr-mode.cc89
-rw-r--r--test/xray/TestCases/Linux/fdr-thread-order.cc38
-rw-r--r--test/xray/TestCases/Linux/fixedsize-logging.cc2
-rw-r--r--test/xray/TestCases/Linux/optional-inmemory-log.cc2
-rw-r--r--test/xray/TestCases/Linux/pic_test.cc33
-rw-r--r--test/xray/Unit/lit.site.cfg.in4
-rw-r--r--test/xray/lit.cfg5
10 files changed, 215 insertions, 9 deletions
diff --git a/test/xray/CMakeLists.txt b/test/xray/CMakeLists.txt
index 50f6926bbe1e5..b51b3cd0ccd80 100644
--- a/test/xray/CMakeLists.txt
+++ b/test/xray/CMakeLists.txt
@@ -9,7 +9,6 @@ set(XRAY_FDR_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
if(NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_BUILD_XRAY AND
COMPILER_RT_HAS_XRAY)
list(APPEND XRAY_TEST_DEPS xray)
- list(APPEND XRAY_FDR_TEST_DEPS xray-fdr)
endif()
set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})
@@ -41,8 +40,3 @@ add_lit_testsuite(check-xray "Running the XRay tests"
${XRAY_TESTSUITES}
DEPENDS ${XRAY_TEST_DEPS})
set_target_properties(check-xray PROPERTIES FOLDER "Compiler-RT Misc")
-
-add_lit_testsuite(check-xray-fdr "Running the XRay flight data recorder tests"
- ${XRAY_FDR_TESTSUITES}
- DEPENDS ${XRAY_FDR_TEST_DEPS})
-set_target_properties(check-xray-fdr PROPERTIES FOLDER "Compiler-RT Misc")
diff --git a/test/xray/TestCases/Linux/arg1-logger.cc b/test/xray/TestCases/Linux/arg1-logger.cc
new file mode 100644
index 0000000000000..955347b153ec7
--- /dev/null
+++ b/test/xray/TestCases/Linux/arg1-logger.cc
@@ -0,0 +1,43 @@
+// Check that we can get the first function argument logged
+// using a custom logging function.
+//
+// RUN: %clangxx_xray -std=c++11 %s -o %t
+// RUN: XRAY_OPTIONS="patch_premain=true verbosity=1 xray_logfile_base=arg1-logger-" %run %t 2>&1 | FileCheck %s
+//
+// After all that, clean up the XRay log file.
+//
+// RUN: rm arg1-logger-*
+//
+// At the time of writing, the ARM trampolines weren't written yet.
+// XFAIL: arm || aarch64 || mips
+// See the mailing list discussion of r296998.
+// UNSUPPORTED: powerpc64le
+
+#include "xray/xray_interface.h"
+
+#include <cinttypes>
+#include <cstdio>
+
+void arg1logger(int32_t fn, XRayEntryType t, uint64_t a1) {
+ printf("Arg1: %" PRIx64 ", XRayEntryType %u\n", a1, t);
+}
+
+[[clang::xray_always_instrument, clang::xray_log_args(1)]] void foo(void *) {}
+
+int main() {
+ // CHECK: XRay: Log file in 'arg1-logger-{{.*}}'
+
+ __xray_set_handler_arg1(arg1logger);
+ foo(nullptr);
+ // CHECK: Arg1: 0, XRayEntryType 0
+
+ __xray_remove_handler_arg1();
+ foo((void *) 0xBADC0DE);
+ // nothing expected to see here
+
+ __xray_set_handler_arg1(arg1logger);
+ foo((void *) 0xDEADBEEFCAFE);
+ // CHECK-NEXT: Arg1: deadbeefcafe, XRayEntryType 0
+ foo((void *) -1);
+ // CHECK-NEXT: Arg1: ffffffffffffffff, XRayEntryType 0
+}
diff --git a/test/xray/TestCases/Linux/argv0-log-file-name.cc b/test/xray/TestCases/Linux/argv0-log-file-name.cc
index 1765ce9b5ba1e..2960c57181e05 100644
--- a/test/xray/TestCases/Linux/argv0-log-file-name.cc
+++ b/test/xray/TestCases/Linux/argv0-log-file-name.cc
@@ -2,7 +2,7 @@
// name.
// RUN: %clangxx_xray -std=c++11 %s -o %t
-// RUN: %run %t > xray.log.file.name 2>&1
+// RUN: XRAY_OPTIONS="patch_premain=true xray_naive_log=true" %run %t > xray.log.file.name 2>&1
// RUN: ls | FileCheck xray.log.file.name
// RUN: rm xray-log.* xray.log.file.name
diff --git a/test/xray/TestCases/Linux/fdr-mode.cc b/test/xray/TestCases/Linux/fdr-mode.cc
new file mode 100644
index 0000000000000..9fb54ce7b030c
--- /dev/null
+++ b/test/xray/TestCases/Linux/fdr-mode.cc
@@ -0,0 +1,89 @@
+// RUN: %clangxx_xray -g -std=c++11 %s -o %t
+// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-logging-test- xray_fdr_log=true verbosity=1 xray_fdr_log_func_duration_threshold_us=0" %run %t 2>&1 | FileCheck %s
+// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-unwrite-test- xray_fdr_log=true verbosity=1 xray_fdr_log_func_duration_threshold_us=5000" %run %t 2>&1 | FileCheck %s
+// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-logging-test-* | head -1`" | FileCheck %s --check-prefix=TRACE
+// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-unwrite-test-* | head -1`" | FileCheck %s --check-prefix=UNWRITE
+// RUN: rm fdr-logging-test-*
+// RUN: rm fdr-unwrite-test-*
+// FIXME: Make llvm-xray work on non-x86_64 as well.
+// REQUIRES: x86_64-linux
+
+#include "xray/xray_log_interface.h"
+#include <cassert>
+#include <chrono>
+#include <cstdio>
+#include <iostream>
+#include <stdlib.h>
+#include <thread>
+#include <time.h>
+
+constexpr auto kBufferSize = 16384;
+constexpr auto kBufferMax = 10;
+
+thread_local uint64_t var = 0;
+[[clang::xray_always_instrument]] void __attribute__((noinline)) fC() { ++var; }
+
+[[clang::xray_always_instrument]] void __attribute__((noinline)) fB() { fC(); }
+
+[[clang::xray_always_instrument]] void __attribute__((noinline)) fA() { fB(); }
+
+int main(int argc, char *argv[]) {
+ using namespace __xray;
+ FDRLoggingOptions Options;
+ std::cout << "Logging before init." << std::endl;
+ // CHECK: Logging before init.
+ auto status = __xray_log_init(kBufferSize, kBufferMax, &Options,
+ sizeof(FDRLoggingOptions));
+ assert(status == XRayLogInitStatus::XRAY_LOG_INITIALIZED);
+ std::cout << "Init status " << status << std::endl;
+ // CHECK: Init status {{.*}}
+ std::cout << "Patching..." << std::endl;
+ // CHECK: Patching...
+ __xray_patch();
+ fA();
+ fC();
+ fB();
+ fA();
+ fC();
+ std::thread other_thread([]() {
+ fC();
+ fB();
+ fA();
+ });
+ other_thread.join();
+ std::cout << "Joined" << std::endl;
+ // CHECK: Joined
+ std::cout << "Finalize status " << __xray_log_finalize() << std::endl;
+ // CHECK: Finalize status {{.*}}
+ fC();
+ std::cout << "Main execution var = " << var << std::endl;
+ // CHECK: Main execution var = 6
+ std::cout << "Flush status " << __xray_log_flushLog() << std::endl;
+ // CHECK: Flush status {{.*}}
+ __xray_unpatch();
+ return 0;
+}
+
+// Check that we're able to see two threads, each entering and exiting fA().
+// TRACE-DAG: - { type: 0, func-id: [[FIDA:[0-9]+]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1]], kind: function-exit, tsc: {{[0-9]+}} }
+// TRACE-DAG: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD2]], kind: function-exit, tsc: {{[0-9]+}} }
+//
+// Do the same as above for fC()
+// TRACE-DAG: - { type: 0, func-id: [[FIDC:[0-9]+]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD1]], kind: function-exit, tsc: {{[0-9]+}} }
+// TRACE-DAG: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD2]], kind: function-exit, tsc: {{[0-9]+}} }
+
+// Do the same as above for fB()
+// TRACE-DAG: - { type: 0, func-id: [[FIDB:[0-9]+]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1]], kind: function-exit, tsc: {{[0-9]+}} }
+// TRACE-DAG: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2]], kind: function-exit, tsc: {{[0-9]+}} }
+
+// Assert that when unwriting is enabled with a high threshold time, all the function records are erased. A CPU switch could erroneously fail this test, but
+// is unlikely given the test program.
+// UNWRITE: header
+// UNWRITE-NOT: function-enter
+// UNWRITE-NOT: function-exit
diff --git a/test/xray/TestCases/Linux/fdr-thread-order.cc b/test/xray/TestCases/Linux/fdr-thread-order.cc
new file mode 100644
index 0000000000000..5edef2be2d814
--- /dev/null
+++ b/test/xray/TestCases/Linux/fdr-thread-order.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx_xray -g -std=c++11 %s -o %t
+// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-thread-order. xray_fdr_log=true verbosity=1" %run %t 2>&1 | FileCheck %s
+// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-thread-order.* | head -1`" | FileCheck %s --check-prefix TRACE
+// RUN: rm fdr-thread-order.*
+// FIXME: Make llvm-xray work on non-x86_64 as well.
+// REQUIRES: x86_64-linux
+#include "xray/xray_log_interface.h"
+#include <thread>
+#include <cassert>
+
+constexpr auto kBufferSize = 16384;
+constexpr auto kBufferMax = 10;
+
+thread_local uint64_t var = 0;
+[[clang::xray_always_instrument]] void __attribute__((noinline)) f1() { ++var; }
+[[clang::xray_always_instrument]] void __attribute__((noinline)) f2() { ++var; }
+
+int main(int argc, char *argv[]) {
+ using namespace __xray;
+ FDRLoggingOptions Options;
+ assert(__xray_log_init(kBufferSize, kBufferMax, &Options,
+ sizeof(FDRLoggingOptions)) ==
+ XRayLogInitStatus::XRAY_LOG_INITIALIZED);
+ __xray_patch();
+ std::thread t1([] { f1(); });
+ std::thread t2([] { f2(); });
+ t1.join();
+ t2.join();
+ __xray_log_finalize();
+ __xray_log_flushLog();
+ // CHECK: =={{[0-9]+}}==XRay: Log file in '{{.*}}'
+}
+
+// We want to make sure that the order of the function log doesn't matter.
+// TRACE-DAG: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE-DAG: - { type: 0, func-id: [[FID2:[0-9]+]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} }
+// TRACE-DAG: - { type: 0, func-id: [[FID1]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1]], kind: function-exit, tsc: {{[0-9]+}} }
+// TRACE-DAG: - { type: 0, func-id: [[FID2]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2]], kind: function-exit, tsc: {{[0-9]+}} }
diff --git a/test/xray/TestCases/Linux/fixedsize-logging.cc b/test/xray/TestCases/Linux/fixedsize-logging.cc
index 90e766876c546..eb32afe93d1ff 100644
--- a/test/xray/TestCases/Linux/fixedsize-logging.cc
+++ b/test/xray/TestCases/Linux/fixedsize-logging.cc
@@ -1,7 +1,7 @@
// Check to make sure that we have a log file with a fixed-size.
// RUN: %clangxx_xray -std=c++11 %s -o %t
-// RUN: XRAY_OPTIONS="verbosity=1 xray_logfile_base=fixedsize-logging-" %run %t 2>&1 | FileCheck %s
+// RUN: XRAY_OPTIONS="patch_premain=true xray_naive_log=true verbosity=1 xray_logfile_base=fixedsize-logging-" %run %t 2>&1 | FileCheck %s
//
// After all that, clean up the output xray log.
//
diff --git a/test/xray/TestCases/Linux/optional-inmemory-log.cc b/test/xray/TestCases/Linux/optional-inmemory-log.cc
index ef2c43f3be776..f459d5ab813f7 100644
--- a/test/xray/TestCases/Linux/optional-inmemory-log.cc
+++ b/test/xray/TestCases/Linux/optional-inmemory-log.cc
@@ -2,7 +2,7 @@
// we turn it off via options.
// RUN: %clangxx_xray -std=c++11 %s -o %t
-// RUN: XRAY_OPTIONS="verbosity=1 xray_naive_log=false xray_logfile_base=optional-inmemory-log.xray-" %run %t 2>&1 | FileCheck %s
+// RUN: XRAY_OPTIONS="patch_premain=true verbosity=1 xray_naive_log=false xray_logfile_base=optional-inmemory-log.xray-" %run %t 2>&1 | FileCheck %s
//
// Make sure we clean out the logs in case there was a bug.
//
diff --git a/test/xray/TestCases/Linux/pic_test.cc b/test/xray/TestCases/Linux/pic_test.cc
new file mode 100644
index 0000000000000..09c40b9e03177
--- /dev/null
+++ b/test/xray/TestCases/Linux/pic_test.cc
@@ -0,0 +1,33 @@
+// Test to check if we handle pic code properly.
+
+// RUN: %clangxx_xray -fxray-instrument -std=c++11 -fpic %s -o %t
+// RUN: XRAY_OPTIONS="patch_premain=true verbosity=1 xray_logfile_base=pic-test-logging-" %run %t 2>&1 | FileCheck %s
+// After all that, clean up the output xray log.
+//
+// RUN: rm pic-test-logging-*
+
+#include <cstdio>
+
+[[clang::xray_always_instrument]]
+unsigned short foo (unsigned b);
+
+[[clang::xray_always_instrument]]
+unsigned short bar (unsigned short a)
+{
+ printf("bar() is always instrumented!\n");
+ return foo(a);
+}
+
+unsigned short foo (unsigned b)
+{
+ printf("foo() is always instrumented!\n");
+ return b + b + 5;
+}
+
+int main ()
+{
+ // CHECK: XRay: Log file in 'pic-test-logging-{{.*}}'
+ bar(10);
+ // CHECK: bar() is always instrumented!
+ // CHECK-NEXT: foo() is always instrumented!
+}
diff --git a/test/xray/Unit/lit.site.cfg.in b/test/xray/Unit/lit.site.cfg.in
index 1ebc7b9ec5f3f..75ea8889bf99c 100644
--- a/test/xray/Unit/lit.site.cfg.in
+++ b/test/xray/Unit/lit.site.cfg.in
@@ -10,3 +10,7 @@ config.name = 'XRay-Unit'
config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/xray/tests"
config.test_source_root = config.test_exec_root
+
+# Do not patch the XRay unit tests pre-main, and also make the error logging
+# verbose to get a more accurate error logging mechanism.
+config.environment['XRAY_OPTIONS'] = 'patch_premain=false verbose=1'
diff --git a/test/xray/lit.cfg b/test/xray/lit.cfg
index 9142ad13618c0..b07dcbd791f86 100644
--- a/test/xray/lit.cfg
+++ b/test/xray/lit.cfg
@@ -16,6 +16,9 @@ clang_xray_cxxflags = config.cxx_mode_flags + clang_xray_cflags
def build_invocation(compile_flags):
return ' ' + ' '.join([config.clang] + compile_flags) + ' '
+# Assume that llvm-xray is in the config.llvm_tools_dir.
+llvm_xray = os.path.join(config.llvm_tools_dir, 'llvm-xray')
+
# Setup substitutions.
config.substitutions.append(
('%clang ', build_invocation([config.target_cflags])))
@@ -26,6 +29,8 @@ config.substitutions.append(
('%clang_xray ', build_invocation(clang_xray_cflags)))
config.substitutions.append(
('%clangxx_xray', build_invocation(clang_xray_cxxflags)))
+config.substitutions.append(
+ ('%llvm_xray', llvm_xray))
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']