Skip to content

Commit f5870b6

Browse files
committed
Add support to run tests with and without opcache
1 parent f354450 commit f5870b6

File tree

4 files changed

+68
-22
lines changed

4 files changed

+68
-22
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Build a PHP extension for a specific version.
6262
php-version: '8.3'
6363
ts: nts
6464
arch: x64
65-
args: --enable-xdebug
65+
args: --with-xdebug
6666
libs: zlib
6767
```
6868

@@ -78,6 +78,7 @@ Build a PHP extension for a specific version.
7878
- `build-directory` (optional) - The directory to build the extension in, defaults to the user's temporary directory.
7979
- `run-tests` (optional) - Run the extension tests. Defaults to `true`.
8080
- `test-runner` (optional) - The test runner to use. Defaults to `run-tests.php`.
81+
- `test-opcache-mode` (optional) - Run tests with opcache `on`, `off` or `both`. Defaults to `on`.
8182
- `auth-token` (optional) - Authentication token to use in case the extension is hosted on a private repository.
8283

8384
Instead of having to configure all the inputs for the extension action, you can use the `extension-matrix` action to get the matrix of jobs with different input configurations.

extension/BuildPhpExtension/private/Get-BuildDirectory.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@ Function Get-BuildDirectory {
22
<#
33
.SYNOPSIS
44
Get the directory to build the extension.
5+
.PARAMETER ParentBuildDirectory
6+
Parent directory to create the build directory.
57
#>
68
[OutputType()]
79
param(
10+
[Parameter(Mandatory = $false, Position=0, HelpMessage='Parent directory to create the build directory.')]
11+
[string] $ParentBuildDirectory = ""
812
)
913
begin {
1014
}
1115
process {
12-
if ($null -ne $env:BUILD_DIRECTORY -and $env:BUILD_DIRECTORY -ne "") {
13-
$parentBuildDirectory = $env:BUILD_DIRECTORY
14-
} else {
15-
$parentBuildDirectory = [System.IO.Path]::GetTempPath()
16+
if($ParentBuildDirectory -eq "") {
17+
if ($null -ne $env:BUILD_DIRECTORY -and $env:BUILD_DIRECTORY -ne "") {
18+
$ParentBuildDirectory = $env:BUILD_DIRECTORY
19+
} else {
20+
$ParentBuildDirectory = [System.IO.Path]::GetTempPath()
21+
}
1622
}
1723

1824
$buildDirectory = [System.Guid]::NewGuid().ToString().substring(0, 8)
1925

20-
$buildDirectoryPath = [System.IO.Path]::Combine($parentBuildDirectory, $buildDirectory)
26+
$buildDirectoryPath = [System.IO.Path]::Combine($ParentBuildDirectory, $buildDirectory)
2127

2228
New-Item "$buildDirectoryPath" -ItemType "directory" -Force > $null 2>&1
2329

extension/BuildPhpExtension/private/Invoke-Tests.ps1

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ Function Invoke-Tests {
1313
begin {
1414
}
1515
process {
16-
Add-StepLog "Running tests for $($Config.name) extension"
1716
try {
1817
$currentDirectory = (Get-Location).Path
1918
$php_dir = Join-Path $currentDirectory php-bin
2019
$env:TEST_PHP_EXECUTABLE = "$php_dir\php.exe"
2120
$env:REPORT_EXIT_STATUS = 1
2221
$env:XDEBUG_MODE = ""
23-
$env:TEMP=$((Get-Item -LiteralPath $Env:TEMP).FullName)
24-
$env:TMP=$((Get-Item -LiteralPath $Env:TMP).FullName)
22+
$tempOriginal = $env:TEMP
2523
$type='extension'
2624
if ((Select-String -Path 'config.w32' -Pattern 'ZEND_EXTENSION\(' -Quiet) -eq $true) {
2725
$type='zend_extension'
@@ -47,22 +45,58 @@ Function Invoke-Tests {
4745
'--show-diff',
4846
'--show-slow 1000',
4947
'--set-timeout 120',
50-
'-g FAIL,XFAIL,BORK,WARN,LEAK,SKIP',
51-
'--temp-source ' + $env:TEMP,
52-
'--temp-target ' + $env:TEMP
48+
'-g FAIL,XFAIL,BORK,WARN,LEAK,SKIP'
5349
)
54-
$phpExpression = "php $env:TEST_RUNNER " + ($test_runner_args -join ' ')
55-
chcp 65001
56-
Write-Output "Running tests... $phpExpression"
57-
Write-Output "TEST_PHP_ARGS $env:TEST_PHP_ARGS"
58-
Write-Output "TEST_PHP_EXECUTABLE $env:TEST_PHP_EXECUTABLE"
59-
Invoke-Expression $phpExpression
60-
if ($LASTEXITCODE -ne 0) {
61-
exit $LASTEXITCODE
50+
51+
$opcacheModes = @($env:TEST_OPCACHE_MODE)
52+
if($env:TEST_OPCACHE_MODE -eq 'both') {
53+
$opcacheModes = @('on', 'off')
6254
}
63-
Add-BuildLog tick $($Config.name) "Tests executed successfully"
55+
$success = $True
56+
foreach($opcacheMode in $opcacheModes) {
57+
$suffix = ""
58+
if($env:TEST_OPCACHE_MODE -eq 'both') {
59+
$suffix = " (opcache=$opcacheMode)"
60+
}
61+
Add-StepLog "Running tests for $($Config.name) extension$suffix"
62+
Set-GAGroup start
63+
$tempDirectory = Get-BuildDirectory $currentDirectory
64+
$env:TEMP=$tempDirectory
65+
$env:TMP=$tempDirectory
66+
$env:OPCACHE = $opcacheMode
67+
$test_runner_args += '--temp-source ' + $tempDirectory;
68+
$test_runner_args += '--temp-target ' + $tempDirectory;
69+
$opcache_args = @()
70+
if($opcacheMode -eq 'on') {
71+
$opcache_args += "-d zend_extension=$php_dir\ext\php_opcache.dll"
72+
$opcache_args += "-d opcache.enable=1"
73+
$opcache_args += "-d opcache.enable_cli=1"
74+
$opcache_args += "-d opcache.optimization_level=1"
75+
}
76+
$phpExpression = @(
77+
'php',
78+
$env:TEST_RUNNER,
79+
($test_runner_args -join ' '),
80+
($opcache_args -join ' ')
81+
) -join ' '
82+
Write-Host "Running tests... $phpExpression"
83+
Write-Host "TEST_PHP_ARGS $env:TEST_PHP_ARGS"
84+
Write-Host "TEST_PHP_EXECUTABLE $env:TEST_PHP_EXECUTABLE"
85+
chcp 65001
86+
Invoke-Expression $phpExpression
87+
if ($LASTEXITCODE -ne 0) {
88+
$success = $False
89+
}
90+
Set-GAGroup end
91+
}
92+
$env:TEMP = $tempOriginal
93+
$env:TMP = $tempOriginal
94+
if(-not $success) {
95+
throw "Failed to run tests successfully"
96+
}
97+
Add-BuildLog tick $($Config.name) "Tests run successfully"
6498
} catch {
65-
Add-BuildLog cross $($Config.name) "Failed to run tests"
99+
Add-BuildLog cross $($Config.name) "Failed to run tests successfully"
66100
throw
67101
}
68102
}

extension/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ inputs:
3939
description: Test runner to use
4040
required: false
4141
default: 'run-tests.php'
42+
test-opcache-mode:
43+
description: Test opcache mode
44+
required: false
45+
default: 'on'
4246
build-directory:
4347
description: Directory to build the extension in
4448
required: false
@@ -58,6 +62,7 @@ runs:
5862
ARTIFACT_NAMING_SCHEME: ${{env.artifact-naming-scheme}}
5963
RUN_TESTS: ${{inputs.run-tests}}
6064
TEST_RUNNER: ${{inputs.test-runner}}
65+
TEST_OPCACHE_MODE: ${{inputs.test-opcache-mode}}
6166
BUILD_DIRECTORY: ${{inputs.build-directory}}
6267
AUTH_TOKEN: ${{inputs.auth-token}}
6368
run: |

0 commit comments

Comments
 (0)