-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from petiaccja/improve_testing
improve code quality and testing on whole project
- Loading branch information
Showing
56 changed files
with
3,550 additions
and
2,168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.