Skip to content

Commit 6540f94

Browse files
committed
adding new tests
1 parent 02e2617 commit 6540f94

File tree

5 files changed

+136
-2
lines changed

5 files changed

+136
-2
lines changed

sapi/fpm/config.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ if test "$PHP_FPM" != "no"; then
356356
AC_CHECK_HEADER([priv.h], [AC_CHECK_FUNCS([setpflags])])
357357
AC_CHECK_HEADER([sys/times.h], [AC_CHECK_FUNCS([times])])
358358
AC_CHECK_HEADER([port.h], [AC_CHECK_FUNCS([port_create])])
359+
AC_CHECK_HEADER([sched.h], [AC_CHECK_FUNCS([sched_setaffinity])])
360+
AC_CHECK_HEADER([sys/cpuset.h], [AC_CHECK_FUNCS([cpuset_setaffinity])])
359361

360362
PHP_ARG_WITH([fpm-user],,
361363
[AS_HELP_STRING([[--with-fpm-user[=USER]]],

sapi/fpm/fpm/fpm_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
#include <selinux/selinux.h>
3838
#endif
3939

40-
#if defined(HAVE_SCHED_H)
40+
#if defined(HAVE_SCHED_SETAFFINITY)
4141
#include <sched.h>
42-
#elif defined(HAVE_SYS_CPUSET_H)
42+
#elif defined(HAVE_CPUSETAFFINITY)
4343
#include <sys/cpuset.h>
4444
typedef cpuset_t cpu_set_t;
4545
#endif

sapi/fpm/tests/cpuaffinity-fail2.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
FPM: cpu affinity test
3+
--SKIPIF--
4+
<?php include "skipif.inc";
5+
6+
if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
7+
die('skipped supported only on Linux and FreeBSD');
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
13+
require_once "tester.inc";
14+
15+
$cfg = <<<EOT
16+
[global]
17+
process.cpu_list = MYcpuListIs1024-2048
18+
error_log = {{FILE:LOG}}
19+
pid = {{FILE:PID}}
20+
[unconfined]
21+
listen = {{ADDR:IPv4}}
22+
pm = dynamic
23+
pm.max_children = 1
24+
pm.start_servers = 1
25+
pm.min_spare_servers = 1
26+
pm.max_spare_servers = 1
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg);
30+
$tester->start();
31+
$tester->expectLogError("FPM initialization failed");
32+
$tester->close();
33+
34+
?>
35+
Done
36+
--EXPECT--
37+
Done
38+
--CLEAN--
39+
<?php
40+
require_once "tester.inc";
41+
FPM\Tester::clean();
42+
?>

sapi/fpm/tests/cpuaffinity-fail3.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
FPM: cpu affinity test
3+
--SKIPIF--
4+
<?php include "skipif.inc";
5+
6+
if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
7+
die('skipped supported only on Linux and FreeBSD');
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
13+
require_once "tester.inc";
14+
15+
$cfg = <<<EOT
16+
[global]
17+
process.cpu_list = 12de-34ad
18+
error_log = {{FILE:LOG}}
19+
pid = {{FILE:PID}}
20+
[unconfined]
21+
listen = {{ADDR:IPv4}}
22+
pm = dynamic
23+
pm.max_children = 1
24+
pm.start_servers = 1
25+
pm.min_spare_servers = 1
26+
pm.max_spare_servers = 1
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg);
30+
$tester->start();
31+
$tester->expectLogError("FPM initialization failed");
32+
$tester->close();
33+
34+
?>
35+
Done
36+
--EXPECT--
37+
Done
38+
--CLEAN--
39+
<?php
40+
require_once "tester.inc";
41+
FPM\Tester::clean();
42+
?>

sapi/fpm/tests/cpuaffinity-multi.phpt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
FPM: cpu affinity test
3+
--SKIPIF--
4+
<?php include "skipif.inc";
5+
6+
if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
7+
die('skipped supported only on Linux and FreeBSD');
8+
}
9+
10+
if (FPM\Tester::getCores() < 4) {
11+
die('skipped supported only on multicores environments');
12+
}
13+
?>
14+
--FILE--
15+
<?php
16+
17+
require_once "tester.inc";
18+
19+
$cfg = <<<EOT
20+
[global]
21+
error_log = {{FILE:LOG}}
22+
pid = {{FILE:PID}}
23+
[unconfined]
24+
listen = {{ADDR:IPv4}}
25+
pm = dynamic
26+
pm.max_children = 1
27+
pm.start_servers = 1
28+
pm.min_spare_servers = 1
29+
pm.max_spare_servers = 1
30+
process.cpu_list = 1,2-3,4
31+
EOT;
32+
33+
$tester = new FPM\Tester($cfg);
34+
$tester->start();
35+
$tester->expectLogStartNotices();
36+
$tester->terminate();
37+
$tester->expectLogTerminatingNotices();
38+
$tester->close();
39+
40+
?>
41+
Done
42+
--EXPECT--
43+
Done
44+
--CLEAN--
45+
<?php
46+
require_once "tester.inc";
47+
FPM\Tester::clean();
48+
?>

0 commit comments

Comments
 (0)