libuv/test/task.h
Jameson Nash 34fff5a15b 2023.11.06, Version 1.47.0 (Stable)
Changes since version 1.46.0:
 
 * test: fix license blurb (Ben Noordhuis)
 
 * linux: fix harmless warn_unused_result warning (Shuduo Sang)
 
 * darwin: fix build warnings (小明)
 
 * linux: don't use io_uring on pre-5.10.186 kernels (Ben Noordhuis)
 
 * fs: fix WTF-8 decoding issue (Jameson Nash)
 
 * test: enable disabled tcp_connect6_error_fault (Ben Noordhuis)
 
 * test: enable disabled fs_link (Ben Noordhuis)
 
 * test: enable disabled spawn_same_stdout_stderr (Ben Noordhuis)
 
 * linux: handle UNAME26 personality (Ben Noordhuis)
 
 * build: move cmake_minimum_required version to 3.9 (Keith Winstein)
 
 * unix: set ipv6 scope id for link-local addresses (Ben Noordhuis)
 
 * unix: match kqueue and epoll code (Trevor Norris)
 
 * win,spawn: allow `%PATH%` to be unset (Kyle Edwards)
 
 * doc: switch to Furo, a more modern Sphinx theme (Saúl Ibarra Corretgé)
 
 * darwin: make TCP_KEEPINTVL and TCP_KEEPCNT available (小明)
 
 * win,fs: avoid winapi macro redefinition (Brad King)
 
 * linux: add missing riscv syscall numbers (michalbiesek)
 
 * doc: fix broken "Shared library" Wikipedia link (Alois Klink)
 
 * unix: get mainline kernel version in Ubuntu (Santiago Gimeno)
 
 * unix: get mainline kernel version in Debian (Ben Noordhuis)
 
 * build: fix qemu install in CI-unix workflow (Santiago Gimeno)
 
 * unix: disable io_uring close on selected kernels (Santiago Gimeno)
 
 * test: skip tests when ipv6 is not available (Santiago Gimeno)
 
 * ibmi: implement ifaddrs, getifaddrs, freeifaddrs (Abdirahim Musse)
 
 * unix: reset signal counters after fork (SmorkalovG)
 
 * win,process: avoid assert after spawning Store app (Jameson Nash)
 
 * unix: remove pread/preadv conditionals (Ben Noordhuis)
 
 * unix: remove pwrite/pwritev conditionals (Ben Noordhuis)
 
 * darwin: remove workaround for data corruption bug (Ben Noordhuis)
 
 * src: default to stream=stderr in handle printer (Ben Noordhuis)
 
 * test: switch to new-style ASSERT_EQ macros (Pleuvens)
 
 * zos: correctly get cpu model in uv_cpu_info() (jolai)
 
 * test: fix get_passwd2 on IBM i (Abdirahim Musse)
 
 * unix: don't malloc on sync uv_fs_read (Ben Noordhuis)
 
 * freebsd: get fs event path with fcntl(F_KINFO) (David Carlier)
 
 * test: switch from ASSERT_* to ASSERT_PTR_* (Pleuvens)
 
 * darwin: workaround apple pthread_cond_wait bug (Julien Roncaglia)
 
 * doc: uv_close should be called after exit callback (Pleuvens)
 
 * test: 192.0.2.0/24 is the actual -TEST-NET-1 (prubel)
 
 * unix: add back preadv/pwritev fallback (Ben Noordhuis)
 
 * unix: rename variable for consistency (Ben Noordhuis)
 
 * unix: merge read/write code into single functions (Ben Noordhuis)
 
 * doc: filename arg to uv_fs_event_cb can be NULL (Ben Noordhuis)
 
 * build,win: we need to link against shell32.lib (Per Allansson)
 
 * unix: no preadv/pwritev workaround if not needed (Jeffrey H. Johnson)
 
 * build: add CI for Windows ARM64 (build only) (Per Allansson)
 
 * linux: disable io_uring on 32 bits arm systems (Ben Noordhuis)
 
 * build: run sanitizers on macos ci (Ben Noordhuis)
 
 * misc: export WTF8 conversion utilities (Jameson Nash)
 
 * build: fix libuv.a file name for cmake (Jameson Nash)
 
 * build: add windows ubsan and clang ci (Matheus Izvekov)
 
 * win: improve accuracy of ProductName between arch (Christian Heimlich)
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEz7ucqaW+r9cOKzxaeaZ8VaNnnIsFAmVJLa4ACgkQeaZ8VaNn
 nIvdMw//XQzU1OasKcghWZZAFmrgy8D+40Q5drSgCFryAA+WA9wXruKOeqQ3vw7+
 9Xwai97fMbxGSFhR2IwjbwD8o8DZotDTMBgSUvuyAlzdw0xB2D+eAnvxaMmYg2km
 R5eNb2KgmzhC7HFuPbpjWbL1mEnBU8rTSzV6yeMs2LXfLquJoopmgAjB2MXS6/Fr
 +WkwJx7/B/3wEhhbX5sopd6PT8UcWdbSvB/S+PU12kI0KgJeJlq0jXd5LyDaQYI6
 j4XYcpgEp8B/gyiXSgso+eg1CiZQUYVMXZ5+6YA5le/s5ieJwJ2cEvo/HJa5guZ/
 PBb+ulucUaupBzQFaPYwnrEzE3YHNVppBcfryxqn48Ih0Z9pNs/6EdxqggYvAyWk
 VA9Yi0qDFSFgD0hZSkvi/m/UEH17FLTac1DSob4EKfwAJ04spmEtiBWaL+7wQ/ca
 Kc819NXBaFUb+BEkN711B1CvaT6aef9wZcis42MPHjHJ19BNgb4uAa3GbmrvB2dt
 EodLGlbOAkKLFC29qAGeKZKhnSWfZS/HvuyqMOgONuJTj0Jm/RdwqIsvILejtj32
 7m9saTkRWav4L1yvksUYT24WIk1e324gBgm9411IggdDILgbLYrwWNZb56FgMDQb
 cqmg0Ap6zMZ9UOf4hfqTiKZPjqqfxgSp20zCjVTy+vsCSXJnFaQ=
 =7yzD
 -----END PGP SIGNATURE-----

Merge tag 'v1.47.0' into merge_1.47.0
2023-11-21 18:41:12 +00:00

372 lines
15 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.
*/
#ifndef TASK_H_
#define TASK_H_
#include "uv.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <stdint.h>
#if !defined(_WIN32)
# include <sys/time.h>
# include <sys/resource.h> /* setrlimit() */
#endif
#define TEST_PORT 9123
#define TEST_PORT_2 9124
#define TEST_PORT_3 9125
#ifdef _WIN32
# define TEST_PIPENAME "\\\\.\\pipe\\uv-test"
# define TEST_PIPENAME_2 "\\\\.\\pipe\\uv-test2"
# define TEST_PIPENAME_3 "\\\\.\\pipe\\uv-test3"
#else
# define TEST_PIPENAME "/tmp/uv-test-sock"
# define TEST_PIPENAME_2 "/tmp/uv-test-sock2"
# define TEST_PIPENAME_3 "/tmp/uv-test-sock3"
#endif
#ifdef _WIN32
# include <sys/stat.h>
# ifndef S_IRUSR
# define S_IRUSR _S_IREAD
# endif
# ifndef S_IWUSR
# define S_IWUSR _S_IWRITE
# endif
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define container_of(ptr, type, member) \
((type *) ((char *) (ptr) - offsetof(type, member)))
typedef enum {
TCP = 0,
UDP,
PIPE
} stream_type;
/* Die with fatal error. */
#define FATAL(msg) \
do { \
fprintf(stderr, \
"Fatal error in %s on line %d: %s\n", \
__FILE__, \
__LINE__, \
msg); \
fflush(stderr); \
abort(); \
} while (0)
/* Have our own assert, so we are sure it does not get optimized away in
* a release build.
*/
#define ASSERT(expr) \
do { \
if (!(expr)) { \
fprintf(stderr, \
"Assertion failed in %s on line %d: %s\n", \
__FILE__, \
__LINE__, \
#expr); \
abort(); \
} \
} while (0)
#define ASSERT_BASE(a, operator, b, type, conv) \
do { \
volatile type eval_a = (type) (a); \
volatile type eval_b = (type) (b); \
if (!(eval_a operator eval_b)) { \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` " \
"(%"conv" %s %"conv")\n", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b, \
eval_a, \
#operator, \
eval_b); \
abort(); \
} \
} while (0)
#define ASSERT_BASE_STR(expr, a, operator, b, type, conv) \
do { \
if (!(expr)) { \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` " \
"(%"conv" %s %"conv")\n", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b, \
(type)a, \
#operator, \
(type)b); \
abort(); \
} \
} while (0)
#define ASSERT_BASE_LEN(expr, a, operator, b, conv, len) \
do { \
if (!(expr)) { \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` " \
"(%.*"#conv" %s %.*"#conv")\n", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b, \
(int)len, \
a, \
#operator, \
(int)len, \
b); \
abort(); \
} \
} while (0)
#define ASSERT_BASE_HEX(expr, a, operator, b, size) \
do { \
if (!(expr)) { \
int i; \
unsigned char* a_ = (unsigned char*)a; \
unsigned char* b_ = (unsigned char*)b; \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` (", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b); \
for (i = 0; i < size; ++i) { \
if (i > 0) fprintf(stderr, ":"); \
fprintf(stderr, "%02X", a_[i]); \
} \
fprintf(stderr, " %s ", #operator); \
for (i = 0; i < size; ++i) { \
if (i > 0) fprintf(stderr, ":"); \
fprintf(stderr, "%02X", b_[i]); \
} \
fprintf(stderr, ")\n"); \
abort(); \
} \
} while (0)
#define ASSERT_EQ(a, b) ASSERT_BASE(a, ==, b, int64_t, PRId64)
#define ASSERT_GE(a, b) ASSERT_BASE(a, >=, b, int64_t, PRId64)
#define ASSERT_GT(a, b) ASSERT_BASE(a, >, b, int64_t, PRId64)
#define ASSERT_LE(a, b) ASSERT_BASE(a, <=, b, int64_t, PRId64)
#define ASSERT_LT(a, b) ASSERT_BASE(a, <, b, int64_t, PRId64)
#define ASSERT_NE(a, b) ASSERT_BASE(a, !=, b, int64_t, PRId64)
#define ASSERT_OK(a) ASSERT_BASE(a, ==, 0, int64_t, PRId64)
#define ASSERT_UINT64_EQ(a, b) ASSERT_BASE(a, ==, b, uint64_t, PRIu64)
#define ASSERT_UINT64_GE(a, b) ASSERT_BASE(a, >=, b, uint64_t, PRIu64)
#define ASSERT_UINT64_GT(a, b) ASSERT_BASE(a, >, b, uint64_t, PRIu64)
#define ASSERT_UINT64_LE(a, b) ASSERT_BASE(a, <=, b, uint64_t, PRIu64)
#define ASSERT_UINT64_LT(a, b) ASSERT_BASE(a, <, b, uint64_t, PRIu64)
#define ASSERT_UINT64_NE(a, b) ASSERT_BASE(a, !=, b, uint64_t, PRIu64)
#define ASSERT_DOUBLE_EQ(a, b) ASSERT_BASE(a, ==, b, double, "f")
#define ASSERT_DOUBLE_GE(a, b) ASSERT_BASE(a, >=, b, double, "f")
#define ASSERT_DOUBLE_GT(a, b) ASSERT_BASE(a, >, b, double, "f")
#define ASSERT_DOUBLE_LE(a, b) ASSERT_BASE(a, <=, b, double, "f")
#define ASSERT_DOUBLE_LT(a, b) ASSERT_BASE(a, <, b, double, "f")
#define ASSERT_DOUBLE_NE(a, b) ASSERT_BASE(a, !=, b, double, "f")
#define ASSERT_STR_EQ(a, b) \
ASSERT_BASE_STR(strcmp(a, b) == 0, a, == , b, char*, "s")
#define ASSERT_STR_NE(a, b) \
ASSERT_BASE_STR(strcmp(a, b) != 0, a, !=, b, char*, "s")
#define ASSERT_MEM_EQ(a, b, size) \
ASSERT_BASE_LEN(memcmp(a, b, size) == 0, a, ==, b, s, size)
#define ASSERT_MEM_NE(a, b, size) \
ASSERT_BASE_LEN(memcmp(a, b, size) != 0, a, !=, b, s, size)
#define ASSERT_MEM_HEX_EQ(a, b, size) \
ASSERT_BASE_HEX(memcmp(a, b, size) == 0, a, ==, b, size)
#define ASSERT_MEM_HEX_NE(a, b, size) \
ASSERT_BASE_HEX(memcmp(a, b, size) != 0, a, !=, b, size)
#define ASSERT_NULL(a) \
ASSERT_BASE(a, ==, NULL, void*, "p")
#define ASSERT_NOT_NULL(a) \
ASSERT_BASE(a, !=, NULL, void*, "p")
#define ASSERT_PTR_EQ(a, b) \
ASSERT_BASE(a, ==, b, void*, "p")
#define ASSERT_PTR_NE(a, b) \
ASSERT_BASE(a, !=, b, void*, "p")
#define ASSERT_PTR_LT(a, b) \
ASSERT_BASE(a, <, b, void*, "p")
/* This macro cleans up the event loop. This is used to avoid valgrind
* warnings about memory being "leaked" by the event loop.
*/
#define MAKE_VALGRIND_HAPPY(loop) \
do { \
close_loop(loop); \
ASSERT_EQ(0, uv_loop_close(loop)); \
uv_library_shutdown(); \
} while (0)
/* Just sugar for wrapping the main() for a task or helper. */
#define TEST_IMPL(name) \
int run_test_##name(void); \
int run_test_##name(void)
#define BENCHMARK_IMPL(name) \
int run_benchmark_##name(void); \
int run_benchmark_##name(void)
#define HELPER_IMPL(name) \
int run_helper_##name(void); \
int run_helper_##name(void)
/* Format big numbers nicely. */
char* fmt(char (*buf)[32], double d);
/* Reserved test exit codes. */
enum test_status {
TEST_OK = 0,
TEST_SKIP = 7
};
#define RETURN_OK() \
do { \
return TEST_OK; \
} while (0)
#define RETURN_SKIP(explanation) \
do { \
fprintf(stderr, "%s\n", explanation); \
fflush(stderr); \
return TEST_SKIP; \
} while (0)
#if !defined(_WIN32)
# define TEST_FILE_LIMIT(num) \
do { \
struct rlimit lim; \
lim.rlim_cur = (num); \
lim.rlim_max = lim.rlim_cur; \
if (setrlimit(RLIMIT_NOFILE, &lim)) \
RETURN_SKIP("File descriptor limit too low."); \
} while (0)
#else /* defined(_WIN32) */
# define TEST_FILE_LIMIT(num) do {} while (0)
#endif
#if defined(__clang__) || \
defined(__GNUC__) || \
defined(__INTEL_COMPILER)
# define UNUSED __attribute__((unused))
#else
# define UNUSED
#endif
#if defined(_WIN32)
#define notify_parent_process() ((void) 0)
#else
extern void notify_parent_process(void);
#endif
/* Fully close a loop */
static void close_walk_cb(uv_handle_t* handle, void* arg) {
if (!uv_is_closing(handle))
uv_close(handle, NULL);
}
UNUSED static void close_loop(uv_loop_t* loop) {
uv_walk(loop, close_walk_cb, NULL);
uv_run(loop, UV_RUN_DEFAULT);
}
UNUSED static int can_ipv6(void) {
uv_interface_address_t* addr;
int supported;
int count;
int i;
if (uv_interface_addresses(&addr, &count))
return 0; /* Assume no IPv6 support on failure. */
supported = 0;
for (i = 0; supported == 0 && i < count; i += 1)
supported = (AF_INET6 == addr[i].address.address6.sin6_family);
uv_free_interface_addresses(addr, count);
return supported;
}
#if defined(__CYGWIN__) || defined(__MSYS__) || defined(__PASE__)
# define NO_FS_EVENTS "Filesystem watching not supported on this platform."
#endif
#if defined(__MSYS__)
# define NO_SEND_HANDLE_ON_PIPE \
"MSYS2 runtime does not support sending handles on pipes."
#elif defined(__CYGWIN__)
# define NO_SEND_HANDLE_ON_PIPE \
"Cygwin runtime does not support sending handles on pipes."
#endif
#if defined(__MSYS__)
# define NO_SELF_CONNECT \
"MSYS2 runtime hangs on listen+connect in same process."
#elif defined(__CYGWIN__)
# define NO_SELF_CONNECT \
"Cygwin runtime hangs on listen+connect in same process."
#endif
#if !defined(__linux__) && \
!(defined(__FreeBSD__) && __FreeBSD_version >= 1301000) && \
!defined(_WIN32)
# define NO_CPU_AFFINITY \
"affinity not supported on this platform."
#endif
#endif /* TASK_H_ */