Skip to content

Commit

Permalink
Add coverage to helio tests (#123)
Browse files Browse the repository at this point in the history
Also add std:: to move calls.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Aug 29, 2023
1 parent 5401d29 commit 4965906
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 36 deletions.
29 changes: 22 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
branches: [ master ]
workflow_dispatch:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
Expand All @@ -20,12 +20,12 @@ jobs:
strategy:
matrix:
# Test of these containers
container: ["ubuntu-dev:20", "alpine-dev:latest"]
compiler: [{cxx: g++, c: gcc}]
cxx_flags: ["-Werror"]
include:
- container: "alpine-dev:latest"
compiler: {cxx: clang++, c: clang}
- container: "ubuntu-dev:20"
compiler: {cxx: g++, c: gcc}
cxx_flags: "-fprofile-arcs -ftest-coverage -Werror"
timeout-minutes: 50
container:
image: ghcr.io/romange/${{ matrix.container }}
Expand All @@ -48,27 +48,42 @@ jobs:
run: |
uname -a
ulimit -a
cat /proc/cpuinfo
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-GNinja \
-DCMAKE_C_COMPILER="${{matrix.compiler.c}}" \
-DCMAKE_CXX_COMPILER="${{matrix.compiler.cxx}}" \
-DCMAKE_CXX_FLAGS_DEBUG="${{matrix.cxx_flags}}" \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_C_COMPILER_LAUNCHER=sccache
- name: Build
run: |
cd ${{github.workspace}}/build
ninja -k 5 base/all io/all strings/all util/all echo_server ping_iouring_server https_client_cli
${SCCACHE_PATH} --show-stats
- name: Test
run: |
cd ${{github.workspace}}/build
GLOG_logtostderr=1 gdb -batch -ex "run" -ex "thread apply all bt" \
./accept_server_test || true
GLOG_logtostderr=1 GLOG_vmodule=proactor=1 ctest -V -L CI
# ./proactor_test --gtest_filter=*Migrate --logtostderr --vmodule=proactor=2,uring_fiber_algo=1
- name: Coverage
if: matrix.compiler.cxx == 'g++'
run: |
lcov -c -d ${{github.workspace}}/build -o coverage.info
lcov --remove coverage.info -o coverage.info '/usr/*' '*/_deps/*' '*/third_party/*'
- name: Upload coverage to Codecov
if: matrix.compiler.cxx == 'g++'
uses: codecov/codecov-action@v3
with:
files: ./coverage.info
fail_ci_if_error: true

build-macos:
runs-on: macos-latest
timeout-minutes: 30
Expand All @@ -79,7 +94,7 @@ jobs:
cmake --version
gcc-13 --version
uname -a
- name: Configure CMake
- name: Configure CMake
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ genfiles/*
third_party
*.pyc
_deps

*.orig
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Async - backend development framework in C++ using io_uring event-loop.
# Helio - backend development framework in C++ using io_uring and epoll event-loop.

=====

[![ci-tests](https://github.com/romange/async/actions/workflows/ci.yml/badge.svg)](https://github.com/romange/async/actions/workflows/ci.yml)

[![codecov](https://codecov.io/gh/romange/helio/graph/badge.svg?token=2TIU52DK17)](https://codecov.io/gh/romange/helio)

Async is a set of c++ primitives that allows you efficient and rapid development
in c++17 on linux systems. The focus is mostly for backend development, data processing etc.


1. Dependency on [abseil-cpp](https://github.com/abseil/abseil-cpp/)
2. Dependency on [Boost 1.71](https://www.boost.org/doc/libs/1_71_0/doc/html/)
3. Uses ninja-build on top of cmake
4. Build artifacts are docker-friendly.
4. Built artifacts are docker-friendly.
6. HTTP server implementation.
7. Many other features.
7. Fibers library and fiber-friendly synchronization primitives.


I will gradually add explanations for most crucial blocks in this library.
Expand All @@ -22,7 +24,7 @@ I will gradually add explanations for most crucial blocks in this library.
## Setting Up & Building
```bash
> sudo ./install-dependencies.sh
> ./blaze.sh -ninja -release
> ./blaze.sh -release
> cd build-opt && ninja -j4 echo_server

```
Expand All @@ -37,6 +39,7 @@ I will gradually add explanations for most crucial blocks in this library.


## HTTP

HTTP handler is implemented using [Boost.Beast](https://www.boost.org/doc/libs/1_71_0/libs/beast/doc/html/index.html) library. It's integrated with the io_uring based ProactorPool.
Please see [http_main.cc](https://github.com/romange/async/blob/master/util/http/http_main.cc), for example. HTTP also provides support for backend monitoring (Varz status page) and for extensible debugging interface. With monitoring C++ backend returns json object that is formatted inside status page in the browser. To check how it looks, please go to [localhost:8080](http://localhost:8080) while `echo_server` is running.

Expand Down
4 changes: 2 additions & 2 deletions base/cxx_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MyType {

template <typename T> class Wrapper {
public:
Wrapper(T s) : t(move(s)) {
Wrapper(T s) : t(std::move(s)) {
}

T t;
Expand Down Expand Up @@ -121,7 +121,7 @@ class Pointer1 {

TEST_F(CxxTest, Move) {
MyType t{"foo"};
MyType a = move(t);
MyType a = std::move(t);
EXPECT_EQ(0, copy_ctors);

vector<MyType> v;
Expand Down
2 changes: 1 addition & 1 deletion cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ endif()


# 1.71 comes with ubuntu 20.04 so that's what we require.
find_package(Boost 1.71.0 REQUIRED COMPONENTS context system fiber)
find_package(Boost 1.71.0 REQUIRED COMPONENTS context system)
Message(STATUS "Found Boost ${Boost_LIBRARY_DIRS} ${Boost_LIB_VERSION} ${Boost_VERSION}")

add_definitions(-DBOOST_BEAST_SEPARATE_COMPILATION -DBOOST_ASIO_SEPARATE_COMPILATION)
Expand Down
6 changes: 3 additions & 3 deletions examples/echo_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct TL {

auto res = uring::OpenLinux(path, flags, 0666);
CHECK(res);
file = move(res.value());
file = std::move(res.value());
#if 0
Proactor* proactor = (Proactor*)ProactorBase::me();
uring::FiberCall fc(proactor);
Expand Down Expand Up @@ -107,7 +107,7 @@ void TL::WriteToFile() {
++pending_write_reqs;
uring::Proactor* proactor = (uring::Proactor*)ProactorBase::me();

uring::SubmitEntry se = proactor->GetSubmitEntry(move(ring_cb), 0);
uring::SubmitEntry se = proactor->GetSubmitEntry(std::move(ring_cb), 0);
se.PrepWrite(file->fd(), blob, 4096, 0);
if (GetFlag(FLAGS_sqe_async))
se.sqe()->flags |= IOSQE_ASYNC;
Expand Down Expand Up @@ -289,7 +289,7 @@ void RunServer(ProactorPool* pp) {
LOG(ERROR) << "Error writing to file " << -res;
};

uring::SubmitEntry se = proactor->GetSubmitEntry(move(ring_cb), 0);
uring::SubmitEntry se = proactor->GetSubmitEntry(std::move(ring_cb), 0);
se.PrepWrite(tl->file->fd(), blob, 4096, 0);
se.sqe()->flags |= IOSQE_ASYNC;
if (i % 1000 == 0) {
Expand Down
2 changes: 1 addition & 1 deletion examples/pingserver/resp_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ auto RespParser::ConsumeBulk(Buffer str) -> Status {
std::unique_ptr<uint8_t[]> nb(new uint8_t[bulk_len_]);
memcpy(nb.get(), str.data(), len);
bulk_str = Buffer{nb.get(), len};
buf_stash_.emplace_back(move(nb));
buf_stash_.emplace_back(std::move(nb));
is_broken_token_ = true;
}
last_consumed_ = len;
Expand Down
2 changes: 1 addition & 1 deletion examples/raw_echo_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void DispatchCqe(FiberInterface* current, const io_uring_cqe& cqe) {
res.flags = cqe.flags;
suspended_list[index].next = next_rp_id;
next_rp_id = index;
auto func = move(suspended_list[index].cb);
auto func = std::move(suspended_list[index].cb);
func(current, res);
}

Expand Down
6 changes: 3 additions & 3 deletions io/proc_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Result<StatusData> ReadStatusInfo() {
}
};

error_code ec = ReadProcFile("/proc/self/status", ':', move(cb));
error_code ec = ReadProcFile("/proc/self/status", ':', std::move(cb));
if (ec)
return make_unexpected(ec);

Expand Down Expand Up @@ -142,7 +142,7 @@ Result<MemInfoData> ReadMemInfo() {
}
};

error_code ec = ReadProcFile("/proc/meminfo", ':', move(cb));
error_code ec = ReadProcFile("/proc/meminfo", ':', std::move(cb));
if (ec)
return make_unexpected(ec);

Expand All @@ -161,7 +161,7 @@ Result<SelfStat> ReadSelfStat() {
}
};

error_code ec = ReadProcFile("/proc/stat", ' ', move(cb));
error_code ec = ReadProcFile("/proc/stat", ' ', std::move(cb));
if (ec)
return make_unexpected(ec);
}
Expand Down
2 changes: 1 addition & 1 deletion util/cloud/s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ io::Result<io::WriteFile*> S3Bucket::OpenWriteFile(std::string_view path) {
} else {
full_path = absl::StrCat(bucket_, "/", path);
}
unique_ptr http_client = move(http_client_);
unique_ptr http_client = std::move(http_client_);
error_code ec = Connect(http_client->connect_timeout_ms());
if (ec)
return make_unexpected(ec);
Expand Down
4 changes: 2 additions & 2 deletions util/fibers/detail/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ void DispatcherImpl::DefaultDispatch(Scheduler* sched) {
unique_lock<mutex> lk{mu_};
if (has_sleeping) {
auto next_tp = sched->NextSleepPoint();
cnd_.wait_until(lk, next_tp, move(cb));
cnd_.wait_until(lk, next_tp, std::move(cb));
} else {
cnd_.wait(lk, move(cb));
cnd_.wait(lk, std::move(cb));
}
wake_suspend_ = false;
}
Expand Down
6 changes: 3 additions & 3 deletions util/fibers/fibers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST_F(FiberTest, Stack) {
// Test with moveable only arguments.
unique_ptr<int> pass(new int(42));
Fiber(
"test3", [](unique_ptr<int> p) { EXPECT_EQ(42, *p); }, move(pass))
"test3", [](unique_ptr<int> p) { EXPECT_EQ(42, *p); }, std::move(pass))
.Detach();
}

Expand Down Expand Up @@ -347,7 +347,7 @@ TEST_F(FiberTest, Future) {
Promise<int> p1;
Future<int> f1 = p1.get_future();

Fiber fb("fb3", [f1 = move(f1)]() mutable { EXPECT_EQ(42, f1.get()); });
Fiber fb("fb3", [f1 = std::move(f1)]() mutable { EXPECT_EQ(42, f1.get()); });
p1.set_value(42);

fb.Join();
Expand All @@ -364,7 +364,7 @@ TEST_F(FiberTest, AsyncEvent) {

ProactorThread pth(0, ProactorBase::IOURING);
pth.get()->DispatchBrief(
[up = reinterpret_cast<UringProactor*>(pth.proactor.get()), cb = move(cb)] {
[up = reinterpret_cast<UringProactor*>(pth.proactor.get()), cb = std::move(cb)] {
SubmitEntry se = up->GetSubmitEntry(std::move(cb));
se.sqe()->opcode = IORING_OP_NOP;
LOG(INFO) << "submit";
Expand Down
4 changes: 2 additions & 2 deletions util/fibers/uring_proactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void UringProactor::DispatchCqe(detail::FiberInterface* current, const io_uring_
auto& e = centries_[index];
DCHECK(e.cb) << index;

CbType func = move(e.cb);
CbType func = std::move(e.cb);

// Set e to be the head of free-list.
e.index = next_free_ce_;
Expand Down Expand Up @@ -688,7 +688,7 @@ void UringProactor::EpollAddInternal(EpollIndex id) {
}
};

SubmitEntry se = GetSubmitEntry(move(uring_cb));
SubmitEntry se = GetSubmitEntry(std::move(uring_cb));
auto& epoll = epoll_entries_[id];
se.PrepPollAdd(epoll.fd, epoll.event_mask);
epoll.index = se.sqe()->user_data;
Expand Down
2 changes: 1 addition & 1 deletion util/http/http_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void ServerRun(ProactorPool* pool) {

auto json_cb = [](const http::QueryArgs& args, HttpContext* send) {
auto resp = sb_resp;
return send->Invoke(move(resp));
return send->Invoke(std::move(resp));
};

listener->RegisterCb("/json", json_cb);
Expand Down
2 changes: 1 addition & 1 deletion util/tls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Message(STATUS "OpenSSL libs ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_VERSION}")
add_library(tls_lib tls_engine.cc tls_socket.cc)

cxx_link(tls_lib fibers2 OpenSSL::SSL)
cxx_test(tls_engine_test tls_lib Boost::fiber LABELS CI)
cxx_test(tls_engine_test tls_lib LABELS CI)
4 changes: 2 additions & 2 deletions util/uring/uring_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ error_code LinuxFile::Write(const iovec* iov, unsigned iovcnt, off_t offset, uns
return res;
};

return io::ApplyExactly(iov, iovcnt, move(cb));
return io::ApplyExactly(iov, iovcnt, std::move(cb));
}

error_code LinuxFile::Read(const iovec* iov, unsigned iovcnt, off_t offset, unsigned flags) {
Expand All @@ -377,7 +377,7 @@ error_code LinuxFile::Read(const iovec* iov, unsigned iovcnt, off_t offset, unsi
return res;
};

return io::ApplyExactly(iov, iovcnt, move(cb));
return io::ApplyExactly(iov, iovcnt, std::move(cb));
}

io::Result<std::unique_ptr<LinuxFile>> OpenLinux(std::string_view path, int flags, mode_t mode) {
Expand Down
2 changes: 1 addition & 1 deletion util/uring/uring_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ auto UringSocket::WriteSome(const iovec* ptr, uint32_t len) -> Result<size_t> {
CHECK_GT(res, 0); // TODO - handle errors.
};

SubmitEntry se = p->GetSubmitEntry(move(cb));
SubmitEntry se = p->GetSubmitEntry(std::move(cb));
se.PrepWriteFixed(fd, reg_buf, short_len, 0, 0);
se.sqe()->flags |= register_flag();

Expand Down

0 comments on commit 4965906

Please sign in to comment.