|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Validate the exact public CLI/micro downloads, including on real WSL2.""" |
| 3 | +import hashlib |
| 4 | +import io |
| 5 | +import json |
| 6 | +from pathlib import Path |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +import tarfile |
| 10 | +import tempfile |
| 11 | +import time |
| 12 | +from urllib.request import Request, urlopen |
| 13 | + |
| 14 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) |
| 15 | +from php_binary import current_jit_profile |
| 16 | +from php_releases import MANIFEST, validate_manifest |
| 17 | + |
| 18 | +base = 'https://download.workerman.net/php/' |
| 19 | +stamp = time.time_ns() |
| 20 | +results = Path('validation/public-jit') |
| 21 | +results.mkdir(parents=True, exist_ok=True) |
| 22 | + |
| 23 | + |
| 24 | +def fetch(name, limit=80 * 1024 * 1024): |
| 25 | + request = Request(base + name + '?jit-verify=' + str(stamp), headers={'Cache-Control': 'no-cache'}) |
| 26 | + with urlopen(request, timeout=180) as response: |
| 27 | + data = response.read(limit + 1) |
| 28 | + if len(data) > limit: |
| 29 | + raise RuntimeError('Oversized public download: ' + name) |
| 30 | + return data |
| 31 | + |
| 32 | + |
| 33 | +with tempfile.TemporaryDirectory(prefix='published-php-jit-') as temporary: |
| 34 | + root = Path(temporary) |
| 35 | + for release in validate_manifest(json.loads(MANIFEST.read_text())): |
| 36 | + branch, version = release['branch'], release['version'] |
| 37 | + name = f'php-{branch}-linux-x86_64' |
| 38 | + info = json.loads(fetch(name + '.json', 128 * 1024)) |
| 39 | + assert info['php_version'] == version and current_jit_profile(info), name + ': stale JIT profile' |
| 40 | + archive = name + '.tar.gz' |
| 41 | + expected = fetch(archive + '.sha256', 1024).decode().split() |
| 42 | + data = fetch(archive) |
| 43 | + assert expected == [hashlib.sha256(data).hexdigest(), archive], name + ': archive checksum mismatch' |
| 44 | + with tarfile.open(fileobj=io.BytesIO(data)) as bundle: |
| 45 | + assert bundle.getnames() == ['php'] |
| 46 | + member = bundle.getmember('php') |
| 47 | + assert member.isfile() and member.size < 80 * 1024 * 1024 |
| 48 | + binary = bundle.extractfile(member).read() |
| 49 | + assert hashlib.sha256(binary).hexdigest() == info['sha256'] and len(binary) == info['binary_bytes'] |
| 50 | + cli = root / ('php' + branch) |
| 51 | + cli.write_bytes(binary) |
| 52 | + cli.chmod(0o755) |
| 53 | + cli_report = results / (branch + '-cli.json') |
| 54 | + subprocess.run(['python3', str(Path(__file__).with_name('run_checks.py')), '--php', str(cli), |
| 55 | + '--expect-jit', 'yes', '--output', str(cli_report)], check=True) |
| 56 | + assert json.loads(cli_report.read_text())['tracing']['php'] == version |
| 57 | + if branch == '8.5': |
| 58 | + subprocess.run(['python3', str(Path(__file__).with_name('run_checks.py')), '--php', str(cli), |
| 59 | + '--fixture', str(Path(__file__).with_name('repro-php85-jit.php')), |
| 60 | + '--jit-modes', 'tracing', '--expect-jit', 'yes', |
| 61 | + '--output', str(results / (branch + '-original-repro.json'))], check=True) |
| 62 | + micro_data = fetch('php' + branch + '.micro.sfx') |
| 63 | + assert hashlib.sha256(micro_data).hexdigest() == info['micro']['sha256'] |
| 64 | + assert len(micro_data) == info['micro']['binary_bytes'] |
| 65 | + micro = root / ('php' + branch + '.micro.sfx') |
| 66 | + micro.write_bytes(micro_data) |
| 67 | + micro_report = results / (branch + '-micro.json') |
| 68 | + subprocess.run(['python3', str(Path(__file__).with_name('run_micro_checks.py')), '--micro', str(micro), |
| 69 | + '--output', str(micro_report)], check=True) |
| 70 | + assert json.loads(micro_report.read_text())['disable']['php'] == version |
| 71 | + print('PUBLIC DOWNLOAD PASS:', name, version, flush=True) |
0 commit comments