Skip to content

Commit

Permalink
feature(test): setup running tests with cmake and IDE (#2)
Browse files Browse the repository at this point in the history
feature(test): setup running tests with cmake and IDE

Signed-off-by: Dusan Malusev <dusan@dusanmalusev.dev>
  • Loading branch information
CodeLieutenant authored Aug 23, 2024
1 parent d4c934e commit cc6eaa8
Show file tree
Hide file tree
Showing 16 changed files with 530 additions and 44 deletions.
53 changes: 53 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: false
AlignTrailingComments: false
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '^".*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseBlocks: true
IndentWidth: 4
InsertNewlineAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 4
...
40 changes: 40 additions & 0 deletions .github/actions/compile-extension/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Compile UV extension
description: Compile UV extension

inputs:
sanitizer:
required: false
description: "ASAN or MSAN"
default: ''
debug:
required: false
description: "Enable debug"
default: 'yes'
static_libuv:
required: false
default: 'no'
description: "Link against static libuv"
libuv_pkgconfig:
required: true
description: "PkgConfig path for Libuv"

runs:
using: composite
steps:
- name: Compile uv extension
shell: bash
run: |
export PKG_CONFIG_PATH="$(pkg-config --variable pc_path pkg-config):${{ inputs.libuv_pkgconfig }}"
phpize
./configure \
${{ inputs.debug == 'yes' && '--enable-debug' || '' }} \
${{ inputs.sanitizer == 'asan' && '--enable-asan' || '' }} \
${{ inputs.sanitizer == 'msan' && '--enable-msan' || '' }} \
${{ inputs.static_libuv == 'yes' && '--enable-libuv-static' || '' }} \
--enable-ext-testing
make -j$(getconf _NPROCESSORS_ONLN)
sudo make install
env:
CFLAGS: -DZEND_TRACK_ARENA_ALLOC
CC: clang
USE_ZEND_ALLOC: 0
85 changes: 85 additions & 0 deletions .github/actions/install-libuv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Install Libuv
description: Install Libuv

inputs:
version:
required: false
default: "1.48.0"
description: "Libuv version"
sanitizer:
required: false
description: "ASAN or MSAN"
default: ''

outputs:
install_dir:
value: ${{ steps.values.outputs.install_dir }}
description: "Libuv Install Dir"
pkg_config_path:
value: ${{ steps.values.outputs.pkg_config_path }}
description: "Libuv PkgConfig script path"

runs:
using: composite
steps:
- name: Cache Libuv
id: cache-libuv
uses: actions/cache@v4
with:
path: /opt/libuv
key: libuv-${{ inputs.version }}-${{ runner.arch }}-${{ runner.os }}${{ inputs.sanitizer }}

- name: Setup cmake
if: steps.cache-libuv.outputs.cache-hit != 'true'
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: "3.24"

- name: Install Deps
if: steps.cache-libuv.outputs.cache-hit != 'true'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y pkg-config clang build-essential ninja-build
- name: Install Deps for Sanitizers
if: steps.cache-libuv.outputs.cache-hit != 'true' && inputs.sanitizer != ''
shell: bash
run: |
sudo apt-get install -y libasan8 libubsan1
sudo sysctl vm.mmap_rnd_bits=28
- name: Download Libuv
if: steps.cache-libuv.outputs.cache-hit != 'true'
shell: bash
working-directory: /opt
run: |
curl -L "https://github.com/libuv/libuv/archive/v${{ inputs.version }}.tar.gz" | tar xzf -
mv "libuv-${{ inputs.version }}" libuv-src
cd libuv-src && mkdir build
- name: 'Install Libuv'
if: steps.cache-libuv.outputs.cache-hit != 'true'
shell: bash
working-directory: /opt/libuv-src/build
run: |
cmake -G Ninja \
-DBUILD_TESTING=OFF \
-DLIBUV_BUILD_SHARED=ON \
-DASAN=${{ inputs.sanitizer == 'asan' && 'ON' || 'OFF' }} \
-DMSAN=${{ inputs.sanitizer == 'msan' && 'ON' || 'OFF' }} \
-DUBSAN=${{ inputs.sanitizer != '' && 'ON' || 'OFF' }} \
-DCMAKE_INSTALL_PREFIX="/opt/libuv" \
-DCMAKE_BUILD_TYPE="RelWithInfo" ..
env:
CC: clang
- name: Compile
if: steps.cache-libuv.outputs.cache-hit != 'true'
shell: bash
working-directory: /opt/libuv-src/build
run: sudo ninja install
- name: Add Libuv to the PATH
id: values
shell: bash
run: |
echo "pkg_config_path=/opt/libuv/lib/pkgconfig" >> "$GITHUB_OUTPUT"
echo "install_dir=/opt/libuv" >> "$GITHUB_OUTPUT"
96 changes: 96 additions & 0 deletions .github/actions/install-php/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Install PHP
description: Install PHP

inputs:
version:
required: true
description: "PHP version"
phpts:
required: true
description: "nts or ts"
sanitizer:
required: false
default: ''
description: "ASAN or MSAN"

outputs:
version:
value: ${{ steps.determine-php-version.outputs.version }}
description: "PHP version"
php_binary_dir:
value: ${{ steps.values.outputs.php_binary_dir }}
description: "PHP binary directory"

runs:
using: composite
steps:
- name: apt update
shell: bash
run: |
sudo apt-get update
sudo apt-get remove 'php*'
- name: Determine PHP version
shell: bash
id: determine-php-version
run: |
curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=${{ inputs.version }}' -o version.json
echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
- name: Cache PHP
id: cache-php
uses: actions/cache@v4
with:
path: /opt/php
key: php-sanitizers-${{ inputs.sanitizer }}-${{ runner.arch }}-${{ steps.determine-php-version.outputs.version }}-${{ inputs.phpts }}

- name: Download php
if: steps.cache-php.outputs.cache-hit != 'true'
working-directory: /opt
shell: bash
run: |
mkdir php-src/
curl -fsSL "${{ steps.determine-php-version.outputs.archive }}" | tar -Jx -C php-src --strip-components=1
- name: Compile PHP
if: steps.cache-php.outputs.cache-hit != 'true'
shell: bash
working-directory: /opt/php-src
run: |
./configure \
CFLAGS="-g -O0 -DZEND_TRACK_ARENA_ALLOC" \
--enable-debug \
--enable-cli \
${{ inputs.phpts == 'ts' && '--enable-zts' || '' }} \
--enable-option-checking=fatal \
--disable-zend-signals \
--without-sqlite3 \
--without-pdo-sqlite \
--without-libxml \
--disable-dom \
--disable-simplexml \
--disable-xml \
--disable-xmlreader \
--disable-xmlwriter \
--without-pcre-jit \
--disable-opcache-jit \
--disable-cgi \
--disable-phpdbg \
--without-pear \
--disable-mbregex \
${{ inputs.sanitizer == 'msan' && '--enable-memory-sanitizer' || '' }} \
${{ inputs.sanitizer == 'asan' && '--enable-address-sanitizer' || '' }} \
--prefix="/opt/php"
make -j"$(getconf _NPROCESSORS_ONLN)"
make install
env:
CC: clang
USE_ZEND_ALLOC: 0

- name: Add PHP to the PATH
id: values
shell: bash
run: |
echo "php_binary_dir=/opt/php/bin" >> "$GITHUB_OUTPUT"
echo "/opt/php/bin" >> "$GITHUB_PATH"
53 changes: 40 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,58 @@ on:
- 0.3.x

jobs:
# Adapted from https://github.com/beberlei/hdrhistogram-php
tests:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
libuv: ["1.48.0"]
php:
- 8.3
- 8.2
- 8.1
- "8.1"
- "8.2"
- "8.3"
- "8.4"
phpts:
- "ts"
- "nts"
steps:
- run: |
sudo apt update
sudo apt-get install -y pkg-config clang-18 clang++-18 build-essential ninja-build
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: phpize, pecl, php-config
- name: install deps
run: sudo apt-get install -y ninja-build ccache pkg-config libasan8 libubsan1 build-essential valgrind >> /dev/null
php-version: ${{ matrix.php }}-${{ matrix.phpts }}
ini-file: development
coverage: none
tools: none
env:
phpts: ${{ matrix.phpts }}
debug: true

- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.24'
- name: 'Install Libuv'
run: sudo ./scripts/compile-libuv.sh RelWithInfo 1.48.0 >> /dev/null
cmake-version: "3.24"

- uses: ./.github/actions/install-libuv
id: libuv
with:
version: ${{ matrix.libuv }}

- name: Compile uv extension
run: phpize && ./configure && make && sudo make install && echo "extension = uv" >> $(php -r 'echo php_ini_loaded_file();')
uses: ./.github/actions/compile-extension
with:
debug: yes
libuv_pkgconfig: ${{ steps.libuv.outputs.pkg_config_path }}

- name: Run the tests
run: php run-tests.php -q -j4 -p $(which php) -m --show-diff --set-timeout 120
run: php run-tests.php -q -j$(getconf _NPROCESSORS_ONLN) -p $(which php) --show-diff --set-timeout 120
env:
USE_ZEND_ALLOC: 0
Loading

0 comments on commit cc6eaa8

Please sign in to comment.