1 //===-- test_helpers.h ----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of XRay, a function call tracing system.
12 //===----------------------------------------------------------------------===//
13 #ifndef COMPILER_RT_LIB_XRAY_TESTS_TEST_HELPERS_H_
14 #define COMPILER_RT_LIB_XRAY_TESTS_TEST_HELPERS_H_
16 #include "xray_buffer_queue.h"
17 #include "xray_segmented_array.h"
18 #include "llvm/XRay/Trace.h"
19 #include "llvm/XRay/XRayRecord.h"
20 #include "gmock/gmock.h"
22 // TODO: Move these to llvm/include/Testing/XRay/...
26 std::string RecordTypeAsString(RecordTypes T);
27 void PrintTo(RecordTypes T, std::ostream *OS);
28 void PrintTo(const XRayRecord &R, std::ostream *OS);
29 void PrintTo(const Trace &T, std::ostream *OS);
33 MATCHER_P(FuncId, F, "") {
34 *result_listener << "where the function id is " << F;
35 return arg.FuncId == F;
38 MATCHER_P(RecordType, T, "") {
39 *result_listener << "where the record type is " << RecordTypeAsString(T);
43 MATCHER_P(HasArg, A, "") {
44 *result_listener << "where args contains " << A;
45 return !arg.CallArgs.empty() &&
46 std::any_of(arg.CallArgs.begin(), arg.CallArgs.end(),
47 [this](decltype(A) V) { return V == A; });
50 MATCHER_P(TSCIs, M, std::string("TSC is ") + ::testing::PrintToString(M)) {
51 return ::testing::Matcher<decltype(arg.TSC)>(M).MatchAndExplain(
52 arg.TSC, result_listener);
55 } // namespace testing
61 std::string serialize(BufferQueue &Buffers, int32_t Version);
63 template <class T> void PrintTo(const Array<T> &A, std::ostream *OS) {
66 for (const auto &E : A) {
78 #endif // COMPILER_RT_LIB_XRAY_TESTS_TEST_HELPERS_H_