Changes since version 1.22.0:
* win,pipe: restore compatibility with the old IPC framing protocol (Bert
Belder)
* fs: add uv_open_osfhandle (Bartosz Sosnowski)
* doc: update Visual C++ Build Tools URL (Michał Kozakiewicz)
* unix: loop starvation on successful write complete (jBarz)
* win: add uv__getnameinfo_work() error handling (A. Hauptmann)
* win: return UV_ENOMEM from uv_loop_init() (cjihrig)
* unix,win: add uv_os_{get,set}priority() (cjihrig)
* test: fix warning in test-tcp-open (Santiago Gimeno)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org
iQIzBAABCgAdFiEElK42Z1xGTWS6+mjddDQ5C9vpucUFAlt2LW8ACgkQdDQ5C9vp
ucXlDBAAlCVoa6GZthYy7fOBddNn2410GVKNZTUwNZ+bZL6ctpFxhgoH/Vir2SVg
/8Je+Se3jz6QXJx0cA2+gLZdZ+nmZn4cAOGo9p6pWq2SVhmtc7F89KkHc8DDG0GR
yGF09utyM4fQL0pnDYLzg66iquQJPCd1BwP32LlHOM0kqDyqli+OVphw/X9ABeHl
GFPMD8i8wuHAKcOQo7xLsIETZVax/LC6N7seeMxO2ZIdAZFSeBw4OEyHra9hLq2r
eleTccsA5R+tZZE9gUyefZ4s0desZkfndC0iL3qoWaM+TVxwpuB379BquDwhVwC1
CFaFv7HLikNjUgwTSz9nUbsqxni2z+QH5gmgaF7WWpPIJcSf3ZH4T8wW9abRwizR
BIehRtVHEM+TmC3Hr1ttfnDjMoFtyO33Tw1lSpQ9vlhll+sotei8RP7+oPumjlAN
rs6dfnZ2FTxjNDWG1yaDXxoh2GWwR9gbxr/SiL/ZhoNHukJNN+gPAamF11S3Sk0v
+h+iC9dtdiOPPWipxCZ+xeB3Tdus5Z+HVgG7Se859nt1r0kwA5zKfGw9pv65La9g
KZuTCZjgvx7fCh4Mcw+uVExJ1vTWy+x5kOKk4l62RQj+L9f1YJZxgljMrBQTG9AU
s4hMGI4gDMblyVM35T3vHModFBvwY0Uy90hn/yBCNILGbznNmD0=
=Uf50
-----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEEYS8OrZQBYiN530QC8ow8jaM8A74FAlt/3vUACgkQ8ow8jaM8
A76jzQ//fAIPMjf42ifdQhD3/EFskQ9AwdiPLmDALUM9qn5hzfGp6XZ/XJKq87kg
i2tm9wqh8m+QknSbnRkZMjDQrpmQuOypS+mqBDTVuPHHJ5V53f0zgStqlZ2dE5h9
B/5YcGTukVjK6BIlazFH5QO8urc9IsYefSvPp9gepO1XnLCzkE9OpVgL9jFTLcaG
Yvovtkbm4tkdYlOYZEp8LitnocRH84eJCZZipA3cfwctaWShKjPL6i/vB6TsmyH2
7QSdKcBkbYJ50r03gUSRYNQYpoJDJEg7eht/XGPVbUGMhcZ53oz6DqGE+bqalZ5P
VbD76KC96tqDhW99nCUij/RdT4Xo7NbK2+RiMXznr2H3KkpIt3eKEdD62B3ax1Hc
cNzk/fINareTe/6gPVg08A8Tzpsg48PNnLpGkzYpHghCn2XBR1iTtQNpIOa1UpxO
Gqe+uEP8k08tQ/n9rpBzBnNsC+fCZQU6Q5LGpWnTXMRjNtQuWM99O9k06TBPmDWI
AQyJ9MByEt5bwNqsIg9nVe+iXkxNbZBOLHmqbkDUWNTDhjY3+oVh8Dq/18nvfgMk
dIIBrBa0FEGbG/r/uKpuMqNmxCQel8nkC0sQ5vdIN8CfzAfQnoMww93GyPEpQTSR
FAwdk7ri+mGcGw3igUp8IsgAKwgjJAkkWzAX3gAwHrw1aoUnc60=
=3idK
-----END PGP SIGNATURE-----
Merge tag 'v1.23.0' into merge_1.23.0
PR-URL: https://github.com/libuv/libuv/pull/1952
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
259 lines
6.2 KiB
C
259 lines
6.2 KiB
C
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#ifdef _WIN32
|
|
# include <io.h>
|
|
#else
|
|
# include <unistd.h>
|
|
# include <sched.h>
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__)
|
|
# include <sys/param.h>
|
|
# include <sys/cpuset.h>
|
|
# include <pthread_np.h>
|
|
#endif
|
|
|
|
#include "uv.h"
|
|
#include "runner.h"
|
|
#include "task.h"
|
|
|
|
/* Actual tests and helpers are defined in test-list.h */
|
|
#include "test-list.h"
|
|
|
|
int ipc_helper(int listen_after_write);
|
|
int ipc_helper_heavy_traffic_deadlock_bug(void);
|
|
int ipc_helper_tcp_connection(void);
|
|
int ipc_helper_closed_handle(void);
|
|
int ipc_send_recv_helper(void);
|
|
int ipc_helper_bind_twice(void);
|
|
int stdio_over_pipes_helper(void);
|
|
int spawn_stdin_stdout(void);
|
|
int spawn_tcp_server_helper(void);
|
|
|
|
static int maybe_run_test(int argc, char **argv);
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
if (platform_init(argc, argv))
|
|
return EXIT_FAILURE;
|
|
|
|
argv = uv_setup_args(argc, argv);
|
|
|
|
switch (argc) {
|
|
case 1: return run_tests(0);
|
|
case 2: return maybe_run_test(argc, argv);
|
|
case 3: return run_test_part(argv[1], argv[2]);
|
|
case 4: return maybe_run_test(argc, argv);
|
|
default:
|
|
fprintf(stderr, "Too many arguments.\n");
|
|
fflush(stderr);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
|
|
static int maybe_run_test(int argc, char **argv) {
|
|
if (strcmp(argv[1], "--list") == 0) {
|
|
print_tests(stdout);
|
|
return 0;
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) {
|
|
return ipc_helper(0);
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) {
|
|
return ipc_helper(1);
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_helper_heavy_traffic_deadlock_bug") == 0) {
|
|
return ipc_helper_heavy_traffic_deadlock_bug();
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_send_recv_helper") == 0) {
|
|
return ipc_send_recv_helper();
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) {
|
|
return ipc_helper_tcp_connection();
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_helper_closed_handle") == 0) {
|
|
return ipc_helper_closed_handle();
|
|
}
|
|
|
|
if (strcmp(argv[1], "ipc_helper_bind_twice") == 0) {
|
|
return ipc_helper_bind_twice();
|
|
}
|
|
|
|
if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) {
|
|
return stdio_over_pipes_helper();
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper1") == 0) {
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper2") == 0) {
|
|
printf("hello world\n");
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) {
|
|
return spawn_tcp_server_helper();
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper3") == 0) {
|
|
char buffer[256];
|
|
ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin));
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
fputs(buffer, stdout);
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper4") == 0) {
|
|
/* Never surrender, never return! */
|
|
while (1) uv_sleep(10000);
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper5") == 0) {
|
|
const char out[] = "fourth stdio!\n";
|
|
#ifdef _WIN32
|
|
DWORD bytes;
|
|
WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL);
|
|
#else
|
|
{
|
|
ssize_t r;
|
|
|
|
do
|
|
r = write(3, out, sizeof(out) - 1);
|
|
while (r == -1 && errno == EINTR);
|
|
|
|
fsync(3);
|
|
}
|
|
#endif
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper6") == 0) {
|
|
int r;
|
|
|
|
r = fprintf(stdout, "hello world\n");
|
|
ASSERT(r > 0);
|
|
|
|
r = fprintf(stderr, "hello errworld\n");
|
|
ASSERT(r > 0);
|
|
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(argv[1], "spawn_helper7") == 0) {
|
|
int r;
|
|
char *test;
|
|
/* Test if the test value from the parent is still set */
|
|
test = getenv("ENV_TEST");
|
|
ASSERT(test != NULL);
|
|
|
|
r = fprintf(stdout, "%s", test);
|
|
ASSERT(r > 0);
|
|
|
|
return 1;
|
|
}
|
|
|
|
#ifndef _WIN32
|
|
if (strcmp(argv[1], "spawn_helper8") == 0) {
|
|
int fd;
|
|
ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd)));
|
|
ASSERT(fd > 2);
|
|
ASSERT(-1 == write(fd, "x", 1));
|
|
|
|
return 1;
|
|
}
|
|
#endif /* !_WIN32 */
|
|
|
|
if (strcmp(argv[1], "spawn_helper9") == 0) {
|
|
return spawn_stdin_stdout();
|
|
}
|
|
|
|
#ifndef _WIN32
|
|
if (strcmp(argv[1], "spawn_helper_setuid_setgid") == 0) {
|
|
uv_uid_t uid = atoi(argv[2]);
|
|
uv_gid_t gid = atoi(argv[3]);
|
|
|
|
ASSERT(uid == getuid());
|
|
ASSERT(gid == getgid());
|
|
|
|
return 1;
|
|
}
|
|
#endif /* !_WIN32 */
|
|
|
|
#if !defined(NO_CPU_AFFINITY)
|
|
if (strcmp(argv[1], "spawn_helper_affinity") == 0) {
|
|
int i;
|
|
int r;
|
|
int cpu;
|
|
int cpumask_size;
|
|
#ifdef _WIN32
|
|
DWORD_PTR procmask;
|
|
DWORD_PTR sysmask;
|
|
#elif defined(__linux__)
|
|
cpu_set_t cpuset;
|
|
#else
|
|
cpuset_t cpuset;
|
|
#endif
|
|
|
|
cpumask_size = uv_cpumask_size();
|
|
ASSERT(cpumask_size > 0);
|
|
|
|
cpu = atoi(argv[2]);
|
|
ASSERT(cpu >= 0);
|
|
ASSERT(cpu < cpumask_size);
|
|
|
|
/* verify the mask has the cpu we expect */
|
|
#ifdef _WIN32
|
|
r = GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask);
|
|
ASSERT(r != 0);
|
|
for (i = 0; i < cpumask_size; ++i) {
|
|
ASSERT(((procmask & (((DWORD_PTR)1) << i)) != 0) == (i == cpu));
|
|
}
|
|
#else
|
|
CPU_ZERO(&cpuset);
|
|
r = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
|
|
ASSERT(r == 0);
|
|
for (i = 0; i < cpumask_size; ++i) {
|
|
ASSERT(CPU_ISSET(i, &cpuset) == (i == cpu));
|
|
}
|
|
#endif
|
|
|
|
return 1;
|
|
}
|
|
#endif
|
|
|
|
return run_test(argv[1], 0, 1);
|
|
}
|