Skip to content

Commit

Permalink
unit test: queue
Browse files Browse the repository at this point in the history
  • Loading branch information
zenshosan committed Aug 14, 2024
1 parent c2a9676 commit 759845b
Show file tree
Hide file tree
Showing 11 changed files with 2,549 additions and 22 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ jobs:
fail-fast: false

matrix:
os: [ubuntu-latest, windows-latest]
# as of 2024-08-15
os: [ubuntu-24.04, windows-2022]
#os: [ubuntu-latest, windows-latest]
build_type: [debugoptimized]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
- os: windows-2022
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
- os: ubuntu-24.04
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
- os: ubuntu-24.04
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
- os: windows-2022
c_compiler: gcc
- os: windows-latest
- os: windows-2022
c_compiler: clang
- os: ubuntu-latest
- os: ubuntu-24.04
c_compiler: cl

steps:
Expand All @@ -42,14 +44,22 @@ jobs:
python-version: '3.x'

- name: Prepare msbuild
if: contains(matrix.os, 'windows-latest')
if: contains(matrix.os, 'windows')
uses: microsoft/setup-msbuild@v2
with:
msbuild-architecture: x64

- name: Install Python Dependencies
run: pip install meson ninja

- name: Compiler version
if: ${{ !contains(matrix.os, 'windows') }}
run: |
dpkg -l | grep gcc
gcc --version
dpkg -l | grep clang
clang --version
- name: Set reusable strings
id: strings
shell: bash
Expand All @@ -61,15 +71,19 @@ jobs:
echo "package_test=${{ github.workspace }}/package_test" >> "$GITHUB_OUTPUT"
- name: Prepare Build for Windows
if: contains(matrix.os, 'windows-latest')
if: contains(matrix.os, 'windows')
run: >
meson setup
--buildtype=${{ matrix.build_type }}
--prefix='${{ steps.strings.outputs.installdir_abs }}'
--backend=vs
${{ steps.strings.outputs.builddir }} ${{ github.workspace }}
env:
CC: ${{ matrix.c_compiler }}
CXX: ${{ matrix.cpp_compiler }}

- name: Prepare Build
if: ${{ !contains(matrix.os, 'windows-latest') }}
if: ${{ !contains(matrix.os, 'windows') }}
run: >
meson setup
--buildtype=${{ matrix.build_type }}
Expand All @@ -89,14 +103,14 @@ jobs:
# run: meson install -C ${{ steps.strings.outputs.builddir }}
#
# - name: Package Test for Windows
# if: contains(matrix.os, 'windows-latest')
# if: contains(matrix.os, 'windows')
# run: |
# meson setup --buildtype=${{ matrix.build_type }} '-Dpackage_install_dir=${{ steps.strings.outputs.installdir }}' ${{ steps.strings.outputs.builddir_pkg }} ${{ steps.strings.outputs.package_test }}
# meson compile -v -C ${{ steps.strings.outputs.builddir_pkg }}
# meson test -v -C ${{ steps.strings.outputs.builddir_pkg }}
#
# - name: Package Test
# if: ${{ !contains(matrix.os, 'windows-latest') }}
# if: ${{ !contains(matrix.os, 'windows') }}
# run: |
# meson setup --buildtype ${{ matrix.build_type }} '-Dpackage_install_dir=${{ steps.strings.outputs.installdir }}' ${{ steps.strings.outputs.builddir_pkg }} ${{ steps.strings.outputs.package_test }} --pkg-config-path '${{ steps.strings.outputs.installdir }}/lib/x86_64-linux-gnu/pkgconfig'
# meson compile -v -C ${{ steps.strings.outputs.builddir_pkg }}
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/sanitizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Sanitize

on:
push:
branches: [ "xxx" ]
# branches: [ "br_*" ]
# pull_request:
# branches: [ "main" ]

jobs:
sanitize:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
build_type: [debugoptimized]
c_compiler: [gcc]
sanitize: [address, undefined, thread, leak]
include:
- c_compiler: gcc
cpp_compiler: g++

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install Python Dependencies
run: pip install meson ninja

- name: Set reusable strings
id: strings
shell: bash
run: |
echo "builddir=${{ github.workspace }}/builddir" >> "$GITHUB_OUTPUT"
echo "result_file=sanitize_${{ matrix.sanitize }}.txt" >> "$GITHUB_OUTPUT"
- name: Prepare Build
if: ${{ !contains(matrix.os, 'windows-latest') }}
run: >
meson setup
--buildtype=${{ matrix.build_type }}
-Db_sanitize=${{ matrix.sanitize }}
${{ steps.strings.outputs.builddir }} ${{ github.workspace }}
env:
CC: ${{ matrix.c_compiler }}
CXX: ${{ matrix.cpp_compiler }}

- name: Run Build
run: meson compile -v -C ${{ steps.strings.outputs.builddir }}

- name: Run Test Suite
run: meson test -v -C ${{ steps.strings.outputs.builddir }} 2>&1 | tee ${{ steps.strings.outputs.result_file }}

#- name: Upload results
# uses: actions/upload-artifact@v4
# with:
# name: sanitize-results-${{ matrix.sanitize }}
# path: ${{ steps.strings.outputs.result_file }}
# overwrite: true
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

project('zaplog', 'cpp',
version : '0.1',
default_options : ['warning_level=3', 'cpp_std=c++20'])
default_options : ['warning_level=2', 'cpp_std=c++20'])

zaplog_build_tests = get_option('zaplog_build_tests')

Expand Down
42 changes: 33 additions & 9 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ git_date_h = vcs_tag(
replace_string : '@git_date@'
)

lib_args = ['-DZAPLOG_BUILDING', '-DZAPLOG_BUILDING_SLIB']
if meson.get_compiler('cpp').get_id() == 'msvc'
extra_args = ['/utf-8']
else
extra_args = []
endif

lib_args = ['-DZAPLOG_BUILDING', '-DZAPLOG_BUILDING_SLIB'] + extra_args
slib_sources = [
config_h,
git_hash_h,
git_date_h,
'zaplog.cpp'
'zaplog.cpp',
]

slib = static_library(
Expand All @@ -43,14 +48,33 @@ slib = static_library(
gtest_dep = dependency('gtest', required : true)
gtest_main_dep = dependency('gtest_main', required : true)

test_args = ['-DZAPLOG_BUILDING', '-DZAPLOG_BUILDING_SLIB']
test_exe = executable(
'zaplog_test',

unit_test_args = ['-DZAPLOG_BUILDING', '-DZAPLOG_BUILDING_SLIB', '-DLIBPT_ENABLE_BUILD_TESTS'] + extra_args
unit_test_sources = [
'pt/pf_bounded_spsc_zero_copy_test.cpp',
'pt/pf_mpsc_ringbuffer_test.cpp'
]
unit_test_exe = executable(
'unit_test',
sources : unit_test_sources,
dependencies : [ gtest_dep, gtest_main_dep, ],
cpp_args : unit_test_args
)
test('unittest', unit_test_exe)


api_test_args = ['-DZAPLOG_BUILDING', '-DZAPLOG_BUILDING_SLIB' ] + extra_args
api_test_sources = [
'zaplog_test.cpp',
]
api_test_exe = executable(
'api_test',
sources : api_test_sources,
dependencies : [ gtest_dep, gtest_main_dep, ],
link_with : slib,
cpp_args : test_args)
test('zaplog', test_exe)
cpp_args : api_test_args)
test('apitest', api_test_exe)


# Make this library usable as a Meson subproject.
zaplog_dep = declare_dependency(
Expand All @@ -65,8 +89,8 @@ pkg_mod = import('pkgconfig')
pkg_mod.generate(
name : 'zaplog',
filebase : 'zaplog',
description : 'Meson sample project.',
description : 'Zaplog: A C++ logging library.',
subdirs : 'zaplog',
libraries : slib,
version : '0.1',
version : meson.project_version(),
)
Loading

0 comments on commit 759845b

Please sign in to comment.