Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Thread-sanitizer and CI issues #32

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
build:
runs-on: macOS-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
name: checkout
Expand All @@ -27,20 +27,29 @@ jobs:
fetch-depth: 1
- name: install
run: |
brew install ninja llvm
set -e
sudo apt-get update || true
sudo apt-get install -y ninja-build gcovr gcc-13 g++-13 clang-15 clang++-15 llvm-15

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 90
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 999
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 999
sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-15/bin/clang-15 999
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-15 999
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 90
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 90
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-13 90

sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install scikit-build
sudo python3 -m pip install cmake requests gitpython gcovr pyyaml
sudo python3 -m pip install cmake==3.25 requests gitpython gcovr pyyaml
- name: run checks
run: |
#!/bin/bash
LLVM_DIR=/usr/local/Cellar/llvm
test -d $LLVM_DIR || echo $(echo "llvm is absent, cannot continue" && exit 1)
VER_COUNT=$(ls -1 ${LLVM_DIR} | wc -l)
LLVM_DIR=/usr/lib/llvm-??
VER_COUNT=$(ls -d -1 ${LLVM_DIR} | wc -l)
test ${VER_COUNT} -eq 0 && echo "no llvm version detected" && exit 1
test $VER_COUNT -gt 1 && echo "wrong llvm installation" && exit 1
LLVM_VER=$(ls -1 ${LLVM_DIR})
export LLVM_ROOT=${LLVM_DIR}/${LLVM_VER}
export LLVM_ROOT=$(ls -r -d -1 ${LLVM_DIR} | head -1)
export PATH=${LLVM_ROOT}/bin:${LLVM_ROOT}/share/clang:${PATH}
cmake . -GNinja -Bbuild
cmake . -Bbuild
.github/aux/clang-tidy.sh build
21 changes: 15 additions & 6 deletions .github/workflows/compilers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
os: [ubuntu-22.04, macOS-14]
compiler: [{
"cc": "gcc",
"cxx": "g++"
}, {
"cc": "clang",
"cxx": "clang++"
}]
}]
exclude:
- os: macOS-latest
- os: macOS-14
compiler:
cc: gcc
steps:
Expand All @@ -49,11 +49,20 @@ jobs:
brew install ninja
else
sudo apt-get update || true
sudo apt-get install -y ninja-build
sudo apt-get install -y ninja-build gcc-13 g++-13 clang-15 clang++-15
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 90
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 999
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 999
sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-15/bin/clang-15 999
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-15 999
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 90
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 90
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-13 90
fi

sudo python3 -m pip install --upgrade pip
sudo pip3 install cmake requests gitpython gcovr pyyaml
sudo python3 -m pip install scikit-build
sudo python3 -m pip install cmake==3.25 requests gitpython gcovr pyyaml

- name: cmake
env:
Expand All @@ -62,7 +71,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # has to be included to access other secrets
GITHUB_HUNTER_USERNAME: ${{ secrets.GITHUB_HUNTER_USERNAME }}
GITHUB_HUNTER_TOKEN: ${{ secrets.GITHUB_HUNTER_TOKEN }}
run: cmake . -GNinja -Bbuild
run: cmake . -Bbuild

- name: build
run: cmake --build build -- -j4
Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
jobs:
coverage:
name: "codecov"
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v1
Expand All @@ -30,16 +30,27 @@ jobs:
run: |
set -e
sudo apt-get update || true
sudo apt-get install -y ninja-build gcovr
sudo apt-get install -y ninja-build gcovr gcc-13 g++-13 clang-15 clang++-15

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 90
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 999
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 999
sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-15/bin/clang-15 999
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-15 999
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 90
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 90
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-13 90

sudo python3 -m pip install --upgrade pip
sudo pip3 install scikit-build
sudo pip3 install cmake requests gitpython gcovr pyyaml
sudo python3 -m pip install scikit-build
sudo python3 -m pip install cmake==3.25 requests gitpython gcovr pyyaml

- name: "cmake"
env:
CC: clang
CXX: clang++
run: |
cmake . -GNinja -Bbuild-coverage -DCOVERAGE=ON -DEXAMPLES=OFF
cmake . -Bbuild-coverage -DCOVERAGE=ON -DEXAMPLES=OFF
cmake --build build-coverage
- name: "build report"
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: "Undefined Behavior Sanitizer"
sanitizer: UBSAN
name: "${{ matrix.options.name }}"
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v1
Expand All @@ -62,7 +62,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # has to be included to access other secrets
GITHUB_HUNTER_USERNAME: ${{ secrets.GITHUB_HUNTER_USERNAME }}
GITHUB_HUNTER_TOKEN: ${{ secrets.GITHUB_HUNTER_TOKEN }}
run: cmake . -GNinja -Bbuild -D${{ matrix.options.sanitizer }}=ON
run: cmake . -Bbuild -D${{ matrix.options.sanitizer }}=ON

- name: build
run: cmake --build build -- -j4
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.12)
include("cmake/Hunter/init.cmake")

cmake_policy(SET CMP0048 NEW)
project(soralog VERSION 0.2.1 LANGUAGES CXX)
project(soralog VERSION 0.2.2 LANGUAGES CXX)

find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
Expand Down
6 changes: 3 additions & 3 deletions cmake/Hunter/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ set(

set(
HUNTER_CACHE_SERVERS
"https://github.com/qdrvm/hunter-binary-cache;https://github.com/soramitsu/hunter-binary-cache"
"https://github.com/qdrvm/hunter-binary-cache"
CACHE STRING "Binary cache server"
)

include(${CMAKE_CURRENT_LIST_DIR}/HunterGate.cmake)

HunterGate(
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.23.257-qdrvm3.zip
SHA1 6bfad5e6ec7b6821814b1bd0c9d3c4fef72c6731
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm3.zip
SHA1 8989599eaa462f367805e2d36a30150c93b1d660
LOCAL
)
4 changes: 2 additions & 2 deletions cmake/toolchain/compiler/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ set(
)

string(REGEX MATCH "([0-9]+).([0-9]+).([0-9]+)" v ${CMAKE_CXX_COMPILER_VERSION})
if (${CMAKE_MATCH_1} LESS 11)
print("Requires Clang compiler at least version 11")
if (${CMAKE_MATCH_1} LESS 15)
print("Requires Clang compiler at least version 15")
endif()

if (${CMAKE_MATCH_1} GREATER_EQUAL 10)
Expand Down
1 change: 1 addition & 0 deletions cmake/toolchain/flags/sanitize_thread.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ endif ()
set(FLAGS
-fsanitize=thread
-g
-O1
)

foreach(FLAG IN LISTS FLAGS)
Expand Down
4 changes: 4 additions & 0 deletions include/soralog/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace soralog {
public:
using element_type = T;

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
struct Node final {
template <typename... Args>
void init(Args &&...args) {
Expand All @@ -36,9 +37,11 @@ namespace soralog {
return *reinterpret_cast<const T *>(item_);
}

// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
std::atomic_flag busy = ATOMIC_VAR_INIT(false);

private:
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
alignas(std::alignment_of_v<T>) char item_[sizeof(T)];
};

Expand Down Expand Up @@ -98,6 +101,7 @@ namespace soralog {
}
};

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
explicit CircularBuffer(size_t capacity) : CircularBuffer(capacity, 0){};

size_t capacity() const noexcept {
Expand Down
2 changes: 2 additions & 0 deletions include/soralog/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ namespace soralog {
return *pos;
}
constexpr auto &operator++() {
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
++pos;
return *this;
}
constexpr auto operator++(int) {
auto origin = *this;
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
++pos;
return origin;
}
Expand Down
2 changes: 1 addition & 1 deletion include/soralog/impl/sink_to_console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace soralog {
std::atomic_bool need_to_flush_ = false;
std::atomic<std::chrono::steady_clock::time_point> next_flush_ =
std::chrono::steady_clock::time_point();
std::atomic_bool flush_in_progress_ = false;
std::atomic_flag flush_in_progress_ = false;
};

} // namespace soralog
2 changes: 1 addition & 1 deletion include/soralog/impl/sink_to_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace soralog {
std::atomic_bool need_to_rotate_ = false;
std::atomic<std::chrono::steady_clock::time_point> next_flush_ =
std::chrono::steady_clock::time_point();
std::atomic_bool flush_in_progress_ = false;
std::atomic_flag flush_in_progress_ = false;
};

} // namespace soralog
2 changes: 1 addition & 1 deletion include/soralog/impl/sink_to_syslog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace soralog {
std::atomic_bool need_to_flush_ = false;
std::atomic<std::chrono::steady_clock::time_point> next_flush_ =
std::chrono::steady_clock::time_point();
std::atomic_bool flush_in_progress_ = false;
std::atomic_flag flush_in_progress_ = false;
};

} // namespace soralog
3 changes: 2 additions & 1 deletion include/soralog/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace soralog {
* name and event's data ({@param format} and {@param args}) to sink
*/
template <typename Format, typename... Args>
void push(Level level, const Format &format, const Args &...args) {
void __attribute__((no_sanitize("thread")))
push(Level level, const Format &format, const Args &...args) {
if (level_ >= level) {
if (level != Level::OFF and level != Level::IGNORE) {
sink_->push(name_, level, format, args...);
Expand Down
16 changes: 8 additions & 8 deletions include/soralog/sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
#define IF_RELEASE false
#endif

#if not defined(likely_if)
#if __cplusplus > 201703L
#define likely_if(x) [[likely]] if (x)
#if not defined(LIKELY_IF)
#if __cplusplus >= 202002L
#define LIKELY_IF(x) [[likely]] if (x)
#elif defined(__has_builtin)
#if __has_builtin(__builtin_expect)
#define likely_if(x) if (__builtin_expect((x), 1))
#define LIKELY_IF(x) if (__builtin_expect((x), 1))
#else
#define likely_if(x) if (x)
#define LIKELY_IF(x) if (x)
#endif
#else
#define likely_if(x) if (x)
#define LIKELY_IF(x) if (x)
#endif
#endif

Expand Down Expand Up @@ -107,7 +107,7 @@ namespace soralog {
max_message_length_, args...);

// Event is queued successfully
likely_if((bool)node) {
LIKELY_IF((bool)node) {
size_ += node->message().size();
break;
}
Expand Down Expand Up @@ -165,4 +165,4 @@ namespace soralog {

} // namespace soralog

#undef likely_if
#undef LIKELY_IF
6 changes: 2 additions & 4 deletions src/impl/sink_to_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ namespace soralog {
}

void SinkToConsole::flush() noexcept {
bool false_v = false;
if (not flush_in_progress_.compare_exchange_strong(
false_v, true, std::memory_order_acq_rel)) {
if (flush_in_progress_.test_and_set()) {
return;
}

Expand Down Expand Up @@ -305,7 +303,7 @@ namespace soralog {
break;
}

flush_in_progress_.store(false, std::memory_order_release);
flush_in_progress_.clear();
}

void SinkToConsole::run() {
Expand Down
6 changes: 2 additions & 4 deletions src/impl/sink_to_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ namespace soralog {
}

void SinkToFile::flush() noexcept {
bool false_v = false;
if (not flush_in_progress_.compare_exchange_strong(
false_v, true, std::memory_order_acq_rel)) {
if (flush_in_progress_.test_and_set()) {
return;
}

Expand Down Expand Up @@ -228,7 +226,7 @@ namespace soralog {
}
}

flush_in_progress_.store(false, std::memory_order_release);
flush_in_progress_.clear();
}

void SinkToFile::rotate() noexcept {
Expand Down
6 changes: 2 additions & 4 deletions src/impl/sink_to_syslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ namespace soralog {
}

void SinkToSyslog::flush() noexcept {
bool false_v = false;
if (not flush_in_progress_.compare_exchange_strong(
false_v, true, std::memory_order_acq_rel)) {
if (flush_in_progress_.test_and_set()) {
return;
}

Expand Down Expand Up @@ -239,7 +237,7 @@ namespace soralog {
}
}

flush_in_progress_.store(false, std::memory_order_release);
flush_in_progress_.clear();
}

void SinkToSyslog::run() {
Expand Down
Loading
Loading