From 43e87a583f0761ec12860a3f9a68df7e9a9c0e04 Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Sun, 26 Jul 2026 15:26:50 +0200 Subject: [PATCH] support/testing: php: new runtime test Signed-off-by: Julien Olivain --- DEVELOPERS | 2 + support/testing/tests/package/test_php.py | 61 +++++++++++++++++++ .../rootfs-overlay/etc/apache2/httpd.conf | 58 ++++++++++++++++++ .../test_php/rootfs-overlay/root/mandel.php | 19 ++++++ .../rootfs-overlay/usr/htdocs/script.php | 1 + 5 files changed, 141 insertions(+) create mode 100644 support/testing/tests/package/test_php.py create mode 100644 support/testing/tests/package/test_php/rootfs-overlay/etc/apache2/httpd.conf create mode 100644 support/testing/tests/package/test_php/rootfs-overlay/root/mandel.php create mode 100644 support/testing/tests/package/test_php/rootfs-overlay/usr/htdocs/script.php diff --git a/DEVELOPERS b/DEVELOPERS index f2713c7239..b4ca50a10e 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1991,6 +1991,8 @@ F: support/testing/tests/package/test_patch.py F: support/testing/tests/package/test_patch/ F: support/testing/tests/package/test_pciutils.py F: support/testing/tests/package/test_perftest.py +F: support/testing/tests/package/test_php.py +F: support/testing/tests/package/test_php/ F: support/testing/tests/package/test_pigz.py F: support/testing/tests/package/test_postgresql.py F: support/testing/tests/package/test_pppd.py diff --git a/support/testing/tests/package/test_php.py b/support/testing/tests/package/test_php.py new file mode 100644 index 0000000000..b328eaa3bb --- /dev/null +++ b/support/testing/tests/package/test_php.py @@ -0,0 +1,61 @@ +import os + +import infra.basetest + + +class TestPhp(infra.basetest.BRTest): + rootfs_overlay = \ + infra.filepath("tests/package/test_php/rootfs-overlay") + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + f""" + BR2_PACKAGE_APACHE=y + BR2_PACKAGE_LIBCURL=y + BR2_PACKAGE_LIBCURL_CURL=y + BR2_PACKAGE_PHP=y + BR2_PACKAGE_PHP_SAPI_APACHE=y + BR2_PACKAGE_PHP_SAPI_CLI=y + BR2_ROOTFS_OVERLAY="{rootfs_overlay}" + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + + def test_run(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv7", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login() + + # We check the php program can execute. + self.assertRunOk("php --version") + + # We check can print a message from the command line. + msg = "Hello Buildroot!" + php_code = f"echo '{msg}' . PHP_EOL;" + cmd = f"php -r \"{php_code}\"" + out, ret = self.emulator.run(cmd) + self.assertEqual(ret, 0) + self.assertEqual(out[0], msg) + + # We check we can exit with a specific code. + exit_code = 123 + php_code = f"exit({exit_code});" + cmd = f"php -r \"{php_code}\"" + out, ret = self.emulator.run(cmd) + self.assertEqual(ret, exit_code) + self.assertEqual(len(out), 0) + + # We check we can run a slightly more complex program. + self.assertRunOk("php mandel.php") + + # We check the apache php module is also working. + # The php script reads the "message" POST variable, + # then write its content back in upper case. + cmd = "curl" + cmd += " -H 'Content-type: multipart/form-data'" + cmd += " -X POST" + cmd += f" -F message='{msg}'" + cmd += " http://127.0.0.1/script.php" + out, ret = self.emulator.run(cmd) + self.assertEqual(ret, 0) + self.assertEqual("\n".join(out), msg.upper()) diff --git a/support/testing/tests/package/test_php/rootfs-overlay/etc/apache2/httpd.conf b/support/testing/tests/package/test_php/rootfs-overlay/etc/apache2/httpd.conf new file mode 100644 index 0000000000..109247514b --- /dev/null +++ b/support/testing/tests/package/test_php/rootfs-overlay/etc/apache2/httpd.conf @@ -0,0 +1,58 @@ +# This file is a minimal Apache config to run PHP scripts for tests. +# It was essentially written from the default package config with: +# - all the comments removed, +# - unneeded modules and config sections removed, +# - "ServerName localhost:80" added to remove startup warning, +# - "AddType application/x-httpd-php .php" added to enable php. + +ServerRoot "/usr" +Listen 80 + +LoadModule authz_core_module modules/mod_authz_core.so +LoadModule mime_module modules/mod_mime.so +LoadModule log_config_module modules/mod_log_config.so +LoadModule unixd_module modules/mod_unixd.so +LoadModule php_module modules/libphp.so + + +User daemon +Group daemon + + +ServerAdmin you@example.com +ServerName localhost:80 + + + AllowOverride none + Require all denied + + +DocumentRoot "/usr/htdocs" + + Options Indexes FollowSymLinks + AllowOverride None + Require all granted + + + + Require all denied + + +ErrorLog "/var/logs/error_log" +LogLevel warn + + + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%h %l %u %t \"%r\" %>s %b" common + + + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio + + + CustomLog "/var/logs/access_log" common + + + + TypesConfig /etc/apache2/mime.types + AddType application/x-httpd-php .php + diff --git a/support/testing/tests/package/test_php/rootfs-overlay/root/mandel.php b/support/testing/tests/package/test_php/rootfs-overlay/root/mandel.php new file mode 100644 index 0000000000..a18e5c6838 --- /dev/null +++ b/support/testing/tests/package/test_php/rootfs-overlay/root/mandel.php @@ -0,0 +1,19 @@ +)|&IH%*Z"; +for ($y = -15; $y <= 15; $y++) { + for ($x = 1; $x <= 84; $x++) { + $i = 0; + $r = 0; + for ($k = 0; $k <= 111; $k++) { + $j = ($r*$r) - ($i*$i) - 2 + ($x/25); + $i = 2 * $r * $i + ($y/10); + if (($j*$j + $i*$i) >= 11) { + break; + } + $r = $j; + } + echo $points[$k & 0xF]; + } + echo PHP_EOL; +} +?> diff --git a/support/testing/tests/package/test_php/rootfs-overlay/usr/htdocs/script.php b/support/testing/tests/package/test_php/rootfs-overlay/usr/htdocs/script.php new file mode 100644 index 0000000000..8f8feaedbf --- /dev/null +++ b/support/testing/tests/package/test_php/rootfs-overlay/usr/htdocs/script.php @@ -0,0 +1 @@ +