From 9827ac3b9d17a0c2043d91c01ab5ecc116ba6e39 Mon Sep 17 00:00:00 2001 From: Cezary Date: Mon, 11 Nov 2024 08:58:05 +0100 Subject: [PATCH] Barrier unit tests - assert that all threads have hit the barrier ensure correct result and thread safety by using atomic to count threads --- ShaderatorTests/barrier_tests.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ShaderatorTests/barrier_tests.cpp b/ShaderatorTests/barrier_tests.cpp index 2823acc..3bd21e7 100644 --- a/ShaderatorTests/barrier_tests.cpp +++ b/ShaderatorTests/barrier_tests.cpp @@ -3,19 +3,19 @@ #include "gtest/gtest.h" #include #include +#include TEST(BarrierTests, 32_treads_are_properly_blocked) { int barrier_size = 32; Barrier barrier(barrier_size); - int beforeBarrier = 0; - int afterBarrier = 0; - + std::atomic beforeBarrier(0); + std::atomic afterBarrier(0); auto use_barrier = [&]() { beforeBarrier++; barrier.Wait(); - afterBarrier++; + afterBarrier++;// Atomic fetch add? }; std::vector threads; @@ -27,4 +27,7 @@ TEST(BarrierTests, 32_treads_are_properly_blocked) for (auto&& thread : threads) { thread.join(); } + + EXPECT_EQ(beforeBarrier.load(), barrier_size); + EXPECT_EQ(afterBarrier.load(), barrier_size); } \ No newline at end of file