1 //===-- test_helpers.h ----------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file is a part of XRay, a function call tracing system. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef COMPILER_RT_LIB_XRAY_TESTS_TEST_HELPERS_H_ 14 #define COMPILER_RT_LIB_XRAY_TESTS_TEST_HELPERS_H_ 15 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" 21 22 // TODO: Move these to llvm/include/Testing/XRay/... 23 namespace llvm { 24 namespace xray { 25 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); 30 31 namespace testing { 32 33 MATCHER_P(FuncId, F, "") { 34 *result_listener << "where the function id is " << F; 35 return arg.FuncId == F; 36 } 37 38 MATCHER_P(RecordType, T, "") { 39 *result_listener << "where the record type is " << RecordTypeAsString(T); 40 return arg.Type == T; 41 } 42 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; }); 48 } 49 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); 53 } 54 55 } // namespace testing 56 } // namespace xray 57 } // namespace llvm 58 59 namespace __xray { 60 61 std::string serialize(BufferQueue &Buffers, int32_t Version); 62 63 template <class T> void PrintTo(const Array<T> &A, std::ostream *OS) { 64 *OS << "["; 65 bool first = true; 66 for (const auto &E : A) { 67 if (!first) { 68 *OS << ", "; 69 } 70 PrintTo(E, OS); 71 first = false; 72 } 73 *OS << "]"; 74 } 75 76 } // namespace __xray 77 78 #endif // COMPILER_RT_LIB_XRAY_TESTS_TEST_HELPERS_H_ 79