Skip to content

Commit

Permalink
Merge pull request #223 from koriym/pecl-aop
Browse files Browse the repository at this point in the history
Extract PECL code from Aspect to PeclAspect
  • Loading branch information
koriym authored Nov 5, 2024
2 parents 8305141 + 02caaff commit 598f50b
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 262 deletions.
132 changes: 75 additions & 57 deletions .github/workflows/continuous-integration-pecl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
php-version: ['8.1', '8.2', '8.3']
fail-fast: false

steps:
- name: Checkout code
Expand All @@ -21,7 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
extensions: mbstring, intl, dom, json, libxml, xml, xmlwriter, tokenizer
tools: phpize, composer:v2

- name: Install build tools and Valgrind
Expand All @@ -30,10 +31,7 @@ jobs:
sudo apt-get install -y autoconf automake libtool bison re2c valgrind
- name: Install Composer dependencies
run: composer install --no-dev --prefer-dist --no-progress

- name: Install PHPUnit
run: composer require phpunit/phpunit --dev --prefer-dist --no-progress
run: composer install --prefer-dist --no-progress

- name: Build extension
id: build_extension
Expand All @@ -43,75 +41,95 @@ jobs:
phpize
./configure
make
- name: PHP info
id: php_info
run: |
php -dextension=./ext-rayaop/modules/rayaop.so -i | grep rayaop
- name: Run PECL demo with debug logging
id: run_pecl_demo
run: |
timeout 60s php -n -dextension=./ext-rayaop/modules/rayaop.so -dmemory_limit=128M -dreport_memleaks=1 -dzend.assertions=1 -dassert.exception=1 ./ext-rayaop/smoke.php
continue-on-error: true

- name: Check loaded extension
id: check_loaded_extension
# Run the demo script
- name: Run demo script
run: |
php -dextension=./ext-rayaop/modules/rayaop.so -r 'var_dump(extension_loaded("rayaop"));'
- name: Check function exists
id: check_function_exists
# Running demo script under Valgrind
valgrind \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
php -n \
-d extension=./ext-rayaop/modules/rayaop.so \
demo/05-pecl.php
# Combined step for PHPUnit and Valgrind analysis
- name: Run Tests with Valgrind
if: success() || failure()
id: test_with_valgrind
run: |
php -dextension=./ext-rayaop/modules/rayaop.so -r 'var_dump(function_exists("method_intercept"));'
- name: Run PHPUnit tests
id: run_phpunit_tests
run: |
php -dextension=./ext-rayaop/modules/rayaop.so vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Run Valgrind memory check
if: steps.build_extension.outcome == 'failure' || steps.run_pecl_demo.outcome == 'failure'
run: |
cat << EOF > valgrind.supp
# Create Valgrind suppression file
cat << EOF > rayaop.supp
{
<insert_a_suppression_name_here>
php_startup_leak
Memcheck:Leak
match-leak-kinds: reachable
...
fun:php_module_startup
...
}
{
zend_mm_startup_leak
Memcheck:Leak
match-leak-kinds: reachable
...
fun:zend_mm_startup
...
}
EOF
valgrind --suppressions=valgrind.supp --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt php -n -dextension=./ext-rayaop/modules/rayaop.so vendor/bin/phpunit
- name: Check Valgrind results
if: steps.build_extension.outcome == 'failure' || steps.run_pecl_demo.outcome == 'failure'
run: |
if [ -f valgrind-out.txt ]; then
echo "Valgrind log found:"
cat valgrind-out.txt
if ! grep -q "ERROR SUMMARY: 0 errors from 0 contexts" valgrind-out.txt; then
echo "Valgrind found errors"
exit 1
fi
else
echo "Valgrind log not found. This is unexpected."
exit 1
fi
- name: Upload Valgrind log file
if: steps.build_extension.outcome == 'failure' || steps.run_pecl_demo.outcome == 'failure'
# Run PHPUnit under Valgrind
valgrind \
--suppressions=rayaop.supp \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose \
--error-exitcode=0 \
--log-file=valgrind.log \
php -n \
-d extension=./ext-rayaop/modules/rayaop.so \
-d memory_limit=256M \
vendor/bin/phpunit \
--coverage-clover=coverage.xml || true
# Display Valgrind log
echo "=== Valgrind Log ==="
cat valgrind.log
# Upload debug information with unique names per PHP version
- name: Upload debug logs
if: always()
uses: actions/upload-artifact@v4
with:
name: valgrind-log
path: valgrind-out.txt
name: debug-logs-php${{ matrix.php-version }}
path: |
valgrind.log
coverage.xml
core*
if-no-files-found: warn

# Upload coverage report
- name: Upload coverage report
if: always()
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true

- name: Final status check
if: always()
run: |
if [[ "${{ steps.build_extension.outcome }}" == 'failure' || "${{ steps.run_pecl_demo.outcome }}" == 'failure' ]]; then
echo "Build extension and run failed. Please check the logs for more information."
exit 1
echo "PHP Version: ${{ matrix.php-version }}"
echo "Extension build status: ${{ steps.build_extension.outcome }}"
echo "Test with Valgrind status: ${{ steps.test_with_valgrind.outcome }}"
# Check for critical issues in Valgrind log
if [ -f valgrind.log ]; then
echo "=== Valgrind Error Summary ==="
grep "ERROR SUMMARY:" valgrind.log || true
grep "definitely lost:" valgrind.log || true
grep "indirectly lost:" valgrind.log || true
fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"autoload-dev": {
"psr-4": {
"Ray\\Aop\\": ["tests/", "tests/Fake/", "tests/Aspect", "tests/Aspect/Fake", "tests/Aspect/Fake/src"]
"Ray\\Aop\\": ["tests/", "tests/Fake/", "tests/Aspect", "tests/Aspect/Fake"]
},
"files": [
"src-mock/method_intercept.php",
Expand Down
29 changes: 29 additions & 0 deletions demo/05-pecl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Ray\Aop\Demo;

use Ray\Aop\Aspect;
use Ray\Aop\Matcher;
use RuntimeException;

use const PHP_EOL;

require __DIR__ . '/bootstrap.php';

$aspect = new Aspect(__DIR__ . '/tmp');
$aspect->bind(
(new Matcher())->any(),
new IsContainsMatcher('charge'),
[new WeekendBlocker()]
);
$aspect->weave(__DIR__. '/src');

try {
$billingService = new RealBillingService();
echo $billingService->chargeOrder();
} catch (RuntimeException $e) {
echo $e->getMessage() . PHP_EOL;
exit(1);
}
1 change: 1 addition & 0 deletions demo/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
passthru('php ' . __DIR__ . '/02-matcher-bind.php');
passthru('php ' . __DIR__ . '/03-annotation-bind.php');
passthru('php ' . __DIR__ . '/04-my-matcher.php');
//passthru('php ' . __DIR__ . '/05-pecl.php');
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ com
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion"/>
<!-- /Base -->
<!-- Option -->
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma"/>
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Used function method_intercept not found\\.$#"
count: 1
path: src/AspectPecl.php
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
includes:
- phpstan-baseline.neon
parameters:
phpVersion: 80200
level: max
Expand Down
Loading

0 comments on commit 598f50b

Please sign in to comment.