nixosTests.php: migrate to runTest

This commit is contained in:
Piotr Kwiecinski 2025-03-14 19:11:10 +01:00 committed by Masum Reza
parent a212f0886c
commit e44f5a37cf
5 changed files with 180 additions and 168 deletions

View File

@ -914,11 +914,26 @@ in {
phosh = handleTest ./phosh.nix {}; phosh = handleTest ./phosh.nix {};
photonvision = handleTest ./photonvision.nix {}; photonvision = handleTest ./photonvision.nix {};
photoprism = handleTest ./photoprism.nix {}; photoprism = handleTest ./photoprism.nix {};
php = handleTest ./php {}; php = import ./php/default.nix {
php81 = handleTest ./php { php = pkgs.php81; }; inherit runTest;
php82 = handleTest ./php { php = pkgs.php82; }; php = pkgs.php;
php83 = handleTest ./php { php = pkgs.php83; }; };
php84 = handleTest ./php { php = pkgs.php84; }; php81 = import ./php/default.nix {
inherit runTest;
php = pkgs.php81;
};
php82 = import ./php/default.nix {
inherit runTest;
php = pkgs.php82;
};
php83 = import ./php/default.nix {
inherit runTest;
php = pkgs.php83;
};
php84 = import ./php/default.nix {
inherit runTest;
php = pkgs.php84;
};
phylactery = handleTest ./web-apps/phylactery.nix {}; phylactery = handleTest ./web-apps/phylactery.nix {};
pict-rs = handleTest ./pict-rs.nix {}; pict-rs = handleTest ./pict-rs.nix {};
pingvin-share = handleTest ./pingvin-share.nix {} ; pingvin-share = handleTest ./pingvin-share.nix {} ;

View File

@ -1,8 +1,6 @@
{ {
system ? builtins.currentSystem, runTest,
config ? { }, php,
pkgs ? import ../../.. { inherit system config; },
php ? pkgs.php,
}: }:
let let
@ -11,16 +9,16 @@ let
}; };
in in
{ {
fpm = import ./fpm.nix { fpm = runTest {
inherit system pkgs; imports = [ ./fpm.nix ];
php = php'; _module.args.php = php';
}; };
httpd = import ./httpd.nix { httpd = runTest {
inherit system pkgs; imports = [ ./httpd.nix ];
php = php'; _module.args.php = php';
}; };
pcre = import ./pcre.nix { pcre = runTest {
inherit system pkgs; imports = [ ./pcre.nix ];
php = php'; _module.args.php = php';
}; };
} }

View File

@ -1,59 +1,64 @@
import ../make-test-python.nix ({ pkgs, lib, php, ... }: { { lib, php, ... }:
{
name = "php-${php.version}-fpm-nginx-test"; name = "php-${php.version}-fpm-nginx-test";
meta.maintainers = lib.teams.php.members; meta.maintainers = lib.teams.php.members;
nodes.machine = { config, lib, pkgs, ... }: { nodes.machine =
environment.systemPackages = [ php ]; { config, pkgs, ... }:
{
environment.systemPackages = [ php ];
services.nginx = { services.nginx = {
enable = true; enable = true;
virtualHosts."phpfpm" = virtualHosts."phpfpm" =
let let
testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();";
in in
{ {
root = "${testdir}/web"; root = "${testdir}/web";
locations."~ \\.php$".extraConfig = '' locations."~ \\.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools.foobar.socket}; fastcgi_pass unix:${config.services.phpfpm.pools.foobar.socket};
fastcgi_index index.php; fastcgi_index index.php;
include ${config.services.nginx.package}/conf/fastcgi_params; include ${config.services.nginx.package}/conf/fastcgi_params;
include ${pkgs.nginx}/conf/fastcgi.conf; include ${pkgs.nginx}/conf/fastcgi.conf;
''; '';
locations."/" = { locations."/" = {
tryFiles = "$uri $uri/ index.php"; tryFiles = "$uri $uri/ index.php";
index = "index.php index.html index.htm"; index = "index.php index.html index.htm";
};
}; };
}; };
};
services.phpfpm.pools."foobar" = { services.phpfpm.pools."foobar" = {
user = "nginx"; user = "nginx";
phpPackage = php; phpPackage = php;
settings = { settings = {
"listen.group" = "nginx"; "listen.group" = "nginx";
"listen.mode" = "0600"; "listen.mode" = "0600";
"listen.owner" = "nginx"; "listen.owner" = "nginx";
"pm" = "dynamic"; "pm" = "dynamic";
"pm.max_children" = 5; "pm.max_children" = 5;
"pm.max_requests" = 500; "pm.max_requests" = 500;
"pm.max_spare_servers" = 3; "pm.max_spare_servers" = 3;
"pm.min_spare_servers" = 1; "pm.min_spare_servers" = 1;
"pm.start_servers" = 2; "pm.start_servers" = 2;
};
}; };
}; };
}; testScript =
testScript = { ... }: '' { ... }:
machine.wait_for_unit("nginx.service") ''
machine.wait_for_unit("phpfpm-foobar.service") machine.wait_for_unit("nginx.service")
machine.wait_for_unit("phpfpm-foobar.service")
# Check so we get an evaluated PHP back # Check so we get an evaluated PHP back
response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/")
assert "PHP Version ${php.version}" in response, "PHP version not detected" assert "PHP Version ${php.version}" in response, "PHP version not detected"
# Check so we have database and some other extensions loaded # Check so we have database and some other extensions loaded
for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]: for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]:
assert ext in response, f"Missing {ext} extension" assert ext in response, f"Missing {ext} extension"
machine.succeed(f'test -n "$(php -m | grep -i {ext})"') machine.succeed(f'test -n "$(php -m | grep -i {ext})"')
''; '';
}) }

View File

@ -1,51 +1,47 @@
import ../make-test-python.nix ( {
{ lib,
pkgs, php,
lib, ...
php, }:
... {
}: name = "php-${php.version}-httpd-test";
{ meta.maintainers = lib.teams.php.members;
name = "php-${php.version}-httpd-test";
meta.maintainers = lib.teams.php.members;
nodes.machine = nodes.machine =
{ {
config, config,
lib, pkgs,
pkgs, ...
... }:
}: {
{ services.httpd = {
services.httpd = { enable = true;
enable = true; adminAddr = "admin@phpfpm";
adminAddr = "admin@phpfpm"; virtualHosts."phpfpm" =
virtualHosts."phpfpm" = let
let testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();";
testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; in
in {
{ documentRoot = "${testdir}/web";
documentRoot = "${testdir}/web"; locations."/" = {
locations."/" = { index = "index.php index.html";
index = "index.php index.html";
};
}; };
phpPackage = php; };
enablePHP = true; phpPackage = php;
}; enablePHP = true;
}; };
testScript = };
{ ... }: testScript =
'' { ... }:
machine.wait_for_unit("httpd.service") ''
machine.wait_for_unit("httpd.service")
# Check so we get an evaluated PHP back # Check so we get an evaluated PHP back
response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/")
assert "PHP Version ${php.version}" in response, "PHP version not detected" assert "PHP Version ${php.version}" in response, "PHP version not detected"
# Check so we have database and some other extensions loaded # Check so we have database and some other extensions loaded
for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]: for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
assert ext in response, f"Missing {ext} extension" assert ext in response, f"Missing {ext} extension"
''; '';
} }
)

View File

@ -1,63 +1,61 @@
let let
testString = "can-use-subgroups"; testString = "can-use-subgroups";
in in
import ../make-test-python.nix ( {
{ pkgs,
pkgs, lib,
lib, php,
php, ...
... }:
}: {
{ name = "php-${php.version}-httpd-pcre-jit-test";
name = "php-${php.version}-httpd-pcre-jit-test"; meta.maintainers = lib.teams.php.members;
meta.maintainers = lib.teams.php.members;
nodes.machine = nodes.machine =
{ lib, pkgs, ... }: { pkgs, ... }:
{ {
time.timeZone = "UTC"; time.timeZone = "UTC";
services.httpd = { services.httpd = {
enable = true; enable = true;
adminAddr = "please@dont.contact"; adminAddr = "please@dont.contact";
phpPackage = php; phpPackage = php;
enablePHP = true; enablePHP = true;
phpOptions = "pcre.jit = true"; phpOptions = "pcre.jit = true";
extraConfig = extraConfig =
let let
testRoot = pkgs.writeText "index.php" '' testRoot = pkgs.writeText "index.php" ''
<?php <?php
preg_match('/(${testString})/', '${testString}', $result); preg_match('/(${testString})/', '${testString}', $result);
var_dump($result); var_dump($result);
'';
in
''
Alias / ${testRoot}/
<Directory ${testRoot}>
Require all granted
</Directory>
''; '';
}; in
''
Alias / ${testRoot}/
<Directory ${testRoot}>
Require all granted
</Directory>
'';
}; };
testScript = };
let testScript =
# PCRE JIT SEAlloc feature does not play well with fork() let
# The feature needs to either be disabled or PHP configured correctly # PCRE JIT SEAlloc feature does not play well with fork()
# More information in https://bugs.php.net/bug.php?id=78927 and https://bugs.php.net/bug.php?id=78630 # The feature needs to either be disabled or PHP configured correctly
pcreJitSeallocForkIssue = pkgs.writeText "pcre-jit-sealloc-issue.php" '' # More information in https://bugs.php.net/bug.php?id=78927 and https://bugs.php.net/bug.php?id=78630
<?php pcreJitSeallocForkIssue = pkgs.writeText "pcre-jit-sealloc-issue.php" ''
preg_match('/nixos/', 'nixos'); <?php
$pid = pcntl_fork(); preg_match('/nixos/', 'nixos');
pcntl_wait($pid); $pid = pcntl_fork();
''; pcntl_wait($pid);
in
''
machine.wait_for_unit("httpd.service")
# Ensure php evaluation by matching on the var_dump syntax
response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/index.php")
expected = 'string(${toString (builtins.stringLength testString)}) "${testString}"'
assert expected in response, "Does not appear to be able to use subgroups."
machine.succeed("${php}/bin/php -f ${pcreJitSeallocForkIssue}")
''; '';
} in
) ''
machine.wait_for_unit("httpd.service")
# Ensure php evaluation by matching on the var_dump syntax
response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/index.php")
expected = 'string(${toString (builtins.stringLength testString)}) "${testString}"'
assert expected in response, "Does not appear to be able to use subgroups."
machine.succeed("${php}/bin/php -f ${pcreJitSeallocForkIssue}")
'';
}