mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-01 21:23:51 -09:00
support/testing: php: new runtime test
Signed-off-by: Julien Olivain <ju.o@free.fr>
This commit is contained in:
@@ -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_patch/
|
||||||
F: support/testing/tests/package/test_pciutils.py
|
F: support/testing/tests/package/test_pciutils.py
|
||||||
F: support/testing/tests/package/test_perftest.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_pigz.py
|
||||||
F: support/testing/tests/package/test_postgresql.py
|
F: support/testing/tests/package/test_postgresql.py
|
||||||
F: support/testing/tests/package/test_pppd.py
|
F: support/testing/tests/package/test_pppd.py
|
||||||
|
|||||||
61
support/testing/tests/package/test_php.py
Normal file
61
support/testing/tests/package/test_php.py
Normal file
@@ -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())
|
||||||
@@ -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
|
||||||
|
|
||||||
|
<IfModule unixd_module>
|
||||||
|
User daemon
|
||||||
|
Group daemon
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
ServerAdmin you@example.com
|
||||||
|
ServerName localhost:80
|
||||||
|
|
||||||
|
<Directory />
|
||||||
|
AllowOverride none
|
||||||
|
Require all denied
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
DocumentRoot "/usr/htdocs"
|
||||||
|
<Directory "/usr/htdocs">
|
||||||
|
Options Indexes FollowSymLinks
|
||||||
|
AllowOverride None
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Files ".ht*">
|
||||||
|
Require all denied
|
||||||
|
</Files>
|
||||||
|
|
||||||
|
ErrorLog "/var/logs/error_log"
|
||||||
|
LogLevel warn
|
||||||
|
|
||||||
|
<IfModule log_config_module>
|
||||||
|
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
||||||
|
LogFormat "%h %l %u %t \"%r\" %>s %b" common
|
||||||
|
|
||||||
|
<IfModule logio_module>
|
||||||
|
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
CustomLog "/var/logs/access_log" common
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
<IfModule mime_module>
|
||||||
|
TypesConfig /etc/apache2/mime.types
|
||||||
|
AddType application/x-httpd-php .php
|
||||||
|
</IfModule>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
$points = ",.:-;!/>)|&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;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<?php echo strtoupper($_POST["message"]) . PHP_EOL; ?>
|
||||||
Reference in New Issue
Block a user