From 3fc18d56ac0c8a88b49d776198e2d1a5e967e3fe Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 26 Jun 2023 16:13:20 +0300 Subject: [PATCH] Remove latch_tests.cpp --- test/CMakeLists.txt | 1 - test/Jamfile.v2 | 1 - test/cfoa/latch_tests.cpp | 139 -------------------------------------- 3 files changed, 141 deletions(-) delete mode 100644 test/cfoa/latch_tests.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5b9307e1..185fb39e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -140,7 +140,6 @@ foa_tests(SOURCES exception/merge_exception_tests.cpp) # CFOA tests -cfoa_tests(SOURCES cfoa/latch_tests.cpp) cfoa_tests(SOURCES cfoa/insert_tests.cpp) cfoa_tests(SOURCES cfoa/erase_tests.cpp) cfoa_tests(SOURCES cfoa/try_emplace_tests.cpp) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1ad15a18..e25f1083 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -176,7 +176,6 @@ alias foa_tests : ; local CFOA_TESTS = - latch_tests insert_tests erase_tests try_emplace_tests diff --git a/test/cfoa/latch_tests.cpp b/test/cfoa/latch_tests.cpp deleted file mode 100644 index 1ce9d65f..00000000 --- a/test/cfoa/latch_tests.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (C) 2023 Christian Mazakas -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#define BOOST_ENABLE_ASSERT_HANDLER - -#include -#include - -#include -#include - -struct exception -{ -}; - -namespace boost { - void assertion_failed( - char const* expr, char const* function, char const* file, long line) - { - (void)expr; - (void)function; - (void)file; - (void)line; - throw exception{}; - } -} // namespace boost - -namespace { - void test_constructor() - { - { - auto const f = [] { - boost::compat::latch l(-1); - (void)l; - }; - BOOST_TEST_THROWS(f(), exception); - } - - { - std::ptrdiff_t n = 0; - - boost::compat::latch l(n); - BOOST_TEST(l.try_wait()); - } - - { - std::ptrdiff_t n = 16; - - boost::compat::latch l(n); - BOOST_TEST_NOT(l.try_wait()); - - l.count_down(16); - BOOST_TEST(l.try_wait()); - } - } - - void test_count_down_and_wait() - { - constexpr std::ptrdiff_t n = 1024; - - boost::compat::latch l(2 * n); - - bool bs[] = {false, false}; - - std::thread t1([&] { - l.wait(); - BOOST_TEST(bs[0]); - BOOST_TEST(bs[1]); - }); - - std::thread t2([&] { - for (int i = 0; i < n; ++i) { - if (i == (n - 1)) { - bs[0] = true; - } else { - BOOST_TEST_NOT(l.try_wait()); - } - - l.count_down(1); - } - }); - - for (int i = 0; i < n; ++i) { - if (i == (n - 1)) { - bs[1] = true; - } else { - BOOST_TEST_NOT(l.try_wait()); - } - - l.count_down(1); - } - - t1.join(); - t2.join(); - - BOOST_TEST(l.try_wait()); - } - - void test_arrive_and_wait() - { - std::ptrdiff_t const n = 16; - - boost::compat::latch l(2 * n); - - int xs[n] = {0}; - - std::vector threads; - for (int i = 0; i < n; ++i) { - threads.emplace_back([&l, &xs, i, n] { - (void)n; - for (int j = 0; j < n; ++j) { - BOOST_TEST_EQ(xs[j], 0); - } - - l.arrive_and_wait(2); - - xs[i] = 1; - }); - } - - for (auto& t : threads) { - t.join(); - } - - for (int i = 0; i < n; ++i) { - BOOST_TEST_EQ(xs[i], 1); - } - } -} // namespace - -int main() -{ - test_constructor(); - test_count_down_and_wait(); - test_arrive_and_wait(); - - return boost::report_errors(); -}