//===- llvm/unittest/XRay/FDRRecordPrinterTest.cpp --------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/Support/raw_ostream.h" #include "llvm/XRay/FDRRecords.h" #include "llvm/XRay/RecordPrinter.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include namespace llvm { namespace xray { namespace { using ::testing::Eq; template struct Helper {}; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1, 2); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1, 2); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(4, 1, 2, "data"); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(); } static const char *expected() { return ""; } }; template class PrinterTest : public ::testing::Test { protected: std::string Data; raw_string_ostream OS; RecordPrinter P; std::unique_ptr R; public: PrinterTest() : Data(), OS(Data), P(OS), R(Helper::construct()) {} }; TYPED_TEST_CASE_P(PrinterTest); TYPED_TEST_P(PrinterTest, PrintsRecord) { ASSERT_NE(nullptr, this->R); ASSERT_FALSE(errorToBool(this->R->apply(this->P))); this->OS.flush(); EXPECT_THAT(this->Data, Eq(Helper::expected())); } REGISTER_TYPED_TEST_CASE_P(PrinterTest, PrintsRecord); using FDRRecordTypes = ::testing::Types; INSTANTIATE_TYPED_TEST_CASE_P(Records, PrinterTest, FDRRecordTypes); TEST(FDRRecordPrinterTest, WriteFunctionRecordEnter) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::ENTER, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } TEST(FDRRecordPrinterTest, WriteFunctionRecordExit) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::EXIT, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } TEST(FDRRecordPrinterTest, WriteFunctionRecordTailExit) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::TAIL_EXIT, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } TEST(FDRRecordPrinterTest, WriteFunctionRecordEnterArg) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::ENTER_ARG, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } } // namespace } // namespace xray } // namespace llvm