[compiler-rt] r367550 - compiler-rt: Rename .cc file in lib/xray/tests/unit to .cpp

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 05:35:27 PDT 2019


Author: nico
Date: Thu Aug  1 05:35:27 2019
New Revision: 367550

URL: http://llvm.org/viewvc/llvm-project?rev=367550&view=rev
Log:
compiler-rt: Rename .cc file in lib/xray/tests/unit to .cpp

Like r367463, but for xray/texts/unit.


Added:
    compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cpp
      - copied unchanged from r367549, compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc
    compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cpp
      - copied, changed from r367549, compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc
Removed:
    compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cc
    compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc
    compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc
Modified:
    compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt

Modified: compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt?rev=367550&r1=367549&r2=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt Thu Aug  1 05:35:27 2019
@@ -1,16 +1,18 @@
 set(TEST_SOURCES
-  allocator_test.cc
-  buffer_queue_test.cc
-  function_call_trie_test.cc
-  profile_collector_test.cc
-  segmented_array_test.cc
-  test_helpers.cc
-  xray_unit_test_main.cc)
+  allocator_test.cpp
+  buffer_queue_test.cpp
+  function_call_trie_test.cpp
+  profile_collector_test.cpp
+  segmented_array_test.cpp
+  test_helpers.cpp
+  xray_unit_test_main.cpp
+  )
 
 if (NOT COMPILER_RT_STANDALONE_BUILD OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
   list(APPEND TEST_SOURCES
-    fdr_controller_test.cc
-    fdr_log_writer_test.cc)
+    fdr_controller_test.cpp
+    fdr_log_writer_test.cpp
+    )
 endif()
 
 add_xray_unittest(XRayTest SOURCES ${TEST_SOURCES})

Removed: compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc (removed)
@@ -1,81 +0,0 @@
-//===-- allocator_test.cc -------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-
-#include "xray_allocator.h"
-#include "xray_buffer_queue.h"
-#include "gtest/gtest.h"
-
-namespace __xray {
-namespace {
-
-struct TestData {
-  s64 First;
-  s64 Second;
-};
-
-TEST(AllocatorTest, Construction) { Allocator<sizeof(TestData)> A(2 << 11); }
-
-TEST(AllocatorTest, Allocate) {
-  Allocator<sizeof(TestData)> A(2 << 11);
-  auto B = A.Allocate();
-  ASSERT_NE(B.Data, nullptr);
-}
-
-TEST(AllocatorTest, OverAllocate) {
-  Allocator<sizeof(TestData)> A(sizeof(TestData));
-  auto B1 = A.Allocate();
-  ASSERT_NE(B1.Data, nullptr);
-  auto B2 = A.Allocate();
-  ASSERT_EQ(B2.Data, nullptr);
-}
-
-struct OddSizedData {
-  s64 A;
-  s32 B;
-};
-
-TEST(AllocatorTest, AllocateBoundaries) {
-  Allocator<sizeof(OddSizedData)> A(GetPageSizeCached());
-
-  // Keep allocating until we hit a nullptr block.
-  unsigned C = 0;
-  auto Expected =
-      GetPageSizeCached() / RoundUpTo(sizeof(OddSizedData), kCacheLineSize);
-  for (auto B = A.Allocate(); B.Data != nullptr; B = A.Allocate(), ++C)
-    ;
-
-  ASSERT_EQ(C, Expected);
-}
-
-TEST(AllocatorTest, AllocateFromNonOwned) {
-  bool Success = false;
-  BufferQueue BQ(GetPageSizeCached(), 10, Success);
-  ASSERT_TRUE(Success);
-  BufferQueue::Buffer B;
-  ASSERT_EQ(BQ.getBuffer(B), BufferQueue::ErrorCode::Ok);
-  {
-    Allocator<sizeof(OddSizedData)> A(B.Data, B.Size);
-
-    // Keep allocating until we hit a nullptr block.
-    unsigned C = 0;
-    auto Expected =
-        GetPageSizeCached() / RoundUpTo(sizeof(OddSizedData), kCacheLineSize);
-    for (auto B = A.Allocate(); B.Data != nullptr; B = A.Allocate(), ++C)
-      ;
-
-    ASSERT_EQ(C, Expected);
-  }
-  ASSERT_EQ(BQ.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-}
-
-} // namespace
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/allocator_test.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- allocator_test.cc -------------------------------------------------===//
+//===-- allocator_test.cpp ------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc (removed)
@@ -1,234 +0,0 @@
-//===-- buffer_queue_test.cc ----------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include "xray_buffer_queue.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-#include <atomic>
-#include <future>
-#include <thread>
-#include <unistd.h>
-
-namespace __xray {
-namespace {
-
-static constexpr size_t kSize = 4096;
-
-using ::testing::Eq;
-
-TEST(BufferQueueTest, API) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  ASSERT_TRUE(Success);
-}
-
-TEST(BufferQueueTest, GetAndRelease) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  ASSERT_TRUE(Success);
-  BufferQueue::Buffer Buf;
-  ASSERT_EQ(Buffers.getBuffer(Buf), BufferQueue::ErrorCode::Ok);
-  ASSERT_NE(nullptr, Buf.Data);
-  ASSERT_EQ(Buffers.releaseBuffer(Buf), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(nullptr, Buf.Data);
-}
-
-TEST(BufferQueueTest, GetUntilFailed) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  ASSERT_TRUE(Success);
-  BufferQueue::Buffer Buf0;
-  EXPECT_EQ(Buffers.getBuffer(Buf0), BufferQueue::ErrorCode::Ok);
-  BufferQueue::Buffer Buf1;
-  EXPECT_EQ(BufferQueue::ErrorCode::NotEnoughMemory, Buffers.getBuffer(Buf1));
-  EXPECT_EQ(Buffers.releaseBuffer(Buf0), BufferQueue::ErrorCode::Ok);
-}
-
-TEST(BufferQueueTest, ReleaseUnknown) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  ASSERT_TRUE(Success);
-  BufferQueue::Buffer Buf;
-  Buf.Data = reinterpret_cast<void *>(0xdeadbeef);
-  Buf.Size = kSize;
-  Buf.Generation = Buffers.generation();
-
-  BufferQueue::Buffer Known;
-  EXPECT_THAT(Buffers.getBuffer(Known), Eq(BufferQueue::ErrorCode::Ok));
-  EXPECT_THAT(Buffers.releaseBuffer(Buf),
-              Eq(BufferQueue::ErrorCode::UnrecognizedBuffer));
-  EXPECT_THAT(Buffers.releaseBuffer(Known), Eq(BufferQueue::ErrorCode::Ok));
-}
-
-TEST(BufferQueueTest, ErrorsWhenFinalising) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 2, Success);
-  ASSERT_TRUE(Success);
-  BufferQueue::Buffer Buf;
-  ASSERT_EQ(Buffers.getBuffer(Buf), BufferQueue::ErrorCode::Ok);
-  ASSERT_NE(nullptr, Buf.Data);
-  ASSERT_EQ(Buffers.finalize(), BufferQueue::ErrorCode::Ok);
-  BufferQueue::Buffer OtherBuf;
-  ASSERT_EQ(BufferQueue::ErrorCode::QueueFinalizing,
-            Buffers.getBuffer(OtherBuf));
-  ASSERT_EQ(BufferQueue::ErrorCode::QueueFinalizing, Buffers.finalize());
-  ASSERT_EQ(Buffers.releaseBuffer(Buf), BufferQueue::ErrorCode::Ok);
-}
-
-TEST(BufferQueueTest, MultiThreaded) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 100, Success);
-  ASSERT_TRUE(Success);
-  auto F = [&] {
-    BufferQueue::Buffer B;
-    while (true) {
-      auto EC = Buffers.getBuffer(B);
-      if (EC != BufferQueue::ErrorCode::Ok)
-        return;
-      Buffers.releaseBuffer(B);
-    }
-  };
-  auto T0 = std::async(std::launch::async, F);
-  auto T1 = std::async(std::launch::async, F);
-  auto T2 = std::async(std::launch::async, [&] {
-    while (Buffers.finalize() != BufferQueue::ErrorCode::Ok)
-      ;
-  });
-  F();
-}
-
-TEST(BufferQueueTest, Apply) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 10, Success);
-  ASSERT_TRUE(Success);
-  auto Count = 0;
-  BufferQueue::Buffer B;
-  for (int I = 0; I < 10; ++I) {
-    ASSERT_EQ(Buffers.getBuffer(B), BufferQueue::ErrorCode::Ok);
-    ASSERT_EQ(Buffers.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-  }
-  Buffers.apply([&](const BufferQueue::Buffer &B) { ++Count; });
-  ASSERT_EQ(Count, 10);
-}
-
-TEST(BufferQueueTest, GenerationalSupport) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 10, Success);
-  ASSERT_TRUE(Success);
-  BufferQueue::Buffer B0;
-  ASSERT_EQ(Buffers.getBuffer(B0), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(Buffers.finalize(),
-            BufferQueue::ErrorCode::Ok); // No more new buffers.
-
-  // Re-initialise the queue.
-  ASSERT_EQ(Buffers.init(kSize, 10), BufferQueue::ErrorCode::Ok);
-
-  BufferQueue::Buffer B1;
-  ASSERT_EQ(Buffers.getBuffer(B1), BufferQueue::ErrorCode::Ok);
-
-  // Validate that the buffers come from different generations.
-  ASSERT_NE(B0.Generation, B1.Generation);
-
-  // We stash the current generation, for use later.
-  auto PrevGen = B1.Generation;
-
-  // At this point, we want to ensure that we can return the buffer from the
-  // first "generation" would still be accepted in the new generation...
-  EXPECT_EQ(Buffers.releaseBuffer(B0), BufferQueue::ErrorCode::Ok);
-
-  // ... and that the new buffer is also accepted.
-  EXPECT_EQ(Buffers.releaseBuffer(B1), BufferQueue::ErrorCode::Ok);
-
-  // A next round will do the same, ensure that we are able to do multiple
-  // rounds in this case.
-  ASSERT_EQ(Buffers.finalize(), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(Buffers.init(kSize, 10), BufferQueue::ErrorCode::Ok);
-  EXPECT_EQ(Buffers.getBuffer(B0), BufferQueue::ErrorCode::Ok);
-  EXPECT_EQ(Buffers.getBuffer(B1), BufferQueue::ErrorCode::Ok);
-
-  // Here we ensure that the generation is different from the previous
-  // generation.
-  EXPECT_NE(B0.Generation, PrevGen);
-  EXPECT_EQ(B1.Generation, B1.Generation);
-  ASSERT_EQ(Buffers.finalize(), BufferQueue::ErrorCode::Ok);
-  EXPECT_EQ(Buffers.releaseBuffer(B0), BufferQueue::ErrorCode::Ok);
-  EXPECT_EQ(Buffers.releaseBuffer(B1), BufferQueue::ErrorCode::Ok);
-}
-
-TEST(BufferQueueTest, GenerationalSupportAcrossThreads) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 10, Success);
-  ASSERT_TRUE(Success);
-
-  std::atomic<int> Counter{0};
-
-  // This function allows us to use thread-local storage to isolate the
-  // instances of the buffers to be used. It also allows us signal the threads
-  // of a new generation, and allow those to get new buffers. This is
-  // representative of how we expect the buffer queue to be used by the XRay
-  // runtime.
-  auto Process = [&] {
-    thread_local BufferQueue::Buffer B;
-    ASSERT_EQ(Buffers.getBuffer(B), BufferQueue::ErrorCode::Ok);
-    auto FirstGen = B.Generation;
-
-    // Signal that we've gotten a buffer in the thread.
-    Counter.fetch_add(1, std::memory_order_acq_rel);
-    while (!Buffers.finalizing()) {
-      Buffers.releaseBuffer(B);
-      Buffers.getBuffer(B);
-    }
-
-    // Signal that we've exited the get/release buffer loop.
-    Counter.fetch_sub(1, std::memory_order_acq_rel);
-    if (B.Data != nullptr)
-      Buffers.releaseBuffer(B);
-
-    // Spin until we find that the Buffer Queue is no longer finalizing.
-    while (Buffers.getBuffer(B) != BufferQueue::ErrorCode::Ok)
-      ;
-
-    // Signal that we've successfully gotten a buffer in the thread.
-    Counter.fetch_add(1, std::memory_order_acq_rel);
-
-    EXPECT_NE(FirstGen, B.Generation);
-    EXPECT_EQ(Buffers.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-
-    // Signal that we've successfully exited.
-    Counter.fetch_sub(1, std::memory_order_acq_rel);
-  };
-
-  // Spawn two threads running Process.
-  std::thread T0(Process), T1(Process);
-
-  // Spin until we find the counter is up to 2.
-  while (Counter.load(std::memory_order_acquire) != 2)
-    ;
-
-  // Then we finalize, then re-initialize immediately.
-  Buffers.finalize();
-
-  // Spin until we find the counter is down to 0.
-  while (Counter.load(std::memory_order_acquire) != 0)
-    ;
-
-  // Then we re-initialize.
-  EXPECT_EQ(Buffers.init(kSize, 10), BufferQueue::ErrorCode::Ok);
-
-  T0.join();
-  T1.join();
-
-  ASSERT_EQ(Counter.load(std::memory_order_acquire), 0);
-}
-
-} // namespace
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- buffer_queue_test.cc ----------------------------------------------===//
+//===-- buffer_queue_test.cpp ---------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc (removed)
@@ -1,423 +0,0 @@
-//===-- fdr_controller_test.cc --------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include <algorithm>
-#include <memory>
-#include <time.h>
-
-#include "test_helpers.h"
-#include "xray/xray_records.h"
-#include "xray_buffer_queue.h"
-#include "xray_fdr_controller.h"
-#include "xray_fdr_log_writer.h"
-#include "llvm/Support/DataExtractor.h"
-#include "llvm/Testing/Support/Error.h"
-#include "llvm/XRay/Trace.h"
-#include "llvm/XRay/XRayRecord.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-namespace __xray {
-namespace {
-
-using ::llvm::HasValue;
-using ::llvm::xray::testing::FuncId;
-using ::llvm::xray::testing::HasArg;
-using ::llvm::xray::testing::RecordType;
-using ::llvm::xray::testing::TSCIs;
-using ::testing::AllOf;
-using ::testing::ElementsAre;
-using ::testing::Eq;
-using ::testing::Field;
-using ::testing::Gt;
-using ::testing::IsEmpty;
-using ::testing::SizeIs;
-
-class FunctionSequenceTest : public ::testing::Test {
-protected:
-  BufferQueue::Buffer B{};
-  std::unique_ptr<BufferQueue> BQ;
-  std::unique_ptr<FDRLogWriter> W;
-  std::unique_ptr<FDRController<>> C;
-
-public:
-  void SetUp() override {
-    bool Success;
-    BQ = llvm::make_unique<BufferQueue>(4096, 1, Success);
-    ASSERT_TRUE(Success);
-    ASSERT_EQ(BQ->getBuffer(B), BufferQueue::ErrorCode::Ok);
-    W = llvm::make_unique<FDRLogWriter>(B);
-    C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 0);
-  }
-};
-
-TEST_F(FunctionSequenceTest, DefaultInitFinalizeFlush) {
-  ASSERT_TRUE(C->functionEnter(1, 2, 3));
-  ASSERT_TRUE(C->functionExit(1, 2, 3));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see we find the expected records.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER)),
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT)))));
-}
-
-TEST_F(FunctionSequenceTest, BoundaryFuncIdEncoding) {
-  // We ensure that we can write function id's that are at the boundary of the
-  // acceptable function ids.
-  int32_t FId = (1 << 28) - 1;
-  uint64_t TSC = 2;
-  uint16_t CPU = 1;
-  ASSERT_TRUE(C->functionEnter(FId, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(FId, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnterArg(FId, TSC++, CPU, 1));
-  ASSERT_TRUE(C->functionTailExit(FId, TSC++, CPU));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see we find the expected records.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(FId), RecordType(llvm::xray::RecordTypes::ENTER)),
-          AllOf(FuncId(FId), RecordType(llvm::xray::RecordTypes::EXIT)),
-          AllOf(FuncId(FId), RecordType(llvm::xray::RecordTypes::ENTER_ARG)),
-          AllOf(FuncId(FId), RecordType(llvm::xray::RecordTypes::TAIL_EXIT)))));
-}
-
-TEST_F(FunctionSequenceTest, ThresholdsAreEnforced) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-  ASSERT_TRUE(C->functionEnter(1, 2, 3));
-  ASSERT_TRUE(C->functionExit(1, 2, 3));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see we find the *no* records, because
-  // the function entry-exit comes under the cycle threshold.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(IsEmpty()));
-}
-
-TEST_F(FunctionSequenceTest, ArgsAreHandledAndKept) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-  ASSERT_TRUE(C->functionEnterArg(1, 2, 3, 4));
-  ASSERT_TRUE(C->functionExit(1, 2, 3));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see we find the function enter arg
-  // record with the specified argument.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER_ARG),
-                HasArg(4)),
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT)))));
-}
-
-TEST_F(FunctionSequenceTest, PreservedCallsHaveCorrectTSC) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-  uint64_t TSC = 1;
-  uint16_t CPU = 0;
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(1, TSC += 1000, CPU));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see if we find the remaining records,
-  // because the function entry-exit comes under the cycle threshold.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER),
-                TSCIs(Eq(1uL))),
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT),
-                TSCIs(Gt(1000uL))))));
-}
-
-TEST_F(FunctionSequenceTest, PreservedCallsSupportLargeDeltas) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-  uint64_t TSC = 1;
-  uint16_t CPU = 0;
-  const auto LargeDelta = uint64_t{std::numeric_limits<int32_t>::max()};
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(1, TSC += LargeDelta, CPU));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffer then test to see if we find the right TSC with a large
-  // delta.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER),
-                TSCIs(Eq(1uL))),
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT),
-                TSCIs(Gt(LargeDelta))))));
-}
-
-TEST_F(FunctionSequenceTest, RewindingMultipleCalls) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-
-  // First we construct an arbitrarily deep function enter/call stack.
-  // We also ensure that we are in the same CPU.
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(3, TSC++, CPU));
-
-  // Then we exit them one at a time, in reverse order of entry.
-  ASSERT_TRUE(C->functionExit(3, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
-
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see we find that all the calls have been
-  // unwound because all of them are under the cycle counter threshold.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(IsEmpty()));
-}
-
-TEST_F(FunctionSequenceTest, RewindingIntermediaryTailExits) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-
-  // First we construct an arbitrarily deep function enter/call stack.
-  // We also ensure that we are in the same CPU.
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(3, TSC++, CPU));
-
-  // Next we tail-exit into a new function multiple times.
-  ASSERT_TRUE(C->functionTailExit(3, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(4, TSC++, CPU));
-  ASSERT_TRUE(C->functionTailExit(4, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(5, TSC++, CPU));
-  ASSERT_TRUE(C->functionTailExit(5, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(6, TSC++, CPU));
-
-  // Then we exit them one at a time, in reverse order of entry.
-  ASSERT_TRUE(C->functionExit(6, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize the buffers then test to see we find that all the calls have been
-  // unwound because all of them are under the cycle counter threshold.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(IsEmpty()));
-}
-
-TEST_F(FunctionSequenceTest, RewindingAfterMigration) {
-  C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 1000);
-
-  // First we construct an arbitrarily deep function enter/call stack.
-  // We also ensure that we are in the same CPU.
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(3, TSC++, CPU));
-
-  // Next we tail-exit into a new function multiple times.
-  ASSERT_TRUE(C->functionTailExit(3, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(4, TSC++, CPU));
-  ASSERT_TRUE(C->functionTailExit(4, TSC++, CPU));
-
-  // But before we enter the next function, we migrate to a different CPU.
-  CPU = 2;
-  ASSERT_TRUE(C->functionEnter(5, TSC++, CPU));
-  ASSERT_TRUE(C->functionTailExit(5, TSC++, CPU));
-  ASSERT_TRUE(C->functionEnter(6, TSC++, CPU));
-
-  // Then we exit them one at a time, in reverse order of entry.
-  ASSERT_TRUE(C->functionExit(6, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(2, TSC++, CPU));
-  ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
-
-  ASSERT_TRUE(C->flush());
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Serialize buffers then test that we can find all the events that span the
-  // CPU migration.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER)),
-          AllOf(FuncId(2), RecordType(llvm::xray::RecordTypes::ENTER)),
-          AllOf(FuncId(2), RecordType(llvm::xray::RecordTypes::EXIT)),
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT)))));
-}
-
-class BufferManagementTest : public ::testing::Test {
-protected:
-  BufferQueue::Buffer B{};
-  std::unique_ptr<BufferQueue> BQ;
-  std::unique_ptr<FDRLogWriter> W;
-  std::unique_ptr<FDRController<>> C;
-
-  static constexpr size_t kBuffers = 10;
-
-public:
-  void SetUp() override {
-    bool Success;
-    BQ = llvm::make_unique<BufferQueue>(sizeof(MetadataRecord) * 5 +
-                                            sizeof(FunctionRecord) * 2,
-                                        kBuffers, Success);
-    ASSERT_TRUE(Success);
-    ASSERT_EQ(BQ->getBuffer(B), BufferQueue::ErrorCode::Ok);
-    W = llvm::make_unique<FDRLogWriter>(B);
-    C = llvm::make_unique<FDRController<>>(BQ.get(), B, *W, clock_gettime, 0);
-  }
-};
-
-constexpr size_t BufferManagementTest::kBuffers;
-
-TEST_F(BufferManagementTest, HandlesOverflow) {
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-  for (size_t I = 0; I < kBuffers + 1; ++I) {
-    ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-    ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
-  }
-  ASSERT_TRUE(C->flush());
-  ASSERT_THAT(BQ->finalize(), Eq(BufferQueue::ErrorCode::Ok));
-
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(SizeIs(kBuffers * 2)));
-}
-
-TEST_F(BufferManagementTest, HandlesOverflowWithArgs) {
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-  uint64_t ARG = 1;
-  for (size_t I = 0; I < kBuffers + 1; ++I) {
-    ASSERT_TRUE(C->functionEnterArg(1, TSC++, CPU, ARG++));
-    ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
-  }
-  ASSERT_TRUE(C->flush());
-  ASSERT_THAT(BQ->finalize(), Eq(BufferQueue::ErrorCode::Ok));
-
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(SizeIs(kBuffers)));
-}
-
-TEST_F(BufferManagementTest, HandlesOverflowWithCustomEvents) {
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-  int32_t D = 0x9009;
-  for (size_t I = 0; I < kBuffers; ++I) {
-    ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-    ASSERT_TRUE(C->functionExit(1, TSC++, CPU));
-    ASSERT_TRUE(C->customEvent(TSC++, CPU, &D, sizeof(D)));
-  }
-  ASSERT_TRUE(C->flush());
-  ASSERT_THAT(BQ->finalize(), Eq(BufferQueue::ErrorCode::Ok));
-
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-
-  // We expect to also now count the kBuffers/2 custom event records showing up
-  // in the Trace.
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(SizeIs(kBuffers + (kBuffers / 2))));
-}
-
-TEST_F(BufferManagementTest, HandlesFinalizedBufferQueue) {
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-
-  // First write one function entry.
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-
-  // Then we finalize the buffer queue, simulating the case where the logging
-  // has been finalized.
-  ASSERT_EQ(BQ->finalize(), BufferQueue::ErrorCode::Ok);
-
-  // At this point further calls to the controller must fail.
-  ASSERT_FALSE(C->functionExit(1, TSC++, CPU));
-
-  // But flushing should succeed.
-  ASSERT_TRUE(C->flush());
-
-  // We expect that we'll only be able to find the function enter event, but not
-  // the function exit event.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr, HasValue(ElementsAre(AllOf(
-                      FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER)))));
-}
-
-TEST_F(BufferManagementTest, HandlesGenerationalBufferQueue) {
-  uint64_t TSC = 1;
-  uint16_t CPU = 1;
-
-  ASSERT_TRUE(C->functionEnter(1, TSC++, CPU));
-  ASSERT_THAT(BQ->finalize(), Eq(BufferQueue::ErrorCode::Ok));
-  ASSERT_THAT(BQ->init(sizeof(MetadataRecord) * 4 + sizeof(FunctionRecord) * 2,
-                       kBuffers),
-              Eq(BufferQueue::ErrorCode::Ok));
-  EXPECT_TRUE(C->functionExit(1, TSC++, CPU));
-  ASSERT_TRUE(C->flush());
-
-  // We expect that we will only be able to find the function exit event, but
-  // not the function enter event, since we only have information about the new
-  // generation of the buffers.
-  std::string Serialized = serialize(*BQ, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr, HasValue(ElementsAre(AllOf(
-                      FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT)))));
-}
-
-} // namespace
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/fdr_controller_test.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- fdr_controller_test.cc --------------------------------------------===//
+//===-- fdr_controller_test.cpp -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc (removed)
@@ -1,161 +0,0 @@
-//===-- fdr_log_writer_test.cc --------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include <time.h>
-
-#include "test_helpers.h"
-#include "xray/xray_records.h"
-#include "xray_fdr_log_writer.h"
-#include "llvm/Support/DataExtractor.h"
-#include "llvm/Testing/Support/Error.h"
-#include "llvm/XRay/Trace.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-namespace __xray {
-namespace {
-
-static constexpr size_t kSize = 4096;
-
-using ::llvm::HasValue;
-using ::llvm::xray::testing::FuncId;
-using ::llvm::xray::testing::RecordType;
-using ::testing::AllOf;
-using ::testing::ElementsAre;
-using ::testing::Eq;
-using ::testing::IsEmpty;
-using ::testing::IsNull;
-
-// Exercise the common code path where we initialize a buffer and are able to
-// write some records successfully.
-TEST(FdrLogWriterTest, WriteSomeRecords) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  BufferQueue::Buffer B;
-  ASSERT_EQ(Buffers.getBuffer(B), BufferQueue::ErrorCode::Ok);
-
-  FDRLogWriter Writer(B);
-  MetadataRecord Preamble[] = {
-      createMetadataRecord<MetadataRecord::RecordKinds::NewBuffer>(int32_t{1}),
-      createMetadataRecord<MetadataRecord::RecordKinds::WalltimeMarker>(
-          int64_t{1}, int32_t{2}),
-      createMetadataRecord<MetadataRecord::RecordKinds::Pid>(int32_t{1}),
-  };
-  ASSERT_THAT(Writer.writeMetadataRecords(Preamble),
-              Eq(sizeof(MetadataRecord) * 3));
-  ASSERT_TRUE(Writer.writeMetadata<MetadataRecord::RecordKinds::NewCPUId>(1));
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Enter, 1, 1));
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Exit, 1, 1));
-  ASSERT_EQ(Buffers.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(B.Data, nullptr);
-  ASSERT_EQ(Buffers.finalize(), BufferQueue::ErrorCode::Ok);
-
-  // We then need to go through each element of the Buffers, and re-create a
-  // flat buffer that we would see if they were laid out in a file. This also
-  // means we need to write out the header manually.
-  std::string Serialized = serialize(Buffers, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr,
-      HasValue(ElementsAre(
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER)),
-          AllOf(FuncId(1), RecordType(llvm::xray::RecordTypes::EXIT)))));
-}
-
-// Ensure that we can handle buffer re-use.
-TEST(FdrLogWriterTest, ReuseBuffers) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  BufferQueue::Buffer B;
-  ASSERT_EQ(Buffers.getBuffer(B), BufferQueue::ErrorCode::Ok);
-
-  FDRLogWriter Writer(B);
-  MetadataRecord Preamble[] = {
-      createMetadataRecord<MetadataRecord::RecordKinds::NewBuffer>(int32_t{1}),
-      createMetadataRecord<MetadataRecord::RecordKinds::WalltimeMarker>(
-          int64_t{1}, int32_t{2}),
-      createMetadataRecord<MetadataRecord::RecordKinds::Pid>(int32_t{1}),
-  };
-
-  // First we write the first set of records into the single buffer in the
-  // queue which includes one enter and one exit record.
-  ASSERT_THAT(Writer.writeMetadataRecords(Preamble),
-              Eq(sizeof(MetadataRecord) * 3));
-  ASSERT_TRUE(Writer.writeMetadata<MetadataRecord::RecordKinds::NewCPUId>(
-      uint16_t{1}, uint64_t{1}));
-  uint64_t TSC = 1;
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Enter, 1, TSC++));
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Exit, 1, TSC++));
-  ASSERT_EQ(Buffers.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-  ASSERT_THAT(B.Data, IsNull());
-
-  // Then we re-use the buffer, but only write one record.
-  ASSERT_EQ(Buffers.getBuffer(B), BufferQueue::ErrorCode::Ok);
-  Writer.resetRecord();
-  ASSERT_THAT(Writer.writeMetadataRecords(Preamble),
-              Eq(sizeof(MetadataRecord) * 3));
-  ASSERT_TRUE(Writer.writeMetadata<MetadataRecord::RecordKinds::NewCPUId>(
-      uint16_t{1}, uint64_t{1}));
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Enter, 1, TSC++));
-  ASSERT_EQ(Buffers.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-  ASSERT_THAT(B.Data, IsNull());
-  ASSERT_EQ(Buffers.finalize(), BufferQueue::ErrorCode::Ok);
-
-  // Then we validate that we only see the single enter record.
-  std::string Serialized = serialize(Buffers, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(
-      TraceOrErr, HasValue(ElementsAre(AllOf(
-                      FuncId(1), RecordType(llvm::xray::RecordTypes::ENTER)))));
-}
-
-TEST(FdrLogWriterTest, UnwriteRecords) {
-  bool Success = false;
-  BufferQueue Buffers(kSize, 1, Success);
-  BufferQueue::Buffer B;
-  ASSERT_EQ(Buffers.getBuffer(B), BufferQueue::ErrorCode::Ok);
-
-  FDRLogWriter Writer(B);
-  MetadataRecord Preamble[] = {
-      createMetadataRecord<MetadataRecord::RecordKinds::NewBuffer>(int32_t{1}),
-      createMetadataRecord<MetadataRecord::RecordKinds::WalltimeMarker>(
-          int64_t{1}, int32_t{2}),
-      createMetadataRecord<MetadataRecord::RecordKinds::Pid>(int32_t{1}),
-  };
-  ASSERT_THAT(Writer.writeMetadataRecords(Preamble),
-              Eq(sizeof(MetadataRecord) * 3));
-  ASSERT_TRUE(Writer.writeMetadata<MetadataRecord::RecordKinds::NewCPUId>(1));
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Enter, 1, 1));
-  ASSERT_TRUE(
-      Writer.writeFunction(FDRLogWriter::FunctionRecordKind::Exit, 1, 1));
-  Writer.undoWrites(sizeof(FunctionRecord) * 2);
-  ASSERT_EQ(Buffers.releaseBuffer(B), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(B.Data, nullptr);
-  ASSERT_EQ(Buffers.finalize(), BufferQueue::ErrorCode::Ok);
-
-  // We've un-done the two function records we've written, and now we expect
-  // that we don't have any function records in the trace.
-  std::string Serialized = serialize(Buffers, 3);
-  llvm::DataExtractor DE(Serialized, true, 8);
-  auto TraceOrErr = llvm::xray::loadTrace(DE);
-  EXPECT_THAT_EXPECTED(TraceOrErr, HasValue(IsEmpty()));
-}
-
-} // namespace
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/fdr_log_writer_test.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- fdr_log_writer_test.cc --------------------------------------------===//
+//===-- fdr_log_writer_test.cpp -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc (removed)
@@ -1,343 +0,0 @@
-//===-- function_call_trie_test.cc ----------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include "xray_function_call_trie.h"
-#include "gtest/gtest.h"
-#include <cstdint>
-
-namespace __xray {
-
-namespace {
-
-TEST(FunctionCallTrieTest, ConstructWithTLSAllocators) {
-  profilingFlags()->setDefaults();
-  FunctionCallTrie::Allocators Allocators = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(Allocators);
-}
-
-TEST(FunctionCallTrieTest, EnterAndExitFunction) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-
-  uint64_t TSC = 1;
-  uint16_t CPU = 0;
-  Trie.enterFunction(1, TSC++, CPU++);
-  Trie.exitFunction(1, TSC++, CPU++);
-  const auto &R = Trie.getRoots();
-
-  ASSERT_EQ(R.size(), 1u);
-  ASSERT_EQ(R.front()->FId, 1);
-  ASSERT_EQ(R.front()->CallCount, 1u);
-  ASSERT_EQ(R.front()->CumulativeLocalTime, 1u);
-}
-
-TEST(FunctionCallTrieTest, HandleTSCOverflow) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-
-  Trie.enterFunction(1, std::numeric_limits<uint64_t>::max(), 0);
-  Trie.exitFunction(1, 1, 0);
-  const auto &R = Trie.getRoots();
-
-  ASSERT_EQ(R.size(), 1u);
-  ASSERT_EQ(R.front()->FId, 1);
-  ASSERT_EQ(R.front()->CallCount, 1u);
-  ASSERT_EQ(R.front()->CumulativeLocalTime, 1u);
-}
-
-TEST(FunctionCallTrieTest, MaximalCumulativeTime) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-
-  Trie.enterFunction(1, 1, 0);
-  Trie.exitFunction(1, 0, 0);
-  const auto &R = Trie.getRoots();
-
-  ASSERT_EQ(R.size(), 1u);
-  ASSERT_EQ(R.front()->FId, 1);
-  ASSERT_EQ(R.front()->CallCount, 1u);
-  ASSERT_EQ(R.front()->CumulativeLocalTime,
-            std::numeric_limits<uint64_t>::max() - 1);
-}
-
-TEST(FunctionCallTrieTest, MissingFunctionEntry) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-  Trie.exitFunction(1, 1, 0);
-  const auto &R = Trie.getRoots();
-
-  ASSERT_TRUE(R.empty());
-}
-
-TEST(FunctionCallTrieTest, NoMatchingEntersForExit) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-  Trie.enterFunction(2, 1, 0);
-  Trie.enterFunction(3, 3, 0);
-  Trie.exitFunction(1, 5, 0);
-  const auto &R = Trie.getRoots();
-
-  ASSERT_FALSE(R.empty());
-  EXPECT_EQ(R.size(), size_t{1});
-}
-
-TEST(FunctionCallTrieTest, MissingFunctionExit) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-  Trie.enterFunction(1, 1, 0);
-  const auto &R = Trie.getRoots();
-
-  ASSERT_FALSE(R.empty());
-  EXPECT_EQ(R.size(), size_t{1});
-}
-
-TEST(FunctionCallTrieTest, MultipleRoots) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-
-  // Enter and exit FId = 1.
-  Trie.enterFunction(1, 1, 0);
-  Trie.exitFunction(1, 2, 0);
-
-  // Enter and exit FId = 2.
-  Trie.enterFunction(2, 3, 0);
-  Trie.exitFunction(2, 4, 0);
-
-  const auto &R = Trie.getRoots();
-  ASSERT_FALSE(R.empty());
-  ASSERT_EQ(R.size(), 2u);
-
-  // Make sure the roots have different IDs.
-  const auto R0 = R[0];
-  const auto R1 = R[1];
-  ASSERT_NE(R0->FId, R1->FId);
-
-  // Inspect the roots that they have the right data.
-  ASSERT_NE(R0, nullptr);
-  EXPECT_EQ(R0->CallCount, 1u);
-  EXPECT_EQ(R0->CumulativeLocalTime, 1u);
-
-  ASSERT_NE(R1, nullptr);
-  EXPECT_EQ(R1->CallCount, 1u);
-  EXPECT_EQ(R1->CumulativeLocalTime, 1u);
-}
-
-// While missing an intermediary entry may be rare in practice, we still enforce
-// that we can handle the case where we've missed the entry event somehow, in
-// between call entry/exits. To illustrate, imagine the following shadow call
-// stack:
-//
-//   f0 at t0 -> f1 at t1 -> f2 at t2
-//
-// If for whatever reason we see an exit for `f2` @ t3, followed by an exit for
-// `f0` @ t4 (i.e. no `f1` exit in between) then we need to handle the case of
-// accounting local time to `f2` from d = (t3 - t2), then local time to `f1`
-// as d' = (t3 - t1) - d, and then local time to `f0` as d'' = (t3 - t0) - d'.
-TEST(FunctionCallTrieTest, MissingIntermediaryExit) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-
-  Trie.enterFunction(1, 0, 0);
-  Trie.enterFunction(2, 100, 0);
-  Trie.enterFunction(3, 200, 0);
-  Trie.exitFunction(3, 300, 0);
-  Trie.exitFunction(1, 400, 0);
-
-  // What we should see at this point is all the functions in the trie in a
-  // specific order (1 -> 2 -> 3) with the appropriate count(s) and local
-  // latencies.
-  const auto &R = Trie.getRoots();
-  ASSERT_FALSE(R.empty());
-  ASSERT_EQ(R.size(), 1u);
-
-  const auto &F1 = *R[0];
-  ASSERT_EQ(F1.FId, 1);
-  ASSERT_FALSE(F1.Callees.empty());
-
-  const auto &F2 = *F1.Callees[0].NodePtr;
-  ASSERT_EQ(F2.FId, 2);
-  ASSERT_FALSE(F2.Callees.empty());
-
-  const auto &F3 = *F2.Callees[0].NodePtr;
-  ASSERT_EQ(F3.FId, 3);
-  ASSERT_TRUE(F3.Callees.empty());
-
-  // Now that we've established the preconditions, we check for specific aspects
-  // of the nodes.
-  EXPECT_EQ(F3.CallCount, 1u);
-  EXPECT_EQ(F2.CallCount, 1u);
-  EXPECT_EQ(F1.CallCount, 1u);
-  EXPECT_EQ(F3.CumulativeLocalTime, 100u);
-  EXPECT_EQ(F2.CumulativeLocalTime, 300u);
-  EXPECT_EQ(F1.CumulativeLocalTime, 100u);
-}
-
-TEST(FunctionCallTrieTest, DeepCallStack) {
-  // Simulate a relatively deep call stack (32 levels) and ensure that we can
-  // properly pop all the way up the stack.
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-  for (int i = 0; i < 32; ++i)
-    Trie.enterFunction(i + 1, i, 0);
-  Trie.exitFunction(1, 33, 0);
-
-  // Here, validate that we have a 32-level deep function call path from the
-  // root (1) down to the leaf (33).
-  const auto &R = Trie.getRoots();
-  ASSERT_EQ(R.size(), 1u);
-  auto F = R[0];
-  for (int i = 0; i < 32; ++i) {
-    EXPECT_EQ(F->FId, i + 1);
-    EXPECT_EQ(F->CallCount, 1u);
-    if (F->Callees.empty() && i != 31)
-      FAIL() << "Empty callees for FId " << F->FId;
-    if (i != 31)
-      F = F->Callees[0].NodePtr;
-  }
-}
-
-// TODO: Test that we can handle cross-CPU migrations, where TSCs are not
-// guaranteed to be synchronised.
-TEST(FunctionCallTrieTest, DeepCopy) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Trie(A);
-
-  Trie.enterFunction(1, 0, 0);
-  Trie.enterFunction(2, 1, 0);
-  Trie.exitFunction(2, 2, 0);
-  Trie.enterFunction(3, 3, 0);
-  Trie.exitFunction(3, 4, 0);
-  Trie.exitFunction(1, 5, 0);
-
-  // We want to make a deep copy and compare notes.
-  auto B = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Copy(B);
-  Trie.deepCopyInto(Copy);
-
-  ASSERT_NE(Trie.getRoots().size(), 0u);
-  ASSERT_EQ(Trie.getRoots().size(), Copy.getRoots().size());
-  const auto &R0Orig = *Trie.getRoots()[0];
-  const auto &R0Copy = *Copy.getRoots()[0];
-  EXPECT_EQ(R0Orig.FId, 1);
-  EXPECT_EQ(R0Orig.FId, R0Copy.FId);
-
-  ASSERT_EQ(R0Orig.Callees.size(), 2u);
-  ASSERT_EQ(R0Copy.Callees.size(), 2u);
-
-  const auto &F1Orig =
-      *R0Orig.Callees
-           .find_element(
-               [](const FunctionCallTrie::NodeIdPair &R) { return R.FId == 2; })
-           ->NodePtr;
-  const auto &F1Copy =
-      *R0Copy.Callees
-           .find_element(
-               [](const FunctionCallTrie::NodeIdPair &R) { return R.FId == 2; })
-           ->NodePtr;
-  EXPECT_EQ(&R0Orig, F1Orig.Parent);
-  EXPECT_EQ(&R0Copy, F1Copy.Parent);
-}
-
-TEST(FunctionCallTrieTest, MergeInto) {
-  profilingFlags()->setDefaults();
-  auto A = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie T0(A);
-  FunctionCallTrie T1(A);
-
-  // 1 -> 2 -> 3
-  T0.enterFunction(1, 0, 0);
-  T0.enterFunction(2, 1, 0);
-  T0.enterFunction(3, 2, 0);
-  T0.exitFunction(3, 3, 0);
-  T0.exitFunction(2, 4, 0);
-  T0.exitFunction(1, 5, 0);
-
-  // 1 -> 2 -> 3
-  T1.enterFunction(1, 0, 0);
-  T1.enterFunction(2, 1, 0);
-  T1.enterFunction(3, 2, 0);
-  T1.exitFunction(3, 3, 0);
-  T1.exitFunction(2, 4, 0);
-  T1.exitFunction(1, 5, 0);
-
-  // We use a different allocator here to make sure that we're able to transfer
-  // data into a FunctionCallTrie which uses a different allocator. This
-  // reflects the inteded usage scenario for when we're collecting profiles that
-  // aggregate across threads.
-  auto B = FunctionCallTrie::InitAllocators();
-  FunctionCallTrie Merged(B);
-
-  T0.mergeInto(Merged);
-  T1.mergeInto(Merged);
-
-  ASSERT_EQ(Merged.getRoots().size(), 1u);
-  const auto &R0 = *Merged.getRoots()[0];
-  EXPECT_EQ(R0.FId, 1);
-  EXPECT_EQ(R0.CallCount, 2u);
-  EXPECT_EQ(R0.CumulativeLocalTime, 10u);
-  EXPECT_EQ(R0.Callees.size(), 1u);
-
-  const auto &F1 = *R0.Callees[0].NodePtr;
-  EXPECT_EQ(F1.FId, 2);
-  EXPECT_EQ(F1.CallCount, 2u);
-  EXPECT_EQ(F1.CumulativeLocalTime, 6u);
-  EXPECT_EQ(F1.Callees.size(), 1u);
-
-  const auto &F2 = *F1.Callees[0].NodePtr;
-  EXPECT_EQ(F2.FId, 3);
-  EXPECT_EQ(F2.CallCount, 2u);
-  EXPECT_EQ(F2.CumulativeLocalTime, 2u);
-  EXPECT_EQ(F2.Callees.size(), 0u);
-}
-
-TEST(FunctionCallTrieTest, PlacementNewOnAlignedStorage) {
-  profilingFlags()->setDefaults();
-  typename std::aligned_storage<sizeof(FunctionCallTrie::Allocators),
-                                alignof(FunctionCallTrie::Allocators)>::type
-      AllocatorsStorage;
-  new (&AllocatorsStorage)
-      FunctionCallTrie::Allocators(FunctionCallTrie::InitAllocators());
-  auto *A =
-      reinterpret_cast<FunctionCallTrie::Allocators *>(&AllocatorsStorage);
-
-  typename std::aligned_storage<sizeof(FunctionCallTrie),
-                                alignof(FunctionCallTrie)>::type FCTStorage;
-  new (&FCTStorage) FunctionCallTrie(*A);
-  auto *T = reinterpret_cast<FunctionCallTrie *>(&FCTStorage);
-
-  // Put some data into it.
-  T->enterFunction(1, 0, 0);
-  T->exitFunction(1, 1, 0);
-
-  // Re-initialize the objects in storage.
-  T->~FunctionCallTrie();
-  A->~Allocators();
-  new (A) FunctionCallTrie::Allocators(FunctionCallTrie::InitAllocators());
-  new (T) FunctionCallTrie(*A);
-
-  // Then put some data into it again.
-  T->enterFunction(1, 0, 0);
-  T->exitFunction(1, 1, 0);
-}
-
-} // namespace
-
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/function_call_trie_test.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- function_call_trie_test.cc ----------------------------------------===//
+//===-- function_call_trie_test.cpp ---------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc (removed)
@@ -1,235 +0,0 @@
-//===-- profile_collector_test.cc -----------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
-
-#include "xray_profile_collector.h"
-#include "xray_profiling_flags.h"
-#include <cstdint>
-#include <cstring>
-#include <memory>
-#include <thread>
-#include <utility>
-#include <vector>
-
-namespace __xray {
-namespace {
-
-static constexpr auto kHeaderSize = 16u;
-
-constexpr uptr ExpectedProfilingVersion = 0x20180424;
-
-struct ExpectedProfilingFileHeader {
-  const u64 MagicBytes = 0x7872617970726f66; // Identifier for XRay profiling
-                                             // files 'xrayprof' in hex.
-  const u64 Version = ExpectedProfilingVersion;
-  u64 Timestamp = 0;
-  u64 PID = 0;
-};
-
-void ValidateFileHeaderBlock(XRayBuffer B) {
-  ASSERT_NE(static_cast<const void *>(B.Data), nullptr);
-  ASSERT_EQ(B.Size, sizeof(ExpectedProfilingFileHeader));
-  typename std::aligned_storage<sizeof(ExpectedProfilingFileHeader)>::type
-      FileHeaderStorage;
-  ExpectedProfilingFileHeader ExpectedHeader;
-  std::memcpy(&FileHeaderStorage, B.Data, B.Size);
-  auto &FileHeader =
-      *reinterpret_cast<ExpectedProfilingFileHeader *>(&FileHeaderStorage);
-  ASSERT_EQ(ExpectedHeader.MagicBytes, FileHeader.MagicBytes);
-  ASSERT_EQ(ExpectedHeader.Version, FileHeader.Version);
-}
-
-void ValidateBlock(XRayBuffer B) {
-  profilingFlags()->setDefaults();
-  ASSERT_NE(static_cast<const void *>(B.Data), nullptr);
-  ASSERT_NE(B.Size, 0u);
-  ASSERT_GE(B.Size, kHeaderSize);
-  // We look at the block size, the block number, and the thread ID to ensure
-  // that none of them are zero (or that the header data is laid out as we
-  // expect).
-  char LocalBuffer[kHeaderSize] = {};
-  internal_memcpy(LocalBuffer, B.Data, kHeaderSize);
-  u32 BlockSize = 0;
-  u32 BlockNumber = 0;
-  u64 ThreadId = 0;
-  internal_memcpy(&BlockSize, LocalBuffer, sizeof(u32));
-  internal_memcpy(&BlockNumber, LocalBuffer + sizeof(u32), sizeof(u32));
-  internal_memcpy(&ThreadId, LocalBuffer + (2 * sizeof(u32)), sizeof(u64));
-  ASSERT_NE(BlockSize, 0u);
-  ASSERT_GE(BlockNumber, 0u);
-  ASSERT_NE(ThreadId, 0u);
-}
-
-std::tuple<u32, u32, u64> ParseBlockHeader(XRayBuffer B) {
-  char LocalBuffer[kHeaderSize] = {};
-  internal_memcpy(LocalBuffer, B.Data, kHeaderSize);
-  u32 BlockSize = 0;
-  u32 BlockNumber = 0;
-  u64 ThreadId = 0;
-  internal_memcpy(&BlockSize, LocalBuffer, sizeof(u32));
-  internal_memcpy(&BlockNumber, LocalBuffer + sizeof(u32), sizeof(u32));
-  internal_memcpy(&ThreadId, LocalBuffer + (2 * sizeof(u32)), sizeof(u64));
-  return std::make_tuple(BlockSize, BlockNumber, ThreadId);
-}
-
-struct Profile {
-  int64_t CallCount;
-  int64_t CumulativeLocalTime;
-  std::vector<int32_t> Path;
-};
-
-std::tuple<Profile, const char *> ParseProfile(const char *P) {
-  Profile Result;
-  // Read the path first, until we find a sentinel 0.
-  int32_t F;
-  do {
-    internal_memcpy(&F, P, sizeof(int32_t));
-    P += sizeof(int32_t);
-    Result.Path.push_back(F);
-  } while (F != 0);
-
-  // Then read the CallCount.
-  internal_memcpy(&Result.CallCount, P, sizeof(int64_t));
-  P += sizeof(int64_t);
-
-  // Then read the CumulativeLocalTime.
-  internal_memcpy(&Result.CumulativeLocalTime, P, sizeof(int64_t));
-  P += sizeof(int64_t);
-  return std::make_tuple(std::move(Result), P);
-}
-
-TEST(profileCollectorServiceTest, PostSerializeCollect) {
-  profilingFlags()->setDefaults();
-  bool Success = false;
-  BufferQueue BQ(profilingFlags()->per_thread_allocator_max,
-                 profilingFlags()->buffers_max, Success);
-  ASSERT_EQ(Success, true);
-  FunctionCallTrie::Allocators::Buffers Buffers;
-  ASSERT_EQ(BQ.getBuffer(Buffers.NodeBuffer), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(BQ.getBuffer(Buffers.RootsBuffer), BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(BQ.getBuffer(Buffers.ShadowStackBuffer),
-            BufferQueue::ErrorCode::Ok);
-  ASSERT_EQ(BQ.getBuffer(Buffers.NodeIdPairBuffer), BufferQueue::ErrorCode::Ok);
-  auto Allocators = FunctionCallTrie::InitAllocatorsFromBuffers(Buffers);
-  FunctionCallTrie T(Allocators);
-
-  // Populate the trie with some data.
-  T.enterFunction(1, 1, 0);
-  T.enterFunction(2, 2, 0);
-  T.exitFunction(2, 3, 0);
-  T.exitFunction(1, 4, 0);
-
-  // Reset the collector data structures.
-  profileCollectorService::reset();
-
-  // Then we post the data to the global profile collector service.
-  profileCollectorService::post(&BQ, std::move(T), std::move(Allocators),
-                                std::move(Buffers), 1);
-
-  // Then we serialize the data.
-  profileCollectorService::serialize();
-
-  // Then we go through two buffers to see whether we're getting the data we
-  // expect. The first block must always be as large as a file header, which
-  // will have a fixed size.
-  auto B = profileCollectorService::nextBuffer({nullptr, 0});
-  ValidateFileHeaderBlock(B);
-
-  B = profileCollectorService::nextBuffer(B);
-  ValidateBlock(B);
-  u32 BlockSize;
-  u32 BlockNum;
-  u64 ThreadId;
-  std::tie(BlockSize, BlockNum, ThreadId) = ParseBlockHeader(B);
-
-  // We look at the serialized buffer to see whether the Trie we're expecting
-  // to see is there.
-  auto DStart = static_cast<const char *>(B.Data) + kHeaderSize;
-  std::vector<char> D(DStart, DStart + BlockSize);
-  B = profileCollectorService::nextBuffer(B);
-  ASSERT_EQ(B.Data, nullptr);
-  ASSERT_EQ(B.Size, 0u);
-
-  Profile Profile1, Profile2;
-  auto P = static_cast<const char *>(D.data());
-  std::tie(Profile1, P) = ParseProfile(P);
-  std::tie(Profile2, P) = ParseProfile(P);
-
-  ASSERT_NE(Profile1.Path.size(), Profile2.Path.size());
-  auto &P1 = Profile1.Path.size() < Profile2.Path.size() ? Profile2 : Profile1;
-  auto &P2 = Profile1.Path.size() < Profile2.Path.size() ? Profile1 : Profile2;
-  std::vector<int32_t> P1Expected = {2, 1, 0};
-  std::vector<int32_t> P2Expected = {1, 0};
-  ASSERT_EQ(P1.Path.size(), P1Expected.size());
-  ASSERT_EQ(P2.Path.size(), P2Expected.size());
-  ASSERT_EQ(P1.Path, P1Expected);
-  ASSERT_EQ(P2.Path, P2Expected);
-}
-
-// We break out a function that will be run in multiple threads, one that will
-// use a thread local allocator, and will post the FunctionCallTrie to the
-// profileCollectorService. This simulates what the threads being profiled would
-// be doing anyway, but through the XRay logging implementation.
-void threadProcessing() {
-  static bool Success = false;
-  static BufferQueue BQ(profilingFlags()->per_thread_allocator_max,
-                        profilingFlags()->buffers_max, Success);
-  thread_local FunctionCallTrie::Allocators::Buffers Buffers = [] {
-    FunctionCallTrie::Allocators::Buffers B;
-    BQ.getBuffer(B.NodeBuffer);
-    BQ.getBuffer(B.RootsBuffer);
-    BQ.getBuffer(B.ShadowStackBuffer);
-    BQ.getBuffer(B.NodeIdPairBuffer);
-    return B;
-  }();
-
-  thread_local auto Allocators =
-      FunctionCallTrie::InitAllocatorsFromBuffers(Buffers);
-
-  FunctionCallTrie T(Allocators);
-
-  T.enterFunction(1, 1, 0);
-  T.enterFunction(2, 2, 0);
-  T.exitFunction(2, 3, 0);
-  T.exitFunction(1, 4, 0);
-
-  profileCollectorService::post(&BQ, std::move(T), std::move(Allocators),
-                                std::move(Buffers), GetTid());
-}
-
-TEST(profileCollectorServiceTest, PostSerializeCollectMultipleThread) {
-  profilingFlags()->setDefaults();
-
-  profileCollectorService::reset();
-
-  std::thread t1(threadProcessing);
-  std::thread t2(threadProcessing);
-
-  t1.join();
-  t2.join();
-
-  // At this point, t1 and t2 are already done with what they were doing.
-  profileCollectorService::serialize();
-
-  // Ensure that we see two buffers.
-  auto B = profileCollectorService::nextBuffer({nullptr, 0});
-  ValidateFileHeaderBlock(B);
-
-  B = profileCollectorService::nextBuffer(B);
-  ValidateBlock(B);
-
-  B = profileCollectorService::nextBuffer(B);
-  ValidateBlock(B);
-}
-
-} // namespace
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/profile_collector_test.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- profile_collector_test.cc -----------------------------------------===//
+//===-- profile_collector_test.cpp ----------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/segmented_array_test.cc (removed)
@@ -1,349 +0,0 @@
-#include "test_helpers.h"
-#include "xray_segmented_array.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-#include <algorithm>
-#include <numeric>
-#include <vector>
-
-namespace __xray {
-namespace {
-
-using ::testing::SizeIs;
-
-struct TestData {
-  s64 First;
-  s64 Second;
-
-  // Need a constructor for emplace operations.
-  TestData(s64 F, s64 S) : First(F), Second(S) {}
-};
-
-void PrintTo(const TestData &D, std::ostream *OS) {
-  *OS << "{ " << D.First << ", " << D.Second << " }";
-}
-
-TEST(SegmentedArrayTest, ConstructWithAllocators) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> Data(A);
-  (void)Data;
-}
-
-TEST(SegmentedArrayTest, ConstructAndPopulate) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> data(A);
-  ASSERT_NE(data.Append(TestData{0, 0}), nullptr);
-  ASSERT_NE(data.Append(TestData{1, 1}), nullptr);
-  ASSERT_EQ(data.size(), 2u);
-}
-
-TEST(SegmentedArrayTest, ConstructPopulateAndLookup) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> data(A);
-  ASSERT_NE(data.Append(TestData{0, 1}), nullptr);
-  ASSERT_EQ(data.size(), 1u);
-  ASSERT_EQ(data[0].First, 0);
-  ASSERT_EQ(data[0].Second, 1);
-}
-
-TEST(SegmentedArrayTest, PopulateWithMoreElements) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 24);
-  Array<TestData> data(A);
-  static const auto kMaxElements = 100u;
-  for (auto I = 0u; I < kMaxElements; ++I) {
-    ASSERT_NE(data.Append(TestData{I, I + 1}), nullptr);
-  }
-  ASSERT_EQ(data.size(), kMaxElements);
-  for (auto I = 0u; I < kMaxElements; ++I) {
-    ASSERT_EQ(data[I].First, I);
-    ASSERT_EQ(data[I].Second, I + 1);
-  }
-}
-
-TEST(SegmentedArrayTest, AppendEmplace) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> data(A);
-  ASSERT_NE(data.AppendEmplace(1, 1), nullptr);
-  ASSERT_EQ(data[0].First, 1);
-  ASSERT_EQ(data[0].Second, 1);
-}
-
-TEST(SegmentedArrayTest, AppendAndTrim) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> data(A);
-  ASSERT_NE(data.AppendEmplace(1, 1), nullptr);
-  ASSERT_EQ(data.size(), 1u);
-  data.trim(1);
-  ASSERT_EQ(data.size(), 0u);
-  ASSERT_TRUE(data.empty());
-}
-
-TEST(SegmentedArrayTest, IteratorAdvance) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> data(A);
-  ASSERT_TRUE(data.empty());
-  ASSERT_EQ(data.begin(), data.end());
-  auto I0 = data.begin();
-  ASSERT_EQ(I0++, data.begin());
-  ASSERT_NE(I0, data.begin());
-  for (const auto &D : data) {
-    (void)D;
-    FAIL();
-  }
-  ASSERT_NE(data.AppendEmplace(1, 1), nullptr);
-  ASSERT_EQ(data.size(), 1u);
-  ASSERT_NE(data.begin(), data.end());
-  auto &D0 = *data.begin();
-  ASSERT_EQ(D0.First, 1);
-  ASSERT_EQ(D0.Second, 1);
-}
-
-TEST(SegmentedArrayTest, IteratorRetreat) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 4);
-  Array<TestData> data(A);
-  ASSERT_TRUE(data.empty());
-  ASSERT_EQ(data.begin(), data.end());
-  ASSERT_NE(data.AppendEmplace(1, 1), nullptr);
-  ASSERT_EQ(data.size(), 1u);
-  ASSERT_NE(data.begin(), data.end());
-  auto &D0 = *data.begin();
-  ASSERT_EQ(D0.First, 1);
-  ASSERT_EQ(D0.Second, 1);
-
-  auto I0 = data.end();
-  ASSERT_EQ(I0--, data.end());
-  ASSERT_NE(I0, data.end());
-  ASSERT_EQ(I0, data.begin());
-  ASSERT_EQ(I0->First, 1);
-  ASSERT_EQ(I0->Second, 1);
-}
-
-TEST(SegmentedArrayTest, IteratorTrimBehaviour) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  AllocatorType A(1 << 20);
-  Array<TestData> Data(A);
-  ASSERT_TRUE(Data.empty());
-  auto I0Begin = Data.begin(), I0End = Data.end();
-  // Add enough elements in Data to have more than one chunk.
-  constexpr auto Segment = Array<TestData>::SegmentSize;
-  constexpr auto SegmentX2 = Segment * 2;
-  for (auto i = SegmentX2; i > 0u; --i) {
-    Data.AppendEmplace(static_cast<s64>(i), static_cast<s64>(i));
-  }
-  ASSERT_EQ(Data.size(), SegmentX2);
-  {
-    auto &Back = Data.back();
-    ASSERT_EQ(Back.First, 1);
-    ASSERT_EQ(Back.Second, 1);
-  }
-
-  // Trim one chunk's elements worth.
-  Data.trim(Segment);
-  ASSERT_EQ(Data.size(), Segment);
-
-  // Check that we are still able to access 'back' properly.
-  {
-    auto &Back = Data.back();
-    ASSERT_EQ(Back.First, static_cast<s64>(Segment + 1));
-    ASSERT_EQ(Back.Second, static_cast<s64>(Segment + 1));
-  }
-
-  // Then trim until it's empty.
-  Data.trim(Segment);
-  ASSERT_TRUE(Data.empty());
-
-  // Here our iterators should be the same.
-  auto I1Begin = Data.begin(), I1End = Data.end();
-  EXPECT_EQ(I0Begin, I1Begin);
-  EXPECT_EQ(I0End, I1End);
-
-  // Then we ensure that adding elements back works just fine.
-  for (auto i = SegmentX2; i > 0u; --i) {
-    Data.AppendEmplace(static_cast<s64>(i), static_cast<s64>(i));
-  }
-  EXPECT_EQ(Data.size(), SegmentX2);
-}
-
-TEST(SegmentedArrayTest, HandleExhaustedAllocator) {
-  using AllocatorType = typename Array<TestData>::AllocatorType;
-  constexpr auto Segment = Array<TestData>::SegmentSize;
-  constexpr auto MaxElements = Array<TestData>::ElementsPerSegment;
-  AllocatorType A(Segment);
-  Array<TestData> Data(A);
-  for (auto i = MaxElements; i > 0u; --i)
-    EXPECT_NE(Data.AppendEmplace(static_cast<s64>(i), static_cast<s64>(i)),
-              nullptr);
-  EXPECT_EQ(Data.AppendEmplace(0, 0), nullptr);
-  EXPECT_THAT(Data, SizeIs(MaxElements));
-
-  // Trimming more elements than there are in the container should be fine.
-  Data.trim(MaxElements + 1);
-  EXPECT_THAT(Data, SizeIs(0u));
-}
-
-struct ShadowStackEntry {
-  uint64_t EntryTSC = 0;
-  uint64_t *NodePtr = nullptr;
-  ShadowStackEntry(uint64_t T, uint64_t *N) : EntryTSC(T), NodePtr(N) {}
-};
-
-TEST(SegmentedArrayTest, SimulateStackBehaviour) {
-  using AllocatorType = typename Array<ShadowStackEntry>::AllocatorType;
-  AllocatorType A(1 << 10);
-  Array<ShadowStackEntry> Data(A);
-  static uint64_t Dummy = 0;
-  constexpr uint64_t Max = 9;
-
-  for (uint64_t i = 0; i < Max; ++i) {
-    auto P = Data.Append({i, &Dummy});
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(P->NodePtr, &Dummy);
-    auto &Back = Data.back();
-    ASSERT_EQ(Back.NodePtr, &Dummy);
-    ASSERT_EQ(Back.EntryTSC, i);
-  }
-
-  // Simulate a stack by checking the data from the end as we're trimming.
-  auto Counter = Max;
-  ASSERT_EQ(Data.size(), size_t(Max));
-  while (!Data.empty()) {
-    const auto &Top = Data.back();
-    uint64_t *TopNode = Top.NodePtr;
-    EXPECT_EQ(TopNode, &Dummy) << "Counter = " << Counter;
-    Data.trim(1);
-    --Counter;
-    ASSERT_EQ(Data.size(), size_t(Counter));
-  }
-}
-
-TEST(SegmentedArrayTest, PlacementNewOnAlignedStorage) {
-  using AllocatorType = typename Array<ShadowStackEntry>::AllocatorType;
-  typename std::aligned_storage<sizeof(AllocatorType),
-                                alignof(AllocatorType)>::type AllocatorStorage;
-  new (&AllocatorStorage) AllocatorType(1 << 10);
-  auto *A = reinterpret_cast<AllocatorType *>(&AllocatorStorage);
-  typename std::aligned_storage<sizeof(Array<ShadowStackEntry>),
-                                alignof(Array<ShadowStackEntry>)>::type
-      ArrayStorage;
-  new (&ArrayStorage) Array<ShadowStackEntry>(*A);
-  auto *Data = reinterpret_cast<Array<ShadowStackEntry> *>(&ArrayStorage);
-
-  static uint64_t Dummy = 0;
-  constexpr uint64_t Max = 9;
-
-  for (uint64_t i = 0; i < Max; ++i) {
-    auto P = Data->Append({i, &Dummy});
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(P->NodePtr, &Dummy);
-    auto &Back = Data->back();
-    ASSERT_EQ(Back.NodePtr, &Dummy);
-    ASSERT_EQ(Back.EntryTSC, i);
-  }
-
-  // Simulate a stack by checking the data from the end as we're trimming.
-  auto Counter = Max;
-  ASSERT_EQ(Data->size(), size_t(Max));
-  while (!Data->empty()) {
-    const auto &Top = Data->back();
-    uint64_t *TopNode = Top.NodePtr;
-    EXPECT_EQ(TopNode, &Dummy) << "Counter = " << Counter;
-    Data->trim(1);
-    --Counter;
-    ASSERT_EQ(Data->size(), size_t(Counter));
-  }
-
-  // Once the stack is exhausted, we re-use the storage.
-  for (uint64_t i = 0; i < Max; ++i) {
-    auto P = Data->Append({i, &Dummy});
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(P->NodePtr, &Dummy);
-    auto &Back = Data->back();
-    ASSERT_EQ(Back.NodePtr, &Dummy);
-    ASSERT_EQ(Back.EntryTSC, i);
-  }
-
-  // We re-initialize the storage, by calling the destructor and
-  // placement-new'ing again.
-  Data->~Array();
-  A->~AllocatorType();
-  new (A) AllocatorType(1 << 10);
-  new (Data) Array<ShadowStackEntry>(*A);
-
-  // Then re-do the test.
-  for (uint64_t i = 0; i < Max; ++i) {
-    auto P = Data->Append({i, &Dummy});
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(P->NodePtr, &Dummy);
-    auto &Back = Data->back();
-    ASSERT_EQ(Back.NodePtr, &Dummy);
-    ASSERT_EQ(Back.EntryTSC, i);
-  }
-
-  // Simulate a stack by checking the data from the end as we're trimming.
-  Counter = Max;
-  ASSERT_EQ(Data->size(), size_t(Max));
-  while (!Data->empty()) {
-    const auto &Top = Data->back();
-    uint64_t *TopNode = Top.NodePtr;
-    EXPECT_EQ(TopNode, &Dummy) << "Counter = " << Counter;
-    Data->trim(1);
-    --Counter;
-    ASSERT_EQ(Data->size(), size_t(Counter));
-  }
-
-  // Once the stack is exhausted, we re-use the storage.
-  for (uint64_t i = 0; i < Max; ++i) {
-    auto P = Data->Append({i, &Dummy});
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(P->NodePtr, &Dummy);
-    auto &Back = Data->back();
-    ASSERT_EQ(Back.NodePtr, &Dummy);
-    ASSERT_EQ(Back.EntryTSC, i);
-  }
-}
-
-TEST(SegmentedArrayTest, ArrayOfPointersIteratorAccess) {
-  using PtrArray = Array<int *>;
-  PtrArray::AllocatorType Alloc(16384);
-  Array<int *> A(Alloc);
-  static constexpr size_t Count = 100;
-  std::vector<int> Integers(Count);
-  std::iota(Integers.begin(), Integers.end(), 0);
-  for (auto &I : Integers)
-    ASSERT_NE(A.Append(&I), nullptr);
-  int V = 0;
-  ASSERT_EQ(A.size(), Count);
-  for (auto P : A) {
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(*P, V++);
-  }
-}
-
-TEST(SegmentedArrayTest, ArrayOfPointersIteratorAccessExhaustion) {
-  using PtrArray = Array<int *>;
-  PtrArray::AllocatorType Alloc(4096);
-  Array<int *> A(Alloc);
-  static constexpr size_t Count = 1000;
-  std::vector<int> Integers(Count);
-  std::iota(Integers.begin(), Integers.end(), 0);
-  for (auto &I : Integers)
-    if (A.Append(&I) == nullptr)
-      break;
-  int V = 0;
-  ASSERT_LT(A.size(), Count);
-  for (auto P : A) {
-    ASSERT_NE(P, nullptr);
-    ASSERT_EQ(*P, V++);
-  }
-}
-
-} // namespace
-} // namespace __xray

Removed: compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc (removed)
@@ -1,94 +0,0 @@
-//===-- test_helpers.cc ---------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include "test_helpers.h"
-#include "xray/xray_records.h"
-#include "xray_buffer_queue.h"
-#include "xray_fdr_log_writer.h"
-#include <type_traits>
-
-// TODO: Move these to llvm/include/Testing/XRay/...
-namespace llvm {
-namespace xray {
-
-std::string RecordTypeAsString(RecordTypes T) {
-  switch (T) {
-  case RecordTypes::ENTER:
-    return "llvm::xray::RecordTypes::ENTER";
-  case RecordTypes::EXIT:
-    return "llvm::xray::RecordTypes::EXIT";
-  case RecordTypes::TAIL_EXIT:
-    return "llvm::xray::RecordTypes::TAIL_EXIT";
-  case RecordTypes::ENTER_ARG:
-    return "llvm::xray::RecordTypes::ENTER_ARG";
-  case RecordTypes::CUSTOM_EVENT:
-    return "llvm::xray::RecordTypes::CUSTOM_EVENT";
-  case RecordTypes::TYPED_EVENT:
-    return "llvm::xray::RecordTypes::TYPED_EVENT";
-  }
-  return "<UNKNOWN>";
-}
-
-void PrintTo(RecordTypes T, std::ostream *OS) {
-  *OS << RecordTypeAsString(T);
-}
-
-void PrintTo(const XRayRecord &R, std::ostream *OS) {
-  *OS << "XRayRecord { CPU = " << R.CPU
-      << "; Type = " << RecordTypeAsString(R.Type) << "; FuncId = " << R.FuncId
-      << "; TSC = " << R.TSC << "; TId = " << R.TId << "; PId = " << R.PId
-      << " Args = " << ::testing::PrintToString(R.CallArgs) << " }";
-}
-
-void PrintTo(const Trace &T, std::ostream *OS) {
-  const auto &H = T.getFileHeader();
-  *OS << "XRay Trace:\nHeader: { Version = " << H.Version
-      << "; Type = " << H.Type
-      << "; ConstantTSC = " << ::testing::PrintToString(H.ConstantTSC)
-      << "; NonstopTSC = " << ::testing::PrintToString(H.NonstopTSC)
-      << "; CycleFrequency = " << H.CycleFrequency << "; FreeFormData = '"
-      << ::testing::PrintToString(H.FreeFormData) << "' }\n";
-  for (const auto &R : T) {
-    PrintTo(R, OS);
-    *OS << "\n";
-  }
-}
-
-} // namespace xray
-} // namespace llvm
-
-namespace __xray {
-
-std::string serialize(BufferQueue &Buffers, int32_t Version) {
-  std::string Serialized;
-  std::aligned_storage<sizeof(XRayFileHeader), alignof(XRayFileHeader)>::type
-      HeaderStorage;
-  auto *Header = reinterpret_cast<XRayFileHeader *>(&HeaderStorage);
-  new (Header) XRayFileHeader();
-  Header->Version = Version;
-  Header->Type = FileTypes::FDR_LOG;
-  Header->CycleFrequency = 3e9;
-  Header->ConstantTSC = 1;
-  Header->NonstopTSC = 1;
-  Serialized.append(reinterpret_cast<const char *>(&HeaderStorage),
-                    sizeof(XRayFileHeader));
-  Buffers.apply([&](const BufferQueue::Buffer &B) {
-    auto Size = atomic_load_relaxed(B.Extents);
-    auto Extents =
-        createMetadataRecord<MetadataRecord::RecordKinds::BufferExtents>(Size);
-    Serialized.append(reinterpret_cast<const char *>(&Extents),
-                      sizeof(Extents));
-    Serialized.append(reinterpret_cast<const char *>(B.Data), Size);
-  });
-  return Serialized;
-}
-
-} // namespace __xray

Copied: compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/test_helpers.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- test_helpers.cc ---------------------------------------------------===//
+//===-- test_helpers.cpp --------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc?rev=367549&view=auto
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc (removed)
@@ -1,17 +0,0 @@
-//===-- xray_unit_test_main.cc --------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of XRay, a function call tracing system.
-//
-//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
-
-int main(int argc, char **argv) {
-  testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}

Copied: compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cpp (from r367549, compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cpp?p2=compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cpp&p1=compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc&r1=367549&r2=367550&rev=367550&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc (original)
+++ compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cpp Thu Aug  1 05:35:27 2019
@@ -1,4 +1,4 @@
-//===-- xray_unit_test_main.cc --------------------------------------------===//
+//===-- xray_unit_test_main.cpp -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.




More information about the llvm-commits mailing list