Skip to content

Commit

Permalink
Merge pull request #9 from petiaccja/improve_testing
Browse files Browse the repository at this point in the history
improve code quality and testing on whole project
  • Loading branch information
petiaccja authored Feb 20, 2024
2 parents 52274be + 14f4567 commit 56548c6
Show file tree
Hide file tree
Showing 56 changed files with 3,550 additions and 2,168 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/sanitizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Sanitize

on:
push:
branches:
- master
tags:
- v**.**
pull_request:
branches:
- master

jobs:
sanitize:
strategy:
fail-fast: false
matrix:
# sanitize: [address, memory, thread]
sanitize: [address]
include:
- sanitize: address
sanitize_flag: ENABLE_LLVM_ADDRESS_SANITIZER
# - sanitize: memory
# sanitize_flag: ENABLE_LLVM_MEMORY_SANITIZER
# - sanitize: thread
# sanitize_flag: ENABLE_LLVM_THREAD_SANITIZER

env:
os: "ubuntu-latest"
build_type: "Debug"
cxx_standard: "20"
c_compiler: "clang"
cxx_compiler: "clang++"
conan_preset: "conan-debug"

name: ${{ matrix.sanitize }}

runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v4
- uses: seanmiddleditch/gha-setup-ninja@v4
- uses: seanmiddleditch/gha-setup-vsdevenv@master
- uses: KyleMayes/install-llvm-action@v1
with:
version: "17.0"
directory: ${{ runner.temp }}/llvm

- name: Install GCC
shell: bash
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-13 g++-13
sudo update-alternatives --remove-all gcc || true
sudo update-alternatives --remove-all g++ || true
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 10 --slave /usr/bin/g++ g++ /usr/bin/g++-13
- name: Install conan
shell: bash
env:
CC: "${{ env.c_compiler != 'cl' && env.c_compiler || '' }}"
CXX: "${{ env.cxx_compiler != 'cl' && env.cxx_compiler || '' }}"
run: |
pip install conan
conan profile detect --name ci --force
python $GITHUB_WORKSPACE/support/update-conan-profile.py $(conan profile path ci) ${{env.build_type}} ${{env.c_compiler}} ${{env.cxx_compiler}} ${{env.cxx_standard}}
- name: Cache conan packages
id: cache-conan
uses: actions/cache@v3
with:
path: ~/.conan2/p
key: conan-cache-packages-${{ env.os }}-${{ env.c_compiler }}-${{ env.build_type }}-${{ env.cxx_standard }}

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
env:
CC: ${{env.c_compiler}}
CXX: ${{env.cxx_compiler}}
run: |
conan install $GITHUB_WORKSPACE --output-folder=. --build="*" -pr ci -pr:b ci -s build_type=${{ env.build_type }}
conan cache clean
cmake $GITHUB_WORKSPACE --preset ${{ env.conan_preset }} -D${{ matrix.sanitize_flag }}:BOOL=ON
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
cmake --build ./build/${{ env.build_type }}
cmake -E make_directory ${{runner.workspace}}/installation/SEDManager
cmake --install ./build/${{ env.build_type }} --prefix '${{runner.workspace}}/installation/SEDManager'
- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
run: ./build/${{ env.build_type }}/bin/test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
#Testing
Makefile
cmake_install.cmake
install_manifest.txt
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options("-fprofile-instr-generate" "-fcoverage-mapping" "-mllvm" "-enable-name-compression=false")
add_link_options("-fprofile-instr-generate" "-fcoverage-mapping")
endif()
file(REAL_PATH "${CMAKE_SOURCE_DIR}/sanitize_ignorelist.txt" sanitize_ignorelist)
if (ENABLE_LLVM_ADDRESS_SANITIZER)
message("Using address sanitizer")
add_compile_options("-fsanitize=address")
add_compile_options("-fsanitize-ignorelist=${sanitize_ignorelist}")
add_link_options("-fsanitize=address")
endif()
if (ENABLE_LLVM_MEMORY_SANITIZER)
message("Using memory sanitizer")
add_compile_options("-fsanitize=memory")
add_compile_options("-fsanitize-ignorelist=${sanitize_ignorelist}")
add_link_options("-fsanitize=memory")
endif()
if (ENABLE_LLVM_THREAD_SANITIZER)
message("Using thread sanitizer")
add_compile_options("-fsanitize=thread")
add_compile_options("-fsanitize-ignorelist=${sanitize_ignorelist}")
add_link_options("-fsanitize=thread")
endif()
endif()
Expand Down
16 changes: 0 additions & 16 deletions include/asyncpp/awaitable.hpp

This file was deleted.

23 changes: 9 additions & 14 deletions include/asyncpp/container/atomic_collection.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "../testing/suspension_point.hpp"

#include <atomic>
#include <limits>
Expand All @@ -10,47 +11,41 @@ namespace asyncpp {
template <class Element, Element* Element::*next>
class atomic_collection {
public:
atomic_collection() = default;
atomic_collection() noexcept = default;

Element* push(Element* element) noexcept {
Element* first = nullptr;
do {
element->*next = first;
} while (first != CLOSED && !m_first.compare_exchange_weak(first, element));
} while (first != CLOSED && !INTERLEAVED(m_first.compare_exchange_weak(first, element)));
return first;
}

Element* detach() noexcept {
return m_first.exchange(nullptr);
return INTERLEAVED(m_first.exchange(nullptr));
}

Element* close() noexcept {
return m_first.exchange(CLOSED);
return INTERLEAVED(m_first.exchange(CLOSED));
}

bool empty() const noexcept {
return m_first.load(std::memory_order_relaxed) == nullptr || closed();
const auto item = m_first.load(std::memory_order_relaxed);
return item == nullptr || closed(item);
}

bool closed() const noexcept {
return m_first.load(std::memory_order_relaxed) == CLOSED;
return closed(m_first.load(std::memory_order_relaxed));
}

static bool closed(Element* element) {
return element == CLOSED;
}

Element* first() {
Element* first() const noexcept {
return m_first.load(std::memory_order_relaxed);
}

const Element* first() const {
return m_first.load(std::memory_order_relaxed);
}

protected:
atomic_collection(Element* first) : m_first(first) {}

private:
std::atomic<Element*> m_first = nullptr;
static inline Element* const CLOSED = reinterpret_cast<Element*>(std::numeric_limits<size_t>::max());
Expand Down
129 changes: 129 additions & 0 deletions include/asyncpp/container/atomic_deque.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#pragma once

#include "../threading/spinlock.hpp"

#include <mutex>
#include <utility>


namespace asyncpp {

template <class Element, Element* Element::*prev, Element* Element::*next>
class deque {
public:
Element* push_front(Element* element) noexcept {
element->*prev = nullptr;
element->*next = m_front;
if (m_front) {
m_front->*prev = element;
}
else {
m_back = element;
}
return std::exchange(m_front, element);
}

Element* push_back(Element* element) noexcept {
element->*prev = m_back;
element->*next = nullptr;
if (m_back) {
m_back->*next = element;
}
else {
m_front = element;
}
return std::exchange(m_back, element);
}

Element* pop_front() noexcept {
if (m_front) {
const auto element = std::exchange(m_front, m_front->*next);
if (m_front) {
m_front->*prev = nullptr;
}
else {
m_back = nullptr;
}
element->*next = nullptr;
return element;
}
return nullptr;
}

Element* pop_back() noexcept {
if (m_back) {
const auto element = std::exchange(m_back, m_back->*prev);
if (m_back) {
m_back->*next = nullptr;
}
else {
m_front = nullptr;
}
element->*prev = nullptr;
return element;
}
return nullptr;
}

Element* front() const noexcept {
return m_front;
}

Element* back() const noexcept {
return m_back;
}

bool empty() const noexcept {
return m_back == nullptr;
}

private:
Element* m_front = nullptr;
Element* m_back = nullptr;
};


template <class Element, Element* Element::*prev, Element* Element::*next>
class atomic_deque {
public:
Element* push_front(Element* element) noexcept {
std::lock_guard lk(m_mutex);
return m_container.push_front(element);
}

Element* push_back(Element* element) noexcept {
std::lock_guard lk(m_mutex);
return m_container.push_back(element);
}

Element* pop_front() noexcept {
std::lock_guard lk(m_mutex);
return m_container.pop_front();
}

Element* pop_back() noexcept {
std::lock_guard lk(m_mutex);
return m_container.pop_back();
}

Element* front() const noexcept {
std::lock_guard lk(m_mutex);
return m_container.front();
}

Element* back() const noexcept {
std::lock_guard lk(m_mutex);
return m_container.back();
}

bool empty() const noexcept {
std::lock_guard lk(m_mutex);
return m_container.empty();
}

private:
deque<Element, prev, next> m_container;
mutable spinlock m_mutex;
};

} // namespace asyncpp
49 changes: 49 additions & 0 deletions include/asyncpp/container/atomic_item.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include "../testing/suspension_point.hpp"

#include <atomic>
#include <limits>


namespace asyncpp {

template <class Element>
class atomic_item {
public:
atomic_item() noexcept = default;

Element* set(Element* element) noexcept {
Element* expected = nullptr;
INTERLEAVED(m_item.compare_exchange_strong(expected, element));
return expected;
}

Element* close() noexcept {
return INTERLEAVED(m_item.exchange(CLOSED));
}

bool empty() const noexcept {
const auto item = m_item.load(std::memory_order_relaxed);
return item == nullptr || closed(item);
}

bool closed() const noexcept {
return closed(m_item.load(std::memory_order_relaxed));
}

static bool closed(Element* element) {
return element == CLOSED;
}

Element* item() const noexcept {
return m_item.load(std::memory_order_relaxed);
}

private:
std::atomic<Element*> m_item = nullptr;
static inline Element* const CLOSED = reinterpret_cast<Element*>(std::numeric_limits<size_t>::max());
};


} // namespace asyncpp
Loading

0 comments on commit 56548c6

Please sign in to comment.