diff --git a/.github/workflows/check-code-format.yml b/.github/workflows/check-code-format.yml new file mode 100644 index 0000000..c8118a3 --- /dev/null +++ b/.github/workflows/check-code-format.yml @@ -0,0 +1,42 @@ +name: Check Code Format + +on: + push: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - .github/workflows/check-code-format.yml + pull_request: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - .github/workflows/check-code-format.yml + +jobs: + check-code-format: + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Install clang-format + env: + CLANG_FORMAT_VERSION: 22 + run: | + UBUNTU_CODENAME=$(. /etc/os-release && echo $VERSION_CODENAME) + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + echo "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-${CLANG_FORMAT_VERSION} main" | sudo tee /etc/apt/sources.list.d/llvm.list + echo "deb-src http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-${CLANG_FORMAT_VERSION} main" | sudo tee -a /etc/apt/sources.list.d/llvm.list + sudo apt-get update + sudo apt-get install clang-format-${CLANG_FORMAT_VERSION} + sudo ln -s -f /usr/bin/clang-format-${CLANG_FORMAT_VERSION} /usr/bin/clang-format + clang-format --version + + - name: Check code format + run: | + find . -type f \( -name "*.h" -o -name "*.cc" \) > source_files.txt + clang-format --dry-run --Werror --verbose --files=source_files.txt diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml new file mode 100644 index 0000000..c05c5f3 --- /dev/null +++ b/.github/workflows/ci-linux.yml @@ -0,0 +1,98 @@ +name: Linux Continuous Integrations + +on: + push: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - Makefile + - 'meson*' + - '**/CMakeLists.txt' + - .github/workflows/ci-linux.yml + pull_request: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - Makefile + - 'meson*' + - '**/CMakeLists.txt' + - .github/workflows/ci-linux.yml + +jobs: + ci-linux: + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04, ubuntu-24.04-arm, ubuntu-22.04, ubuntu-22.04-arm] + compiler: + - {c: gcc, cpp: g++} + - {c: clang, cpp: clang++} + sanitize: [address, undefined, thread] + build_system: [cmake, meson] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install --yes -qq meson libboost-all-dev + + - name: Build and test with CMake + if: matrix.build_system == 'cmake' + env: + CC: ${{ matrix.compiler.c }} + CXX: ${{ matrix.compiler.cpp }} + run: | + cmake -S . -G Ninja -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_INIT="-fsanitize=${{ matrix.sanitize }}" -DCMAKE_CXX_FLAGS_INIT="-fsanitize=${{ matrix.sanitize }}" -DCMAKE_EXE_LINKER_FLAGS_INIT="-fsanitize=${{ matrix.sanitize }}" -DATOMIC_QUEUE_BUILD_TESTS=ON -DATOMIC_QUEUE_BUILD_EXAMPLES=ON + cmake --build build --target all + ctest --test-dir build --output-on-failure + + - name: Build and test with Meson + if: matrix.build_system == 'meson' + env: + CC: ${{ matrix.compiler.c }} + CXX: ${{ matrix.compiler.cpp }} + run: | + meson setup build -Dwerror=true -Dwarning_level=3 -Db_sanitize=${{ matrix.sanitize }} + meson compile -C build + meson test -C build --print-errorlogs + + ci-linux-makefile: + strategy: + fail-fast: false + matrix: + toolset: [gcc, clang] + os: [ubuntu-22.04, ubuntu-24.04, ubuntu-22.04-arm, ubuntu-24.04-arm] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v6 + + - name: Install Boost.Test + run: | + sudo apt-get update + sudo apt-get install --yes -qq libboost-test-dev + + - name: Environment variables + run: make -r TOOLSET=${{ matrix.toolset }} env + + - name: Toolset versions + run: make -r TOOLSET=${{ matrix.toolset }} versions + + - name: Build and run unit tests + run: make -rj2 TOOLSET=${{ matrix.toolset }} example run_tests + + - name: Build and run unit tests with address sanitizer + run: make -rj2 TOOLSET=${{ matrix.toolset }} BUILD=sanitize2 run_tests + + - name: Build and run unit tests with thread sanitizer + run: make -rj2 TOOLSET=${{ matrix.toolset }} BUILD=sanitize run_tests diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml new file mode 100644 index 0000000..074f177 --- /dev/null +++ b/.github/workflows/ci-macos.yml @@ -0,0 +1,62 @@ +name: macOS Continuous Integrations + +on: + push: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - 'meson*' + - '**/CMakeLists.txt' + - .github/workflows/ci-macos.yml + pull_request: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - 'meson*' + - '**/CMakeLists.txt' + - .github/workflows/ci-macos.yml + +jobs: + ci-macos: + strategy: + fail-fast: false + matrix: + os: [macos-26, macos-26-intel] + compiler: + - {c: clang, cpp: clang++} + sanitize: [address, undefined, thread] + build_system: [cmake, meson] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Install dependencies + run: | + brew install meson boost + + - name: Build and test with CMake + if: matrix.build_system == 'cmake' + env: + CC: ${{ matrix.compiler.c }} + CXX: ${{ matrix.compiler.cpp }} + run: | + cmake -S . -G Ninja -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_INIT="-fsanitize=${{ matrix.sanitize }}" -DCMAKE_CXX_FLAGS_INIT="-fsanitize=${{ matrix.sanitize }}" -DCMAKE_EXE_LINKER_FLAGS_INIT="-fsanitize=${{ matrix.sanitize }}" -DATOMIC_QUEUE_BUILD_TESTS=ON -DATOMIC_QUEUE_BUILD_EXAMPLES=ON + cmake --build build --target all + ctest --test-dir build --output-on-failure + + - name: Build and test with Meson + if: matrix.build_system == 'meson' + env: + CC: ${{ matrix.compiler.c }} + CXX: ${{ matrix.compiler.cpp }} + run: | + meson setup build -Dwerror=true -Dwarning_level=3 -Db_sanitize=${{ matrix.sanitize }} + meson compile -C build + meson test -C build --print-errorlogs diff --git a/.github/workflows/ci-meson.yml b/.github/workflows/ci-meson.yml deleted file mode 100644 index fcd1b04..0000000 --- a/.github/workflows/ci-meson.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Meson Continuous Integrations - -on: - push: - branches: [ master ] - paths: - - '!**' - - '**.h' - - '**.cc' - - 'meson*' - - .github/workflows/ci-meson.yml - pull_request: - branches: [ master ] - paths: - - '!**' - - '**.h' - - '**.cc' - - 'meson*' - - .github/workflows/ci-meson.yml - -jobs: - build-and-test: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, ubuntu-24.04-arm] - cpp_compiler: [g++, clang++] - sanitize: [address, undefined, thread] - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v6 - - - name: Install Meson and Boost.Test - run: | - sudo apt-get update - sudo apt-get install --yes -qq meson libboost-test-dev - - - name: Setup - env: - CXX: ${{ matrix.cpp_compiler }} - run: meson setup build -Dwerror=true -Dwarning_level=3 -Db_sanitize=${{ matrix.sanitize }} - - - name: Compile - run: meson compile -C build - - - name: Test - run: meson test -C build --print-errorlogs diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml new file mode 100644 index 0000000..2e43a4e --- /dev/null +++ b/.github/workflows/ci-windows.yml @@ -0,0 +1,48 @@ +name: Windows Continuous Integrations + +on: + push: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - '**/CMakeLists.txt' + - .github/workflows/ci-windows.yml + pull_request: + branches: [ master ] + paths: + - '!**' + - '**.h' + - '**.cc' + - '**/CMakeLists.txt' + - .github/workflows/ci-windows.yml + +jobs: + ci-windows: + strategy: + fail-fast: false + matrix: + os: [windows-2025, windows-2022] + build_system: [cmake] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Install boost + uses: MarkusJx/install-boost@v2.6.0 + id: install-boost-windows + with: + boost_version: 1.89.0 + platform_version: 2022 + toolset: msvc + + - name: Build and test with CMake + if: matrix.build_system == 'cmake' + run: | + cmake -S . -G Ninja -B build -DCMAKE_BUILD_TYPE=Release -DBOOST_ROOT="${{steps.install-boost-windows.outputs.BOOST_ROOT}}" -DATOMIC_QUEUE_BUILD_TESTS=ON -DATOMIC_QUEUE_BUILD_EXAMPLES=ON + cmake --build build --target all + ctest --test-dir build --output-on-failure diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 3027c4f..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Makefile Continuous Integrations - -on: - push: - branches: [ master ] - paths: - - '!**' - - '**.h' - - '**.cc' - - Makefile - - .github/workflows/ci.yml - pull_request: - branches: [ master ] - paths: - - '!**' - - '**.h' - - '**.cc' - - Makefile - - .github/workflows/ci.yml - -jobs: - unit-test: - strategy: - fail-fast: false - matrix: - toolset: [gcc, clang] - os: [ubuntu-22.04, ubuntu-24.04, ubuntu-22.04-arm, ubuntu-24.04-arm] - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v6 - - - name: Install Boost.Test - run: | - sudo apt-get update - sudo apt-get install --yes -qq libboost-test-dev - - - name: Environment variables - run: make -r TOOLSET=${{ matrix.toolset }} env - - - name: Toolset versions - run: make -r TOOLSET=${{ matrix.toolset }} versions - - - name: Build and run unit tests - run: make -rj2 TOOLSET=${{ matrix.toolset }} example run_tests - - - name: Build and run unit tests with address sanitizer - run: make -rj2 TOOLSET=${{ matrix.toolset }} BUILD=sanitize2 run_tests - - - name: Build and run unit tests with thread sanitizer - run: make -rj2 TOOLSET=${{ matrix.toolset }} BUILD=sanitize run_tests diff --git a/.github/workflows/cmake-gcc-clang.yml b/.github/workflows/cmake-gcc-clang.yml deleted file mode 100644 index b9655ce..0000000 --- a/.github/workflows/cmake-gcc-clang.yml +++ /dev/null @@ -1,118 +0,0 @@ -# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. -# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml -name: CMake Continuous Integrations - -on: - push: - branches: [ "master", "CMake-support"] - paths: - - '!**' - - '**.h' - - '**.cc' - - '**/CMakeLists.txt' - - .github/workflows/cmake-gcc-clang.yml - pull_request: - branches: [ "master" ] - paths: - - '!**' - - '**.h' - - '**.cc' - - '**/CMakeLists.txt' - - .github/workflows/cmake-gcc-clang.yml - -jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. - fail-fast: false - - # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. - # - # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. - matrix: - include: - # --- Linux x64 --- - # We define 'compiler' as a dictionary (object) here - - os: ubuntu-latest - build_type: Release - compiler: { c: gcc, cpp: g++ } - - - os: ubuntu-latest - build_type: Release - compiler: { c: clang, cpp: clang++ } - - # --- Linux ARM --- - - os: ubuntu-24.04-arm - build_type: Release - compiler: { c: gcc, cpp: g++ } - - - os: ubuntu-24.04-arm - build_type: Release - compiler: { c: clang, cpp: clang++ } - - # --- Windows --- - - os: windows-latest - build_type: Release - compiler: { c: cl, cpp: cl } - - steps: - - uses: actions/checkout@v6 - - - name: Set reusable strings - # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. - id: strings - shell: bash - run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - - name: Install boost on linux - if: startsWith(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install --yes -qq libboost-all-dev - - - name: Install boost on windows - if: startsWith(matrix.os, 'windows') && matrix.compiler.cpp == 'cl' - uses: MarkusJx/install-boost@v2.6.0 - id: install-boost-windows - with: - boost_version: 1.89.0 - platform_version: 2022 - toolset: msvc - - - name: Configure CMake Ubuntu - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - if: startsWith(matrix.os, 'ubuntu') - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} - -DCMAKE_C_COMPILER=${{ matrix.compiler.c }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -DATOMIC_QUEUE_BUILD_TESTS=ON - -DATOMIC_QUEUE_BUILD_EXAMPLES=ON - -S ${{ github.workspace }} - - - name: Configure CMake Windows - MSVC - if: startsWith(matrix.os, 'windows') && matrix.compiler.cpp == 'cl' - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DATOMIC_QUEUE_BUILD_TESTS=ON - -DATOMIC_QUEUE_BUILD_EXAMPLES=ON - -S ${{ github.workspace }} - -DBOOST_ROOT=${{steps.install-boost-windows.outputs.BOOST_ROOT}} - - - name: Build - # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} - - - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} - # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --build-config ${{ matrix.build_type }} diff --git a/README.md b/README.md index de010f4..bde0547 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ [![Conan Center](https://img.shields.io/conan/v/atomic_queue)](https://conan.io/center/recipes/atomic_queue) [![Vcpkg Version](https://img.shields.io/vcpkg/v/atomic-queue)](https://vcpkg.io/en/package/atomic-queue)
-[![Makefile Continuous Integrations](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci.yml/badge.svg)](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci.yml) -[![CMake Continuous Integrations](https://github.com/max0x7ba/atomic_queue/actions/workflows/cmake-gcc-clang.yml/badge.svg)](https://github.com/max0x7ba/atomic_queue/actions/workflows/cmake-gcc-clang.yml) -[![Meson Continuous Integrations](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-meson.yml/badge.svg)](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-meson.yml) +[![Linux Continuous Integrations](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-linux.yml/badge.svg)](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-linux.yml) +[![macOS Continuous Integrations](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-macos.yml/badge.svg)](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-macos.yml) +[![Windows Continuous Integrations](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-windows.yml/badge.svg)](https://github.com/max0x7ba/atomic_queue/actions/workflows/ci-windows.yml)
![platform Linux x86_64](https://img.shields.io/badge/platform-Linux%20x86_64--bit-gold) ![platform Linux ARM](https://img.shields.io/badge/platform-Linux%20ARM-gold) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3f53bce..2394799 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,4 +30,23 @@ if ( ATOMIC_QUEUE_BUILD_TESTS ) NAME atomic_queue_tests COMMAND atomic_queue_tests ) + + if (APPLE) + add_executable( + atomic_queue_tests_objcpp + ${CMAKE_CURRENT_SOURCE_DIR}/tests.mm + ) + + target_link_libraries( + atomic_queue_tests_objcpp + atomic_queue + Boost::unit_test_framework + ) + + add_test( + NAME atomic_queue_tests_objcpp + COMMAND atomic_queue_tests_objcpp + ) + endif() + endif() \ No newline at end of file diff --git a/src/tests.cc b/src/tests.cc index 7b29644..d2d8472 100644 --- a/src/tests.cc +++ b/src/tests.cc @@ -223,7 +223,7 @@ using move_constructor_assignment_queues = boost::mpl::list< BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor_assignment, Queue, move_constructor_assignment_queues) { Queue q; auto const capacity = q.capacity(); - BOOST_CHECK_GE(capacity, 2); + BOOST_CHECK_GE(capacity, 2u); Queue q2 = std::move(q); BOOST_CHECK(!q.capacity()); @@ -287,8 +287,9 @@ BOOST_AUTO_TEST_CASE(try_push_pop) { } BOOST_AUTO_TEST_CASE(size) { + constexpr unsigned CAPACITY = CACHE_LINE_SIZE * CACHE_LINE_SIZE; atomic_queue::RetryDecorator> q(10); - BOOST_CHECK_EQUAL(q.capacity(), CACHE_LINE_SIZE * CACHE_LINE_SIZE); + BOOST_CHECK_EQUAL(q.capacity(), CAPACITY); BOOST_CHECK(q.was_empty()); BOOST_CHECK(!q.was_full()); } diff --git a/src/tests.mm b/src/tests.mm new file mode 100644 index 0000000..2f08cb6 --- /dev/null +++ b/src/tests.mm @@ -0,0 +1,3 @@ +// For objective-c++ compatibility tests +#import +#include "tests.cc"