summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/tests
diff options
context:
space:
mode:
authorDouglas Yung <douglas.yung@sony.com>2018-10-19 04:09:32 +0000
committerDouglas Yung <douglas.yung@sony.com>2018-10-19 04:09:32 +0000
commite61c8eb98f40a10a71d4d5c2f90d27b5d9d270bf (patch)
treed908d25065b82a5971eaaf0ad03211160e7afd30 /compiler-rt/lib/xray/tests
parent392e0061294cc7933f610f306237076775867259 (diff)
downloadbcm5719-llvm-e61c8eb98f40a10a71d4d5c2f90d27b5d9d270bf.tar.gz
bcm5719-llvm-e61c8eb98f40a10a71d4d5c2f90d27b5d9d270bf.zip
Revert commit r344670 as the test fails on a bot http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/2683/.
llvm-svn: 344771
Diffstat (limited to 'compiler-rt/lib/xray/tests')
-rw-r--r--compiler-rt/lib/xray/tests/unit/buffer_queue_test.cc116
1 files changed, 2 insertions, 114 deletions
diff --git a/compiler-rt/lib/xray/tests/unit/buffer_queue_test.cc b/compiler-rt/lib/xray/tests/unit/buffer_queue_test.cc
index 8aa366a20df..c0d4ccb268d 100644
--- a/compiler-rt/lib/xray/tests/unit/buffer_queue_test.cc
+++ b/compiler-rt/lib/xray/tests/unit/buffer_queue_test.cc
@@ -13,9 +13,7 @@
#include "xray_buffer_queue.h"
#include "gtest/gtest.h"
-#include <atomic>
#include <future>
-#include <thread>
#include <unistd.h>
namespace __xray {
@@ -57,7 +55,6 @@ TEST(BufferQueueTest, ReleaseUnknown) {
BufferQueue::Buffer Buf;
Buf.Data = reinterpret_cast<void *>(0xdeadbeef);
Buf.Size = kSize;
- Buf.Generation = Buffers.generation();
EXPECT_EQ(BufferQueue::ErrorCode::UnrecognizedBuffer,
Buffers.releaseBuffer(Buf));
}
@@ -73,7 +70,8 @@ TEST(BufferQueueTest, ErrorsWhenFinalising) {
BufferQueue::Buffer OtherBuf;
ASSERT_EQ(BufferQueue::ErrorCode::QueueFinalizing,
Buffers.getBuffer(OtherBuf));
- ASSERT_EQ(BufferQueue::ErrorCode::QueueFinalizing, Buffers.finalize());
+ ASSERT_EQ(BufferQueue::ErrorCode::QueueFinalizing,
+ Buffers.finalize());
ASSERT_EQ(Buffers.releaseBuffer(Buf), BufferQueue::ErrorCode::Ok);
}
@@ -113,114 +111,4 @@ TEST(BufferQueueTest, Apply) {
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 __xray
OpenPOWER on IntegriCloud