libuv/test/runner-win.c
Jameson Nash 29a708a434 2024.02.07, Version 1.48.0 (Stable)
Changes since version 1.47.0:
 
 * misc: remove deprecated stalebot file (Jameson Nash)
 
 * build: disable windows asan buildbot (Ben Noordhuis)
 
 * test: don't run tcp_writealot under msan (Ben Noordhuis)
 
 * build,win: remove extraneous -lshell32 (Ben Noordhuis)
 
 * unix: ignore ifaddrs with NULL ifa_addr (Stephen Gallagher)
 
 * unix,win: utility for setting priority for thread (Hao Hu)
 
 * pipe: add back error handling to connect / bind (Jameson Nash)
 
 * test: check if ipv6 link-local traffic is routable (Ben Noordhuis)
 
 * win: remove check for UV_PIPE_NO_TRUNCATE (Jameson Nash)
 
 * linux: disable io_uring on hppa below kernel 6.1.51 (matoro)
 
 * unix,win: fix read past end of pipe name buffer (Ben Noordhuis)
 
 * unix: unbreak macOS < 10.14 (Sergey Fedorov)
 
 * aix: disable ipv6 link local (Abdirahim Musse)
 
 * doc: move cjihrig to emeriti (cjihrig)
 
 * unix: correct pwritev conditional (Bo Anderson)
 
 * test_fs.c: Fix issue on 32-bit systems using btrfs (Stephen Gallagher)
 
 * misc: ignore libuv-release-tool files (Jameson Nash)
 
 * win: honor NoDefaultCurrentDirectoryInExePath env var (Ardi Nugraha)
 
 * idna: fix compilation warning (Saúl Ibarra Corretgé)
 
 * linux: remove HAVE_IFADDRS_H macro (Ben Noordhuis)
 
 * test: skip tcp-write-in-a-row on IBM i (Abdirahim Musse)
 
 * build,win: work around missing uuid.dll on MinGW (Anton Bachin)
 
 * win: stop using deprecated names (Matheus Izvekov)
 
 * unix,win: fix busy loop with zero timeout timers (Matheus Izvekov)
 
 * aix,ibmi: use uv_interface_addresses instead of getifaddrs (Abdirahim Musse)
 
 * linux: fix bind/connect for abstract sockets (Santiago Gimeno)
 
 * win: replace c99 comments with c89 comments (Trevor Flynn)
 
 * build: add .cache clangd folder to .gitignore (Juan José Arboleda)
 
 * unix: support full TCP keep-alive on Solaris (Andy Pan)
 
 * freebsd: fix F_KINFO file path handling (David Carlier)
 
 * linux: retry fs op if unsupported by io_uring (Santiago Gimeno)
 
 * freebsd: fix build on non-intel archs (David Carlier)
 
 * unix: optimize uv__tcp_keepalive cpp directives (Andy Pan)
 
 * linux: disable io_uring on ppc64 and ppc64le (Brad King)
 
 * doc: add very basic Security Policy document (Santiago Gimeno)
 
 * build: re-enable msvc-asan job on CI (Jameson Nash)
 
 * win/spawn: optionally run executable paths with no file extension (Brad King)
 
 * win: fix ESRCH implementation (Jameson Nash)
 
 * unix,win: reset the timer queue on stop (Santiago Gimeno)
 
 * fix: always zero-terminate idna output (Ben Noordhuis)
 
 * fix: reject zero-length idna inputs (Ben Noordhuis)
 
 * test: empty strings are not valid IDNA (Santiago Gimeno)
 
 * Merge pull request from GHSA-f74f-cvh7-c6q6 (Ben Noordhuis)
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEYS8OrZQBYiN530QC8ow8jaM8A74FAmXD5fwACgkQ8ow8jaM8
 A76H+g/9F2O6hXWfm5LACvIRhcDovK1NLprTp5Ae5qA9klSDzClxi6n7/B9NtDhv
 X2EwEXhQpc/Y600dbfcmKr6P5Gt2FDhjO3iy9gCrkUN+ZHV7kRCb8dmp+eyGcOag
 uKqkkpZN6aiT0Jp4H4x66VnSotvLeilHzs16+A3/r5wUNmqzhj0cG/UVaDyZfYEH
 NCqv5MFw2N9qO5lnsu2g1sDEujnjWhXUcY9D1vVUDf63CU09n+lz1LKRB5LKEGRy
 bPF/IjuxJAJQA+gsgj1dP2nuUH8IGhNOpkQ2WG8wEuPp6hahGvND4YovP/sDY7pV
 9oo+73v1boAlYVS9IhAINVnKiPJx7tHJQvMcmgezSBCrd6v+PoWfL4A9oAWOp1qX
 ju+PC2Xk7E9Kt5gC9hjDzdMt6nw7Ab5pJ3ZcVF/2Sq27w0T4nxAOOpAt7JnJ53ug
 o26RWlO9NvBe30Uh2fwqye1UuL17Qjo7Y+ztrMQGmeV+RW693xqZ/bnVOhQupfqI
 fJNl1BBgInT9IU+A8ZtHeDuRf04hEit0rzS/yGrcHa1bHEHorG5W52nazYIsQURM
 hwWBDQ2dH2iTogHGdQ/CKdMGwuo+RwCavBXCHu03jf10hy+ImHF5ifJA7WLeH0oF
 QlCmeJl/26sOHlEa7wQnjhzh7YNg6JDuq6K22a9iR5vnduK1ByU=
 =67rH
 -----END PGP SIGNATURE-----

Merge tag 'v1.48.0' into merge_1.48.0
2024-02-09 19:52:08 +00:00

336 lines
8.0 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 <fcntl.h>
#include <io.h>
#include <malloc.h>
#include <stdio.h>
#include <process.h>
#include <crtdbg.h>
#include "task.h"
#include "runner.h"
/* Do platform-specific initialization. */
void platform_init(int argc, char **argv) {
/* Disable the "application crashed" popup. */
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
SEM_NOOPENFILEERRORBOX);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
/* make output mode sane */
_fmode = _O_BINARY;
_setmode(0, _O_BINARY);
_setmode(1, _O_BINARY);
_setmode(2, _O_BINARY);
#ifdef _MSC_VER
_set_fmode(_O_BINARY);
#else
_fmode = _O_BINARY;
#endif
/* Disable stdio output buffering. */
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
strcpy(executable_path, argv[0]);
}
int process_start(char *name, char *part, process_info_t *p, int is_helper) {
HANDLE file = INVALID_HANDLE_VALUE;
HANDLE nul = INVALID_HANDLE_VALUE;
WCHAR path[MAX_PATH], filename[MAX_PATH];
WCHAR image[MAX_PATH + 1];
WCHAR args[MAX_PATH * 2];
STARTUPINFOW si;
PROCESS_INFORMATION pi;
DWORD result;
if (!is_helper) {
/* Give the helpers time to settle. Race-y, fix this. */
uv_sleep(250);
}
if (GetTempPathW(sizeof(path) / sizeof(WCHAR), (WCHAR*)&path) == 0)
goto error;
if (GetTempFileNameW((WCHAR*)&path, L"uv", 0, (WCHAR*)&filename) == 0)
goto error;
file = CreateFileW((WCHAR*)filename,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
NULL);
if (file == INVALID_HANDLE_VALUE)
goto error;
if (!SetHandleInformation(file, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
goto error;
nul = CreateFileA("nul",
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (nul == INVALID_HANDLE_VALUE)
goto error;
if (!SetHandleInformation(nul, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))
goto error;
result = GetModuleFileNameW(NULL,
(WCHAR*) &image,
sizeof(image) / sizeof(WCHAR));
if (result == 0 || result == sizeof(image))
goto error;
if (part) {
if (_snwprintf((WCHAR*)args,
sizeof(args) / sizeof(WCHAR),
L"\"%s\" %S %S",
image,
name,
part) < 0) {
goto error;
}
} else {
if (_snwprintf((WCHAR*)args,
sizeof(args) / sizeof(WCHAR),
L"\"%s\" %S",
image,
name) < 0) {
goto error;
}
}
memset((void*)&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = nul;
si.hStdOutput = file;
si.hStdError = file;
if (!CreateProcessW(image, args, NULL, NULL, TRUE,
0, NULL, NULL, &si, &pi))
goto error;
CloseHandle(pi.hThread);
SetHandleInformation(nul, HANDLE_FLAG_INHERIT, 0);
SetHandleInformation(file, HANDLE_FLAG_INHERIT, 0);
p->stdio_in = nul;
p->stdio_out = file;
p->process = pi.hProcess;
p->name = part;
return 0;
error:
if (file != INVALID_HANDLE_VALUE)
CloseHandle(file);
if (nul != INVALID_HANDLE_VALUE)
CloseHandle(nul);
return -1;
}
/* Timeout is in msecs. Set timeout < 0 to never time out. Returns 0 when all
* processes are terminated, -2 on timeout. */
int process_wait(process_info_t *vec, int n, int timeout) {
int i;
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
DWORD timeout_api, result;
/* If there's nothing to wait for, return immediately. */
if (n == 0)
return 0;
ASSERT_LE(n, MAXIMUM_WAIT_OBJECTS);
for (i = 0; i < n; i++)
handles[i] = vec[i].process;
if (timeout >= 0) {
timeout_api = (DWORD)timeout;
} else {
timeout_api = INFINITE;
}
result = WaitForMultipleObjects(n, handles, TRUE, timeout_api);
if (result < WAIT_OBJECT_0 + n) {
/* All processes are terminated. */
return 0;
}
if (result == WAIT_TIMEOUT) {
return -2;
}
return -1;
}
long int process_output_size(process_info_t *p) {
LARGE_INTEGER size;
if (!GetFileSizeEx(p->stdio_out, &size))
return -1;
return (long int)size.QuadPart;
}
int process_copy_output(process_info_t* p, FILE* stream) {
char buf[1024];
int fd, r;
fd = _open_osfhandle((intptr_t)p->stdio_out, _O_RDONLY | _O_TEXT);
if (fd == -1)
return -1;
r = _lseek(fd, 0, SEEK_SET);
if (r < 0)
return -1;
while ((r = _read(fd, buf, sizeof(buf))) != 0)
print_lines(buf, r, stream);
_close(fd);
return 0;
}
int process_read_last_line(process_info_t *p,
char * buffer,
size_t buffer_len) {
DWORD size;
DWORD read;
DWORD start;
OVERLAPPED overlapped;
ASSERT_GT(buffer_len, 0);
size = GetFileSize(p->stdio_out, NULL);
if (size == INVALID_FILE_SIZE)
return -1;
if (size == 0) {
buffer[0] = '\0';
return 1;
}
memset(&overlapped, 0, sizeof overlapped);
if (size >= buffer_len)
overlapped.Offset = size - buffer_len - 1;
if (!ReadFile(p->stdio_out, buffer, buffer_len - 1, &read, &overlapped))
return -1;
start = read;
while (start-- > 0) {
if (buffer[start] == '\n' || buffer[start] == '\r')
break;
}
if (start > 0)
memmove(buffer, buffer + start, read - start);
buffer[read - start] = '\0';
return 0;
}
char* process_get_name(process_info_t *p) {
return p->name;
}
int process_terminate(process_info_t *p) {
if (!TerminateProcess(p->process, 1))
return -1;
return 0;
}
int process_reap(process_info_t *p) {
DWORD exitCode;
if (!GetExitCodeProcess(p->process, &exitCode))
return -1;
return (int)exitCode;
}
void process_cleanup(process_info_t *p) {
CloseHandle(p->process);
CloseHandle(p->stdio_in);
}
static int clear_line(void) {
HANDLE handle;
CONSOLE_SCREEN_BUFFER_INFO info;
COORD coord;
DWORD written;
handle = (HANDLE)_get_osfhandle(_fileno(stderr));
if (handle == INVALID_HANDLE_VALUE)
return -1;
if (!GetConsoleScreenBufferInfo(handle, &info))
return -1;
coord = info.dwCursorPosition;
if (coord.Y <= 0)
return -1;
coord.X = 0;
if (!SetConsoleCursorPosition(handle, coord))
return -1;
if (!FillConsoleOutputCharacterW(handle,
0x20,
info.dwSize.X,
coord,
&written)) {
return -1;
}
return 0;
}
void rewind_cursor() {
if (clear_line() == -1) {
/* If clear_line fails (stdout is not a console), print a newline. */
fprintf(stderr, "\n");
}
}