#!/usr/bin/env php
os}\n";
echo "CPU Arch: {$environment->cpuArch}\n";
echo "ZTS: " . ($environment->zts ? 'Yes' : 'No') . "\n";
echo "DEBUG: " . ($environment->debug ? 'Yes' : 'No') . "\n";
echo "=====================================================================\n";
try {
output_group_start($environment, 'Running Opcache TLS tests');
if (!run_opcache_tls_tests($environment)) {
echo "Failed\n";
exit(1);
}
} finally {
output_group_end($environment);
}
echo "All OK\n";
}
function run_opcache_tls_tests(Environment $environment): bool
{
if (!$environment->zts) {
echo "Skipping: NTS\n";
return true;
}
if (!$environment->debug) {
echo "Skipping: NDEBUG\n";
return true;
}
$tlsc = '';
$machine = '';
$static_support = 'yes';
switch ($environment->cpuArch) {
case 'x86':
$machine = '-m32';
break;
case 'x86_64':
case 'aarch64':
break;
default:
echo "Skipping: {$environment->cpuArch}\n";
return true;
}
switch ($environment->os) {
case 'Linux':
case 'FreeBSD':
$tlsc = __DIR__ . "/ext/opcache/jit/tls/zend_jit_tls_{$environment->cpuArch}.c";
break;
case 'Darwin':
if ($environment->cpuArch === 'aarch64') {
echo "Skipping: JIT+TLS not supported on MacOS Apple Silicon\n";
return true;
}
$tlsc = __DIR__ . "/ext/opcache/jit/tls/zend_jit_tls_darwin.c";
$static_support = 'no';
break;
default:
echo "Skipping: {$environment->os}\n";
return true;
}
echo "TLSC=$tlsc MACHINE=$machine STATIC_SUPPORT=$static_support ext/opcache/jit/tls/testing/test.sh\n";
$proc = proc_open(
__DIR__ . '/ext/opcache/jit/tls/testing/test.sh',
[
0 => ['pipe', 'r'],
],
$pipes,
env_vars: array_merge(getenv(), [
'TLSC' => $tlsc,
'MACHINE' => $machine,
'STATIC_SUPPORT' => $static_support,
]),
);
if (!$proc) {
echo "proc_open() failed\n";
return false;
}
fclose($pipes[0]);
return proc_close($proc) === 0;
}
function output_group_start(Environment $environment, string $name): void
{
if ($environment->githubAction) {
printf("::group::%s\n", $name);
} else {
printf("%s\n", $name);
}
}
function output_group_end(Environment $environment): void
{
if ($environment->githubAction) {
printf("::endgroup::\n");
}
}
/**
* Returns getenv('TEST_PHP_OS') if defined, otherwise returns one of
* 'Windows NT', 'Linux', 'FreeBSD', 'Darwin', ...
*/
function detect_os(): string
{
$os = (string) getenv('TEST_PHP_OS');
if ($os !== '') {
return $os;
}
return php_uname('s');
}
/**
* Returns getenv('TEST_PHP_CPU_ARCH') if defined, otherwise returns one of
* 'x86', 'x86_64', 'aarch64', ...
*/
function detect_cpu_arch(): string
{
$cpu = (string) getenv('TEST_PHP_CPU_ARCH');
if ($cpu !== '') {
return $cpu;
}
$cpu = php_uname('m');
if (strtolower($cpu) === 'amd64') {
$cpu = 'x86_64';
} else if (in_array($cpu, ['i386', 'i686'])) {
$cpu = 'x86';
} else if ($cpu === 'arm64') {
$cpu = 'aarch64';
}
return $cpu;
}
main($argc, $argv);