aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/core/blocking_counter_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/lib/core/blocking_counter_test.cc')
-rw-r--r--tensorflow/core/lib/core/blocking_counter_test.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/tensorflow/core/lib/core/blocking_counter_test.cc b/tensorflow/core/lib/core/blocking_counter_test.cc
new file mode 100644
index 0000000000..feb0342086
--- /dev/null
+++ b/tensorflow/core/lib/core/blocking_counter_test.cc
@@ -0,0 +1,36 @@
+#include <gtest/gtest.h>
+
+#include "tensorflow/core/lib/core/blocking_counter.h"
+#include "tensorflow/core/lib/core/threadpool.h"
+
+namespace tensorflow {
+namespace {
+
+TEST(BlockingCounterTest, TestZero) {
+ BlockingCounter bc(0);
+ bc.Wait();
+}
+
+TEST(BlockingCounterTest, TestSingleThread) {
+ BlockingCounter bc(2);
+ bc.DecrementCount();
+ bc.DecrementCount();
+ bc.Wait();
+}
+
+TEST(BlockingCounterTest, TestMultipleThread) {
+ int N = 3;
+ thread::ThreadPool* thread_pool =
+ new thread::ThreadPool(Env::Default(), "test", N);
+
+ BlockingCounter bc(N);
+ for (int i = 0; i < N; ++i) {
+ thread_pool->Schedule([&bc] { bc.DecrementCount(); });
+ }
+
+ bc.Wait();
+ delete thread_pool;
+}
+
+} // namespace
+} // namespace tensorflow