Skip to content

Commit aa0a61f

Browse files
committed
test(windows): adapt portable PHPT fixtures --filter=[win-unit]
1 parent 8789bb4 commit aa0a61f

17 files changed

Lines changed: 91 additions & 36 deletions

File tree

.github/workflows/windows.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ jobs:
130130
run: |
131131
& .github\workflows\windows-phpt.ps1 -Path tests\swoole_coroutine_util -TimeoutSeconds 12
132132
133+
- name: Run Windows coroutine system tests
134+
id: coroutine-system
135+
continue-on-error: true
136+
timeout-minutes: 2
137+
shell: powershell
138+
run: |
139+
& .github\workflows\windows-phpt.ps1 -Path tests\swoole_coroutine_system -TimeoutSeconds 12
140+
133141
- name: Run Windows timer and event tests
134142
id: timer-event
135143
continue-on-error: true
@@ -193,6 +201,7 @@ jobs:
193201
'${{ steps.channel-lock.outcome }}',
194202
'${{ steps.scheduler.outcome }}',
195203
'${{ steps.coroutine-util.outcome }}',
204+
'${{ steps.coroutine-system.outcome }}',
196205
'${{ steps.timer-event.outcome }}',
197206
'${{ steps.iocp-socket-1.outcome }}',
198207
'${{ steps.iocp-socket-2.outcome }}',

ext-src/swoole_socket_coro.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,32 @@ void php_swoole_socket_coro_minit(int module_number) {
745745
#endif
746746
}
747747

748+
static sw_inline int socket_coro_public_error_code(int code) {
749+
#ifdef _WIN32
750+
// ext/sockets exposes Winsock error constants on Windows, while Swoole
751+
// uses CRT errno values internally. Keep errCode comparable with the
752+
// visible SOCKET_E* constants when both extensions are loaded.
753+
if (zend_hash_str_find_ptr(&module_registry, ZEND_STRL("sockets"))) {
754+
switch (code) {
755+
case EINVAL:
756+
return WSAEINVAL;
757+
case EBADF:
758+
return WSAEBADF;
759+
case ENOTCONN:
760+
return WSAENOTCONN;
761+
default:
762+
break;
763+
}
764+
}
765+
#endif
766+
return code;
767+
}
768+
748769
static sw_inline void socket_coro_sync_properties(const zval *zobject, const SocketObject *sock) {
749-
zend_update_property_long(swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("errCode"), sock->socket->errCode);
770+
zend_update_property_long(swoole_socket_coro_ce,
771+
SW_Z8_OBJ_P(zobject),
772+
ZEND_STRL("errCode"),
773+
socket_coro_public_error_code(sock->socket->errCode));
750774
zend_update_property_string(swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("errMsg"), sock->socket->errMsg);
751775
}
752776

@@ -807,6 +831,7 @@ SW_API zend_object *php_swoole_create_socket(swSocketType type) {
807831
}
808832

809833
SW_API void php_swoole_socket_set_error_properties(const zval *zobject, int code, const char *msg) {
834+
code = socket_coro_public_error_code(code);
810835
swoole_set_last_error(code);
811836
zend_update_property_long(Z_OBJCE_P(zobject), SW_Z8_OBJ_P(zobject), ZEND_STRL("errCode"), code);
812837
zend_update_property_string(Z_OBJCE_P(zobject), SW_Z8_OBJ_P(zobject), ZEND_STRL("errMsg"), msg);

tests/swoole_coroutine_scheduler/preemptive/timer.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ swoole_coroutine_scheduler/preemptive: child coroutine timer
33
--SKIPIF--
44
<?php
55
require __DIR__ . '/../../include/skipif.inc';
6+
skip_if_not_linux();
67
?>
78
--FILE--
89
<?php

tests/swoole_coroutine_system/wait.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
--TEST--
22
swoole_coroutine_system: wait
33
--SKIPIF--
4-
<?php require __DIR__ . '/../include/skipif.inc'; ?>
4+
<?php
5+
require __DIR__ . '/../include/skipif.inc';
6+
skip_if_win();
7+
?>
58
--FILE--
69
<?php
710
require __DIR__ . '/../include/bootstrap.php';

tests/swoole_coroutine_system/waitPid.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
--TEST--
22
swoole_coroutine_system: waitPid
33
--SKIPIF--
4-
<?php require __DIR__ . '/../include/skipif.inc'; ?>
4+
<?php
5+
require __DIR__ . '/../include/skipif.inc';
6+
skip_if_win();
7+
?>
58
--FILE--
69
<?php
710
require __DIR__ . '/../include/bootstrap.php';

tests/swoole_coroutine_system/waitSignal.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
--TEST--
22
swoole_coroutine_system: waitSignal
33
--SKIPIF--
4-
<?php require __DIR__ . '/../include/skipif.inc'; ?>
4+
<?php
5+
require __DIR__ . '/../include/skipif.inc';
6+
skip_if_win();
7+
?>
58
--FILE--
69
<?php
710
require __DIR__ . '/../include/bootstrap.php';

tests/swoole_coroutine_system/waitSignal_2.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
--TEST--
22
swoole_coroutine_system: waitSignal 2
33
--SKIPIF--
4-
<?php require __DIR__ . '/../include/skipif.inc'; ?>
4+
<?php
5+
require __DIR__ . '/../include/skipif.inc';
6+
skip_if_win();
7+
?>
58
--FILE--
69
<?php
710
require __DIR__ . '/../include/bootstrap.php';

tests/swoole_coroutine_util/exec.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ swoole_coroutine_util: exec
33
--SKIPIF--
44
<?php
55
require __DIR__ . '/../include/skipif.inc';
6+
skip_if_win();
67
skip_if_command_not_found('md5sum');
78
?>
89
--FILE--

tests/swoole_coroutine_util/exec_sleep.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
swoole_coroutine_util: coroutine exec
33
--SKIPIF--
44
<?php require __DIR__ . '/../include/skipif.inc';
5+
skip_if_win();
56
?>
67
--FILE--
78
<?php

tests/swoole_socket_coro/complete_test.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ use Swoole\Coroutine\Socket;
1111
use Swoole\Event;
1212

1313
$pm = new ProcessManager();
14-
$port = get_one_free_port();
15-
$pm->parentFunc = function ($pid) use ($pm, $port) {
14+
$pm->parentFunc = function ($pid) use ($pm) {
1615
$socket = new Socket(AF_INET, SOCK_STREAM, 0);
1716
Assert::isInstanceOf($socket, Socket::class);
1817
Assert::same($socket->errCode, 0);
19-
go(function () use ($socket, $port) {
20-
Assert::assert($socket->connect('localhost', $port));
18+
go(function () use ($socket, $pm) {
19+
Assert::assert($socket->connect('localhost', $pm->getFreePort()));
2120
$i = 0.000;
2221
while (true) {
2322
$socket->send('hello');
@@ -35,9 +34,9 @@ $pm->parentFunc = function ($pid) use ($pm, $port) {
3534
Event::wait();
3635
};
3736

38-
$pm->childFunc = function () use ($pm, $port) {
37+
$pm->childFunc = function () use ($pm) {
3938
$socket = new Socket(AF_INET, SOCK_STREAM, 0);
40-
Assert::assert($socket->bind('127.0.0.1', $port));
39+
Assert::assert($socket->bind('127.0.0.1', $pm->getFreePort()));
4140
Assert::assert($socket->listen(128));
4241
go(function () use ($socket, $pm) {
4342
$pm->wakeup();

0 commit comments

Comments
 (0)