From f164c6c38a9e9ce0e6375cd0a04aa370b6d69d53 Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 18:03:18 +0900 Subject: [PATCH 01/10] =?UTF-8?q?ci:=20com0com=20=E3=82=92=E3=83=A9?= =?UTF-8?q?=E3=83=B3=E3=83=8A=E3=83=BC=E3=81=B8=E5=85=A5=E3=82=8C=E3=82=89?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=81=8B=E8=A9=A6=E3=81=99=EF=BC=88=E8=A9=A6?= =?UTF-8?q?=E8=A1=8C=E3=80=81=E5=BE=8C=E3=81=A7=E5=89=8A=E9=99=A4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../workflows/integration-windows-trial.yml | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/integration-windows-trial.yml diff --git a/.github/workflows/integration-windows-trial.yml b/.github/workflows/integration-windows-trial.yml new file mode 100644 index 0000000..9a6278f --- /dev/null +++ b/.github/workflows/integration-windows-trial.yml @@ -0,0 +1,92 @@ +name: Integration (Windows trial) + +# 試行用。ホストランナーへ com0com のドライバーを非対話で入れられるかを確かめる。 +# 確かめ終えたら削除する。 +on: + push: + branches: [ 'claude/ci-windows-integration-*' ] + +permissions: + contents: read + +jobs: + com0com: + runs-on: windows-latest + timeout-minutes: 10 + defaults: + run: + shell: pwsh + env: + COM0COM_ZIP_URL: https://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/com0com-3.0.0.0-i386-and-x64-signed.zip/download + COM0COM_ZIP_SHA256: 6e5d4359865277430d4ae88c73fb7e648a0ed8e81aea5002478179cfcb0bb0e1 + COM0COM_DIR: C:\com0com + + steps: + - name: Diagnostics + run: | + Get-CimInstance Win32_OperatingSystem | Format-List Caption, Version, BuildNumber + try { "SecureBoot: $(Confirm-SecureBootUEFI)" } catch { "SecureBoot: $($_.Exception.Message)" } + bcdedit /enum '{current}' | Select-String -Pattern 'testsigning|nointegritychecks|hypervisor' + whoami /groups | Select-String -Pattern 'Administrators|Mandatory Label' + [System.IO.Ports.SerialPort]::GetPortNames() + + - name: Download com0com + run: | + $work = Join-Path $env:RUNNER_TEMP 'com0com-dl' + New-Item -ItemType Directory -Force $work | Out-Null + $zip = Join-Path $work 'com0com.zip' + curl.exe -fsSL --retry 3 -o $zip $env:COM0COM_ZIP_URL + $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLowerInvariant() + if ($hash -ne $env:COM0COM_ZIP_SHA256) { throw "SHA256 が一致しない: $hash" } + Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'x') + $setup = Join-Path $work 'x\Setup_com0com_v3.0.0.0_W7_x64_signed.exe' + $sig = Get-AuthenticodeSignature $setup + "$($sig.Status) $($sig.SignerCertificate.Subject)" + "SETUP_EXE=$setup" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV + + - name: Trust publisher + run: | + $cert = (Get-AuthenticodeSignature $env:SETUP_EXE).SignerCertificate + $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('TrustedPublisher', 'LocalMachine') + $store.Open('ReadWrite') + $store.Add($cert) + $store.Close() + "trusted: $($cert.Thumbprint)" + + - name: Install com0com (silent) + timeout-minutes: 3 + run: | + $p = Start-Process -FilePath $env:SETUP_EXE -ArgumentList '/S', "/D=$env:COM0COM_DIR" -Wait -PassThru + "setup exit: $($p.ExitCode)" + Get-ChildItem $env:COM0COM_DIR + + - name: Create port pair + timeout-minutes: 3 + working-directory: C:\com0com + run: | + .\setupc.exe --silent install PortName=COM10 PortName=COM11 + "setupc exit: $LASTEXITCODE" + .\setupc.exe list + + - name: Device status + if: always() + run: | + Get-PnpDevice -Class Ports, CNCPorts -ErrorAction SilentlyContinue | + Format-Table Status, Class, FriendlyName, InstanceId -AutoSize + Get-CimInstance Win32_PnPEntity | + Where-Object { $_.Name -match 'com0com' } | + Format-Table Name, ConfigManagerErrorCode, Status -AutoSize + [System.IO.Ports.SerialPort]::GetPortNames() + + - name: Loopback check + timeout-minutes: 2 + run: | + $a = [System.IO.Ports.SerialPort]::new('COM10', 115200) + $b = [System.IO.Ports.SerialPort]::new('COM11', 115200) + $a.ReadTimeout = 3000; $b.ReadTimeout = 3000 + $a.Open(); $b.Open() + $a.WriteLine('ping') + $got = $b.ReadLine() + $a.Close(); $b.Close() + "received: $got" + if ($got.Trim() -ne 'ping') { throw 'loopback failed' } From b0d554d1b13bcdbb95e3f92d0bd6b509cd177fcb Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:14:28 +0900 Subject: [PATCH 02/10] =?UTF-8?q?ci:=20Windows=20=E3=81=AE=E7=B5=90?= =?UTF-8?q?=E5=90=88=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=20com0com=20?= =?UTF-8?q?=E3=81=A8=20serdevmock=20=E3=81=A7=E6=B5=81=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../workflows/integration-windows-trial.yml | 92 ------------ .github/workflows/integration-windows.yml | 134 ++++++++++++++++++ tests/Integration/start-serdevmock.ps1 | 91 ++++++++++++ tests/Integration/stop-serdevmock.ps1 | 33 +++++ 4 files changed, 258 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/integration-windows-trial.yml create mode 100644 .github/workflows/integration-windows.yml create mode 100644 tests/Integration/start-serdevmock.ps1 create mode 100644 tests/Integration/stop-serdevmock.ps1 diff --git a/.github/workflows/integration-windows-trial.yml b/.github/workflows/integration-windows-trial.yml deleted file mode 100644 index 9a6278f..0000000 --- a/.github/workflows/integration-windows-trial.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Integration (Windows trial) - -# 試行用。ホストランナーへ com0com のドライバーを非対話で入れられるかを確かめる。 -# 確かめ終えたら削除する。 -on: - push: - branches: [ 'claude/ci-windows-integration-*' ] - -permissions: - contents: read - -jobs: - com0com: - runs-on: windows-latest - timeout-minutes: 10 - defaults: - run: - shell: pwsh - env: - COM0COM_ZIP_URL: https://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/com0com-3.0.0.0-i386-and-x64-signed.zip/download - COM0COM_ZIP_SHA256: 6e5d4359865277430d4ae88c73fb7e648a0ed8e81aea5002478179cfcb0bb0e1 - COM0COM_DIR: C:\com0com - - steps: - - name: Diagnostics - run: | - Get-CimInstance Win32_OperatingSystem | Format-List Caption, Version, BuildNumber - try { "SecureBoot: $(Confirm-SecureBootUEFI)" } catch { "SecureBoot: $($_.Exception.Message)" } - bcdedit /enum '{current}' | Select-String -Pattern 'testsigning|nointegritychecks|hypervisor' - whoami /groups | Select-String -Pattern 'Administrators|Mandatory Label' - [System.IO.Ports.SerialPort]::GetPortNames() - - - name: Download com0com - run: | - $work = Join-Path $env:RUNNER_TEMP 'com0com-dl' - New-Item -ItemType Directory -Force $work | Out-Null - $zip = Join-Path $work 'com0com.zip' - curl.exe -fsSL --retry 3 -o $zip $env:COM0COM_ZIP_URL - $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLowerInvariant() - if ($hash -ne $env:COM0COM_ZIP_SHA256) { throw "SHA256 が一致しない: $hash" } - Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'x') - $setup = Join-Path $work 'x\Setup_com0com_v3.0.0.0_W7_x64_signed.exe' - $sig = Get-AuthenticodeSignature $setup - "$($sig.Status) $($sig.SignerCertificate.Subject)" - "SETUP_EXE=$setup" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV - - - name: Trust publisher - run: | - $cert = (Get-AuthenticodeSignature $env:SETUP_EXE).SignerCertificate - $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('TrustedPublisher', 'LocalMachine') - $store.Open('ReadWrite') - $store.Add($cert) - $store.Close() - "trusted: $($cert.Thumbprint)" - - - name: Install com0com (silent) - timeout-minutes: 3 - run: | - $p = Start-Process -FilePath $env:SETUP_EXE -ArgumentList '/S', "/D=$env:COM0COM_DIR" -Wait -PassThru - "setup exit: $($p.ExitCode)" - Get-ChildItem $env:COM0COM_DIR - - - name: Create port pair - timeout-minutes: 3 - working-directory: C:\com0com - run: | - .\setupc.exe --silent install PortName=COM10 PortName=COM11 - "setupc exit: $LASTEXITCODE" - .\setupc.exe list - - - name: Device status - if: always() - run: | - Get-PnpDevice -Class Ports, CNCPorts -ErrorAction SilentlyContinue | - Format-Table Status, Class, FriendlyName, InstanceId -AutoSize - Get-CimInstance Win32_PnPEntity | - Where-Object { $_.Name -match 'com0com' } | - Format-Table Name, ConfigManagerErrorCode, Status -AutoSize - [System.IO.Ports.SerialPort]::GetPortNames() - - - name: Loopback check - timeout-minutes: 2 - run: | - $a = [System.IO.Ports.SerialPort]::new('COM10', 115200) - $b = [System.IO.Ports.SerialPort]::new('COM11', 115200) - $a.ReadTimeout = 3000; $b.ReadTimeout = 3000 - $a.Open(); $b.Open() - $a.WriteLine('ping') - $got = $b.ReadLine() - $a.Close(); $b.Close() - "received: $got" - if ($got.Trim() -ne 'ping') { throw 'loopback failed' } diff --git a/.github/workflows/integration-windows.yml b/.github/workflows/integration-windows.yml new file mode 100644 index 0000000..ed920f8 --- /dev/null +++ b/.github/workflows/integration-windows.yml @@ -0,0 +1,134 @@ +name: Integration (Windows) + +# com0com の仮想 COM ポート対と serdevmock を使い、FFI 実装の送受信を実機なしで確かめる。 +# ドライバーの導入に時間がかかるため、macOS 版と同じく実行の機会を絞る。 +on: + workflow_dispatch: + # TEMP: PR 作成前に削除する + push: + branches: [ 'claude/ci-windows-integration-*' ] + schedule: + # 毎週月曜 03:00(日本時間) + - cron: '0 18 * * 0' + pull_request: + branches: [ main ] + paths: + - '.github/workflows/integration-windows.yml' + - 'tests/Integration/**' + - 'tests/fixtures/serdevmock/**' + - 'tests/fixtures/windows/**' + - 'src/PhpSerial/Platform/Windows*.php' + +permissions: + contents: read + +jobs: + serdevmock: + name: serdevmock - windows-latest + runs-on: windows-latest + # 相手が読まないと write() が戻らない経路があるため、上限を設けて CI を止めない + timeout-minutes: 15 + defaults: + run: + shell: pwsh + env: + # SourceForge の com0com 3.0.0.0 署名版。ハッシュが合わなければ導入しない + COM0COM_ZIP_URL: https://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/com0com-3.0.0.0-i386-and-x64-signed.zip/download + COM0COM_ZIP_SHA256: 6e5d4359865277430d4ae88c73fb7e648a0ed8e81aea5002478179cfcb0bb0e1 + COM0COM_SETUP: Setup_com0com_v3.0.0.0_W7_x64_signed.exe + APP_PORT: COM10 + MOCK_PORT: COM11 + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Setup PHP + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: '8.5' + extensions: ffi + ini-values: ffi.enable=true + coverage: none + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Setup Python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.13' + + - name: Install serdevmock + run: python -m pip install --require-hashes -r tests/Integration/requirements.txt + + # ホストランナーは Secure Boot が無効のため、2016 年の証明書で署名されたドライバーも読み込める + - name: Install com0com + id: com0com + timeout-minutes: 3 + run: | + $work = Join-Path $env:RUNNER_TEMP 'com0com' + $installDir = Join-Path $work 'install' + $zip = Join-Path $work 'com0com.zip' + New-Item -ItemType Directory -Force $work | Out-Null + + curl.exe -fsSL --retry 3 -o $zip $env:COM0COM_ZIP_URL + $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLowerInvariant() + if ($hash -ne $env:COM0COM_ZIP_SHA256) { + throw "com0com の SHA256 が一致しない: $hash" + } + + Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'zip') + $setup = Join-Path $work "zip\$env:COM0COM_SETUP" + $p = Start-Process -FilePath $setup -ArgumentList '/S', "/D=$installDir" -Wait -PassThru + if ($p.ExitCode -ne 0) { + throw "com0com のインストーラーが失敗した: $($p.ExitCode)" + } + + Push-Location $installDir + try { + .\setupc.exe --silent install "PortName=$env:APP_PORT" "PortName=$env:MOCK_PORT" + if ($LASTEXITCODE -ne 0) { + throw "setupc が失敗した: $LASTEXITCODE" + } + .\setupc.exe list + } finally { + Pop-Location + } + + $ports = [System.IO.Ports.SerialPort]::GetPortNames() + foreach ($name in $env:APP_PORT, $env:MOCK_PORT) { + if ($ports -notcontains $name) { + throw "$name が見つからない: $($ports -join ', ')" + } + } + + - name: Start serdevmock + run: >- + ./tests/Integration/start-serdevmock.ps1 + -AppPort $env:APP_PORT -MockPort $env:MOCK_PORT + -WorkDir (Join-Path $env:RUNNER_TEMP 'serdevmock') + + # 環境変数が欠けて全件が飛ばされたまま緑になるのを防ぐため、skip と空を失敗として扱う + - name: Run integration tests + timeout-minutes: 3 + env: + SERDEVMOCK_PORT: ${{ env.APP_PORT }} + run: >- + php vendor/bin/phpunit --group integration --testdox + --fail-on-skipped --fail-on-empty-test-suite + + - name: Stop serdevmock + if: ${{ !cancelled() }} + run: ./tests/Integration/stop-serdevmock.ps1 -WorkDir (Join-Path $env:RUNNER_TEMP 'serdevmock') + + # serdevmock を止めた後の COM10 は、相手が読まないポートになる + - name: Run idle port tests + if: ${{ !cancelled() && steps.com0com.outcome == 'success' }} + timeout-minutes: 3 + env: + WINDOWS_IDLE_PORT: ${{ env.APP_PORT }} + run: >- + php vendor/bin/phpunit --group windows-idle-port --testdox + --fail-on-skipped --fail-on-empty-test-suite diff --git a/tests/Integration/start-serdevmock.ps1 b/tests/Integration/start-serdevmock.ps1 new file mode 100644 index 0000000..3292cc9 --- /dev/null +++ b/tests/Integration/start-serdevmock.ps1 @@ -0,0 +1,91 @@ +<# +com0com の対の片側で、エコーモードの serdevmock を動かす(Windows 用)。 + +使い方: pwsh tests/Integration/start-serdevmock.ps1 -AppPort COM10 -MockPort COM11 -WorkDir <作業ディレクトリ> + +-AppPort は php-serial 側、-MockPort は serdevmock 側のポートである。 +serdevmock が PATH に無いときは、-Serdevmock に実行ファイルのパスを渡す。 +停止は stop-serdevmock.ps1 に同じ -WorkDir を渡して行う。 +#> +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$AppPort, + [Parameter(Mandatory)][string]$MockPort, + [Parameter(Mandatory)][string]$WorkDir, + [string]$Serdevmock = 'serdevmock' +) + +$ErrorActionPreference = 'Stop' + +$fixtureDir = Join-Path $PSScriptRoot '..\fixtures\serdevmock' +$exe = (Get-Command $Serdevmock -CommandType Application | Select-Object -First 1).Source + +New-Item -ItemType Directory -Force $WorkDir | Out-Null +$WorkDir = (Resolve-Path $WorkDir).Path + +# 設定ファイルは作業ディレクトリからの相対名で渡し、パスの空白で引数が割れるのを避ける +$env:PYTHONUNBUFFERED = '1' +$proc = Start-Process -FilePath $exe -PassThru -NoNewWindow ` + -WorkingDirectory $fixtureDir ` + -ArgumentList '--protocol', 'uart', '--port', $MockPort, '--config', 'echo.json' ` + -RedirectStandardOutput (Join-Path $WorkDir 'serdevmock.log') ` + -RedirectStandardError (Join-Path $WorkDir 'serdevmock.err.log') +Set-Content -Path (Join-Path $WorkDir 'serdevmock.pid') -Value $proc.Id + +function Write-SerdevmockLog { + foreach ($name in 'serdevmock.log', 'serdevmock.err.log') { + $path = Join-Path $WorkDir $name + if (Test-Path $path) { + Write-Host "----- $name" + Get-Content $path | Write-Host + } + } +} + +# serdevmock はポートを開くときに受信バッファを捨てる。 +# 開き終える前に送ったデータは失われるため、エコーが返るまで確かめてから戻る。 +$port = [System.IO.Ports.SerialPort]::new($AppPort, 9600) +$port.NewLine = "`n" +$port.ReadTimeout = 1000 +$ready = $false + +$port.Open() +try { + for ($i = 1; $i -le 30 -and -not $ready; $i++) { + # 起動直後に落ちた場合は、待ち続けずに打ち切る + if ($proc.HasExited) { + break + } + + $probe = "probe-$i" + $port.WriteLine($probe) + $deadline = [DateTime]::UtcNow.AddSeconds(1) + + while (-not $ready -and [DateTime]::UtcNow -lt $deadline) { + try { + $ready = $port.ReadLine().TrimEnd("`r") -eq $probe + } catch [System.TimeoutException] { + break + } + } + } + + # 遅れて届いた古い応答を読み捨て、テストへ持ち越さない + try { + while ($true) { + [void]$port.ReadLine() + } + } catch [System.TimeoutException] { + } +} finally { + $port.Close() +} + +if (-not $ready) { + Write-Error 'serdevmock からエコーが返らなかった' -ErrorAction Continue + Write-SerdevmockLog + exit 1 +} + +Write-Host "php-serial 側: $AppPort / serdevmock 側: $MockPort" +Write-Host 'serdevmock の準備ができた' diff --git a/tests/Integration/stop-serdevmock.ps1 b/tests/Integration/stop-serdevmock.ps1 new file mode 100644 index 0000000..b7118bf --- /dev/null +++ b/tests/Integration/stop-serdevmock.ps1 @@ -0,0 +1,33 @@ +<# +start-serdevmock.ps1 で起動した serdevmock を止め、ログを出す(Windows 用)。 + +使い方: pwsh tests/Integration/stop-serdevmock.ps1 -WorkDir <作業ディレクトリ> +#> +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$WorkDir +) + +$pidFile = Join-Path $WorkDir 'serdevmock.pid' + +if (Test-Path $pidFile) { + $id = [int](Get-Content $pidFile -TotalCount 1) + $proc = Get-Process -Id $id -ErrorAction SilentlyContinue + + if ($null -ne $proc) { + # serdevmock.exe は python.exe を子として起動するため、子まで含めて止める + & taskkill.exe /PID $id /T /F | Out-Null + # ポートが閉じ切る前に次の試験が開くと、使用中で失敗するため終了を待つ + $null = $proc.WaitForExit(5000) + } + + Remove-Item $pidFile -Force +} + +foreach ($name in 'serdevmock.log', 'serdevmock.err.log') { + $path = Join-Path $WorkDir $name + if (Test-Path $path) { + Write-Host "----- $name" + Get-Content $path | Write-Host + } +} From 7bbcbd165c06f6d14dc5bacee938e0c11608cf5c Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:18:51 +0900 Subject: [PATCH 03/10] =?UTF-8?q?ci:=20com0com=20=E3=81=AE=E7=99=BA?= =?UTF-8?q?=E8=A1=8C=E5=85=83=E3=82=92=E4=BF=A1=E9=A0=BC=E6=B8=88=E3=81=BF?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=A6=E7=A2=BA=E8=AA=8D=E3=83=80=E3=82=A4?= =?UTF-8?q?=E3=82=A2=E3=83=AD=E3=82=B0=E3=82=92=E9=81=BF=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .github/workflows/integration-windows.yml | 12 ++++++ README.md | 1 + docs/INTEGRATION_TESTING.md | 52 ++++++++++++++++++++--- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/.github/workflows/integration-windows.yml b/.github/workflows/integration-windows.yml index ed920f8..03bf2fd 100644 --- a/.github/workflows/integration-windows.yml +++ b/.github/workflows/integration-windows.yml @@ -81,6 +81,18 @@ jobs: Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'zip') $setup = Join-Path $work "zip\$env:COM0COM_SETUP" + + # 発行元を信頼済みにしておかないと、ドライバー導入の確認ダイアログで止まる。 + # 使い捨てのランナーに限った操作であり、手元では行わない + $cert = (Get-AuthenticodeSignature $setup).SignerCertificate + $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('TrustedPublisher', 'LocalMachine') + $store.Open('ReadWrite') + try { + $store.Add($cert) + } finally { + $store.Close() + } + $p = Start-Process -FilePath $setup -ArgumentList '/S', "/D=$installDir" -Wait -PassThru if ($p.ExitCode -ne 0) { throw "com0com のインストーラーが失敗した: $($p.ExitCode)" diff --git a/README.md b/README.md index 006d50d..db02579 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ composer test 実機なしで送受信を確かめる結合テストもあります。 serdevmock と仮想ポートの対を使います。 +CI では、Linux を push と PR のたびに、macOS と Windows を週 1 回と関係する PR で実行します。 手順は [docs/INTEGRATION_TESTING.md](docs/INTEGRATION_TESTING.md) を参照してください。 ## 使用例 diff --git a/docs/INTEGRATION_TESTING.md b/docs/INTEGRATION_TESTING.md index 74a6c81..0cb457a 100644 --- a/docs/INTEGRATION_TESTING.md +++ b/docs/INTEGRATION_TESTING.md @@ -6,7 +6,8 @@ 実機を使わずに、ポートを開いて送受信するまでを確かめる手順をまとめます。 仮想ポートの対を作り、片側で serdevmock を動かします。 もう片側を php-serial で開き、送ったデータがそのまま返るかを確かめます。 -Linux は CI で毎回、macOS は CI で週 1 回、Windows は手元で確かめます。 +Linux は CI で毎回、macOS と Windows は CI で週 1 回確かめます。 +Windows は手元でも確かめられます。 ## 📑 目次 @@ -41,7 +42,7 @@ serdevmock には `tests/fixtures/serdevmock/echo.json` を読ませます。 |---|---|---| | Linux | socat | CI(push と PR ごと) | | macOS | socat | CI(手動、週 1 回、関係する PR) | -| Windows | com0com | 手元 | +| Windows | com0com | CI(手動、週 1 回、関係する PR)と手元 | ## 🐧 Linux と macOS @@ -100,6 +101,17 @@ vendor\bin\phpunit --group integration --testdox `.env` に `SERDEVMOCK_PORT=COM10` と書いても指定できます。 +serdevmock を別のターミナルで動かす代わりに、起動スクリプトも使えます。 +CI と同じく、エコーが返るのを確かめてから戻ります。 + +```powershell +pwsh tests\Integration\start-serdevmock.ps1 -AppPort COM10 -MockPort COM11 -WorkDir $env:TEMP\serdevmock -Serdevmock .\.venv-serdevmock\Scripts\serdevmock.exe +``` + +```powershell +pwsh tests\Integration\stop-serdevmock.ps1 -WorkDir $env:TEMP\serdevmock +``` + ### 相手が読まないポートでの試験 serdevmock を止めると、COM10 は「相手が読まないポート」になります。 @@ -116,23 +128,49 @@ serdevmock の試験と同時には指定しないでください。 ## ⚙ CI での扱い -Linux は `.github/workflows/integration.yml` で、push と PR のたびに実行します。 -macOS は `.github/workflows/integration-macos.yml` で実行します。 +表 2. OS ごとのワークフローと実行の機会 + +| OS | ワークフロー | 実行の機会 | +|---|---|---| +| Linux | `integration.yml` | push と PR のたび | +| macOS | `integration-macos.yml` | 手動、週 1 回、関係する PR | +| Windows | `integration-windows.yml` | 手動、週 1 回、関係する PR | + +ワークフローは `.github/workflows/` にあります。 macOS ランナーは空き待ちが 10 分前後になることがあるため、実行の機会を絞っています。 +Windows もドライバーの導入を伴うため、macOS に合わせています。 +どちらも次の機会に実行します。 - 手動実行(`workflow_dispatch`) - 毎週月曜 03:00(日本時間) -- 結合テストの仕組みか `Unix.php` を変えた PR +- 結合テストの仕組みか、その OS のプラットフォーム実装を変えた PR -どちらも `--fail-on-skipped` と `--fail-on-empty-test-suite` を付けて実行します。 +関係する PR の判定には、macOS は `Unix.php`、Windows は `Windows.php` と `WindowsFFI.php` を使います。 + +いずれも `--fail-on-skipped` と `--fail-on-empty-test-suite` を付けて実行します。 環境変数の設定漏れで全件が skip されたまま、緑になるのを防ぐためです。 +### 🪟 Windows ランナーでの com0com + +Windows のジョブは、com0com 3.0.0.0 の署名版を SourceForge から取得します。 +SHA256 を照合してから、インストーラーを `/S` で非対話のまま実行します。 +続けて `setupc.exe` で COM10 と COM11 の対を作ります。 + +このドライバーは 2016 年の証明書で署名されています。 +Secure Boot が有効な Windows 10 以降では、読み込みを拒まれることがあります。 +GitHub のホストランナーは Secure Boot が無効のため、そのまま読み込めます。 +ランナーの構成が変わって導入に失敗したときは、この点を最初に疑ってください。 + +ジョブは 2 段で試験します。 +まず serdevmock を COM11 で動かし、COM10 で `integration` グループを流します。 +次に serdevmock を止め、COM10 で `windows-idle-port` グループを流します。 + ## 🔍 この試験で見つけた問題 Windows の FFI 実装で、次の問題を見つけて直しました。 同じ問題が戻ってきたときは、ここに挙げたテストが失敗します。 -表 2. 見つけた問題と、それを確かめるテスト +表 3. 見つけた問題と、それを確かめるテスト | 問題 | 確かめるテスト | |---|---| From 94a96d9cd41e3e2a416927799278d86c85e1e8b2 Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:20:47 +0900 Subject: [PATCH 04/10] =?UTF-8?q?ci:=20serdevmock=20=E3=81=AE=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=82=92=20UTF-8=20=E3=81=AB=E3=81=97=E3=80=81FFI=20?= =?UTF-8?q?=E3=81=AE=E6=9C=89=E5=8A=B9=E5=8C=96=E3=82=92=E7=A2=BA=E3=81=8B?= =?UTF-8?q?=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .github/workflows/integration-windows.yml | 12 ++++++++++++ tests/Integration/start-serdevmock.ps1 | 2 ++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/integration-windows.yml b/.github/workflows/integration-windows.yml index 03bf2fd..4023159 100644 --- a/.github/workflows/integration-windows.yml +++ b/.github/workflows/integration-windows.yml @@ -52,6 +52,18 @@ jobs: ini-values: ffi.enable=true coverage: none + # FFI が無効だと SerialPort は fopen 版へ切り替わり、FFI 実装を試験しないまま通ってしまう + - name: Check FFI + run: | + $info = php --ri ffi + if ($LASTEXITCODE -ne 0) { + throw 'FFI 拡張が読み込まれていない' + } + $info + if (-not ($info -match '^ffi\.enable => (true|on|1)\b')) { + throw 'ffi.enable が有効になっていない' + } + - name: Install dependencies run: composer install --prefer-dist --no-progress diff --git a/tests/Integration/start-serdevmock.ps1 b/tests/Integration/start-serdevmock.ps1 index 3292cc9..4e6ec3c 100644 --- a/tests/Integration/start-serdevmock.ps1 +++ b/tests/Integration/start-serdevmock.ps1 @@ -25,6 +25,8 @@ $WorkDir = (Resolve-Path $WorkDir).Path # 設定ファイルは作業ディレクトリからの相対名で渡し、パスの空白で引数が割れるのを避ける $env:PYTHONUNBUFFERED = '1' +# 出力先がファイルだと既定の文字コードになり、serdevmock の日本語のメッセージで落ちる +$env:PYTHONIOENCODING = 'utf-8' $proc = Start-Process -FilePath $exe -PassThru -NoNewWindow ` -WorkingDirectory $fixtureDir ` -ArgumentList '--protocol', 'uart', '--port', $MockPort, '--config', 'echo.json' ` From a691164d74d0fc58841d24adf97abdf93e848f00 Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:24:07 +0900 Subject: [PATCH 05/10] =?UTF-8?q?ci:=20TEMP=20=E8=AA=AD=E3=81=BF=E5=8F=96?= =?UTF-8?q?=E3=82=8A=E3=81=8C=E7=A9=BA=E3=81=AB=E3=81=AA=E3=82=8B=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E3=82=92=E8=AA=BF=E3=81=B9=E3=82=8B=E8=A8=BA=E6=96=AD?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../workflows/integration-windows-diag.yml | 140 ++++++++++++++++++ tests/Integration/diag-dcb.php | 62 ++++++++ 2 files changed, 202 insertions(+) create mode 100644 .github/workflows/integration-windows-diag.yml create mode 100644 tests/Integration/diag-dcb.php diff --git a/.github/workflows/integration-windows-diag.yml b/.github/workflows/integration-windows-diag.yml new file mode 100644 index 0000000..ac42130 --- /dev/null +++ b/.github/workflows/integration-windows-diag.yml @@ -0,0 +1,140 @@ +name: Integration (Windows diag) + +# TEMP: 原因調査用。PR 作成前に削除する。 +on: + push: + branches: [ 'claude/ci-windows-integration-*' ] + +permissions: + contents: read + +jobs: + diag: + runs-on: windows-latest + timeout-minutes: 15 + defaults: + run: + shell: pwsh + env: + COM0COM_ZIP_URL: https://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/com0com-3.0.0.0-i386-and-x64-signed.zip/download + COM0COM_ZIP_SHA256: 6e5d4359865277430d4ae88c73fb7e648a0ed8e81aea5002478179cfcb0bb0e1 + COM0COM_SETUP: Setup_com0com_v3.0.0.0_W7_x64_signed.exe + APP_PORT: COM10 + MOCK_PORT: COM11 + SERDEVMOCK_PORT: COM10 + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: '8.5' + extensions: ffi + ini-values: ffi.enable=true + coverage: none + + - run: composer install --prefer-dist --no-progress + + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.13' + + - run: python -m pip install --require-hashes -r tests/Integration/requirements.txt + + - name: Install com0com + id: com0com + timeout-minutes: 3 + run: | + $work = Join-Path $env:RUNNER_TEMP 'com0com' + $installDir = Join-Path $work 'install' + $zip = Join-Path $work 'com0com.zip' + New-Item -ItemType Directory -Force $work | Out-Null + + curl.exe -fsSL --retry 3 -o $zip $env:COM0COM_ZIP_URL + $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLowerInvariant() + if ($hash -ne $env:COM0COM_ZIP_SHA256) { + throw "com0com の SHA256 が一致しない: $hash" + } + + Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'zip') + $setup = Join-Path $work "zip\$env:COM0COM_SETUP" + + # 発行元を信頼済みにしておかないと、ドライバー導入の確認ダイアログで止まる。 + # 使い捨てのランナーに限った操作であり、手元では行わない + $cert = (Get-AuthenticodeSignature $setup).SignerCertificate + $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('TrustedPublisher', 'LocalMachine') + $store.Open('ReadWrite') + try { + $store.Add($cert) + } finally { + $store.Close() + } + + $p = Start-Process -FilePath $setup -ArgumentList '/S', "/D=$installDir" -Wait -PassThru + if ($p.ExitCode -ne 0) { + throw "com0com のインストーラーが失敗した: $($p.ExitCode)" + } + + Push-Location $installDir + try { + .\setupc.exe --silent install "PortName=$env:APP_PORT" "PortName=$env:MOCK_PORT" + if ($LASTEXITCODE -ne 0) { + throw "setupc が失敗した: $LASTEXITCODE" + } + .\setupc.exe list + } finally { + Pop-Location + } + + $ports = [System.IO.Ports.SerialPort]::GetPortNames() + foreach ($name in $env:APP_PORT, $env:MOCK_PORT) { + if ($ports -notcontains $name) { + throw "$name が見つからない: $($ports -join ', ')" + } + } + + + - name: A DCB before serdevmock + run: php tests/Integration/diag-dcb.php COM10 + + - name: Start serdevmock without probe + run: | + $env:PYTHONIOENCODING = 'utf-8' + $env:PYTHONUNBUFFERED = '1' + $exe = (Get-Command serdevmock -CommandType Application).Source + $d = Join-Path $env:RUNNER_TEMP 'sdm' + New-Item -ItemType Directory -Force $d | Out-Null + $p = Start-Process -FilePath $exe -PassThru -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` + -ArgumentList '--protocol', 'uart', '--port', 'COM11', '--config', 'echo.json' ` + -RedirectStandardOutput (Join-Path $d 'out.log') -RedirectStandardError (Join-Path $d 'err.log') + Start-Sleep -Seconds 6 + "alive: $(-not $p.HasExited)" + + - name: B DCB with serdevmock, no probe + run: php tests/Integration/diag-dcb.php COM10 + + - name: C phpunit, no probe + continue-on-error: true + run: php vendor/bin/phpunit --group integration --testdox + + - name: D .NET probe + run: | + $a = [System.IO.Ports.SerialPort]::new('COM10', 9600) + $a.NewLine = "`n"; $a.ReadTimeout = 2000 + $a.Open() + $a.WriteLine('probe') + try { "got: $($a.ReadLine())" } catch { "read failed: $_" } + $a.Close() + + - name: E DCB after .NET probe + run: php tests/Integration/diag-dcb.php COM10 + + - name: F phpunit after .NET probe + continue-on-error: true + run: php vendor/bin/phpunit --group integration --testdox + + - name: Logs + if: always() + run: Get-Content (Join-Path $env:RUNNER_TEMP 'sdm\*.log') diff --git a/tests/Integration/diag-dcb.php b/tests/Integration/diag-dcb.php new file mode 100644 index 0000000..2ad451c --- /dev/null +++ b/tests/Integration/diag-dcb.php @@ -0,0 +1,62 @@ +CreateFileA("\\\\.\\{$device}", 0xC0000000, 0, null, 3, 0x80, null); +$dcb = $ffi->new('DCB'); +$dcb->DCBlength = FFI::sizeof($dcb); +$ffi->GetCommState($h, FFI::addr($dcb)); + +foreach (['BaudRate', 'fBinary', 'fParity', 'fOutxCtsFlow', 'fOutxDsrFlow', 'fDtrControl', 'fDsrSensitivity', + 'fTXContinueOnXoff', 'fOutX', 'fInX', 'fErrorChar', 'fNull', 'fRtsControl', 'fAbortOnError', + 'XonLim', 'XoffLim', 'ByteSize', 'Parity', 'StopBits'] as $f) { + echo "{$f}={$dcb->$f} "; +} +echo "\n"; + +$ms = $ffi->new('DWORD'); +$ffi->GetCommModemStatus($h, FFI::addr($ms)); +printf("modem=0x%02x (CTS=%d DSR=%d RING=%d RLSD=%d)\n", $ms->cdata, ($ms->cdata >> 4) & 1, ($ms->cdata >> 5) & 1, ($ms->cdata >> 6) & 1, ($ms->cdata >> 7) & 1); + +$data = "diag\n"; +$n = $ffi->new('DWORD'); +$ok = $ffi->WriteFile($h, $data, strlen($data), FFI::addr($n), null); +echo "write ok={$ok} n={$n->cdata}\n"; +usleep(800000); + +$err = $ffi->new('DWORD'); +$st = $ffi->new('COMSTAT'); +$ffi->ClearCommError($h, FFI::addr($err), FFI::addr($st)); +echo "errors={$err->cdata} inQue={$st->cbInQue} outQue={$st->cbOutQue} fFlags={$st->fFlags}\n"; +$ffi->CloseHandle($h); From 8fa2de6fc39f522b6c81292d60fd1b84984f5825 Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:42:10 +0900 Subject: [PATCH 06/10] =?UTF-8?q?ci:=20TEMP=20Ports=20=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E5=AF=BE=E3=81=A8=20mode=20=E3=81=AB?= =?UTF-8?q?=E3=82=88=E3=82=8B=E5=9B=9E=E9=81=BF=E3=82=92=E6=AF=94=E3=81=B9?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../workflows/integration-windows-diag.yml | 78 +++++++++++++------ 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/.github/workflows/integration-windows-diag.yml b/.github/workflows/integration-windows-diag.yml index ac42130..0901489 100644 --- a/.github/workflows/integration-windows-diag.yml +++ b/.github/workflows/integration-windows-diag.yml @@ -19,9 +19,8 @@ jobs: COM0COM_ZIP_URL: https://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/com0com-3.0.0.0-i386-and-x64-signed.zip/download COM0COM_ZIP_SHA256: 6e5d4359865277430d4ae88c73fb7e648a0ed8e81aea5002478179cfcb0bb0e1 COM0COM_SETUP: Setup_com0com_v3.0.0.0_W7_x64_signed.exe - APP_PORT: COM10 - MOCK_PORT: COM11 - SERDEVMOCK_PORT: COM10 + APP_PORT: COM20 + MOCK_PORT: COM21 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -96,45 +95,78 @@ jobs: } - - name: A DCB before serdevmock + - name: Create Ports class pair COM10-COM11 + timeout-minutes: 3 + working-directory: D:\a\_temp\com0com\install + run: | + .\setupc.exe --silent install PortName=COM# PortName=COM# + .\setupc.exe list + .\setupc.exe --silent change CNCA1 RealPortName=COM10 + .\setupc.exe --silent change CNCB1 RealPortName=COM11 + .\setupc.exe list + [System.IO.Ports.SerialPort]::GetPortNames() + Get-PnpDevice -Class Ports, CNCPorts | Format-Table Status, Class, FriendlyName -AutoSize + + - name: V1 DCB before serdevmock (Ports class) + timeout-minutes: 1 run: php tests/Integration/diag-dcb.php COM10 - - name: Start serdevmock without probe + - name: V1 start serdevmock on COM11 run: | $env:PYTHONIOENCODING = 'utf-8' $env:PYTHONUNBUFFERED = '1' $exe = (Get-Command serdevmock -CommandType Application).Source - $d = Join-Path $env:RUNNER_TEMP 'sdm' + $d = Join-Path $env:RUNNER_TEMP 'sdm1' New-Item -ItemType Directory -Force $d | Out-Null - $p = Start-Process -FilePath $exe -PassThru -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` + Start-Process -FilePath $exe -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` -ArgumentList '--protocol', 'uart', '--port', 'COM11', '--config', 'echo.json' ` -RedirectStandardOutput (Join-Path $d 'out.log') -RedirectStandardError (Join-Path $d 'err.log') - Start-Sleep -Seconds 6 - "alive: $(-not $p.HasExited)" + Start-Sleep -Seconds 5 - - name: B DCB with serdevmock, no probe + - name: V1 DCB with serdevmock (Ports class) + timeout-minutes: 1 run: php tests/Integration/diag-dcb.php COM10 - - name: C phpunit, no probe + - name: V1 phpunit (Ports class) continue-on-error: true + timeout-minutes: 3 + env: + SERDEVMOCK_PORT: COM10 run: php vendor/bin/phpunit --group integration --testdox - - name: D .NET probe + - name: V2 start serdevmock on COM21 run: | - $a = [System.IO.Ports.SerialPort]::new('COM10', 9600) - $a.NewLine = "`n"; $a.ReadTimeout = 2000 - $a.Open() - $a.WriteLine('probe') - try { "got: $($a.ReadLine())" } catch { "read failed: $_" } - $a.Close() - - - name: E DCB after .NET probe - run: php tests/Integration/diag-dcb.php COM10 + $env:PYTHONIOENCODING = 'utf-8' + $env:PYTHONUNBUFFERED = '1' + $exe = (Get-Command serdevmock -CommandType Application).Source + $d = Join-Path $env:RUNNER_TEMP 'sdm2' + New-Item -ItemType Directory -Force $d | Out-Null + Start-Process -FilePath $exe -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` + -ArgumentList '--protocol', 'uart', '--port', 'COM21', '--config', 'echo.json' ` + -RedirectStandardOutput (Join-Path $d 'out.log') -RedirectStandardError (Join-Path $d 'err.log') + Start-Sleep -Seconds 5 + + - name: V2 DCB with serdevmock (CNCPorts) + timeout-minutes: 1 + run: php tests/Integration/diag-dcb.php COM20 + + - name: V2 mode to disable flow control + timeout-minutes: 1 + run: | + mode COM20: BAUD=9600 PARITY=n DATA=8 STOP=1 octs=off odsr=off dtr=on rts=on idsr=off + php tests/Integration/diag-dcb.php COM20 - - name: F phpunit after .NET probe + - name: V2 phpunit (CNCPorts + mode) continue-on-error: true + timeout-minutes: 3 + env: + SERDEVMOCK_PORT: COM20 run: php vendor/bin/phpunit --group integration --testdox - name: Logs if: always() - run: Get-Content (Join-Path $env:RUNNER_TEMP 'sdm\*.log') + run: | + Get-ChildItem (Join-Path $env:RUNNER_TEMP 'sdm*') -Recurse -File | ForEach-Object { + "----- $($_.FullName)" + Get-Content $_.FullName -Encoding utf8 + } From 49ee0a4ee22a67687cfb76fd8f7bef8346d7e3cc Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:46:13 +0900 Subject: [PATCH 07/10] =?UTF-8?q?ci:=20TEMP=20=E3=83=95=E3=83=A9=E3=82=B0?= =?UTF-8?q?=E8=AA=9E=E3=82=92=E7=94=9F=E3=81=A7=E8=AA=AD=E3=81=BF=E3=80=81?= =?UTF-8?q?=E3=83=A2=E3=83=87=E3=83=A0=E7=B7=9A=E3=81=A8=E5=8F=97=E4=BF=A1?= =?UTF-8?q?=E3=81=AE=E6=B5=81=E3=82=8C=E3=82=92=E8=BF=BD=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../workflows/integration-windows-diag.yml | 82 ++++++++----------- tests/Integration/diag-dcb.php | 73 +++++++++-------- 2 files changed, 72 insertions(+), 83 deletions(-) diff --git a/.github/workflows/integration-windows-diag.yml b/.github/workflows/integration-windows-diag.yml index 0901489..f6bf5c6 100644 --- a/.github/workflows/integration-windows-diag.yml +++ b/.github/workflows/integration-windows-diag.yml @@ -95,78 +95,64 @@ jobs: } - - name: Create Ports class pair COM10-COM11 - timeout-minutes: 3 - working-directory: D:\a\_temp\com0com\install - run: | - .\setupc.exe --silent install PortName=COM# PortName=COM# - .\setupc.exe list - .\setupc.exe --silent change CNCA1 RealPortName=COM10 - .\setupc.exe --silent change CNCB1 RealPortName=COM11 - .\setupc.exe list - [System.IO.Ports.SerialPort]::GetPortNames() - Get-PnpDevice -Class Ports, CNCPorts | Format-Table Status, Class, FriendlyName -AutoSize - - - name: V1 DCB before serdevmock (Ports class) + - name: 1 fresh COM21 and COM20 timeout-minutes: 1 - run: php tests/Integration/diag-dcb.php COM10 - - - name: V1 start serdevmock on COM11 run: | - $env:PYTHONIOENCODING = 'utf-8' - $env:PYTHONUNBUFFERED = '1' - $exe = (Get-Command serdevmock -CommandType Application).Source - $d = Join-Path $env:RUNNER_TEMP 'sdm1' - New-Item -ItemType Directory -Force $d | Out-Null - Start-Process -FilePath $exe -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` - -ArgumentList '--protocol', 'uart', '--port', 'COM11', '--config', 'echo.json' ` - -RedirectStandardOutput (Join-Path $d 'out.log') -RedirectStandardError (Join-Path $d 'err.log') - Start-Sleep -Seconds 5 - - - name: V1 DCB with serdevmock (Ports class) - timeout-minutes: 1 - run: php tests/Integration/diag-dcb.php COM10 - - - name: V1 phpunit (Ports class) - continue-on-error: true - timeout-minutes: 3 - env: - SERDEVMOCK_PORT: COM10 - run: php vendor/bin/phpunit --group integration --testdox + php tests/Integration/diag-dcb.php COM21 + php tests/Integration/diag-dcb.php COM20 - - name: V2 start serdevmock on COM21 + - name: 2 start serdevmock on COM21 run: | $env:PYTHONIOENCODING = 'utf-8' $env:PYTHONUNBUFFERED = '1' $exe = (Get-Command serdevmock -CommandType Application).Source - $d = Join-Path $env:RUNNER_TEMP 'sdm2' + $d = Join-Path $env:RUNNER_TEMP 'sdm' New-Item -ItemType Directory -Force $d | Out-Null - Start-Process -FilePath $exe -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` + $p = Start-Process -FilePath $exe -PassThru -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` -ArgumentList '--protocol', 'uart', '--port', 'COM21', '--config', 'echo.json' ` -RedirectStandardOutput (Join-Path $d 'out.log') -RedirectStandardError (Join-Path $d 'err.log') + Set-Content (Join-Path $d 'pid') $p.Id Start-Sleep -Seconds 5 + "alive: $(-not $p.HasExited)" + Get-CimInstance Win32_Process | Where-Object { $_.Name -match 'python|serdevmock' } | Format-Table ProcessId, ParentProcessId, Name -AutoSize - - name: V2 DCB with serdevmock (CNCPorts) + - name: 3 COM20 write with serdevmock (PHP raw) timeout-minutes: 1 - run: php tests/Integration/diag-dcb.php COM20 + run: php tests/Integration/diag-dcb.php COM20 write - - name: V2 mode to disable flow control + - name: 4 .NET probe on COM20 timeout-minutes: 1 run: | - mode COM20: BAUD=9600 PARITY=n DATA=8 STOP=1 octs=off odsr=off dtr=on rts=on idsr=off - php tests/Integration/diag-dcb.php COM20 + $a = [System.IO.Ports.SerialPort]::new('COM20', 9600) + $a.NewLine = "`n"; $a.ReadTimeout = 2000; $a.WriteTimeout = 2000 + $a.Open() + "dtr=$($a.DtrEnable) rts=$($a.RtsEnable) cts=$($a.CtsHolding) dsr=$($a.DsrHolding) cd=$($a.CDHolding)" + try { $a.WriteLine('probe'); "written" } catch { "write failed: $_" } + try { "got: $($a.ReadLine())" } catch { "read failed: $_" } + $a.Close() + + - name: 5 COM20 after .NET (PHP raw) + timeout-minutes: 1 + run: php tests/Integration/diag-dcb.php COM20 write - - name: V2 phpunit (CNCPorts + mode) + - name: 6 phpunit continue-on-error: true timeout-minutes: 3 env: SERDEVMOCK_PORT: COM20 run: php vendor/bin/phpunit --group integration --testdox + - name: 7 COM20 after phpunit (PHP raw) + timeout-minutes: 1 + run: php tests/Integration/diag-dcb.php COM20 write + - name: Logs if: always() run: | - Get-ChildItem (Join-Path $env:RUNNER_TEMP 'sdm*') -Recurse -File | ForEach-Object { - "----- $($_.FullName)" - Get-Content $_.FullName -Encoding utf8 + $d = Join-Path $env:RUNNER_TEMP 'sdm' + $id = [int](Get-Content (Join-Path $d 'pid')) + "serdevmock alive: $($null -ne (Get-Process -Id $id -ErrorAction SilentlyContinue))" + foreach ($n in 'out.log', 'err.log') { + "----- $n" + Get-Content (Join-Path $d $n) -Encoding utf8 } diff --git a/tests/Integration/diag-dcb.php b/tests/Integration/diag-dcb.php index 2ad451c..d775d67 100644 --- a/tests/Integration/diag-dcb.php +++ b/tests/Integration/diag-dcb.php @@ -1,62 +1,65 @@ CreateFileA("\\\\.\\{$device}", 0xC0000000, 0, null, 3, 0x80, null); -$dcb = $ffi->new('DCB'); -$dcb->DCBlength = FFI::sizeof($dcb); -$ffi->GetCommState($h, FFI::addr($dcb)); - -foreach (['BaudRate', 'fBinary', 'fParity', 'fOutxCtsFlow', 'fOutxDsrFlow', 'fDtrControl', 'fDsrSensitivity', - 'fTXContinueOnXoff', 'fOutX', 'fInX', 'fErrorChar', 'fNull', 'fRtsControl', 'fAbortOnError', - 'XonLim', 'XoffLim', 'ByteSize', 'Parity', 'StopBits'] as $f) { - echo "{$f}={$dcb->$f} "; +if ($h == $ffi->cast('HANDLE', -1)) { + echo "open failed: error=" . $ffi->GetLastError() . "\n"; + exit(0); } -echo "\n"; + +$dcb = $ffi->new('DCB'); +FFI::memcpy($dcb, pack('V', 28), 4); +$ok = $ffi->GetCommState($h, FFI::addr($dcb)); +$v = unpack('Vlen/Vbaud/Vflags/vres/vxon/vxoff/CbyteSize/Cparity/CstopBits', FFI::string(FFI::addr($dcb), 21)); +$f = $v['flags']; +printf( + "get=%d baud=%d %d%s%d flags=0x%04x fBinary=%d fParity=%d CtsFlow=%d DsrFlow=%d DtrCtl=%d DsrSens=%d TXCont=%d OutX=%d InX=%d Null=%d RtsCtl=%d Abort=%d\n", + $ok, $v['baud'], $v['byteSize'], ['N', 'O', 'E', 'M', 'S'][$v['parity']] ?? '?', $v['stopBits'], $f, + $f & 1, ($f >> 1) & 1, ($f >> 2) & 1, ($f >> 3) & 1, ($f >> 4) & 3, ($f >> 6) & 1, ($f >> 7) & 1, + ($f >> 8) & 1, ($f >> 9) & 1, ($f >> 11) & 1, ($f >> 12) & 3, ($f >> 14) & 1 +); $ms = $ffi->new('DWORD'); $ffi->GetCommModemStatus($h, FFI::addr($ms)); -printf("modem=0x%02x (CTS=%d DSR=%d RING=%d RLSD=%d)\n", $ms->cdata, ($ms->cdata >> 4) & 1, ($ms->cdata >> 5) & 1, ($ms->cdata >> 6) & 1, ($ms->cdata >> 7) & 1); - -$data = "diag\n"; -$n = $ffi->new('DWORD'); -$ok = $ffi->WriteFile($h, $data, strlen($data), FFI::addr($n), null); -echo "write ok={$ok} n={$n->cdata}\n"; -usleep(800000); - -$err = $ffi->new('DWORD'); -$st = $ffi->new('COMSTAT'); -$ffi->ClearCommError($h, FFI::addr($err), FFI::addr($st)); -echo "errors={$err->cdata} inQue={$st->cbInQue} outQue={$st->cbOutQue} fFlags={$st->fFlags}\n"; +printf("modem CTS=%d DSR=%d RING=%d RLSD=%d\n", ($ms->cdata >> 4) & 1, ($ms->cdata >> 5) & 1, ($ms->cdata >> 6) & 1, ($ms->cdata >> 7) & 1); + +if ($doWrite) { + $t = $ffi->new('COMMTIMEOUTS'); + $t->a = 1; $t->b = 0; $t->c = 1; $t->d = 0; $t->e = 1000; + $ffi->SetCommTimeouts($h, FFI::addr($t)); + $data = "diag\n"; + $n = $ffi->new('DWORD'); + $wok = $ffi->WriteFile($h, $data, strlen($data), FFI::addr($n), null); + echo "write ok={$wok} n={$n->cdata}\n"; + usleep(800000); + $err = $ffi->new('DWORD'); + $st = $ffi->new('COMSTAT'); + $ffi->ClearCommError($h, FFI::addr($err), FFI::addr($st)); + echo "errors={$err->cdata} inQue={$st->cbInQue} outQue={$st->cbOutQue} holdFlags=0x" . dechex($st->fFlags) . "\n"; +} + $ffi->CloseHandle($h); From 064a615230b0837939331b48f071cd9da655481f Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:48:34 +0900 Subject: [PATCH 08/10] =?UTF-8?q?test:=20serdevmock=20=E3=82=92=E5=88=A5?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=BD=E3=83=BC=E3=83=AB=E3=81=A7=E5=8B=95?= =?UTF-8?q?=E3=81=8B=E3=81=97=E3=80=81=E3=82=B9=E3=83=86=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=81=AE=E7=B5=82=E3=82=8F=E3=82=8A=E3=81=A7=E6=AD=A2=E3=81=BE?= =?UTF-8?q?=E3=82=89=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 診断用のワークフローとスクリプトは役目を終えたため消す。 Co-Authored-By: Claude Opus 5.5 --- .../workflows/integration-windows-diag.yml | 158 ------------------ tests/Integration/diag-dcb.php | 65 ------- tests/Integration/start-serdevmock.ps1 | 6 +- tests/Integration/stop-serdevmock.ps1 | 5 +- 4 files changed, 8 insertions(+), 226 deletions(-) delete mode 100644 .github/workflows/integration-windows-diag.yml delete mode 100644 tests/Integration/diag-dcb.php diff --git a/.github/workflows/integration-windows-diag.yml b/.github/workflows/integration-windows-diag.yml deleted file mode 100644 index f6bf5c6..0000000 --- a/.github/workflows/integration-windows-diag.yml +++ /dev/null @@ -1,158 +0,0 @@ -name: Integration (Windows diag) - -# TEMP: 原因調査用。PR 作成前に削除する。 -on: - push: - branches: [ 'claude/ci-windows-integration-*' ] - -permissions: - contents: read - -jobs: - diag: - runs-on: windows-latest - timeout-minutes: 15 - defaults: - run: - shell: pwsh - env: - COM0COM_ZIP_URL: https://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/com0com-3.0.0.0-i386-and-x64-signed.zip/download - COM0COM_ZIP_SHA256: 6e5d4359865277430d4ae88c73fb7e648a0ed8e81aea5002478179cfcb0bb0e1 - COM0COM_SETUP: Setup_com0com_v3.0.0.0_W7_x64_signed.exe - APP_PORT: COM20 - MOCK_PORT: COM21 - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - - uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 - with: - php-version: '8.5' - extensions: ffi - ini-values: ffi.enable=true - coverage: none - - - run: composer install --prefer-dist --no-progress - - - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 - with: - python-version: '3.13' - - - run: python -m pip install --require-hashes -r tests/Integration/requirements.txt - - - name: Install com0com - id: com0com - timeout-minutes: 3 - run: | - $work = Join-Path $env:RUNNER_TEMP 'com0com' - $installDir = Join-Path $work 'install' - $zip = Join-Path $work 'com0com.zip' - New-Item -ItemType Directory -Force $work | Out-Null - - curl.exe -fsSL --retry 3 -o $zip $env:COM0COM_ZIP_URL - $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLowerInvariant() - if ($hash -ne $env:COM0COM_ZIP_SHA256) { - throw "com0com の SHA256 が一致しない: $hash" - } - - Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'zip') - $setup = Join-Path $work "zip\$env:COM0COM_SETUP" - - # 発行元を信頼済みにしておかないと、ドライバー導入の確認ダイアログで止まる。 - # 使い捨てのランナーに限った操作であり、手元では行わない - $cert = (Get-AuthenticodeSignature $setup).SignerCertificate - $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('TrustedPublisher', 'LocalMachine') - $store.Open('ReadWrite') - try { - $store.Add($cert) - } finally { - $store.Close() - } - - $p = Start-Process -FilePath $setup -ArgumentList '/S', "/D=$installDir" -Wait -PassThru - if ($p.ExitCode -ne 0) { - throw "com0com のインストーラーが失敗した: $($p.ExitCode)" - } - - Push-Location $installDir - try { - .\setupc.exe --silent install "PortName=$env:APP_PORT" "PortName=$env:MOCK_PORT" - if ($LASTEXITCODE -ne 0) { - throw "setupc が失敗した: $LASTEXITCODE" - } - .\setupc.exe list - } finally { - Pop-Location - } - - $ports = [System.IO.Ports.SerialPort]::GetPortNames() - foreach ($name in $env:APP_PORT, $env:MOCK_PORT) { - if ($ports -notcontains $name) { - throw "$name が見つからない: $($ports -join ', ')" - } - } - - - - name: 1 fresh COM21 and COM20 - timeout-minutes: 1 - run: | - php tests/Integration/diag-dcb.php COM21 - php tests/Integration/diag-dcb.php COM20 - - - name: 2 start serdevmock on COM21 - run: | - $env:PYTHONIOENCODING = 'utf-8' - $env:PYTHONUNBUFFERED = '1' - $exe = (Get-Command serdevmock -CommandType Application).Source - $d = Join-Path $env:RUNNER_TEMP 'sdm' - New-Item -ItemType Directory -Force $d | Out-Null - $p = Start-Process -FilePath $exe -PassThru -NoNewWindow -WorkingDirectory tests/fixtures/serdevmock ` - -ArgumentList '--protocol', 'uart', '--port', 'COM21', '--config', 'echo.json' ` - -RedirectStandardOutput (Join-Path $d 'out.log') -RedirectStandardError (Join-Path $d 'err.log') - Set-Content (Join-Path $d 'pid') $p.Id - Start-Sleep -Seconds 5 - "alive: $(-not $p.HasExited)" - Get-CimInstance Win32_Process | Where-Object { $_.Name -match 'python|serdevmock' } | Format-Table ProcessId, ParentProcessId, Name -AutoSize - - - name: 3 COM20 write with serdevmock (PHP raw) - timeout-minutes: 1 - run: php tests/Integration/diag-dcb.php COM20 write - - - name: 4 .NET probe on COM20 - timeout-minutes: 1 - run: | - $a = [System.IO.Ports.SerialPort]::new('COM20', 9600) - $a.NewLine = "`n"; $a.ReadTimeout = 2000; $a.WriteTimeout = 2000 - $a.Open() - "dtr=$($a.DtrEnable) rts=$($a.RtsEnable) cts=$($a.CtsHolding) dsr=$($a.DsrHolding) cd=$($a.CDHolding)" - try { $a.WriteLine('probe'); "written" } catch { "write failed: $_" } - try { "got: $($a.ReadLine())" } catch { "read failed: $_" } - $a.Close() - - - name: 5 COM20 after .NET (PHP raw) - timeout-minutes: 1 - run: php tests/Integration/diag-dcb.php COM20 write - - - name: 6 phpunit - continue-on-error: true - timeout-minutes: 3 - env: - SERDEVMOCK_PORT: COM20 - run: php vendor/bin/phpunit --group integration --testdox - - - name: 7 COM20 after phpunit (PHP raw) - timeout-minutes: 1 - run: php tests/Integration/diag-dcb.php COM20 write - - - name: Logs - if: always() - run: | - $d = Join-Path $env:RUNNER_TEMP 'sdm' - $id = [int](Get-Content (Join-Path $d 'pid')) - "serdevmock alive: $($null -ne (Get-Process -Id $id -ErrorAction SilentlyContinue))" - foreach ($n in 'out.log', 'err.log') { - "----- $n" - Get-Content (Join-Path $d $n) -Encoding utf8 - } diff --git a/tests/Integration/diag-dcb.php b/tests/Integration/diag-dcb.php deleted file mode 100644 index d775d67..0000000 --- a/tests/Integration/diag-dcb.php +++ /dev/null @@ -1,65 +0,0 @@ -CreateFileA("\\\\.\\{$device}", 0xC0000000, 0, null, 3, 0x80, null); -if ($h == $ffi->cast('HANDLE', -1)) { - echo "open failed: error=" . $ffi->GetLastError() . "\n"; - exit(0); -} - -$dcb = $ffi->new('DCB'); -FFI::memcpy($dcb, pack('V', 28), 4); -$ok = $ffi->GetCommState($h, FFI::addr($dcb)); -$v = unpack('Vlen/Vbaud/Vflags/vres/vxon/vxoff/CbyteSize/Cparity/CstopBits', FFI::string(FFI::addr($dcb), 21)); -$f = $v['flags']; -printf( - "get=%d baud=%d %d%s%d flags=0x%04x fBinary=%d fParity=%d CtsFlow=%d DsrFlow=%d DtrCtl=%d DsrSens=%d TXCont=%d OutX=%d InX=%d Null=%d RtsCtl=%d Abort=%d\n", - $ok, $v['baud'], $v['byteSize'], ['N', 'O', 'E', 'M', 'S'][$v['parity']] ?? '?', $v['stopBits'], $f, - $f & 1, ($f >> 1) & 1, ($f >> 2) & 1, ($f >> 3) & 1, ($f >> 4) & 3, ($f >> 6) & 1, ($f >> 7) & 1, - ($f >> 8) & 1, ($f >> 9) & 1, ($f >> 11) & 1, ($f >> 12) & 3, ($f >> 14) & 1 -); - -$ms = $ffi->new('DWORD'); -$ffi->GetCommModemStatus($h, FFI::addr($ms)); -printf("modem CTS=%d DSR=%d RING=%d RLSD=%d\n", ($ms->cdata >> 4) & 1, ($ms->cdata >> 5) & 1, ($ms->cdata >> 6) & 1, ($ms->cdata >> 7) & 1); - -if ($doWrite) { - $t = $ffi->new('COMMTIMEOUTS'); - $t->a = 1; $t->b = 0; $t->c = 1; $t->d = 0; $t->e = 1000; - $ffi->SetCommTimeouts($h, FFI::addr($t)); - $data = "diag\n"; - $n = $ffi->new('DWORD'); - $wok = $ffi->WriteFile($h, $data, strlen($data), FFI::addr($n), null); - echo "write ok={$wok} n={$n->cdata}\n"; - usleep(800000); - $err = $ffi->new('DWORD'); - $st = $ffi->new('COMSTAT'); - $ffi->ClearCommError($h, FFI::addr($err), FFI::addr($st)); - echo "errors={$err->cdata} inQue={$st->cbInQue} outQue={$st->cbOutQue} holdFlags=0x" . dechex($st->fFlags) . "\n"; -} - -$ffi->CloseHandle($h); diff --git a/tests/Integration/start-serdevmock.ps1 b/tests/Integration/start-serdevmock.ps1 index 4e6ec3c..dbfeb1a 100644 --- a/tests/Integration/start-serdevmock.ps1 +++ b/tests/Integration/start-serdevmock.ps1 @@ -23,11 +23,13 @@ $exe = (Get-Command $Serdevmock -CommandType Application | Select-Object -First New-Item -ItemType Directory -Force $WorkDir | Out-Null $WorkDir = (Resolve-Path $WorkDir).Path -# 設定ファイルは作業ディレクトリからの相対名で渡し、パスの空白で引数が割れるのを避ける $env:PYTHONUNBUFFERED = '1' # 出力先がファイルだと既定の文字コードになり、serdevmock の日本語のメッセージで落ちる $env:PYTHONIOENCODING = 'utf-8' -$proc = Start-Process -FilePath $exe -PassThru -NoNewWindow ` +# 設定ファイルは作業ディレクトリからの相対名で渡し、パスの空白で引数が割れるのを避ける。 +# -NoNewWindow で呼び出し元のコンソールを共有すると、そのコンソールが閉じたとき +# (CI ではステップの終わり)に serdevmock も終了するため、別の非表示コンソールで動かす +$proc = Start-Process -FilePath $exe -PassThru -WindowStyle Hidden ` -WorkingDirectory $fixtureDir ` -ArgumentList '--protocol', 'uart', '--port', $MockPort, '--config', 'echo.json' ` -RedirectStandardOutput (Join-Path $WorkDir 'serdevmock.log') ` diff --git a/tests/Integration/stop-serdevmock.ps1 b/tests/Integration/stop-serdevmock.ps1 index b7118bf..7eeaf01 100644 --- a/tests/Integration/stop-serdevmock.ps1 +++ b/tests/Integration/stop-serdevmock.ps1 @@ -14,7 +14,10 @@ if (Test-Path $pidFile) { $id = [int](Get-Content $pidFile -TotalCount 1) $proc = Get-Process -Id $id -ErrorAction SilentlyContinue - if ($null -ne $proc) { + if ($null -eq $proc) { + # 試験の途中で落ちていた場合は、失敗の原因として目に付くように残す + Write-Warning 'serdevmock は停止の前に終了していた' + } else { # serdevmock.exe は python.exe を子として起動するため、子まで含めて止める & taskkill.exe /PID $id /T /F | Out-Null # ポートが閉じ切る前に次の試験が開くと、使用中で失敗するため終了を待つ From 5b863e9a4a1a7a40d630765484cd029e7faba36f Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:50:42 +0900 Subject: [PATCH 09/10] =?UTF-8?q?ci:=20serdevmock=20=E3=81=AE=E8=B5=B7?= =?UTF-8?q?=E5=8B=95=E3=83=BB=E8=A9=A6=E9=A8=93=E3=83=BB=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E3=82=92=201=20=E3=82=B9=E3=83=86=E3=83=83=E3=83=97=E3=81=AB?= =?UTF-8?q?=E3=81=BE=E3=81=A8=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows のランナーはステップ内で起動したプロセスをステップの終わりに止めるため。 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/integration-windows.yml | 27 +++++++++++------------ tests/Integration/start-serdevmock.ps1 | 8 +++---- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/integration-windows.yml b/.github/workflows/integration-windows.yml index 4023159..2dad2a7 100644 --- a/.github/workflows/integration-windows.yml +++ b/.github/workflows/integration-windows.yml @@ -128,24 +128,23 @@ jobs: } } - - name: Start serdevmock - run: >- - ./tests/Integration/start-serdevmock.ps1 - -AppPort $env:APP_PORT -MockPort $env:MOCK_PORT - -WorkDir (Join-Path $env:RUNNER_TEMP 'serdevmock') - + # Windows のランナーは、ステップ内で起動したプロセスをステップの終わりに止める。 + # このため serdevmock の起動・試験・停止を 1 つのステップで行う。 # 環境変数が欠けて全件が飛ばされたまま緑になるのを防ぐため、skip と空を失敗として扱う - - name: Run integration tests + - name: Run integration tests with serdevmock timeout-minutes: 3 env: SERDEVMOCK_PORT: ${{ env.APP_PORT }} - run: >- - php vendor/bin/phpunit --group integration --testdox - --fail-on-skipped --fail-on-empty-test-suite - - - name: Stop serdevmock - if: ${{ !cancelled() }} - run: ./tests/Integration/stop-serdevmock.ps1 -WorkDir (Join-Path $env:RUNNER_TEMP 'serdevmock') + run: | + $work = Join-Path $env:RUNNER_TEMP 'serdevmock' + try { + ./tests/Integration/start-serdevmock.ps1 -AppPort $env:APP_PORT -MockPort $env:MOCK_PORT -WorkDir $work + php vendor/bin/phpunit --group integration --testdox --fail-on-skipped --fail-on-empty-test-suite + $code = $LASTEXITCODE + } finally { + ./tests/Integration/stop-serdevmock.ps1 -WorkDir $work + } + exit $code # serdevmock を止めた後の COM10 は、相手が読まないポートになる - name: Run idle port tests diff --git a/tests/Integration/start-serdevmock.ps1 b/tests/Integration/start-serdevmock.ps1 index dbfeb1a..40acad1 100644 --- a/tests/Integration/start-serdevmock.ps1 +++ b/tests/Integration/start-serdevmock.ps1 @@ -26,9 +26,7 @@ $WorkDir = (Resolve-Path $WorkDir).Path $env:PYTHONUNBUFFERED = '1' # 出力先がファイルだと既定の文字コードになり、serdevmock の日本語のメッセージで落ちる $env:PYTHONIOENCODING = 'utf-8' -# 設定ファイルは作業ディレクトリからの相対名で渡し、パスの空白で引数が割れるのを避ける。 -# -NoNewWindow で呼び出し元のコンソールを共有すると、そのコンソールが閉じたとき -# (CI ではステップの終わり)に serdevmock も終了するため、別の非表示コンソールで動かす +# 設定ファイルは作業ディレクトリからの相対名で渡し、パスの空白で引数が割れるのを避ける $proc = Start-Process -FilePath $exe -PassThru -WindowStyle Hidden ` -WorkingDirectory $fixtureDir ` -ArgumentList '--protocol', 'uart', '--port', $MockPort, '--config', 'echo.json' ` @@ -86,9 +84,9 @@ try { } if (-not $ready) { - Write-Error 'serdevmock からエコーが返らなかった' -ErrorAction Continue Write-SerdevmockLog - exit 1 + # 呼び出し元が後続の試験へ進まないよう、終了コードでなく例外で知らせる + throw 'serdevmock からエコーが返らなかった' } Write-Host "php-serial 側: $AppPort / serdevmock 側: $MockPort" From 4be4575b7bc3ea6d2e3b531fa97edb0b569ad981 Mon Sep 17 00:00:00 2001 From: Shota Nishihara Date: Mon, 16 Nov 2026 23:54:22 +0900 Subject: [PATCH 10/10] =?UTF-8?q?ci:=20=E4=B8=80=E6=99=82=E3=83=88?= =?UTF-8?q?=E3=83=AA=E3=82=AC=E3=83=BC=E3=82=92=E5=A4=96=E3=81=97=E3=80=81?= =?UTF-8?q?=E8=B5=B7=E5=8B=95=E7=A2=BA=E8=AA=8D=E3=81=AE=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E8=BE=BC=E3=81=BF=E3=81=AB=E4=B8=8A=E9=99=90=E3=82=92=E8=A8=AD?= =?UTF-8?q?=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 文書を実際の構成(1 ステップでの起動・試験・停止、発行元の登録、FFI の確認)に合わせる。 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/integration-windows.yml | 5 +---- docs/INTEGRATION_TESTING.md | 14 +++++++++++++- tests/Integration/start-serdevmock.ps1 | 8 +++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/integration-windows.yml b/.github/workflows/integration-windows.yml index 2dad2a7..eff94d3 100644 --- a/.github/workflows/integration-windows.yml +++ b/.github/workflows/integration-windows.yml @@ -1,12 +1,9 @@ name: Integration (Windows) # com0com の仮想 COM ポート対と serdevmock を使い、FFI 実装の送受信を実機なしで確かめる。 -# ドライバーの導入に時間がかかるため、macOS 版と同じく実行の機会を絞る。 +# FFI 実装に関係しない変更まで走らせないよう、macOS 版と同じく実行の機会を絞る。 on: workflow_dispatch: - # TEMP: PR 作成前に削除する - push: - branches: [ 'claude/ci-windows-integration-*' ] schedule: # 毎週月曜 03:00(日本時間) - cron: '0 18 * * 0' diff --git a/docs/INTEGRATION_TESTING.md b/docs/INTEGRATION_TESTING.md index 0cb457a..862538d 100644 --- a/docs/INTEGRATION_TESTING.md +++ b/docs/INTEGRATION_TESTING.md @@ -138,7 +138,8 @@ serdevmock の試験と同時には指定しないでください。 ワークフローは `.github/workflows/` にあります。 macOS ランナーは空き待ちが 10 分前後になることがあるため、実行の機会を絞っています。 -Windows もドライバーの導入を伴うため、macOS に合わせています。 +Windows のジョブは 1 分ほどで終わります。 +ただし FFI 実装に関係しない変更まで走らせないよう、macOS に合わせています。 どちらも次の機会に実行します。 - 手動実行(`workflow_dispatch`) @@ -156,6 +157,10 @@ Windows のジョブは、com0com 3.0.0.0 の署名版を SourceForge から取 SHA256 を照合してから、インストーラーを `/S` で非対話のまま実行します。 続けて `setupc.exe` で COM10 と COM11 の対を作ります。 +インストーラーの前に、署名者の証明書を「信頼された発行元」へ登録します。 +登録しないと、ドライバー導入の確認ダイアログで止まるためです。 +この操作は使い捨てのランナーに限り、手元では行いません。 + このドライバーは 2016 年の証明書で署名されています。 Secure Boot が有効な Windows 10 以降では、読み込みを拒まれることがあります。 GitHub のホストランナーは Secure Boot が無効のため、そのまま読み込めます。 @@ -165,6 +170,13 @@ GitHub のホストランナーは Secure Boot が無効のため、そのまま まず serdevmock を COM11 で動かし、COM10 で `integration` グループを流します。 次に serdevmock を止め、COM10 で `windows-idle-port` グループを流します。 +Windows のランナーは、ステップ内で起動したプロセスをステップの終わりに止めます。 +このため、serdevmock の起動・試験・停止を 1 つのステップにまとめています。 +分けると、試験の時点で serdevmock が止まっており、エコーが返りません。 + +FFI が無効だと、php-serial は fopen 版の実装へ切り替わります。 +FFI 実装を試験しないまま通るのを防ぐため、最初に `php --ri ffi` で有効化を確かめます。 + ## 🔍 この試験で見つけた問題 Windows の FFI 実装で、次の問題を見つけて直しました。 diff --git a/tests/Integration/start-serdevmock.ps1 b/tests/Integration/start-serdevmock.ps1 index 40acad1..b2341f9 100644 --- a/tests/Integration/start-serdevmock.ps1 +++ b/tests/Integration/start-serdevmock.ps1 @@ -49,6 +49,8 @@ function Write-SerdevmockLog { $port = [System.IO.Ports.SerialPort]::new($AppPort, 9600) $port.NewLine = "`n" $port.ReadTimeout = 1000 +# 相手が読まないと書き込みが戻らないため、上限を設ける +$port.WriteTimeout = 1000 $ready = $false $port.Open() @@ -60,7 +62,11 @@ try { } $probe = "probe-$i" - $port.WriteLine($probe) + try { + $port.WriteLine($probe) + } catch [System.TimeoutException] { + continue + } $deadline = [DateTime]::UtcNow.AddSeconds(1) while (-not $ready -and [DateTime]::UtcNow -lt $deadline) {