diff options
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/unit_tests/epee_boosted_tcp_server.cpp | 21 | ||||
-rw-r--r-- | tests/unit_tests/epee_levin_protocol_handler_async.cpp | 26 |
3 files changed, 25 insertions, 24 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index e70ed1a24..79a1a9438 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -75,6 +75,8 @@ target_link_libraries(unit_tests wallet p2p epee + ${Boost_CHRONO_LIBRARY} + ${Boost_THREAD_LIBRARY} ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBRARIES}) diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp index 946db292d..261d81f84 100644 --- a/tests/unit_tests/epee_boosted_tcp_server.cpp +++ b/tests/unit_tests/epee_boosted_tcp_server.cpp @@ -28,10 +28,9 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -#include <condition_variable> -#include <chrono> -#include <mutex> -#include <thread> +#include <boost/chrono/chrono.hpp> +#include <boost/thread/condition_variable.hpp> +#include <boost/thread/mutex.hpp> #include "gtest/gtest.h" @@ -88,13 +87,13 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant) test_tcp_server srv(epee::net_utils::e_connection_type_RPC); // RPC disables network limit for unit tests ASSERT_TRUE(srv.init_server(test_server_port, test_server_host)); - std::mutex mtx; - std::condition_variable cond; + boost::mutex mtx; + boost::condition_variable cond; int counter = 0; auto counter_incrementer = [&counter, &cond, &mtx]() { - std::unique_lock<std::mutex> lock(mtx); + boost::unique_lock<boost::mutex> lock(mtx); ++counter; if (4 <= counter) { @@ -110,8 +109,8 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant) ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw 4; })); { - std::unique_lock<std::mutex> lock(mtx); - ASSERT_NE(std::cv_status::timeout, cond.wait_for(lock, std::chrono::seconds(5))); + boost::unique_lock<boost::mutex> lock(mtx); + ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5))); ASSERT_EQ(4, counter); } @@ -124,8 +123,8 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant) ASSERT_TRUE(srv.async_call(counter_incrementer)); { - std::unique_lock<std::mutex> lock(mtx); - ASSERT_NE(std::cv_status::timeout, cond.wait_for(lock, std::chrono::seconds(5))); + boost::unique_lock<boost::mutex> lock(mtx); + ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5))); ASSERT_EQ(4, counter); } diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index 2dd3ffe29..e1ce50e2f 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -28,8 +28,8 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -#include <mutex> -#include <thread> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> #include "gtest/gtest.h" @@ -59,7 +59,7 @@ namespace virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context) { m_invoke_counter.inc(); - std::unique_lock<std::mutex> lock(m_mutex); + boost::unique_lock<boost::mutex> lock(m_mutex); m_last_command = command; m_last_in_buf = in_buff; buff_out = m_invoke_out_buf; @@ -69,7 +69,7 @@ namespace virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context) { m_notify_counter.inc(); - std::unique_lock<std::mutex> lock(m_mutex); + boost::unique_lock<boost::mutex> lock(m_mutex); m_last_command = command; m_last_in_buf = in_buff; return m_return_code; @@ -115,7 +115,7 @@ namespace unit_test::call_counter m_new_connection_counter; unit_test::call_counter m_close_connection_counter; - std::mutex m_mutex; + boost::mutex m_mutex; int m_return_code; std::string m_invoke_out_buf; @@ -144,7 +144,7 @@ namespace { //std::cout << "test_connection::do_send()" << std::endl; m_send_counter.inc(); - std::unique_lock<std::mutex> lock(m_mutex); + boost::unique_lock<boost::mutex> lock(m_mutex); m_last_send_data.append(reinterpret_cast<const char*>(ptr), cb); return m_send_return; } @@ -159,7 +159,7 @@ namespace size_t send_counter() const { return m_send_counter.get(); } const std::string& last_send_data() const { return m_last_send_data; } - void reset_last_send_data() { std::unique_lock<std::mutex> lock(m_mutex); m_last_send_data.clear(); } + void reset_last_send_data() { boost::unique_lock<boost::mutex> lock(m_mutex); m_last_send_data.clear(); } bool send_return() const { return m_send_return; } void send_return(bool v) { m_send_return = v; } @@ -172,7 +172,7 @@ namespace test_levin_connection_context m_context; unit_test::call_counter m_send_counter; - std::mutex m_mutex; + boost::mutex m_mutex; std::string m_last_send_data; @@ -305,14 +305,14 @@ TEST_F(positive_test_connection_to_levin_protocol_handler_calls, concurent_handl } }; - const size_t thread_count = std::thread::hardware_concurrency(); - std::vector<std::thread> threads(thread_count); - for (std::thread& th : threads) + const size_t thread_count = boost::thread::hardware_concurrency(); + std::vector<boost::thread> threads(thread_count); + for (boost::thread& th : threads) { - th = std::thread(create_and_destroy_connections); + th = boost::thread(create_and_destroy_connections); } - for (std::thread& th : threads) + for (boost::thread& th : threads) { th.join(); } |