Skip to content

Commit

Permalink
Upgrade to catch2 v3 amalgamated headers (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaldwin authored Jul 3, 2022
1 parent 5495bfa commit cf82122
Show file tree
Hide file tree
Showing 24 changed files with 22,933 additions and 17,797 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ should_clang_format() {

local result=0

# Ignore the test/catch.hpp file
# Ignore the test/catch*.hpp file
if [[ "$1" != *"catch"* ]]; then
for ext in $FILE_EXTS; do
# Otherwise, if the extension is in the array of extensions to reformat, echo 1.
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ jobs:
run: |
cd build-release-g++
ctest -VV
build-ubuntu-22-04:
name: ubuntu-22.04
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
env:
TZ: America/New_York
DEBIAN_FRONTEND: noninteractive
steps:
- name: apt
run: |
apt-get update
apt-get -y upgrade
apt install -y build-essential software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get install -y \
cmake \
git \
ninja-build \
g++ \
libssl-dev
- name: Checkout # recurisve checkout requires git to be installed first
uses: actions/checkout@v2
with:
submodules: recursive
- name: build-release-g++
run: |
mkdir build-release-g++
cd build-release-g++
cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
..
ninja
- name: test-release-g++
run: |
cd build-release-g++
ctest -VV
build-fedora-32:
name: fedora-32
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set(LIBCORO_TEST_SOURCE_FILES
test_task.cpp
test_thread_pool.cpp
test_when_all.cpp

catch_amalgamated.cpp
)

add_executable(${PROJECT_NAME} main.cpp ${LIBCORO_TEST_SOURCE_FILES})
Expand Down
110 changes: 64 additions & 46 deletions test/bench.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include "catch_amalgamated.hpp"

#include <coro/coro.hpp>

Expand Down Expand Up @@ -31,7 +31,8 @@ TEST_CASE("benchmark counter func direct call", "[benchmark]")
{
constexpr std::size_t iterations = default_iterations;
std::atomic<uint64_t> counter{0};
auto func = [&]() -> void {
auto func = [&]() -> void
{
counter.fetch_add(1, std::memory_order::relaxed);
return;
};
Expand Down Expand Up @@ -119,7 +120,8 @@ TEST_CASE("benchmark thread_pool{1} counter task", "[benchmark]")
coro::thread_pool tp{coro::thread_pool::options{1}};
std::atomic<uint64_t> counter{0};

auto make_task = [](coro::thread_pool& tp, std::atomic<uint64_t>& c) -> coro::task<void> {
auto make_task = [](coro::thread_pool& tp, std::atomic<uint64_t>& c) -> coro::task<void>
{
co_await tp.schedule();
c.fetch_add(1, std::memory_order::relaxed);
co_return;
Expand Down Expand Up @@ -154,7 +156,8 @@ TEST_CASE("benchmark thread_pool{2} counter task", "[benchmark]")
coro::thread_pool tp{coro::thread_pool::options{2}};
std::atomic<uint64_t> counter{0};

auto make_task = [](coro::thread_pool& tp, std::atomic<uint64_t>& c) -> coro::task<void> {
auto make_task = [](coro::thread_pool& tp, std::atomic<uint64_t>& c) -> coro::task<void>
{
co_await tp.schedule();
c.fetch_add(1, std::memory_order::relaxed);
co_return;
Expand Down Expand Up @@ -189,7 +192,8 @@ TEST_CASE("benchmark thread_pool{N} counter task", "[benchmark]")
coro::thread_pool tp{};
std::atomic<uint64_t> counter{0};

auto make_task = [](coro::thread_pool& tp, std::atomic<uint64_t>& c) -> coro::task<void> {
auto make_task = [](coro::thread_pool& tp, std::atomic<uint64_t>& c) -> coro::task<void>
{
co_await tp.schedule();
c.fetch_add(1, std::memory_order::relaxed);
co_return;
Expand Down Expand Up @@ -228,7 +232,8 @@ TEST_CASE("benchmark counter task scheduler{1} yield", "[benchmark]")
std::vector<coro::task<void>> tasks{};
tasks.reserve(iterations);

auto make_task = [&]() -> coro::task<void> {
auto make_task = [&]() -> coro::task<void>
{
co_await s.schedule();
co_await s.yield();
counter.fetch_add(1, std::memory_order::relaxed);
Expand Down Expand Up @@ -261,7 +266,8 @@ TEST_CASE("benchmark counter task scheduler{1} yield_for", "[benchmark]")
std::vector<coro::task<void>> tasks{};
tasks.reserve(iterations);

auto make_task = [&]() -> coro::task<void> {
auto make_task = [&]() -> coro::task<void>
{
co_await s.schedule();
co_await s.yield_for(std::chrono::milliseconds{1});
counter.fetch_add(1, std::memory_order::relaxed);
Expand Down Expand Up @@ -302,14 +308,16 @@ TEST_CASE("benchmark counter task scheduler await event from another coroutine",

std::atomic<uint64_t> counter{0};

auto wait_func = [&](std::size_t index) -> coro::task<void> {
auto wait_func = [&](std::size_t index) -> coro::task<void>
{
co_await s.schedule();
co_await* events[index];
co_await *events[index];
counter.fetch_add(1, std::memory_order::relaxed);
co_return;
};

auto resume_func = [&](std::size_t index) -> coro::task<void> {
auto resume_func = [&](std::size_t index) -> coro::task<void>
{
co_await s.schedule();
events[index]->set();
co_return;
Expand Down Expand Up @@ -376,7 +384,8 @@ TEST_CASE("benchmark tcp_server echo server thread pool", "[benchmark]")
std::vector<coro::task<void>> tasks{};
};

auto make_on_connection_task = [&](server& s, coro::net::tcp_client client) -> coro::task<void> {
auto make_on_connection_task = [&](server& s, coro::net::tcp_client client) -> coro::task<void>
{
std::string in(64, '\0');

// Echo the messages until the socket is closed.
Expand Down Expand Up @@ -408,7 +417,8 @@ TEST_CASE("benchmark tcp_server echo server thread pool", "[benchmark]")
co_return;
};

auto make_server_task = [&](server& s) -> coro::task<void> {
auto make_server_task = [&](server& s) -> coro::task<void>
{
co_await s.scheduler->schedule();

coro::net::tcp_server server{s.scheduler};
Expand Down Expand Up @@ -439,7 +449,8 @@ TEST_CASE("benchmark tcp_server echo server thread pool", "[benchmark]")
std::mutex g_histogram_mutex;
std::map<std::chrono::milliseconds, uint64_t> g_histogram;

auto make_client_task = [&](client& c) -> coro::task<void> {
auto make_client_task = [&](client& c) -> coro::task<void>
{
co_await c.scheduler->schedule();
std::map<std::chrono::milliseconds, uint64_t> histogram;
coro::net::tcp_client client{c.scheduler};
Expand Down Expand Up @@ -487,12 +498,13 @@ TEST_CASE("benchmark tcp_server echo server thread pool", "[benchmark]")
std::vector<std::thread> server_threads{};
for (size_t i = 0; i < server_count; ++i)
{
server_threads.emplace_back(std::thread{[&]() {
server s{};
s.id = server_id++;
coro::sync_wait(make_server_task(s));
s.scheduler->shutdown();
}});
server_threads.emplace_back(std::thread{[&]()
{
server s{};
s.id = server_id++;
coro::sync_wait(make_server_task(s));
s.scheduler->shutdown();
}});
}

// The server can take a small bit of time to start up, if we don't wait for it to notify then
Expand All @@ -507,15 +519,16 @@ TEST_CASE("benchmark tcp_server echo server thread pool", "[benchmark]")
std::vector<client> clients{};
for (size_t i = 0; i < client_count; ++i)
{
client_threads.emplace_back(std::thread{[&]() {
client c{};
for (size_t i = 0; i < connections / client_count; ++i)
{
c.tasks.emplace_back(make_client_task(c));
}
coro::sync_wait(coro::when_all(std::move(c.tasks)));
c.scheduler->shutdown();
}});
client_threads.emplace_back(std::thread{[&]()
{
client c{};
for (size_t i = 0; i < connections / client_count; ++i)
{
c.tasks.emplace_back(make_client_task(c));
}
coro::sync_wait(coro::when_all(std::move(c.tasks)));
c.scheduler->shutdown();
}});
}

for (auto& ct : client_threads)
Expand Down Expand Up @@ -573,7 +586,8 @@ TEST_CASE("benchmark tcp_server echo server inline", "[benchmark]")
std::vector<coro::task<void>> tasks{};
};

auto make_on_connection_task = [&](server& s, coro::net::tcp_client client) -> coro::task<void> {
auto make_on_connection_task = [&](server& s, coro::net::tcp_client client) -> coro::task<void>
{
std::string in(64, '\0');

// Echo the messages until the socket is closed.
Expand Down Expand Up @@ -605,7 +619,8 @@ TEST_CASE("benchmark tcp_server echo server inline", "[benchmark]")
co_return;
};

auto make_server_task = [&](server& s) -> coro::task<void> {
auto make_server_task = [&](server& s) -> coro::task<void>
{
co_await s.scheduler->schedule();

coro::net::tcp_server server{s.scheduler};
Expand Down Expand Up @@ -636,7 +651,8 @@ TEST_CASE("benchmark tcp_server echo server inline", "[benchmark]")
std::mutex g_histogram_mutex;
std::map<std::chrono::milliseconds, uint64_t> g_histogram;

auto make_client_task = [&](client& c) -> coro::task<void> {
auto make_client_task = [&](client& c) -> coro::task<void>
{
co_await c.scheduler->schedule();
std::map<std::chrono::milliseconds, uint64_t> histogram;
coro::net::tcp_client client{c.scheduler};
Expand Down Expand Up @@ -684,12 +700,13 @@ TEST_CASE("benchmark tcp_server echo server inline", "[benchmark]")
std::vector<std::thread> server_threads{};
for (size_t i = 0; i < server_count; ++i)
{
server_threads.emplace_back(std::thread{[&]() {
server s{};
s.id = server_id++;
coro::sync_wait(make_server_task(s));
s.scheduler->shutdown();
}});
server_threads.emplace_back(std::thread{[&]()
{
server s{};
s.id = server_id++;
coro::sync_wait(make_server_task(s));
s.scheduler->shutdown();
}});
}

// The server can take a small bit of time to start up, if we don't wait for it to notify then
Expand All @@ -704,15 +721,16 @@ TEST_CASE("benchmark tcp_server echo server inline", "[benchmark]")
std::vector<client> clients{};
for (size_t i = 0; i < client_count; ++i)
{
client_threads.emplace_back(std::thread{[&]() {
client c{};
for (size_t i = 0; i < connections / client_count; ++i)
{
c.tasks.emplace_back(make_client_task(c));
}
coro::sync_wait(coro::when_all(std::move(c.tasks)));
c.scheduler->shutdown();
}});
client_threads.emplace_back(std::thread{[&]()
{
client c{};
for (size_t i = 0; i < connections / client_count; ++i)
{
c.tasks.emplace_back(make_client_task(c));
}
coro::sync_wait(coro::when_all(std::move(c.tasks)));
c.scheduler->shutdown();
}});
}

for (auto& ct : client_threads)
Expand Down
Loading

0 comments on commit cf82122

Please sign in to comment.