libuv 1.47.0.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4615 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-11-07 17:30:39 +00:00
parent 889773c38d
commit ee9cb63327
226 changed files with 6648 additions and 6444 deletions

View File

@ -355,6 +355,7 @@ $(UV_OBJS): CFLAGS += \
-Wno-incompatible-pointer-types \ -Wno-incompatible-pointer-types \
-Wno-maybe-uninitialized \ -Wno-maybe-uninitialized \
-Wno-sign-compare \ -Wno-sign-compare \
-Wno-unused-but-set-parameter \
-Wno-unused-but-set-variable \ -Wno-unused-but-set-variable \
-Wno-unused-result \ -Wno-unused-result \
-Wno-unused-variable -Wno-unused-variable

View File

@ -125,7 +125,7 @@ jobs:
# this ensure install latest qemu on ubuntu, apt get version is old # this ensure install latest qemu on ubuntu, apt get version is old
env: env:
QEMU_SRC: "http://archive.ubuntu.com/ubuntu/pool/universe/q/qemu" QEMU_SRC: "http://archive.ubuntu.com/ubuntu/pool/universe/q/qemu"
QEMU_VER: "qemu-user-static_7\\.0+dfsg-.*_amd64.deb$" QEMU_VER: "qemu-user-static_7\\.2+dfsg-.*_amd64.deb$"
run: | run: |
DEB=`curl -s $QEMU_SRC/ | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | grep $QEMU_VER | tail -1` DEB=`curl -s $QEMU_SRC/ | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | grep $QEMU_VER | tail -1`
wget $QEMU_SRC/$DEB wget $QEMU_SRC/$DEB

View File

@ -26,6 +26,8 @@ jobs:
- {toolchain: Visual Studio 17 2022, arch: Win32, server: 2022} - {toolchain: Visual Studio 17 2022, arch: Win32, server: 2022}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022} - {toolchain: Visual Studio 17 2022, arch: x64, server: 2022}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022, config: ASAN} - {toolchain: Visual Studio 17 2022, arch: x64, server: 2022, config: ASAN}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022, config: UBSAN}
- {toolchain: Visual Studio 17 2022, arch: arm64, server: 2022}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Envinfo - name: Envinfo
@ -35,30 +37,33 @@ jobs:
run: run:
cmake -S . -B build -DBUILD_TESTING=ON cmake -S . -B build -DBUILD_TESTING=ON
-G "${{ matrix.config.toolchain }}" -A ${{ matrix.config.arch }} -G "${{ matrix.config.toolchain }}" -A ${{ matrix.config.arch }}
${{ matrix.config.config == 'ASAN' && '-DASAN=on -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded' || '' }} ${{ matrix.config.config == 'ASAN' && '-DASAN=on -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded' ||
matrix.config.config == 'UBSAN' && '-DUBSAN=on' || '' }}
cmake --build build --config RelWithDebInfo cmake --build build --config RelWithDebInfo
ls -l build ls -l build
- name: platform_output - name: platform_output
if: ${{ matrix.config.arch != 'arm64' }}
shell: cmd shell: cmd
run: run:
build\\RelWithDebInfo\\uv_run_tests.exe platform_output build\\RelWithDebInfo\\uv_run_tests.exe platform_output
- name: platform_output_a - name: platform_output_a
if: ${{ matrix.config.arch != 'arm64' }}
shell: cmd shell: cmd
run: run:
build\\RelWithDebInfo\\uv_run_tests_a.exe platform_output build\\RelWithDebInfo\\uv_run_tests_a.exe platform_output
- name: Test - name: Test
# only valid with libuv-master with the fix for # only valid with libuv-master with the fix for
# https://github.com/libuv/leps/blob/master/005-windows-handles-not-fd.md # https://github.com/libuv/leps/blob/master/005-windows-handles-not-fd.md
if: ${{ matrix.config.config != 'ASAN' }} if: ${{ matrix.config.config != 'ASAN' && matrix.config.arch != 'arm64' }}
shell: cmd shell: cmd
run: run:
cd build cd build
ctest -C RelWithDebInfo -V ctest -C RelWithDebInfo -V
- name: Test only static - name: Test only static
if: ${{ matrix.config.config == 'ASAN' }} if: ${{ matrix.config.config == 'ASAN' && matrix.config.arch != 'arm64' }}
shell: cmd shell: cmd
run: run:
build\\RelWithDebInfo\\uv_run_tests_a.exe build\\RelWithDebInfo\\uv_run_tests_a.exe

View File

@ -13,7 +13,7 @@ on:
- master - master
jobs: jobs:
sanitizers: sanitizers-linux:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -60,3 +60,64 @@ jobs:
- name: UBSAN Test - name: UBSAN Test
run: | run: |
./build-ubsan/uv_run_tests_a ./build-ubsan/uv_run_tests_a
sanitizers-macos:
runs-on: macos-11
steps:
- uses: actions/checkout@v2
- name: Envinfo
run: npx envinfo
- name: ASAN Build
run: |
mkdir build-asan
(cd build-asan && cmake .. -DBUILD_TESTING=ON -DASAN=ON -DCMAKE_BUILD_TYPE=Debug)
cmake --build build-asan
- name: ASAN Test
run: |
./build-asan/uv_run_tests_a
- name: TSAN Build
run: |
mkdir build-tsan
(cd build-tsan && cmake .. -DBUILD_TESTING=ON -DTSAN=ON -DCMAKE_BUILD_TYPE=Release)
cmake --build build-tsan
- name: TSAN Test
run: |
./build-tsan/uv_run_tests_a
- name: UBSAN Build
run: |
mkdir build-ubsan
(cd build-ubsan && cmake .. -DBUILD_TESTING=ON -DUBSAN=ON -DCMAKE_BUILD_TYPE=Debug)
cmake --build build-ubsan
- name: UBSAN Test
run: |
./build-ubsan/uv_run_tests_a
sanitizers-windows:
runs-on: windows-2022
steps:
- uses: actions/checkout@v2
- name: Setup
run: |
choco install ninja
# Note: clang shipped with VS2022 has an issue where the UBSAN runtime doesn't link.
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
version: "17"
- name: Envinfo
run: npx envinfo
- name: UBSAN Build
run: |
mkdir build-ubsan
cmake -B build-ubsan -G Ninja -DBUILD_TESTING=ON -DUBSAN=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang
cmake --build build-ubsan
- name: UBSAN Test
run: |
./build-ubsan/uv_run_tests_a

12
deps/libuv/AUTHORS vendored
View File

@ -548,3 +548,15 @@ liuxiang88 <94350585+liuxiang88@users.noreply.github.com>
Jeffrey H. Johnson <trnsz@pobox.com> Jeffrey H. Johnson <trnsz@pobox.com>
Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Abdirahim Musse <33973272+abmusse@users.noreply.github.com>
小明 <7737673+caobug@users.noreply.github.com> 小明 <7737673+caobug@users.noreply.github.com>
Shuduo Sang <sangshuduo@gmail.com>
Keith Winstein <keithw@cs.stanford.edu>
michalbiesek <michalbiesek@gmail.com>
Alois Klink <alois@aloisklink.com>
SmorkalovG <smorkalov.g@gmail.com>
Pleuvens <pleuvens.fervil@gmail.com>
jolai <58589285+laijonathan@users.noreply.github.com>
Julien Roncaglia <fox@vbfox.net>
prubel <paul@rubels.net>
Per Allansson <65364157+per-allansson@users.noreply.github.com>
Matheus Izvekov <mizvekov@gmail.com>
Christian Heimlich <chris@pcserenity.com>

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.4) cmake_minimum_required(VERSION 3.9)
if(POLICY CMP0091) if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW) # Enable MSVC_RUNTIME_LIBRARY setting cmake_policy(SET CMP0091 NEW) # Enable MSVC_RUNTIME_LIBRARY setting
@ -186,7 +186,8 @@ if(WIN32)
ws2_32 ws2_32
dbghelp dbghelp
ole32 ole32
uuid) uuid
shell32)
list(APPEND uv_sources list(APPEND uv_sources
src/win/async.c src/win/async.c
src/win/core.c src/win/core.c
@ -477,7 +478,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
endif() endif()
target_link_libraries(uv_a ${uv_libraries}) target_link_libraries(uv_a ${uv_libraries})
set_target_properties(uv_a PROPERTIES OUTPUT_NAME "uv") set_target_properties(uv_a PROPERTIES OUTPUT_NAME "uv")
if(MSVC) if(WIN32)
set_target_properties(uv_a PROPERTIES PREFIX "lib") set_target_properties(uv_a PROPERTIES PREFIX "lib")
endif() endif()

111
deps/libuv/ChangeLog vendored
View File

@ -1,4 +1,113 @@
2023.06.30, Version 1.46.0 (Stable) 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)
2023.06.30, Version 1.46.0 (Stable), f0bb7e40f0508bedf6fad33769b3f87bb8aedfa6
Changes since version 1.45.0: Changes since version 1.45.0:

View File

@ -13,7 +13,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_PREREQ(2.57) AC_PREREQ(2.57)
AC_INIT([libuv], [1.46.0], [https://github.com/libuv/libuv/issues]) AC_INIT([libuv], [1.47.0], [https://github.com/libuv/libuv/issues])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/libuv-extra-automake-flags.m4]) m4_include([m4/libuv-extra-automake-flags.m4])
m4_include([m4/as_case.m4]) m4_include([m4/as_case.m4])
@ -74,7 +74,7 @@ AM_CONDITIONAL([OS400], [AS_CASE([$host_os],[os400], [true], [false])
AM_CONDITIONAL([SUNOS], [AS_CASE([$host_os],[solaris*], [true], [false])]) AM_CONDITIONAL([SUNOS], [AS_CASE([$host_os],[solaris*], [true], [false])])
AM_CONDITIONAL([WINNT], [AS_CASE([$host_os],[mingw*], [true], [false])]) AM_CONDITIONAL([WINNT], [AS_CASE([$host_os],[mingw*], [true], [false])])
AS_CASE([$host_os],[mingw*], [ AS_CASE([$host_os],[mingw*], [
LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32 -ldbghelp -lole32 -luuid" LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32 -ldbghelp -lole32 -luuid -lshell32"
]) ])
AS_CASE([$host_os], [solaris2.10], [ AS_CASE([$host_os], [solaris2.10], [
CFLAGS="$CFLAGS -DSUNOS_NO_IFADDRS" CFLAGS="$CFLAGS -DSUNOS_NO_IFADDRS"

View File

@ -1,27 +1,36 @@
# primary # primary
sphinx==6.1.3 furo==2023.5.20
Sphinx==6.1.3
# dependencies # dependencies
alabaster==0.7.13 alabaster==0.7.13
Babel==2.11.0 Babel==2.11.0
beautifulsoup4==4.12.2
certifi==2022.12.7 certifi==2022.12.7
charset-normalizer==3.0.1 charset-normalizer==3.0.1
colorama==0.4.6
docutils==0.19 docutils==0.19
idna==3.4 idna==3.4
imagesize==1.4.1 imagesize==1.4.1
importlib-metadata==6.0.0 importlib-metadata==6.0.0
Jinja2==3.1.2 Jinja2==3.1.2
livereload==2.6.3
MarkupSafe==2.1.2 MarkupSafe==2.1.2
packaging==23.0 packaging==23.0
Pygments==2.14.0 Pygments==2.14.0
pytz==2022.7.1 pytz==2022.7.1
requests==2.28.2 requests==2.28.2
six==1.16.0
snowballstemmer==2.2.0 snowballstemmer==2.2.0
sphinxcontrib-applehelp==1.0.3 soupsieve==2.4.1
sphinx-autobuild==2021.3.14
sphinx-basic-ng==1.0.0b2
sphinxcontrib-devhelp==1.0.2 sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0 sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1 sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3 sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5 sphinxcontrib-serializinghtml==1.1.5
sphinxcontrib.applehelp==1.0.3
tornado==6.3.2
urllib3==1.26.14 urllib3==1.26.14
zipp==3.11.0 zipp==3.11.0

View File

@ -118,7 +118,7 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
html_theme = 'nature' html_theme = 'furo'
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the

View File

@ -39,8 +39,12 @@ Data types
.. c:type:: void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename, int events, int status) .. c:type:: void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename, int events, int status)
Callback passed to :c:func:`uv_fs_event_start` which will be called repeatedly Callback passed to :c:func:`uv_fs_event_start` which will be called repeatedly
after the handle is started. If the handle was started with a directory the after the handle is started.
`filename` parameter will be a relative path to a file contained in the directory.
If the handle was started with a directory the `filename` parameter will
be a relative path to a file contained in the directory, or `NULL` if the
file name cannot be determined.
The `events` parameter is an ORed mask of :c:type:`uv_fs_event` elements. The `events` parameter is an ORed mask of :c:type:`uv_fs_event` elements.
.. c:type:: uv_fs_event .. c:type:: uv_fs_event

View File

@ -53,6 +53,8 @@ ID of the child process.
The exit callback will be invoked with the *exit status* and the type of *signal* The exit callback will be invoked with the *exit status* and the type of *signal*
which caused the exit. which caused the exit.
Note that it is important **not** to call ``uv_close`` before the exit callback.
.. rubric:: spawn/main.c .. rubric:: spawn/main.c
.. literalinclude:: ../../code/spawn/main.c .. literalinclude:: ../../code/spawn/main.c
:language: c :language: c
@ -126,7 +128,8 @@ of ``uv_kill`` is::
For processes started using libuv, you may use ``uv_process_kill`` instead, For processes started using libuv, you may use ``uv_process_kill`` instead,
which accepts the ``uv_process_t`` watcher as the first argument, rather than which accepts the ``uv_process_t`` watcher as the first argument, rather than
the pid. In this case, **remember to call** ``uv_close`` on the watcher. the pid. In this case, **remember to call** ``uv_close`` on the watcher _after_
the exit callback has been called.
Signals Signals
------- -------

View File

@ -363,7 +363,7 @@ to get the error message.
argument. ``init_plugin_function`` is a function pointer to the sort of argument. ``init_plugin_function`` is a function pointer to the sort of
function we are looking for in the application's plugins. function we are looking for in the application's plugins.
.. _shared libraries: https://en.wikipedia.org/wiki/Shared_library#Shared_libraries .. _shared libraries: https://en.wikipedia.org/wiki/Shared_library
TTY TTY
--- ---

View File

@ -839,3 +839,50 @@ API
Causes the calling thread to sleep for `msec` milliseconds. Causes the calling thread to sleep for `msec` milliseconds.
.. versionadded:: 1.34.0 .. versionadded:: 1.34.0
String manipulation functions
-----------------------------
These string utilities are needed internally for dealing with Windows, and are
exported to allow clients to work uniformly with this data when the libuv API
is not complete.
.. c:function:: size_t uv_utf16_length_as_wtf8(const uint16_t* utf16, ssize_t utf16_len)
Get the length of a UTF-16 (or UCS-2) `utf16` value after converting it to
WTF-8. If `utf16` is NUL terminated, `utf16_len` can be set to -1,
otherwise it must be specified.
.. versionadded:: 1.47.0
.. c:function:: int uv_utf16_to_wtf8(const uint16_t* utf16, ssize_t utf16_len, char** wtf8_ptr, size_t* wtf8_len_ptr)
Convert UTF-16 (or UCS-2) data in `utf16` to WTF-8 data in `*wtf8_ptr`. The
`utf16_len` count (in characters) gives the length of `utf16`. If `utf16`
is NUL terminated, `utf16_len` can be set to -1, otherwise it must be
specified. If `wtf8_ptr` is `NULL`, no result will be computed, but the
length (equal to `uv_utf16_length_as_wtf8`) will be stored in `wtf8_ptr`.
If `*wtf8_ptr` is `NULL`, space for the conversion will be allocated and
returned in `wtf8_ptr` and the length will be returned in `wtf8_len_ptr`.
Otherwise, the length of `*wtf8_ptr` must be passed in `wtf8_len_ptr`. The
`wtf8_ptr` must contain an extra space for an extra NUL after the result.
If the result is truncated, `UV_ENOBUFS` will be returned and
`wtf8_len_ptr` will be the length of the required `wtf8_ptr` to contain the
whole result.
.. versionadded:: 1.47.0
.. c:function:: ssize_t uv_wtf8_length_as_utf16(const char* wtf8)
Get the length in characters of a NUL-terminated WTF-8 `wtf8` value
after converting it to UTF-16 (or UCS-2), including NUL terminator.
.. versionadded:: 1.47.0
.. c:function:: void uv_wtf8_to_utf16(const char* utf8, uint16_t* utf16, size_t utf16_len)
Convert NUL-terminated WTF-8 data in `wtf8` to UTF-16 (or UCS-2) data
in `utf16`. The `utf16_len` count (in characters) must include space
for the NUL terminator.
.. versionadded:: 1.47.0

View File

@ -1885,6 +1885,18 @@ struct uv_loop_s {
UV_EXTERN void* uv_loop_get_data(const uv_loop_t*); UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data); UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
/* String utilities needed internally for dealing with Windows. */
size_t uv_utf16_length_as_wtf8(const uint16_t* utf16,
ssize_t utf16_len);
int uv_utf16_to_wtf8(const uint16_t* utf16,
ssize_t utf16_len,
char** wtf8_ptr,
size_t* wtf8_len_ptr);
ssize_t uv_wtf8_length_as_utf16(const char* wtf8);
void uv_wtf8_to_utf16(const char* wtf8,
uint16_t* utf16,
size_t utf16_len);
/* Don't export the private CPP symbols. */ /* Don't export the private CPP symbols. */
#undef UV_HANDLE_TYPE_PRIVATE #undef UV_HANDLE_TYPE_PRIVATE
#undef UV_REQ_TYPE_PRIVATE #undef UV_REQ_TYPE_PRIVATE

View File

@ -31,7 +31,7 @@
*/ */
#define UV_VERSION_MAJOR 1 #define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 46 #define UV_VERSION_MINOR 47
#define UV_VERSION_PATCH 0 #define UV_VERSION_PATCH 0
#define UV_VERSION_IS_RELEASE 1 #define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX "" #define UV_VERSION_SUFFIX ""

244
deps/libuv/src/idna.c vendored
View File

@ -1,4 +1,4 @@
/* Copyright (c) 2011, 2018 Ben Noordhuis <info@bnoordhuis.nl> /* Copyright libuv contributors. All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -18,11 +18,56 @@
*/ */
#include "uv.h" #include "uv.h"
#include "uv-common.h"
#include "idna.h" #include "idna.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <limits.h> /* UINT_MAX */ #include <limits.h> /* UINT_MAX */
static int32_t uv__wtf8_decode1(const char** input) {
uint32_t code_point;
uint8_t b1;
uint8_t b2;
uint8_t b3;
uint8_t b4;
b1 = **input;
if (b1 <= 0x7F)
return b1; /* ASCII code point */
if (b1 < 0xC2)
return -1; /* invalid: continuation byte */
code_point = b1;
b2 = *++*input;
if ((b2 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b2 & 0x3F);
if (b1 <= 0xDF)
return 0x7FF & code_point; /* two-byte character */
b3 = *++*input;
if ((b3 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b3 & 0x3F);
if (b1 <= 0xEF)
return 0xFFFF & code_point; /* three-byte character */
b4 = *++*input;
if ((b4 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b4 & 0x3F);
if (b1 <= 0xF4) {
code_point &= 0x1FFFFF;
if (code_point <= 0x10FFFF)
return code_point; /* four-byte character */
}
/* code point too large */
return -1;
}
static unsigned uv__utf8_decode1_slow(const char** p, static unsigned uv__utf8_decode1_slow(const char** p,
const char* pe, const char* pe,
unsigned a) { unsigned a) {
@ -89,6 +134,7 @@ static unsigned uv__utf8_decode1_slow(const char** p,
return a; return a;
} }
unsigned uv__utf8_decode1(const char** p, const char* pe) { unsigned uv__utf8_decode1(const char** p, const char* pe) {
unsigned a; unsigned a;
@ -102,6 +148,7 @@ unsigned uv__utf8_decode1(const char** p, const char* pe) {
return uv__utf8_decode1_slow(p, pe, a); return uv__utf8_decode1_slow(p, pe, a);
} }
static int uv__idna_toascii_label(const char* s, const char* se, static int uv__idna_toascii_label(const char* s, const char* se,
char** d, char* de) { char** d, char* de) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789"; static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789";
@ -267,7 +314,8 @@ static int uv__idna_toascii_label(const char* s, const char* se,
return 0; return 0;
} }
long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
ssize_t uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
const char* si; const char* si;
const char* st; const char* st;
unsigned c; unsigned c;
@ -313,3 +361,195 @@ long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
return d - ds; /* Number of bytes written. */ return d - ds; /* Number of bytes written. */
} }
ssize_t uv_wtf8_length_as_utf16(const char* source_ptr) {
size_t w_target_len = 0;
int32_t code_point;
do {
code_point = uv__wtf8_decode1(&source_ptr);
if (code_point < 0)
return -1;
if (code_point > 0xFFFF)
w_target_len++;
w_target_len++;
} while (*source_ptr++);
return w_target_len;
}
void uv_wtf8_to_utf16(const char* source_ptr,
uint16_t* w_target,
size_t w_target_len) {
int32_t code_point;
do {
code_point = uv__wtf8_decode1(&source_ptr);
/* uv_wtf8_length_as_utf16 should have been called and checked first. */
assert(code_point >= 0);
if (code_point > 0x10000) {
assert(code_point < 0x10FFFF);
*w_target++ = (((code_point - 0x10000) >> 10) + 0xD800);
*w_target++ = ((code_point - 0x10000) & 0x3FF) + 0xDC00;
w_target_len -= 2;
} else {
*w_target++ = code_point;
w_target_len -= 1;
}
} while (*source_ptr++);
assert(w_target_len == 0);
}
static int32_t uv__get_surrogate_value(const uint16_t* w_source_ptr,
ssize_t w_source_len) {
uint16_t u;
uint16_t next;
u = w_source_ptr[0];
if (u >= 0xD800 && u <= 0xDBFF && w_source_len != 1) {
next = w_source_ptr[1];
if (next >= 0xDC00 && next <= 0xDFFF)
return 0x10000 + ((u - 0xD800) << 10) + (next - 0xDC00);
}
return u;
}
size_t uv_utf16_length_as_wtf8(const uint16_t* w_source_ptr,
ssize_t w_source_len) {
size_t target_len;
int32_t code_point;
target_len = 0;
while (w_source_len) {
code_point = uv__get_surrogate_value(w_source_ptr, w_source_len);
/* Can be invalid UTF-8 but must be valid WTF-8. */
assert(code_point >= 0);
if (w_source_len < 0 && code_point == 0)
break;
if (code_point < 0x80)
target_len += 1;
else if (code_point < 0x800)
target_len += 2;
else if (code_point < 0x10000)
target_len += 3;
else {
target_len += 4;
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
return target_len;
}
int uv_utf16_to_wtf8(const uint16_t* w_source_ptr,
ssize_t w_source_len,
char** target_ptr,
size_t* target_len_ptr) {
size_t target_len;
char* target;
char* target_end;
int32_t code_point;
/* If *target_ptr is provided, then *target_len_ptr must be its length
* (excluding space for NUL), otherwise we will compute the target_len_ptr
* length and may return a new allocation in *target_ptr if target_ptr is
* provided. */
if (target_ptr == NULL || *target_ptr == NULL) {
target_len = uv_utf16_length_as_wtf8(w_source_ptr, w_source_len);
if (target_len_ptr != NULL)
*target_len_ptr = target_len;
} else {
target_len = *target_len_ptr;
}
if (target_ptr == NULL)
return 0;
if (*target_ptr == NULL) {
target = uv__malloc(target_len + 1);
if (target == NULL) {
return UV_ENOMEM;
}
*target_ptr = target;
} else {
target = *target_ptr;
}
target_end = target + target_len;
while (target != target_end && w_source_len) {
code_point = uv__get_surrogate_value(w_source_ptr, w_source_len);
/* Can be invalid UTF-8 but must be valid WTF-8. */
assert(code_point >= 0);
if (w_source_len < 0 && code_point == 0) {
w_source_len = 0;
break;
}
if (code_point < 0x80) {
*target++ = code_point;
} else if (code_point < 0x800) {
*target++ = 0xC0 | (code_point >> 6);
if (target == target_end)
break;
*target++ = 0x80 | (code_point & 0x3F);
} else if (code_point < 0x10000) {
*target++ = 0xE0 | (code_point >> 12);
if (target == target_end)
break;
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
if (target == target_end)
break;
*target++ = 0x80 | (code_point & 0x3F);
} else {
*target++ = 0xF0 | (code_point >> 18);
if (target == target_end)
break;
*target++ = 0x80 | ((code_point >> 12) & 0x3F);
if (target == target_end)
break;
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
if (target == target_end)
break;
*target++ = 0x80 | (code_point & 0x3F);
/* uv__get_surrogate_value consumed 2 input characters */
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
target_len = target - *target_ptr;
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
if (target != target_end && target_len_ptr != NULL)
/* Did not fill all of the provided buffer, so update the target_len_ptr
* output with the space used. */
*target_len_ptr = target - *target_ptr;
/* Check if input fit into target exactly. */
if (w_source_len < 0 && target == target_end && w_source_ptr[0] == 0)
w_source_len = 0;
*target++ = '\0';
/* Characters remained after filling the buffer, compute the remaining length now. */
if (w_source_len) {
if (target_len_ptr != NULL)
*target_len_ptr = target_len + uv_utf16_length_as_wtf8(w_source_ptr, w_source_len);
return UV_ENOBUFS;
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2011, 2018 Ben Noordhuis <info@bnoordhuis.nl> /* Copyright libuv contributors. All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -26,6 +26,6 @@ unsigned uv__utf8_decode1(const char** p, const char* pe);
* is the number of bytes written to |d|, including the trailing nul byte. * is the number of bytes written to |d|, including the trailing nul byte.
* A return value < 0 is a libuv error code. |s| and |d| can not overlap. * A return value < 0 is a libuv error code. |s| and |d| can not overlap.
*/ */
long uv__idna_toascii(const char* s, const char* se, char* d, char* de); ssize_t uv__idna_toascii(const char* s, const char* se, char* d, char* de);
#endif /* UV_SRC_IDNA_H_ */ #endif /* UV_SRC_IDNA_H_ */

View File

@ -209,7 +209,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
if (cpuspeed == 0) if (cpuspeed == 0)
/* If sysctl hw.cputype == CPU_TYPE_ARM64, the correct value is unavailable /* If sysctl hw.cputype == CPU_TYPE_ARM64, the correct value is unavailable
* from Apple, but we can hard-code it here to a plausible value. */ * from Apple, but we can hard-code it here to a plausible value. */
cpuspeed = 2400000000; cpuspeed = 2400000000U;
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus, if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info, (processor_info_array_t*)&info,
@ -235,7 +235,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->cpu_times.irq = 0; cpu_info->cpu_times.irq = 0;
cpu_info->model = uv__strdup(model); cpu_info->model = uv__strdup(model);
cpu_info->speed = cpuspeed/1000000; cpu_info->speed = (int)(cpuspeed / 1000000);
} }
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type); vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);

View File

@ -41,25 +41,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h> #include <poll.h>
#if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
# define HAVE_PREADV 1
#else
# define HAVE_PREADV 0
#endif
/* preadv() and pwritev() were added in Android N (level 24) */
#if defined(__linux__) && !(defined(__ANDROID__) && __ANDROID_API__ < 24)
# define TRY_PREADV 1
#endif
#if defined(__linux__) #if defined(__linux__)
# include <sys/sendfile.h> # include <sys/sendfile.h>
#endif #endif
@ -97,6 +82,15 @@
# include <sys/statfs.h> # include <sys/statfs.h>
#endif #endif
#if defined(__CYGWIN__) || \
(defined(__HAIKU__) && B_HAIKU_VERSION < B_HAIKU_VERSION_1_PRE_BETA_5) || \
(defined(__sun) && !defined(__illumos__))
#define preadv(fd, bufs, nbufs, off) \
pread(fd, (bufs)->iov_base, (bufs)->iov_len, off)
#define pwritev(fd, bufs, nbufs, off) \
pwrite(fd, (bufs)->iov_base, (bufs)->iov_len, off)
#endif
#if defined(_AIX) && _XOPEN_SOURCE <= 600 #if defined(_AIX) && _XOPEN_SOURCE <= 600
extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */ extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
#endif #endif
@ -410,123 +404,57 @@ static ssize_t uv__fs_open(uv_fs_t* req) {
} }
#if !HAVE_PREADV
static ssize_t uv__fs_preadv(uv_file fd,
uv_buf_t* bufs,
unsigned int nbufs,
off_t off) {
uv_buf_t* buf;
uv_buf_t* end;
ssize_t result;
ssize_t rc;
size_t pos;
assert(nbufs > 0);
result = 0;
pos = 0;
buf = bufs + 0;
end = bufs + nbufs;
for (;;) {
do
rc = pread(fd, buf->base + pos, buf->len - pos, off + result);
while (rc == -1 && errno == EINTR);
if (rc == 0)
break;
if (rc == -1 && result == 0)
return UV__ERR(errno);
if (rc == -1)
break; /* We read some data so return that, ignore the error. */
pos += rc;
result += rc;
if (pos < buf->len)
continue;
pos = 0;
buf += 1;
if (buf == end)
break;
}
return result;
}
#endif
static ssize_t uv__fs_read(uv_fs_t* req) { static ssize_t uv__fs_read(uv_fs_t* req) {
#if TRY_PREADV const struct iovec* bufs;
static _Atomic int no_preadv;
#endif
unsigned int iovmax; unsigned int iovmax;
ssize_t result; size_t nbufs;
ssize_t r;
off_t off;
int fd;
fd = req->file;
off = req->off;
bufs = (const struct iovec*) req->bufs;
nbufs = req->nbufs;
iovmax = uv__getiovmax(); iovmax = uv__getiovmax();
if (req->nbufs > iovmax) if (nbufs > iovmax)
req->nbufs = iovmax; nbufs = iovmax;
if (req->off < 0) { r = 0;
if (req->nbufs == 1) if (off < 0) {
result = read(req->file, req->bufs[0].base, req->bufs[0].len); if (nbufs == 1)
else r = read(fd, bufs->iov_base, bufs->iov_len);
result = readv(req->file, (struct iovec*) req->bufs, req->nbufs); else if (nbufs > 1)
r = readv(fd, bufs, nbufs);
} else { } else {
if (req->nbufs == 1) { if (nbufs == 1)
result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off); r = pread(fd, bufs->iov_base, bufs->iov_len, off);
goto done; else if (nbufs > 1)
} r = preadv(fd, bufs, nbufs, off);
#if HAVE_PREADV
result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if TRY_PREADV
if (atomic_load_explicit(&no_preadv, memory_order_relaxed)) retry:
# endif
{
result = uv__fs_preadv(req->file, req->bufs, req->nbufs, req->off);
}
# if TRY_PREADV
else {
result = preadv(req->file,
(struct iovec*) req->bufs,
req->nbufs,
req->off);
if (result == -1 && errno == ENOSYS) {
atomic_store_explicit(&no_preadv, 1, memory_order_relaxed);
goto retry;
}
}
# endif
#endif
} }
done:
/* Early cleanup of bufs allocation, since we're done with it. */
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
req->nbufs = 0;
#ifdef __PASE__ #ifdef __PASE__
/* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */ /* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */
if (result == -1 && errno == EOPNOTSUPP) { if (r == -1 && errno == EOPNOTSUPP) {
struct stat buf; struct stat buf;
ssize_t rc; ssize_t rc;
rc = uv__fstat(req->file, &buf); rc = uv__fstat(fd, &buf);
if (rc == 0 && S_ISDIR(buf.st_mode)) { if (rc == 0 && S_ISDIR(buf.st_mode)) {
errno = EISDIR; errno = EISDIR;
} }
} }
#endif #endif
return result; /* We don't own the buffer list in the synchronous case. */
if (req->cb != NULL)
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
req->nbufs = 0;
return r;
} }
@ -1161,65 +1089,34 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) {
static ssize_t uv__fs_write(uv_fs_t* req) { static ssize_t uv__fs_write(uv_fs_t* req) {
#if TRY_PREADV const struct iovec* bufs;
static _Atomic int no_pwritev; size_t nbufs;
#endif
ssize_t r; ssize_t r;
off_t off;
int fd;
/* Serialize writes on OS X, concurrent write() and pwrite() calls result in fd = req->file;
* data loss. We can't use a per-file descriptor lock, the descriptor may be off = req->off;
* a dup(). bufs = (const struct iovec*) req->bufs;
*/ nbufs = req->nbufs;
#if defined(__APPLE__)
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
if (pthread_mutex_lock(&lock)) r = 0;
abort(); if (off < 0) {
#endif if (nbufs == 1)
r = write(fd, bufs->iov_base, bufs->iov_len);
if (req->off < 0) { else if (nbufs > 1)
if (req->nbufs == 1) r = writev(fd, bufs, nbufs);
r = write(req->file, req->bufs[0].base, req->bufs[0].len);
else
r = writev(req->file, (struct iovec*) req->bufs, req->nbufs);
} else { } else {
if (req->nbufs == 1) { if (nbufs == 1)
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off); r = pwrite(fd, bufs->iov_base, bufs->iov_len, off);
goto done; else if (nbufs > 1)
} r = pwritev(fd, bufs, nbufs, off);
#if HAVE_PREADV
r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if TRY_PREADV
if (atomic_load_explicit(&no_pwritev, memory_order_relaxed)) retry:
# endif
{
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
}
# if TRY_PREADV
else {
r = pwritev(req->file,
(struct iovec*) req->bufs,
req->nbufs,
req->off);
if (r == -1 && errno == ENOSYS) {
atomic_store_explicit(&no_pwritev, 1, memory_order_relaxed);
goto retry;
}
}
# endif
#endif
} }
done:
#if defined(__APPLE__)
if (pthread_mutex_unlock(&lock))
abort();
#endif
return r; return r;
} }
static ssize_t uv__fs_copyfile(uv_fs_t* req) { static ssize_t uv__fs_copyfile(uv_fs_t* req) {
uv_fs_t fs_req; uv_fs_t fs_req;
uv_file srcfd; uv_file srcfd;
@ -1979,9 +1876,14 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
if (bufs == NULL || nbufs == 0) if (bufs == NULL || nbufs == 0)
return UV_EINVAL; return UV_EINVAL;
req->off = off;
req->file = file; req->file = file;
req->bufs = (uv_buf_t*) bufs; /* Safe, doesn't mutate |bufs| */
req->nbufs = nbufs; req->nbufs = nbufs;
if (cb == NULL)
goto post;
req->bufs = req->bufsml; req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml)) if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs)); req->bufs = uv__malloc(nbufs * sizeof(*bufs));
@ -1991,12 +1893,10 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs)); memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
req->off = off; if (uv__iou_fs_read_or_write(loop, req, /* is_read */ 1))
return 0;
if (cb != NULL)
if (uv__iou_fs_read_or_write(loop, req, /* is_read */ 1))
return 0;
post:
POST; POST;
} }

View File

@ -30,6 +30,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/event.h> #include <sys/event.h>
#include <sys/time.h> #include <sys/time.h>
#if defined(__FreeBSD__)
#include <sys/user.h>
#endif
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <time.h> #include <time.h>
@ -262,6 +265,9 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (nfds == -1) if (nfds == -1)
assert(errno == EINTR); assert(errno == EINTR);
else if (nfds == 0)
/* Unlimited timeout should only return with events or signal. */
assert(timeout != -1);
if (pset != NULL) if (pset != NULL)
pthread_sigmask(SIG_UNBLOCK, pset, NULL); pthread_sigmask(SIG_UNBLOCK, pset, NULL);
@ -286,8 +292,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
timeout = user_timeout; timeout = user_timeout;
reset_timeout = 0; reset_timeout = 0;
} else if (nfds == 0) { } else if (nfds == 0) {
/* Reached the user timeout value. */
assert(timeout != -1);
return; return;
} }
@ -479,6 +483,16 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags) {
*/ */
if (fcntl(handle->event_watcher.fd, F_GETPATH, pathbuf) == 0) if (fcntl(handle->event_watcher.fd, F_GETPATH, pathbuf) == 0)
path = uv__basename_r(pathbuf); path = uv__basename_r(pathbuf);
#elif defined(F_KINFO)
/* We try to get the file info reference from the file descriptor.
* the struct's kf_structsize must be initialised beforehand
* whether with the KINFO_FILE_SIZE constant or this way.
*/
struct kinfo_file kf;
kf.kf_structsize = sizeof(kf);
if (fcntl(handle->event_watcher.fd, F_KINFO, &kf) == 0)
path = uv__basename_r(kf.kf_path);
#endif #endif
handle->cb(handle, path, events, 0); handle->cb(handle, path, events, 0);

View File

@ -79,6 +79,8 @@
# define __NR_copy_file_range 379 # define __NR_copy_file_range 379
# elif defined(__arc__) # elif defined(__arc__)
# define __NR_copy_file_range 285 # define __NR_copy_file_range 285
# elif defined(__riscv)
# define __NR_copy_file_range 285
# endif # endif
#endif /* __NR_copy_file_range */ #endif /* __NR_copy_file_range */
@ -95,6 +97,8 @@
# define __NR_statx 383 # define __NR_statx 383
# elif defined(__s390__) # elif defined(__s390__)
# define __NR_statx 379 # define __NR_statx 379
# elif defined(__riscv)
# define __NR_statx 291
# endif # endif
#endif /* __NR_statx */ #endif /* __NR_statx */
@ -111,6 +115,8 @@
# define __NR_getrandom 359 # define __NR_getrandom 359
# elif defined(__s390__) # elif defined(__s390__)
# define __NR_getrandom 349 # define __NR_getrandom 349
# elif defined(__riscv)
# define __NR_getrandom 278
# endif # endif
#endif /* __NR_getrandom */ #endif /* __NR_getrandom */
@ -317,17 +323,64 @@ unsigned uv__kernel_version(void) {
unsigned major; unsigned major;
unsigned minor; unsigned minor;
unsigned patch; unsigned patch;
char v_sig[256];
char* needle;
version = atomic_load_explicit(&cached_version, memory_order_relaxed); version = atomic_load_explicit(&cached_version, memory_order_relaxed);
if (version != 0) if (version != 0)
return version; return version;
/* Check /proc/version_signature first as it's the way to get the mainline
* kernel version in Ubuntu. The format is:
* Ubuntu ubuntu_kernel_version mainline_kernel_version
* For example:
* Ubuntu 5.15.0-79.86-generic 5.15.111
*/
if (0 == uv__slurp("/proc/version_signature", v_sig, sizeof(v_sig)))
if (3 == sscanf(v_sig, "Ubuntu %*s %u.%u.%u", &major, &minor, &patch))
goto calculate_version;
if (-1 == uname(&u)) if (-1 == uname(&u))
return 0; return 0;
/* In Debian we need to check `version` instead of `release` to extract the
* mainline kernel version. This is an example of how it looks like:
* #1 SMP Debian 5.10.46-4 (2021-08-03)
*/
needle = strstr(u.version, "Debian ");
if (needle != NULL)
if (3 == sscanf(needle, "Debian %u.%u.%u", &major, &minor, &patch))
goto calculate_version;
if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch)) if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch))
return 0; return 0;
/* Handle it when the process runs under the UNAME26 personality:
*
* - kernels >= 3.x identify as 2.6.40+x
* - kernels >= 4.x identify as 2.6.60+x
*
* UNAME26 is a poorly conceived hack that doesn't let us distinguish
* between 4.x kernels and 5.x/6.x kernels so we conservatively assume
* that 2.6.60+x means 4.x.
*
* Fun fact of the day: it's technically possible to observe the actual
* kernel version for a brief moment because uname() first copies out the
* real release string before overwriting it with the backcompat string.
*/
if (major == 2 && minor == 6) {
if (patch >= 60) {
major = 4;
minor = patch - 60;
patch = 0;
} else if (patch >= 40) {
major = 3;
minor = patch - 40;
patch = 0;
}
}
calculate_version:
version = major * 65536 + minor * 256 + patch; version = major * 65536 + minor * 256 + patch;
atomic_store_explicit(&cached_version, version, memory_order_relaxed); atomic_store_explicit(&cached_version, version, memory_order_relaxed);
@ -422,6 +475,9 @@ int uv__io_uring_register(int fd, unsigned opcode, void* arg, unsigned nargs) {
static int uv__use_io_uring(void) { static int uv__use_io_uring(void) {
#if defined(__ANDROID_API__) #if defined(__ANDROID_API__)
return 0; /* Possibly available but blocked by seccomp. */ return 0; /* Possibly available but blocked by seccomp. */
#elif defined(__arm__) && __SIZEOF_POINTER__ == 4
/* See https://github.com/libuv/libuv/issues/4158. */
return 0; /* All 32 bits kernels appear buggy. */
#else #else
/* Ternary: unknown=0, yes=1, no=-1 */ /* Ternary: unknown=0, yes=1, no=-1 */
static _Atomic int use_io_uring; static _Atomic int use_io_uring;
@ -431,8 +487,14 @@ static int uv__use_io_uring(void) {
use = atomic_load_explicit(&use_io_uring, memory_order_relaxed); use = atomic_load_explicit(&use_io_uring, memory_order_relaxed);
if (use == 0) { if (use == 0) {
/* Older kernels have a bug where the sqpoll thread uses 100% CPU. */
use = uv__kernel_version() >= /* 5.10.186 */ 0x050ABA ? 1 : -1;
/* But users can still enable it if they so desire. */
val = getenv("UV_USE_IO_URING"); val = getenv("UV_USE_IO_URING");
use = val == NULL || atoi(val) ? 1 : -1; if (val != NULL)
use = atoi(val) ? 1 : -1;
atomic_store_explicit(&use_io_uring, use, memory_order_relaxed); atomic_store_explicit(&use_io_uring, use, memory_order_relaxed);
} }
@ -756,7 +818,9 @@ static void uv__iou_submit(struct uv__iou* iou) {
int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req) { int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req) {
struct uv__io_uring_sqe* sqe; struct uv__io_uring_sqe* sqe;
struct uv__iou* iou; struct uv__iou* iou;
int kv;
kv = uv__kernel_version();
/* Work around a poorly understood bug in older kernels where closing a file /* Work around a poorly understood bug in older kernels where closing a file
* descriptor pointing to /foo/bar results in ETXTBSY errors when trying to * descriptor pointing to /foo/bar results in ETXTBSY errors when trying to
* execve("/foo/bar") later on. The bug seems to have been fixed somewhere * execve("/foo/bar") later on. The bug seems to have been fixed somewhere
@ -764,10 +828,17 @@ int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req) {
* but good candidates are the several data race fixes. Interestingly, it * but good candidates are the several data race fixes. Interestingly, it
* seems to manifest only when running under Docker so the possibility of * seems to manifest only when running under Docker so the possibility of
* a Docker bug can't be completely ruled out either. Yay, computers. * a Docker bug can't be completely ruled out either. Yay, computers.
* Also, disable on non-longterm versions between 5.16.0 (non-longterm) and
* 6.1.0 (longterm). Starting with longterm 6.1.x, the issue seems to be
* solved.
*/ */
if (uv__kernel_version() < /* 5.15.90 */ 0x050F5A) if (kv < /* 5.15.90 */ 0x050F5A)
return 0; return 0;
if (kv >= /* 5.16.0 */ 0x050A00 && kv < /* 6.1.0 */ 0x060100)
return 0;
iou = &uv__get_internal_fields(loop)->iou; iou = &uv__get_internal_fields(loop)->iou;
sqe = uv__iou_get_sqe(iou, loop, req); sqe = uv__iou_get_sqe(iou, loop, req);
@ -1364,41 +1435,20 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
*/ */
SAVE_ERRNO(uv__update_time(loop)); SAVE_ERRNO(uv__update_time(loop));
if (nfds == 0) { if (nfds == -1)
assert(errno == EINTR);
else if (nfds == 0)
/* Unlimited timeout should only return with events or signal. */
assert(timeout != -1); assert(timeout != -1);
if (nfds == 0 || nfds == -1) {
if (reset_timeout != 0) { if (reset_timeout != 0) {
timeout = user_timeout; timeout = user_timeout;
reset_timeout = 0; reset_timeout = 0;
} else if (nfds == 0) {
return;
} }
if (timeout == -1)
continue;
if (timeout == 0)
break;
/* We may have been inside the system call for longer than |timeout|
* milliseconds so we need to update the timestamp to avoid drift.
*/
goto update_timeout;
}
if (nfds == -1) {
if (errno != EINTR)
abort();
if (reset_timeout != 0) {
timeout = user_timeout;
reset_timeout = 0;
}
if (timeout == -1)
continue;
if (timeout == 0)
break;
/* Interrupted by a signal. Update timeout and poll again. */ /* Interrupted by a signal. Update timeout and poll again. */
goto update_timeout; goto update_timeout;
} }
@ -1509,13 +1559,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
break; break;
} }
update_timeout:
if (timeout == 0) if (timeout == 0)
break; break;
if (timeout == -1) if (timeout == -1)
continue; continue;
update_timeout:
assert(timeout > 0); assert(timeout > 0);
real_timeout -= (loop->time - base); real_timeout -= (loop->time - base);
@ -1718,7 +1768,8 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
return UV__ERR(errno); return UV__ERR(errno);
} }
fgets(buf, sizeof(buf), fp); /* Skip first line. */ if (NULL == fgets(buf, sizeof(buf), fp))
abort();
for (;;) { for (;;) {
memset(&t, 0, sizeof(t)); memset(&t, 0, sizeof(t));
@ -1729,7 +1780,8 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
if (n != 7) if (n != 7)
break; break;
fgets(buf, sizeof(buf), fp); /* Skip rest of line. */ if (NULL == fgets(buf, sizeof(buf), fp))
abort();
if (cpu >= ARRAY_SIZE(*cpus)) if (cpu >= ARRAY_SIZE(*cpus))
continue; continue;
@ -1809,7 +1861,8 @@ nocpuinfo:
if (fp == NULL) if (fp == NULL)
continue; continue;
fscanf(fp, "%llu", &(*cpus)[cpu].freq); if (1 != fscanf(fp, "%llu", &(*cpus)[cpu].freq))
abort();
fclose(fp); fclose(fp);
fp = NULL; fp = NULL;
} }

View File

@ -19,6 +19,7 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
#include "uv.h"
#include "internal.h" #include "internal.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <net/if.h> #include <net/if.h>
@ -30,6 +31,7 @@
#include <sys/msg.h> #include <sys/msg.h>
#include <sys/resource.h> #include <sys/resource.h>
#include "zos-base.h" #include "zos-base.h"
#include "zos-sys-info.h"
#if defined(__clang__) #if defined(__clang__)
#include "csrsic.h" #include "csrsic.h"
#else #else
@ -66,9 +68,6 @@
/* Total number of frames currently on all available frame queues. */ /* Total number of frames currently on all available frame queues. */
#define RCEAFC_OFFSET 0x088 #define RCEAFC_OFFSET 0x088
/* CPC model length from the CSRSI Service. */
#define CPCMODEL_LENGTH 16
/* Pointer to the home (current) ASCB. */ /* Pointer to the home (current) ASCB. */
#define PSAAOLD 0x224 #define PSAAOLD 0x224
@ -258,9 +257,12 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
idx = 0; idx = 0;
while (idx < *count) { while (idx < *count) {
cpu_info->speed = *(int*)(info.siv1v2si22v1.si22v1cpucapability); cpu_info->speed = *(int*)(info.siv1v2si22v1.si22v1cpucapability);
cpu_info->model = uv__malloc(CPCMODEL_LENGTH + 1); cpu_info->model = uv__malloc(ZOSCPU_MODEL_LENGTH + 1);
memset(cpu_info->model, '\0', CPCMODEL_LENGTH + 1); if (cpu_info->model == NULL) {
memcpy(cpu_info->model, info.siv1v2si11v1.si11v1cpcmodel, CPCMODEL_LENGTH); uv_free_cpu_info(*cpu_infos, idx);
return UV_ENOMEM;
}
__get_cpu_model(cpu_info->model, ZOSCPU_MODEL_LENGTH + 1);
cpu_info->cpu_times.user = cpu_usage_avg; cpu_info->cpu_times.user = cpu_usage_avg;
/* TODO: implement the following */ /* TODO: implement the following */
cpu_info->cpu_times.sys = 0; cpu_info->cpu_times.sys = 0;

View File

@ -279,6 +279,8 @@ static int uv__signal_loop_once_init(uv_loop_t* loop) {
int uv__signal_loop_fork(uv_loop_t* loop) { int uv__signal_loop_fork(uv_loop_t* loop) {
struct uv__queue* q;
if (loop->signal_pipefd[0] == -1) if (loop->signal_pipefd[0] == -1)
return 0; return 0;
uv__io_stop(loop, &loop->signal_io_watcher, POLLIN); uv__io_stop(loop, &loop->signal_io_watcher, POLLIN);
@ -286,6 +288,19 @@ int uv__signal_loop_fork(uv_loop_t* loop) {
uv__close(loop->signal_pipefd[1]); uv__close(loop->signal_pipefd[1]);
loop->signal_pipefd[0] = -1; loop->signal_pipefd[0] = -1;
loop->signal_pipefd[1] = -1; loop->signal_pipefd[1] = -1;
uv__queue_foreach(q, &loop->handle_queue) {
uv_handle_t* handle = uv__queue_data(q, uv_handle_t, handle_queue);
uv_signal_t* sh;
if (handle->type != UV_SIGNAL)
continue;
sh = (uv_signal_t*) handle;
sh->caught_signals = 0;
sh->dispatched_signals = 0;
}
return uv__signal_loop_once_init(loop); return uv__signal_loop_once_init(loop);
} }

View File

@ -27,6 +27,17 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#if defined(__PASE__)
#include <as400_protos.h>
#define ifaddrs ifaddrs_pase
#define getifaddrs Qp2getifaddrs
#define freeifaddrs Qp2freeifaddrs
#else
#include <ifaddrs.h>
#endif
static int maybe_bind_socket(int fd) { static int maybe_bind_socket(int fd) {
union uv__sockaddr s; union uv__sockaddr s;
@ -198,11 +209,50 @@ int uv__tcp_bind(uv_tcp_t* tcp,
} }
static int uv__is_ipv6_link_local(const struct sockaddr* addr) {
const struct sockaddr_in6* a6;
uint8_t b[2];
if (addr->sa_family != AF_INET6)
return 0;
a6 = (const struct sockaddr_in6*) addr;
memcpy(b, &a6->sin6_addr, sizeof(b));
return b[0] == 0xFE && b[1] == 0x80;
}
static int uv__ipv6_link_local_scope_id(void) {
struct sockaddr_in6* a6;
struct ifaddrs* ifa;
struct ifaddrs* p;
int rv;
if (getifaddrs(&ifa))
return 0;
for (p = ifa; p != NULL; p = p->ifa_next)
if (uv__is_ipv6_link_local(p->ifa_addr))
break;
rv = 0;
if (p != NULL) {
a6 = (struct sockaddr_in6*) p->ifa_addr;
rv = a6->sin6_scope_id;
}
freeifaddrs(ifa);
return rv;
}
int uv__tcp_connect(uv_connect_t* req, int uv__tcp_connect(uv_connect_t* req,
uv_tcp_t* handle, uv_tcp_t* handle,
const struct sockaddr* addr, const struct sockaddr* addr,
unsigned int addrlen, unsigned int addrlen,
uv_connect_cb cb) { uv_connect_cb cb) {
struct sockaddr_in6 tmp6;
int err; int err;
int r; int r;
@ -220,6 +270,14 @@ int uv__tcp_connect(uv_connect_t* req,
if (err) if (err)
return err; return err;
if (uv__is_ipv6_link_local(addr)) {
memcpy(&tmp6, addr, sizeof(tmp6));
if (tmp6.sin6_scope_id == 0) {
tmp6.sin6_scope_id = uv__ipv6_link_local_scope_id();
addr = (void*) &tmp6;
}
}
do { do {
errno = 0; errno = 0;
r = connect(uv__stream_fd(handle), addr, addrlen); r = connect(uv__stream_fd(handle), addr, addrlen);
@ -374,28 +432,39 @@ int uv__tcp_nodelay(int fd, int on) {
int uv__tcp_keepalive(int fd, int on, unsigned int delay) { int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
int intvl;
int cnt;
(void) &intvl;
(void) &cnt;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
return UV__ERR(errno); return UV__ERR(errno);
if (!on)
return 0;
#ifdef TCP_KEEPIDLE #ifdef TCP_KEEPIDLE
if (on) { if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
int intvl = 1; /* 1 second; same as default on Win32 */ return UV__ERR(errno);
int cnt = 10; /* 10 retries; same as hardcoded on Win32 */ /* Solaris/SmartOS, if you don't support keep-alive,
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) * then don't advertise it in your system headers...
return UV__ERR(errno); */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl))) /* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
return UV__ERR(errno); #elif defined(TCP_KEEPALIVE) && !defined(__sun)
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt))) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
return UV__ERR(errno); return UV__ERR(errno);
}
#endif #endif
/* Solaris/SmartOS, if you don't support keep-alive, #ifdef TCP_KEEPINTVL
* then don't advertise it in your system headers... intvl = 1; /* 1 second; same as default on Win32 */
*/ if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
/* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */ return UV__ERR(errno);
#if defined(TCP_KEEPALIVE) && !defined(__sun) #endif
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
#ifdef TCP_KEEPCNT
cnt = 10; /* 10 retries; same as hardcoded on Win32 */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
return UV__ERR(errno); return UV__ERR(errno);
#endif #endif

View File

@ -789,11 +789,33 @@ void uv_cond_broadcast(uv_cond_t* cond) {
abort(); abort();
} }
#if defined(__APPLE__) && defined(__MACH__)
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
int r;
errno = 0;
r = pthread_cond_wait(cond, mutex);
/* Workaround for a bug in OS X at least up to 13.6
* See https://github.com/libuv/libuv/issues/4165
*/
if (r == EINVAL)
if (errno == EBUSY)
return;
if (r)
abort();
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) { void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
if (pthread_cond_wait(cond, mutex)) if (pthread_cond_wait(cond, mutex))
abort(); abort();
} }
#endif
int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
int r; int r;

View File

@ -559,6 +559,9 @@ static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) {
if (loop == NULL) if (loop == NULL)
loop = uv_default_loop(); loop = uv_default_loop();
if (stream == NULL)
stream = stderr;
uv__queue_foreach(q, &loop->handle_queue) { uv__queue_foreach(q, &loop->handle_queue) {
h = uv__queue_data(q, uv_handle_t, handle_queue); h = uv__queue_data(q, uv_handle_t, handle_queue);

View File

@ -27,18 +27,17 @@ static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno);
int uv_dlopen(const char* filename, uv_lib_t* lib) { int uv_dlopen(const char* filename, uv_lib_t* lib) {
WCHAR filename_w[32768]; WCHAR filename_w[32768];
ssize_t r;
lib->handle = NULL; lib->handle = NULL;
lib->errmsg = NULL; lib->errmsg = NULL;
if (!MultiByteToWideChar(CP_UTF8, r = uv_wtf8_length_as_utf16(filename);
0, if (r < 0)
filename, return uv__dlerror(lib, filename, ERROR_NO_UNICODE_TRANSLATION);
-1, if ((size_t) r > ARRAY_SIZE(filename_w))
filename_w, return uv__dlerror(lib, filename, ERROR_INSUFFICIENT_BUFFER);
ARRAY_SIZE(filename_w))) { uv_wtf8_to_utf16(filename, filename_w, r);
return uv__dlerror(lib, filename, GetLastError());
}
lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (lib->handle == NULL) { if (lib->handle == NULL) {

View File

@ -157,7 +157,8 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb, uv_fs_event_cb cb,
const char* path, const char* path,
unsigned int flags) { unsigned int flags) {
int name_size, is_path_dir, size; int is_path_dir;
size_t size;
DWORD attr, last_error; DWORD attr, last_error;
WCHAR* dir = NULL, *dir_to_watch, *pathw = NULL; WCHAR* dir = NULL, *dir_to_watch, *pathw = NULL;
DWORD short_path_buffer_len; DWORD short_path_buffer_len;
@ -176,23 +177,9 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv__handle_start(handle); uv__handle_start(handle);
/* Convert name to UTF16. */ last_error = uv__convert_utf8_to_utf16(path, &pathw);
if (last_error)
name_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0) * goto error_uv;
sizeof(WCHAR);
pathw = (WCHAR*)uv__malloc(name_size);
if (!pathw) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!MultiByteToWideChar(CP_UTF8,
0,
path,
-1,
pathw,
name_size / sizeof(WCHAR))) {
return uv_translate_sys_error(GetLastError());
}
/* Determine whether path is a file or a directory. */ /* Determine whether path is a file or a directory. */
attr = GetFileAttributesW(pathw); attr = GetFileAttributesW(pathw);
@ -333,6 +320,9 @@ short_path_done:
return 0; return 0;
error: error:
last_error = uv_translate_sys_error(last_error);
error_uv:
if (handle->path) { if (handle->path) {
uv__free(handle->path); uv__free(handle->path);
handle->path = NULL; handle->path = NULL;
@ -365,7 +355,7 @@ error:
uv__free(short_path); uv__free(short_path);
return uv_translate_sys_error(last_error); return last_error;
} }

View File

@ -31,13 +31,16 @@
#include <stdio.h> #include <stdio.h>
#include "uv.h" #include "uv.h"
/* <winioctl.h> requires <windows.h>, included via "uv.h" above, but needs to
be included before our "winapi.h", included via "internal.h" below. */
#include <winioctl.h>
#include "internal.h" #include "internal.h"
#include "req-inl.h" #include "req-inl.h"
#include "handle-inl.h" #include "handle-inl.h"
#include "fs-fd-hash-inl.h" #include "fs-fd-hash-inl.h"
#include <winioctl.h>
#define UV_FS_FREE_PATHS 0x0002 #define UV_FS_FREE_PATHS 0x0002
#define UV_FS_FREE_PTR 0x0008 #define UV_FS_FREE_PTR 0x0008
@ -144,279 +147,6 @@ void uv__fs_init(void) {
} }
static int32_t fs__decode_wtf8_char(const char** input) {
uint32_t code_point;
uint8_t b1;
uint8_t b2;
uint8_t b3;
uint8_t b4;
b1 = **input;
if (b1 <= 0x7F)
return b1; /* ASCII code point */
if (b1 < 0xC2)
return -1; /* invalid: continuation byte */
code_point = b1;
b2 = *++*input;
if ((b2 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b2 & 0x3F);
if (b1 <= 0xDF)
return 0x7FF & code_point; /* two-byte character */
b3 = *++*input;
if ((b3 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b3 & 0x3F);
if (b1 <= 0xEF)
return 0xFFFF & code_point; /* three-byte character */
b4 = *++*input;
if ((b4 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b4 & 0x3F);
if (b1 <= 0xF4)
if (code_point <= 0x10FFFF)
return code_point; /* four-byte character */
/* code point too large */
return -1;
}
static ssize_t fs__get_length_wtf8(const char* source_ptr) {
size_t w_target_len = 0;
int32_t code_point;
do {
code_point = fs__decode_wtf8_char(&source_ptr);
if (code_point < 0)
return -1;
if (code_point > 0xFFFF)
w_target_len++;
w_target_len++;
} while (*source_ptr++);
return w_target_len;
}
static void fs__wtf8_to_wide(const char* source_ptr, WCHAR* w_target) {
int32_t code_point;
do {
code_point = fs__decode_wtf8_char(&source_ptr);
/* fs__get_length_wtf8 should have been called and checked first. */
assert(code_point >= 0);
if (code_point > 0x10000) {
assert(code_point < 0x10FFFF);
*w_target++ = (((code_point - 0x10000) >> 10) + 0xD800);
*w_target++ = ((code_point - 0x10000) & 0x3FF) + 0xDC00;
} else {
*w_target++ = code_point;
}
} while (*source_ptr++);
}
INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
const char* new_path, const int copy_path) {
WCHAR* buf;
WCHAR* pos;
size_t buf_sz = 0;
size_t path_len = 0;
ssize_t pathw_len = 0;
ssize_t new_pathw_len = 0;
/* new_path can only be set if path is also set. */
assert(new_path == NULL || path != NULL);
if (path != NULL) {
pathw_len = fs__get_length_wtf8(path);
if (pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += pathw_len * sizeof(WCHAR);
}
if (path != NULL && copy_path) {
path_len = 1 + strlen(path);
buf_sz += path_len;
}
if (new_path != NULL) {
new_pathw_len = fs__get_length_wtf8(new_path);
if (new_pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += new_pathw_len * sizeof(WCHAR);
}
if (buf_sz == 0) {
req->file.pathw = NULL;
req->fs.info.new_pathw = NULL;
req->path = NULL;
return 0;
}
buf = uv__malloc(buf_sz);
if (buf == NULL) {
return ERROR_OUTOFMEMORY;
}
pos = buf;
if (path != NULL) {
fs__wtf8_to_wide(path, pos);
req->file.pathw = pos;
pos += pathw_len;
} else {
req->file.pathw = NULL;
}
if (new_path != NULL) {
fs__wtf8_to_wide(new_path, pos);
req->fs.info.new_pathw = pos;
pos += new_pathw_len;
} else {
req->fs.info.new_pathw = NULL;
}
req->path = path;
if (path != NULL && copy_path) {
memcpy(pos, path, path_len);
assert(path_len == buf_sz - (pos - buf) * sizeof(WCHAR));
req->path = (char*) pos;
}
req->flags |= UV_FS_FREE_PATHS;
return 0;
}
INLINE static void uv__fs_req_init(uv_loop_t* loop, uv_fs_t* req,
uv_fs_type fs_type, const uv_fs_cb cb) {
uv__once_init();
UV_REQ_INIT(req, UV_FS);
req->loop = loop;
req->flags = 0;
req->fs_type = fs_type;
req->sys_errno_ = 0;
req->result = 0;
req->ptr = NULL;
req->path = NULL;
req->cb = cb;
memset(&req->fs, 0, sizeof(req->fs));
}
static int32_t fs__get_surrogate_value(const WCHAR* w_source_ptr,
size_t w_source_len) {
WCHAR u;
WCHAR next;
u = w_source_ptr[0];
if (u >= 0xD800 && u <= 0xDBFF && w_source_len > 1) {
next = w_source_ptr[1];
if (next >= 0xDC00 && next <= 0xDFFF)
return 0x10000 + ((u - 0xD800) << 10) + (next - 0xDC00);
}
return u;
}
static size_t fs__get_length_wide(const WCHAR* w_source_ptr,
size_t w_source_len) {
size_t target_len;
int32_t code_point;
target_len = 0;
for (; w_source_len; w_source_len--, w_source_ptr++) {
code_point = fs__get_surrogate_value(w_source_ptr, w_source_len);
/* Can be invalid UTF-8 but must be valid WTF-8. */
assert(code_point >= 0);
if (code_point < 0x80)
target_len += 1;
else if (code_point < 0x800)
target_len += 2;
else if (code_point < 0x10000)
target_len += 3;
else {
target_len += 4;
w_source_ptr++;
w_source_len--;
}
}
return target_len;
}
static int fs__wide_to_wtf8(WCHAR* w_source_ptr,
size_t w_source_len,
char** target_ptr,
size_t* target_len_ptr) {
size_t target_len;
char* target;
int32_t code_point;
/* If *target_ptr is provided, then *target_len_ptr must be its length
* (excluding space for null), otherwise we will compute the target_len_ptr
* length and may return a new allocation in *target_ptr if target_ptr is
* provided. */
if (target_ptr == NULL || *target_ptr == NULL) {
target_len = fs__get_length_wide(w_source_ptr, w_source_len);
if (target_len_ptr != NULL)
*target_len_ptr = target_len;
} else {
target_len = *target_len_ptr;
}
if (target_ptr == NULL)
return 0;
if (*target_ptr == NULL) {
target = uv__malloc(target_len + 1);
if (target == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return -1;
}
*target_ptr = target;
} else {
target = *target_ptr;
}
for (; w_source_len; w_source_len--, w_source_ptr++) {
code_point = fs__get_surrogate_value(w_source_ptr, w_source_len);
/* Can be invalid UTF-8 but must be valid WTF-8. */
assert(code_point >= 0);
if (code_point < 0x80) {
*target++ = code_point;
} else if (code_point < 0x800) {
*target++ = 0xC0 | (code_point >> 6);
*target++ = 0x80 | (code_point & 0x3F);
} else if (code_point < 0x10000) {
*target++ = 0xE0 | (code_point >> 12);
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
*target++ = 0x80 | (code_point & 0x3F);
} else {
*target++ = 0xF0 | (code_point >> 18);
*target++ = 0x80 | ((code_point >> 12) & 0x3F);
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
*target++ = 0x80 | (code_point & 0x3F);
w_source_ptr++;
w_source_len--;
}
}
assert((size_t) (target - *target_ptr) == target_len);
*target++ = '\0';
return 0;
}
INLINE static int fs__readlink_handle(HANDLE handle, INLINE static int fs__readlink_handle(HANDLE handle,
char** target_ptr, char** target_ptr,
size_t* target_len_ptr) { size_t* target_len_ptr) {
@ -550,7 +280,98 @@ INLINE static int fs__readlink_handle(HANDLE handle,
} }
assert(target_ptr == NULL || *target_ptr == NULL); assert(target_ptr == NULL || *target_ptr == NULL);
return fs__wide_to_wtf8(w_target, w_target_len, target_ptr, target_len_ptr); return uv_utf16_to_wtf8(w_target, w_target_len, target_ptr, target_len_ptr);
}
INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
const char* new_path, const int copy_path) {
WCHAR* buf;
WCHAR* pos;
size_t buf_sz = 0;
size_t path_len = 0;
ssize_t pathw_len = 0;
ssize_t new_pathw_len = 0;
/* new_path can only be set if path is also set. */
assert(new_path == NULL || path != NULL);
if (path != NULL) {
pathw_len = uv_wtf8_length_as_utf16(path);
if (pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += pathw_len * sizeof(WCHAR);
}
if (path != NULL && copy_path) {
path_len = 1 + strlen(path);
buf_sz += path_len;
}
if (new_path != NULL) {
new_pathw_len = uv_wtf8_length_as_utf16(new_path);
if (new_pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += new_pathw_len * sizeof(WCHAR);
}
if (buf_sz == 0) {
req->file.pathw = NULL;
req->fs.info.new_pathw = NULL;
req->path = NULL;
return 0;
}
buf = uv__malloc(buf_sz);
if (buf == NULL) {
return ERROR_OUTOFMEMORY;
}
pos = buf;
if (path != NULL) {
uv_wtf8_to_utf16(path, pos, pathw_len);
req->file.pathw = pos;
pos += pathw_len;
} else {
req->file.pathw = NULL;
}
if (new_path != NULL) {
uv_wtf8_to_utf16(new_path, pos, new_pathw_len);
req->fs.info.new_pathw = pos;
pos += new_pathw_len;
} else {
req->fs.info.new_pathw = NULL;
}
req->path = path;
if (path != NULL && copy_path) {
memcpy(pos, path, path_len);
assert(path_len == buf_sz - (pos - buf) * sizeof(WCHAR));
req->path = (char*) pos;
}
req->flags |= UV_FS_FREE_PATHS;
return 0;
}
INLINE static void uv__fs_req_init(uv_loop_t* loop, uv_fs_t* req,
uv_fs_type fs_type, const uv_fs_cb cb) {
uv__once_init();
UV_REQ_INIT(req, UV_FS);
req->loop = loop;
req->flags = 0;
req->fs_type = fs_type;
req->sys_errno_ = 0;
req->result = 0;
req->ptr = NULL;
req->path = NULL;
req->cb = cb;
memset(&req->fs, 0, sizeof(req->fs));
} }
@ -1569,7 +1390,7 @@ void fs__scandir(uv_fs_t* req) {
continue; continue;
/* Compute the space required to store the filename as WTF-8. */ /* Compute the space required to store the filename as WTF-8. */
wtf8_len = fs__get_length_wide(&info->FileName[0], wchar_len); wtf8_len = uv_utf16_length_as_wtf8(&info->FileName[0], wchar_len);
/* Resize the dirent array if needed. */ /* Resize the dirent array if needed. */
if (dirents_used >= dirents_size) { if (dirents_used >= dirents_size) {
@ -1597,8 +1418,8 @@ void fs__scandir(uv_fs_t* req) {
/* Convert file name to UTF-8. */ /* Convert file name to UTF-8. */
wtf8 = &dirent->d_name[0]; wtf8 = &dirent->d_name[0];
if (fs__wide_to_wtf8(&info->FileName[0], wchar_len, &wtf8, &wtf8_len) == -1) if (uv_utf16_to_wtf8(&info->FileName[0], wchar_len, &wtf8, &wtf8_len) != 0)
goto win32_error; goto out_of_memory_error;
/* Fill out the type field. */ /* Fill out the type field. */
if (info->FileAttributes & FILE_ATTRIBUTE_DEVICE) if (info->FileAttributes & FILE_ATTRIBUTE_DEVICE)
@ -2824,7 +2645,7 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
} }
assert(*realpath_ptr == NULL); assert(*realpath_ptr == NULL);
r = fs__wide_to_wtf8(w_realpath_ptr, w_realpath_len, realpath_ptr, NULL); r = uv_utf16_to_wtf8(w_realpath_ptr, w_realpath_len, realpath_ptr, NULL);
uv__free(w_realpath_buf); uv__free(w_realpath_buf);
return r; return r;
} }

View File

@ -104,13 +104,14 @@ static void uv__getaddrinfo_work(struct uv__work* w) {
*/ */
static void uv__getaddrinfo_done(struct uv__work* w, int status) { static void uv__getaddrinfo_done(struct uv__work* w, int status) {
uv_getaddrinfo_t* req; uv_getaddrinfo_t* req;
int addrinfo_len = 0; size_t addrinfo_len = 0;
int name_len = 0; ssize_t name_len = 0;
size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo)); size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo));
struct addrinfoW* addrinfow_ptr; struct addrinfoW* addrinfow_ptr;
struct addrinfo* addrinfo_ptr; struct addrinfo* addrinfo_ptr;
char* alloc_ptr = NULL; char* alloc_ptr = NULL;
char* cur_ptr = NULL; char* cur_ptr = NULL;
int r;
req = container_of(w, uv_getaddrinfo_t, work_req); req = container_of(w, uv_getaddrinfo_t, work_req);
@ -131,19 +132,12 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
addrinfo_len += addrinfo_struct_len + addrinfo_len += addrinfo_struct_len +
ALIGNED_SIZE(addrinfow_ptr->ai_addrlen); ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);
if (addrinfow_ptr->ai_canonname != NULL) { if (addrinfow_ptr->ai_canonname != NULL) {
name_len = WideCharToMultiByte(CP_UTF8, name_len = uv_utf16_length_as_wtf8(addrinfow_ptr->ai_canonname, -1);
0, if (name_len < 0) {
addrinfow_ptr->ai_canonname, req->retcode = name_len;
-1,
NULL,
0,
NULL,
NULL);
if (name_len == 0) {
req->retcode = uv_translate_sys_error(GetLastError());
goto complete; goto complete;
} }
addrinfo_len += ALIGNED_SIZE(name_len); addrinfo_len += ALIGNED_SIZE(name_len + 1);
} }
addrinfow_ptr = addrinfow_ptr->ai_next; addrinfow_ptr = addrinfow_ptr->ai_next;
} }
@ -182,27 +176,14 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
/* convert canonical name to UTF-8 */ /* convert canonical name to UTF-8 */
if (addrinfow_ptr->ai_canonname != NULL) { if (addrinfow_ptr->ai_canonname != NULL) {
name_len = WideCharToMultiByte(CP_UTF8, name_len = alloc_ptr + addrinfo_len - cur_ptr;
0, r = uv__copy_utf16_to_utf8(addrinfow_ptr->ai_canonname,
addrinfow_ptr->ai_canonname, -1,
-1, cur_ptr,
NULL, (size_t*)&name_len);
0, assert(r == 0);
NULL,
NULL);
assert(name_len > 0);
assert(cur_ptr + name_len <= alloc_ptr + addrinfo_len);
name_len = WideCharToMultiByte(CP_UTF8,
0,
addrinfow_ptr->ai_canonname,
-1,
cur_ptr,
name_len,
NULL,
NULL);
assert(name_len > 0);
addrinfo_ptr->ai_canonname = cur_ptr; addrinfo_ptr->ai_canonname = cur_ptr;
cur_ptr += ALIGNED_SIZE(name_len); cur_ptr += ALIGNED_SIZE(name_len + 1);
} }
assert(cur_ptr <= alloc_ptr + addrinfo_len); assert(cur_ptr <= alloc_ptr + addrinfo_len);
@ -261,12 +242,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* service, const char* service,
const struct addrinfo* hints) { const struct addrinfo* hints) {
char hostname_ascii[256]; char hostname_ascii[256];
int nodesize = 0; size_t nodesize = 0;
int servicesize = 0; size_t servicesize = 0;
int hintssize = 0; size_t hintssize = 0;
char* alloc_ptr = NULL; char* alloc_ptr = NULL;
int err; ssize_t rc;
long rc;
if (req == NULL || (node == NULL && service == NULL)) { if (req == NULL || (node == NULL && service == NULL)) {
return UV_EINVAL; return UV_EINVAL;
@ -286,56 +266,36 @@ int uv_getaddrinfo(uv_loop_t* loop,
hostname_ascii + sizeof(hostname_ascii)); hostname_ascii + sizeof(hostname_ascii));
if (rc < 0) if (rc < 0)
return rc; return rc;
nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, hostname_ascii, nodesize = strlen(hostname_ascii) + 1;
-1, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
err = GetLastError();
goto error;
}
node = hostname_ascii; node = hostname_ascii;
} }
if (service != NULL) { if (service != NULL) {
servicesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, rc = uv_wtf8_length_as_utf16(service);
0, if (rc < 0)
service, return rc;
-1, servicesize = rc;
NULL,
0) *
sizeof(WCHAR));
if (servicesize == 0) {
err = GetLastError();
goto error;
}
} }
if (hints != NULL) { if (hints != NULL) {
hintssize = ALIGNED_SIZE(sizeof(struct addrinfoW)); hintssize = ALIGNED_SIZE(sizeof(struct addrinfoW));
} }
/* allocate memory for inputs, and partition it as needed */ /* allocate memory for inputs, and partition it as needed */
alloc_ptr = (char*)uv__malloc(nodesize + servicesize + hintssize); alloc_ptr = uv__malloc(ALIGNED_SIZE(nodesize * sizeof(WCHAR)) +
if (!alloc_ptr) { ALIGNED_SIZE(servicesize * sizeof(WCHAR)) +
err = WSAENOBUFS; hintssize);
goto error; if (!alloc_ptr)
} return UV_ENOMEM;
/* save alloc_ptr now so we can free if error */ /* save alloc_ptr now so we can free if error */
req->alloc = (void*)alloc_ptr; req->alloc = (void*) alloc_ptr;
/* Convert node string to UTF16 into allocated memory and save pointer in the /* Convert node string to UTF16 into allocated memory and save pointer in the
* request. */ * request. The node here has been converted to ascii. */
if (node != NULL) { if (node != NULL) {
req->node = (WCHAR*)alloc_ptr; req->node = (WCHAR*) alloc_ptr;
if (MultiByteToWideChar(CP_UTF8, uv_wtf8_to_utf16(node, (WCHAR*) alloc_ptr, nodesize);
0, alloc_ptr += ALIGNED_SIZE(nodesize * sizeof(WCHAR));
node,
-1,
(WCHAR*) alloc_ptr,
nodesize / sizeof(WCHAR)) == 0) {
err = GetLastError();
goto error;
}
alloc_ptr += nodesize;
} else { } else {
req->node = NULL; req->node = NULL;
} }
@ -343,24 +303,16 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* Convert service string to UTF16 into allocated memory and save pointer in /* Convert service string to UTF16 into allocated memory and save pointer in
* the req. */ * the req. */
if (service != NULL) { if (service != NULL) {
req->service = (WCHAR*)alloc_ptr; req->service = (WCHAR*) alloc_ptr;
if (MultiByteToWideChar(CP_UTF8, uv_wtf8_to_utf16(service, (WCHAR*) alloc_ptr, servicesize);
0, alloc_ptr += ALIGNED_SIZE(servicesize * sizeof(WCHAR));
service,
-1,
(WCHAR*) alloc_ptr,
servicesize / sizeof(WCHAR)) == 0) {
err = GetLastError();
goto error;
}
alloc_ptr += servicesize;
} else { } else {
req->service = NULL; req->service = NULL;
} }
/* copy hints to allocated memory and save pointer in req */ /* copy hints to allocated memory and save pointer in req */
if (hints != NULL) { if (hints != NULL) {
req->addrinfow = (struct addrinfoW*)alloc_ptr; req->addrinfow = (struct addrinfoW*) alloc_ptr;
req->addrinfow->ai_family = hints->ai_family; req->addrinfow->ai_family = hints->ai_family;
req->addrinfow->ai_socktype = hints->ai_socktype; req->addrinfow->ai_socktype = hints->ai_socktype;
req->addrinfow->ai_protocol = hints->ai_protocol; req->addrinfow->ai_protocol = hints->ai_protocol;
@ -387,19 +339,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
uv__getaddrinfo_done(&req->work_req, 0); uv__getaddrinfo_done(&req->work_req, 0);
return req->retcode; return req->retcode;
} }
error:
if (req != NULL) {
uv__free(req->alloc);
req->alloc = NULL;
}
return uv_translate_sys_error(err);
} }
int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) { int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
NET_LUID luid; NET_LUID luid;
wchar_t wname[NDIS_IF_MAX_STRING_SIZE + 1]; /* Add one for the NUL. */ wchar_t wname[NDIS_IF_MAX_STRING_SIZE + 1]; /* Add one for the NUL. */
DWORD bufsize;
int r; int r;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
@ -415,31 +359,7 @@ int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
if (r != 0) if (r != 0)
return uv_translate_sys_error(r); return uv_translate_sys_error(r);
/* Check how much space we need */ return uv__copy_utf16_to_utf8(wname, -1, buffer, size);
bufsize = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL, 0, NULL, NULL);
if (bufsize == 0) {
return uv_translate_sys_error(GetLastError());
} else if (bufsize > *size) {
*size = bufsize;
return UV_ENOBUFS;
}
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
wname,
-1,
buffer,
*size,
NULL,
NULL);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
*size = bufsize - 1;
return 0;
} }
int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) { int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) {

View File

@ -42,6 +42,7 @@ static void uv__getnameinfo_work(struct uv__work* w) {
uv_getnameinfo_t* req; uv_getnameinfo_t* req;
WCHAR host[NI_MAXHOST]; WCHAR host[NI_MAXHOST];
WCHAR service[NI_MAXSERV]; WCHAR service[NI_MAXSERV];
size_t size;
int ret; int ret;
req = container_of(w, uv_getnameinfo_t, work_req); req = container_of(w, uv_getnameinfo_t, work_req);
@ -57,29 +58,17 @@ static void uv__getnameinfo_work(struct uv__work* w) {
return; return;
} }
ret = WideCharToMultiByte(CP_UTF8, size = sizeof(req->host);
0, ret = uv__copy_utf16_to_utf8(host, -1, req->host, &size);
host, if (ret < 0) {
-1, req->retcode = ret;
req->host,
sizeof(req->host),
NULL,
NULL);
if (ret == 0) {
req->retcode = uv_translate_sys_error(GetLastError());
return; return;
} }
ret = WideCharToMultiByte(CP_UTF8, size = sizeof(req->service);
0, ret = uv__copy_utf16_to_utf8(service, -1, req->service, &size);
service, if (ret < 0) {
-1, req->retcode = ret;
req->service,
sizeof(req->service),
NULL,
NULL);
if (ret == 0) {
req->retcode = uv_translate_sys_error(GetLastError());
} }
} }

View File

@ -257,8 +257,9 @@ void uv__util_init(void);
uint64_t uv__hrtime(unsigned int scale); uint64_t uv__hrtime(unsigned int scale);
__declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall); __declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8); int uv__convert_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char** utf8);
int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16); int uv__copy_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char* utf8, size_t *size);
int uv__convert_utf8_to_utf16(const char* utf8, WCHAR** utf16);
typedef int (WINAPI *uv__peersockfunc)(SOCKET, struct sockaddr*, int*); typedef int (WINAPI *uv__peersockfunc)(SOCKET, struct sockaddr*, int*);

View File

@ -49,7 +49,7 @@ static const int default_pending_pipe_instances = 4;
/* Pipe prefix */ /* Pipe prefix */
static char pipe_prefix[] = "\\\\?\\pipe"; static char pipe_prefix[] = "\\\\?\\pipe";
static const int pipe_prefix_len = sizeof(pipe_prefix) - 1; static const size_t pipe_prefix_len = sizeof(pipe_prefix) - 1;
/* IPC incoming xfer queue item. */ /* IPC incoming xfer queue item. */
typedef struct { typedef struct {
@ -703,7 +703,7 @@ int uv_pipe_bind2(uv_pipe_t* handle,
size_t namelen, size_t namelen,
unsigned int flags) { unsigned int flags) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int i, err, nameSize; int i, err;
uv_pipe_accept_t* req; uv_pipe_accept_t* req;
if (flags & ~UV_PIPE_NO_TRUNCATE) { if (flags & ~UV_PIPE_NO_TRUNCATE) {
@ -742,9 +742,8 @@ int uv_pipe_bind2(uv_pipe_t* handle,
handle->pipe.serv.accept_reqs = (uv_pipe_accept_t*) handle->pipe.serv.accept_reqs = (uv_pipe_accept_t*)
uv__malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances); uv__malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances);
if (!handle->pipe.serv.accept_reqs) { if (!handle->pipe.serv.accept_reqs)
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); return UV_ENOMEM;
}
for (i = 0; i < handle->pipe.serv.pending_instances; i++) { for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
req = &handle->pipe.serv.accept_reqs[i]; req = &handle->pipe.serv.accept_reqs[i];
@ -754,22 +753,9 @@ int uv_pipe_bind2(uv_pipe_t* handle,
req->next_pending = NULL; req->next_pending = NULL;
} }
/* Convert name to UTF16. */ err = uv__convert_utf8_to_utf16(name, &handle->name);
nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0) * sizeof(WCHAR); if (err)
handle->name = uv__malloc(nameSize); return err;
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!MultiByteToWideChar(CP_UTF8,
0,
name,
-1,
handle->name,
nameSize / sizeof(WCHAR))) {
err = GetLastError();
goto error;
}
/* /*
* Attempt to create the first pipe with FILE_FLAG_FIRST_PIPE_INSTANCE. * Attempt to create the first pipe with FILE_FLAG_FIRST_PIPE_INSTANCE.
@ -795,10 +781,8 @@ int uv_pipe_bind2(uv_pipe_t* handle,
return 0; return 0;
error: error:
if (handle->name) { uv__free(handle->name);
uv__free(handle->name); handle->name = NULL;
handle->name = NULL;
}
return uv_translate_sys_error(err); return uv_translate_sys_error(err);
} }
@ -861,7 +845,8 @@ int uv_pipe_connect2(uv_connect_t* req,
unsigned int flags, unsigned int flags,
uv_connect_cb cb) { uv_connect_cb cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int err, nameSize; int err;
size_t nameSize;
HANDLE pipeHandle = INVALID_HANDLE_VALUE; HANDLE pipeHandle = INVALID_HANDLE_VALUE;
DWORD duplex_flags; DWORD duplex_flags;
@ -904,26 +889,16 @@ int uv_pipe_connect2(uv_connect_t* req,
} }
uv__pipe_connection_init(handle); uv__pipe_connection_init(handle);
/* Convert name to UTF16. */ err = uv__convert_utf8_to_utf16(name, &handle->name);
nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0) * sizeof(WCHAR); if (err) {
handle->name = uv__malloc(nameSize); err = ERROR_NO_UNICODE_TRANSLATION;
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!MultiByteToWideChar(CP_UTF8,
0,
name,
-1,
handle->name,
nameSize / sizeof(WCHAR))) {
err = GetLastError();
goto error; goto error;
} }
pipeHandle = open_named_pipe(handle->name, &duplex_flags); pipeHandle = open_named_pipe(handle->name, &duplex_flags);
if (pipeHandle == INVALID_HANDLE_VALUE) { if (pipeHandle == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_PIPE_BUSY) { if (GetLastError() == ERROR_PIPE_BUSY) {
nameSize = (wcslen(handle->name) + 1) * sizeof(WCHAR);
req->u.connect.name = uv__malloc(nameSize); req->u.connect.name = uv__malloc(nameSize);
if (!req->u.connect.name) { if (!req->u.connect.name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
@ -2439,7 +2414,6 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
FILE_NAME_INFORMATION tmp_name_info; FILE_NAME_INFORMATION tmp_name_info;
FILE_NAME_INFORMATION* name_info; FILE_NAME_INFORMATION* name_info;
WCHAR* name_buf; WCHAR* name_buf;
unsigned int addrlen;
unsigned int name_size; unsigned int name_size;
unsigned int name_len; unsigned int name_len;
int err; int err;
@ -2450,46 +2424,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
if (handle->name != NULL) { if (handle->name != NULL) {
/* The user might try to query the name before we are connected, /* The user might try to query the name before we are connected,
* and this is just easier to return the cached value if we have it. */ * and this is just easier to return the cached value if we have it. */
name_buf = handle->name; return uv__copy_utf16_to_utf8(handle->name, -1, buffer, size);
name_len = wcslen(name_buf);
/* check how much space we need */
addrlen = WideCharToMultiByte(CP_UTF8,
0,
name_buf,
name_len,
NULL,
0,
NULL,
NULL);
if (!addrlen) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
return err;
} else if (addrlen >= *size) {
*size = addrlen + 1;
err = UV_ENOBUFS;
goto error;
}
addrlen = WideCharToMultiByte(CP_UTF8,
0,
name_buf,
name_len,
buffer,
addrlen,
NULL,
NULL);
if (!addrlen) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
return err;
}
*size = addrlen;
buffer[addrlen] = '\0';
return 0;
} }
if (handle->handle == INVALID_HANDLE_VALUE) { if (handle->handle == INVALID_HANDLE_VALUE) {
@ -2517,8 +2452,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
name_info = uv__malloc(name_size); name_info = uv__malloc(name_size);
if (!name_info) { if (!name_info) {
*size = 0; *size = 0;
err = UV_ENOMEM; return UV_ENOMEM;
goto cleanup;
} }
nt_status = pNtQueryInformationFile(handle->handle, nt_status = pNtQueryInformationFile(handle->handle,
@ -2551,51 +2485,19 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
name_len /= sizeof(WCHAR); name_len /= sizeof(WCHAR);
/* check how much space we need */ /* "\\\\.\\pipe" + name */
addrlen = WideCharToMultiByte(CP_UTF8, if (*size < pipe_prefix_len) {
0,
name_buf,
name_len,
NULL,
0,
NULL,
NULL);
if (!addrlen) {
*size = 0; *size = 0;
err = uv_translate_sys_error(GetLastError());
goto error;
} else if (pipe_prefix_len + addrlen >= *size) {
/* "\\\\.\\pipe" + name */
*size = pipe_prefix_len + addrlen + 1;
err = UV_ENOBUFS;
goto error;
} }
else {
memcpy(buffer, pipe_prefix, pipe_prefix_len); memcpy(buffer, pipe_prefix, pipe_prefix_len);
addrlen = WideCharToMultiByte(CP_UTF8, *size -= pipe_prefix_len;
0,
name_buf,
name_len,
buffer+pipe_prefix_len,
*size-pipe_prefix_len,
NULL,
NULL);
if (!addrlen) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
goto error;
} }
err = uv__copy_utf16_to_utf8(name_buf, name_len, buffer+pipe_prefix_len, size);
addrlen += pipe_prefix_len; *size += pipe_prefix_len;
*size = addrlen;
buffer[addrlen] = '\0';
err = 0;
error: error:
uv__free(name_info); uv__free(name_info);
cleanup:
return err; return err;
} }

View File

@ -105,38 +105,26 @@ static void uv__init_global_job_handle(void) {
&info, &info,
sizeof info)) sizeof info))
uv_fatal_error(GetLastError(), "SetInformationJobObject"); uv_fatal_error(GetLastError(), "SetInformationJobObject");
if (!AssignProcessToJobObject(uv_global_job_handle_, GetCurrentProcess())) {
/* Make sure this handle is functional. The Windows kernel has a bug that
* if the first use of AssignProcessToJobObject is for a Windows Store
* program, subsequent attempts to use the handle with fail with
* INVALID_PARAMETER (87). This is possibly because all uses of the handle
* must be for the same Terminal Services session. We can ensure it is tied
* to our current session now by adding ourself to it. We could remove
* ourself afterwards, but there doesn't seem to be a reason to.
*/
DWORD err = GetLastError();
if (err != ERROR_ACCESS_DENIED)
uv_fatal_error(err, "AssignProcessToJobObject");
}
} }
static int uv__utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) { static int uv__utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
int ws_len, r; return uv__convert_utf8_to_utf16(s, ws_ptr);
WCHAR* ws;
ws_len = MultiByteToWideChar(CP_UTF8,
0,
s,
-1,
NULL,
0);
if (ws_len <= 0) {
return GetLastError();
}
ws = (WCHAR*) uv__malloc(ws_len * sizeof(WCHAR));
if (ws == NULL) {
return ERROR_OUTOFMEMORY;
}
r = MultiByteToWideChar(CP_UTF8,
0,
s,
-1,
ws,
ws_len);
assert(r == ws_len);
*ws_ptr = ws;
return 0;
} }
@ -396,7 +384,7 @@ static WCHAR* search_path(const WCHAR *file,
name_has_ext); name_has_ext);
while (result == NULL) { while (result == NULL) {
if (*dir_end == L'\0') { if (dir_end == NULL || *dir_end == L'\0') {
break; break;
} }
@ -539,21 +527,15 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
/* Count the required size. */ /* Count the required size. */
for (arg = args; *arg; arg++) { for (arg = args; *arg; arg++) {
DWORD arg_len; ssize_t arg_len;
arg_len = MultiByteToWideChar(CP_UTF8, arg_len = uv_wtf8_length_as_utf16(*arg);
0, if (arg_len < 0)
*arg, return arg_len;
-1,
NULL,
0);
if (arg_len == 0) {
return GetLastError();
}
dst_len += arg_len; dst_len += arg_len;
if (arg_len > temp_buffer_len) if ((size_t) arg_len > temp_buffer_len)
temp_buffer_len = arg_len; temp_buffer_len = arg_len;
arg_count++; arg_count++;
@ -564,34 +546,28 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
dst_len = dst_len * 2 + arg_count * 2; dst_len = dst_len * 2 + arg_count * 2;
/* Allocate buffer for the final command line. */ /* Allocate buffer for the final command line. */
dst = (WCHAR*) uv__malloc(dst_len * sizeof(WCHAR)); dst = uv__malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) { if (dst == NULL) {
err = ERROR_OUTOFMEMORY; err = UV_ENOMEM;
goto error; goto error;
} }
/* Allocate temporary working buffer. */ /* Allocate temporary working buffer. */
temp_buffer = (WCHAR*) uv__malloc(temp_buffer_len * sizeof(WCHAR)); temp_buffer = uv__malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) { if (temp_buffer == NULL) {
err = ERROR_OUTOFMEMORY; err = UV_ENOMEM;
goto error; goto error;
} }
pos = dst; pos = dst;
for (arg = args; *arg; arg++) { for (arg = args; *arg; arg++) {
DWORD arg_len; ssize_t arg_len;
/* Convert argument to wide char. */ /* Convert argument to wide char. */
arg_len = MultiByteToWideChar(CP_UTF8, arg_len = uv_wtf8_length_as_utf16(*arg);
0, assert(arg_len > 0);
*arg, assert(temp_buffer_len >= (size_t) arg_len);
-1, uv_wtf8_to_utf16(*arg, temp_buffer, arg_len);
temp_buffer,
(int) (dst + dst_len - pos));
if (arg_len == 0) {
err = GetLastError();
goto error;
}
if (verbatim_arguments) { if (verbatim_arguments) {
/* Copy verbatim. */ /* Copy verbatim. */
@ -603,6 +579,7 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
} }
*pos++ = *(arg + 1) ? L' ' : L'\0'; *pos++ = *(arg + 1) ? L' ' : L'\0';
assert(pos <= dst + dst_len);
} }
uv__free(temp_buffer); uv__free(temp_buffer);
@ -688,55 +665,43 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
WCHAR* ptr; WCHAR* ptr;
char** env; char** env;
size_t env_len = 0; size_t env_len = 0;
int len; size_t len;
size_t i; size_t i;
DWORD var_size; size_t var_size;
size_t env_block_count = 1; /* 1 for null-terminator */ size_t env_block_count = 1; /* 1 for null-terminator */
WCHAR* dst_copy; WCHAR* dst_copy;
WCHAR** ptr_copy; WCHAR** ptr_copy;
WCHAR** env_copy; WCHAR** env_copy;
DWORD required_vars_value_len[ARRAY_SIZE(required_vars)]; size_t required_vars_value_len[ARRAY_SIZE(required_vars)];
/* first pass: determine size in UTF-16 */ /* first pass: determine size in UTF-16 */
for (env = env_block; *env; env++) { for (env = env_block; *env; env++) {
int len; ssize_t len;
if (strchr(*env, '=')) { if (strchr(*env, '=')) {
len = MultiByteToWideChar(CP_UTF8, len = uv_wtf8_length_as_utf16(*env);
0, if (len < 0)
*env, return len;
-1,
NULL,
0);
if (len <= 0) {
return GetLastError();
}
env_len += len; env_len += len;
env_block_count++; env_block_count++;
} }
} }
/* second pass: copy to UTF-16 environment block */ /* second pass: copy to UTF-16 environment block */
dst_copy = (WCHAR*)uv__malloc(env_len * sizeof(WCHAR)); dst_copy = uv__malloc(env_len * sizeof(WCHAR));
if (dst_copy == NULL && env_len > 0) { if (dst_copy == NULL && env_len > 0) {
return ERROR_OUTOFMEMORY; return UV_ENOMEM;
} }
env_copy = alloca(env_block_count * sizeof(WCHAR*)); env_copy = alloca(env_block_count * sizeof(WCHAR*));
ptr = dst_copy; ptr = dst_copy;
ptr_copy = env_copy; ptr_copy = env_copy;
for (env = env_block; *env; env++) { for (env = env_block; *env; env++) {
ssize_t len;
if (strchr(*env, '=')) { if (strchr(*env, '=')) {
len = MultiByteToWideChar(CP_UTF8, len = uv_wtf8_length_as_utf16(*env);
0, assert(len > 0);
*env, assert((size_t) len <= env_len - (ptr - dst_copy));
-1, uv_wtf8_to_utf16(*env, ptr, len);
ptr,
(int) (env_len - (ptr - dst_copy)));
if (len <= 0) {
DWORD err = GetLastError();
uv__free(dst_copy);
return err;
}
*ptr_copy++ = ptr; *ptr_copy++ = ptr;
ptr += len; ptr += len;
} }
@ -754,7 +719,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
cmp = -1; cmp = -1;
} else { } else {
cmp = env_strncmp(required_vars[i].wide_eq, cmp = env_strncmp(required_vars[i].wide_eq,
required_vars[i].len, required_vars[i].len,
*ptr_copy); *ptr_copy);
} }
if (cmp < 0) { if (cmp < 0) {
@ -777,7 +742,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
dst = uv__malloc((1+env_len) * sizeof(WCHAR)); dst = uv__malloc((1+env_len) * sizeof(WCHAR));
if (!dst) { if (!dst) {
uv__free(dst_copy); uv__free(dst_copy);
return ERROR_OUTOFMEMORY; return UV_ENOMEM;
} }
for (ptr = dst, ptr_copy = env_copy, i = 0; for (ptr = dst, ptr_copy = env_copy, i = 0;
@ -975,26 +940,26 @@ int uv_spawn(uv_loop_t* loop,
err = uv__utf8_to_utf16_alloc(options->file, &application); err = uv__utf8_to_utf16_alloc(options->file, &application);
if (err) if (err)
goto done; goto done_uv;
err = make_program_args( err = make_program_args(
options->args, options->args,
options->flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS, options->flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
&arguments); &arguments);
if (err) if (err)
goto done; goto done_uv;
if (options->env) { if (options->env) {
err = make_program_env(options->env, &env); err = make_program_env(options->env, &env);
if (err) if (err)
goto done; goto done_uv;
} }
if (options->cwd) { if (options->cwd) {
/* Explicit cwd */ /* Explicit cwd */
err = uv__utf8_to_utf16_alloc(options->cwd, &cwd); err = uv__utf8_to_utf16_alloc(options->cwd, &cwd);
if (err) if (err)
goto done; goto done_uv;
} else { } else {
/* Inherit cwd */ /* Inherit cwd */
@ -1025,22 +990,19 @@ int uv_spawn(uv_loop_t* loop,
DWORD path_len, r; DWORD path_len, r;
path_len = GetEnvironmentVariableW(L"PATH", NULL, 0); path_len = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (path_len == 0) { if (path_len != 0) {
err = GetLastError(); alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR));
goto done; if (alloc_path == NULL) {
} err = ERROR_OUTOFMEMORY;
goto done;
}
path = alloc_path;
alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR)); r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (alloc_path == NULL) { if (r == 0 || r >= path_len) {
err = ERROR_OUTOFMEMORY; err = GetLastError();
goto done; goto done;
} }
path = alloc_path;
r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) {
err = GetLastError();
goto done;
} }
} }
@ -1102,6 +1064,7 @@ int uv_spawn(uv_loop_t* loop,
* breakaway. * breakaway.
*/ */
process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP; process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;
process_flags |= CREATE_SUSPENDED;
} }
if (!CreateProcessW(application_path, if (!CreateProcessW(application_path,
@ -1119,11 +1082,6 @@ int uv_spawn(uv_loop_t* loop,
goto done; goto done;
} }
/* Spawn succeeded. Beyond this point, failure is reported asynchronously. */
process->process_handle = info.hProcess;
process->pid = info.dwProcessId;
/* If the process isn't spawned as detached, assign to the global job object /* If the process isn't spawned as detached, assign to the global job object
* so windows will kill it when the parent process dies. */ * so windows will kill it when the parent process dies. */
if (!(options->flags & UV_PROCESS_DETACHED)) { if (!(options->flags & UV_PROCESS_DETACHED)) {
@ -1146,6 +1104,19 @@ int uv_spawn(uv_loop_t* loop,
} }
} }
if (process_flags & CREATE_SUSPENDED) {
if (ResumeThread(info.hThread) == ((DWORD)-1)) {
err = GetLastError();
TerminateProcess(info.hProcess, 1);
goto done;
}
}
/* Spawn succeeded. Beyond this point, failure is reported asynchronously. */
process->process_handle = info.hProcess;
process->pid = info.dwProcessId;
/* Set IPC pid to all IPC pipes. */ /* Set IPC pid to all IPC pipes. */
for (i = 0; i < options->stdio_count; i++) { for (i = 0; i < options->stdio_count; i++) {
const uv_stdio_container_t* fdopt = &options->stdio[i]; const uv_stdio_container_t* fdopt = &options->stdio[i];
@ -1173,8 +1144,13 @@ int uv_spawn(uv_loop_t* loop,
* made or the handle is closed, whichever happens first. */ * made or the handle is closed, whichever happens first. */
uv__handle_start(process); uv__handle_start(process);
goto done_uv;
/* Cleanup, whether we succeeded or failed. */ /* Cleanup, whether we succeeded or failed. */
done: done:
err = uv_translate_sys_error(err);
done_uv:
uv__free(application); uv__free(application);
uv__free(application_path); uv__free(application_path);
uv__free(arguments); uv__free(arguments);
@ -1188,7 +1164,7 @@ int uv_spawn(uv_loop_t* loop,
child_stdio_buffer = NULL; child_stdio_buffer = NULL;
} }
return uv_translate_sys_error(err); return err;
} }

View File

@ -482,9 +482,11 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
uv_loop_t* loop; uv_loop_t* loop;
uv_tty_t* handle; uv_tty_t* handle;
uv_req_t* req; uv_req_t* req;
DWORD bytes, read_bytes; DWORD bytes;
size_t read_bytes;
WCHAR utf16[MAX_INPUT_BUFFER_LENGTH / 3]; WCHAR utf16[MAX_INPUT_BUFFER_LENGTH / 3];
DWORD chars, read_chars; DWORD chars;
DWORD read_chars;
LONG status; LONG status;
COORD pos; COORD pos;
BOOL read_console_success; BOOL read_console_success;
@ -525,16 +527,13 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
NULL); NULL);
if (read_console_success) { if (read_console_success) {
read_bytes = WideCharToMultiByte(CP_UTF8, read_bytes = bytes;
0, uv_utf16_to_wtf8(utf16,
utf16, read_chars,
read_chars, &handle->tty.rd.read_line_buffer.base,
handle->tty.rd.read_line_buffer.base, &read_bytes);
bytes,
NULL,
NULL);
SET_REQ_SUCCESS(req); SET_REQ_SUCCESS(req);
req->u.io.overlapped.InternalHigh = read_bytes; req->u.io.overlapped.InternalHigh = (DWORD) read_bytes;
} else { } else {
SET_REQ_ERROR(req, GetLastError()); SET_REQ_ERROR(req, GetLastError());
} }
@ -798,7 +797,9 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
} }
if (KEV.uChar.UnicodeChar != 0) { if (KEV.uChar.UnicodeChar != 0) {
int prefix_len, char_len; int prefix_len;
size_t char_len;
char* last_key_buf;
/* Character key pressed */ /* Character key pressed */
if (KEV.uChar.UnicodeChar >= 0xD800 && if (KEV.uChar.UnicodeChar >= 0xD800 &&
@ -819,38 +820,31 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
prefix_len = 0; prefix_len = 0;
} }
if (KEV.uChar.UnicodeChar >= 0xDC00 && char_len = sizeof handle->tty.rd.last_key;
KEV.uChar.UnicodeChar < 0xE000) { last_key_buf = &handle->tty.rd.last_key[prefix_len];
if (handle->tty.rd.last_utf16_high_surrogate) {
/* UTF-16 surrogate pair */ /* UTF-16 surrogate pair */
WCHAR utf16_buffer[2]; WCHAR utf16_buffer[2];
utf16_buffer[0] = handle->tty.rd.last_utf16_high_surrogate; utf16_buffer[0] = handle->tty.rd.last_utf16_high_surrogate;
utf16_buffer[1] = KEV.uChar.UnicodeChar; utf16_buffer[1] = KEV.uChar.UnicodeChar;
char_len = WideCharToMultiByte(CP_UTF8, if (uv_utf16_to_wtf8(utf16_buffer,
0, 2,
utf16_buffer, &last_key_buf,
2, &char_len))
&handle->tty.rd.last_key[prefix_len], char_len = 0;
sizeof handle->tty.rd.last_key, handle->tty.rd.last_utf16_high_surrogate = 0;
NULL,
NULL);
} else { } else {
/* Single UTF-16 character */ /* Single UTF-16 character */
char_len = WideCharToMultiByte(CP_UTF8, if (uv_utf16_to_wtf8(&KEV.uChar.UnicodeChar,
0, 1,
&KEV.uChar.UnicodeChar, &last_key_buf,
1, &char_len))
&handle->tty.rd.last_key[prefix_len], char_len = 0;
sizeof handle->tty.rd.last_key,
NULL,
NULL);
} }
/* Whatever happened, the last character wasn't a high surrogate. */
handle->tty.rd.last_utf16_high_surrogate = 0;
/* If the utf16 character(s) couldn't be converted something must be /* If the utf16 character(s) couldn't be converted something must be
* wrong. */ * wrong. */
if (!char_len) { if (char_len == 0) {
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle, handle->read_cb((uv_stream_t*) handle,

View File

@ -95,7 +95,7 @@ void uv__util_init(void) {
int uv_exepath(char* buffer, size_t* size_ptr) { int uv_exepath(char* buffer, size_t* size_ptr) {
int utf8_len, utf16_buffer_len, utf16_len; size_t utf8_len, utf16_buffer_len, utf16_len;
WCHAR* utf16_buffer; WCHAR* utf16_buffer;
int err; int err;
@ -123,25 +123,17 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
} }
/* Convert to UTF-8 */ /* Convert to UTF-8 */
utf8_len = WideCharToMultiByte(CP_UTF8, utf8_len = *size_ptr - 1; /* Reserve space for NUL */
0, err = uv_utf16_to_wtf8(utf16_buffer, utf16_len, &buffer, &utf8_len);
utf16_buffer, if (err == UV_ENOBUFS) {
-1, utf8_len = *size_ptr - 1;
buffer, err = 0;
(int) *size_ptr,
NULL,
NULL);
if (utf8_len == 0) {
err = GetLastError();
goto error;
} }
*size_ptr = utf8_len;
uv__free(utf16_buffer); uv__free(utf16_buffer);
/* utf8_len *does* include the terminating null at this point, but the return err;
* returned size shouldn't. */
*size_ptr = utf8_len - 1;
return 0;
error: error:
uv__free(utf16_buffer); uv__free(utf16_buffer);
@ -204,45 +196,14 @@ int uv_cwd(char* buffer, size_t* size) {
} }
r = uv__cwd(&utf16_buffer, &utf16_len); r = uv__cwd(&utf16_buffer, &utf16_len);
if (r < 0) { if (r < 0)
return r; return r;
}
/* Check how much space we need */ r = uv__copy_utf16_to_utf8(utf16_buffer, utf16_len, buffer, size);
r = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
-1,
NULL,
0,
NULL,
NULL);
if (r == 0) {
uv__free(utf16_buffer);
return uv_translate_sys_error(GetLastError());
} else if (r > (int) *size) {
uv__free(utf16_buffer);
*size = r;
return UV_ENOBUFS;
}
/* Convert to UTF-8 */
r = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
-1,
buffer,
*size > INT_MAX ? INT_MAX : (int) *size,
NULL,
NULL);
uv__free(utf16_buffer); uv__free(utf16_buffer);
if (r == 0) { return r;
return uv_translate_sys_error(GetLastError());
}
*size = r - 1;
return 0;
} }
@ -252,33 +213,10 @@ int uv_chdir(const char* dir) {
WCHAR drive_letter, env_var[4]; WCHAR drive_letter, env_var[4];
int r; int r;
if (dir == NULL) { /* Convert to UTF-16 */
return UV_EINVAL; r = uv__convert_utf8_to_utf16(dir, &utf16_buffer);
} if (r)
return r;
utf16_len = MultiByteToWideChar(CP_UTF8,
0,
dir,
-1,
NULL,
0);
if (utf16_len == 0) {
return uv_translate_sys_error(GetLastError());
}
utf16_buffer = uv__malloc(utf16_len * sizeof(WCHAR));
if (utf16_buffer == NULL) {
return UV_ENOMEM;
}
if (MultiByteToWideChar(CP_UTF8,
0,
dir,
-1,
utf16_buffer,
utf16_len) == 0) {
uv__free(utf16_buffer);
return uv_translate_sys_error(GetLastError());
}
if (!SetCurrentDirectoryW(utf16_buffer)) { if (!SetCurrentDirectoryW(utf16_buffer)) {
uv__free(utf16_buffer); uv__free(utf16_buffer);
@ -416,29 +354,14 @@ int uv_set_process_title(const char* title) {
uv__once_init(); uv__once_init();
/* Find out how big the buffer for the wide-char title must be */ err = uv__convert_utf8_to_utf16(title, &title_w);
length = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0); if (err)
if (!length) { return err;
err = GetLastError();
goto done;
}
/* Convert to wide-char string */
title_w = (WCHAR*)uv__malloc(sizeof(WCHAR) * length);
if (!title_w) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
length = MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, length);
if (!length) {
err = GetLastError();
goto done;
}
/* If the title must be truncated insert a \0 terminator there */ /* If the title must be truncated insert a \0 terminator there */
if (length > MAX_TITLE_LENGTH) { length = wcslen(title_w);
if (length >= MAX_TITLE_LENGTH)
title_w[MAX_TITLE_LENGTH - 1] = L'\0'; title_w[MAX_TITLE_LENGTH - 1] = L'\0';
}
if (!SetConsoleTitleW(title_w)) { if (!SetConsoleTitleW(title_w)) {
err = GetLastError(); err = GetLastError();
@ -460,20 +383,19 @@ done:
static int uv__get_process_title(void) { static int uv__get_process_title(void) {
WCHAR title_w[MAX_TITLE_LENGTH]; WCHAR title_w[MAX_TITLE_LENGTH];
DWORD wlen;
if (!GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR))) { wlen = GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR));
return -1; if (wlen == 0)
} return uv_translate_sys_error(GetLastError());
if (uv__convert_utf16_to_utf8(title_w, -1, &process_title) != 0) return uv__convert_utf16_to_utf8(title_w, wlen, &process_title);
return -1;
return 0;
} }
int uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
size_t len; size_t len;
int r;
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return UV_EINVAL; return UV_EINVAL;
@ -485,9 +407,12 @@ int uv_get_process_title(char* buffer, size_t size) {
* If the process_title was never read before nor explicitly set, * If the process_title was never read before nor explicitly set,
* we must query it with getConsoleTitleW * we must query it with getConsoleTitleW
*/ */
if (!process_title && uv__get_process_title() == -1) { if (process_title == NULL) {
LeaveCriticalSection(&process_title_lock); r = uv__get_process_title();
return uv_translate_sys_error(GetLastError()); if (r) {
LeaveCriticalSection(&process_title_lock);
return r;
}
} }
assert(process_title); assert(process_title);
@ -833,19 +758,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
continue; continue;
/* Compute the size of the interface name. */ /* Compute the size of the interface name. */
name_size = WideCharToMultiByte(CP_UTF8, name_size = uv_utf16_length_as_wtf8(adapter->FriendlyName, -1);
0, uv_address_buf_size += name_size + 1;
adapter->FriendlyName,
-1,
NULL,
0,
NULL,
FALSE);
if (name_size <= 0) {
uv__free(win_address_buf);
return uv_translate_sys_error(GetLastError());
}
uv_address_buf_size += name_size;
/* Count the number of addresses associated with this interface, and /* Count the number of addresses associated with this interface, and
* compute the size. */ * compute the size. */
@ -875,30 +789,25 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
adapter != NULL; adapter != NULL;
adapter = adapter->Next) { adapter = adapter->Next) {
IP_ADAPTER_UNICAST_ADDRESS* unicast_address; IP_ADAPTER_UNICAST_ADDRESS* unicast_address;
int name_size; size_t name_size;
size_t max_name_size; int r;
if (adapter->OperStatus != IfOperStatusUp || if (adapter->OperStatus != IfOperStatusUp ||
adapter->FirstUnicastAddress == NULL) adapter->FirstUnicastAddress == NULL)
continue; continue;
/* Convert the interface name to UTF8. */ /* Convert the interface name to UTF8. */
max_name_size = (char*) uv_address_buf + uv_address_buf_size - name_buf; name_size = (char*) uv_address_buf + uv_address_buf_size - name_buf;
if (max_name_size > (size_t) INT_MAX) r = uv__copy_utf16_to_utf8(adapter->FriendlyName,
max_name_size = INT_MAX; -1,
name_size = WideCharToMultiByte(CP_UTF8, name_buf,
0, &name_size);
adapter->FriendlyName, if (r) {
-1,
name_buf,
(int) max_name_size,
NULL,
FALSE);
if (name_size <= 0) {
uv__free(win_address_buf); uv__free(win_address_buf);
uv__free(uv_address_buf); uv__free(uv_address_buf);
return uv_translate_sys_error(GetLastError()); return r;
} }
name_size += 1; /* Add NUL byte. */
/* Add an uv_interface_address_t element for every unicast address. */ /* Add an uv_interface_address_t element for every unicast address. */
for (unicast_address = (IP_ADAPTER_UNICAST_ADDRESS*) for (unicast_address = (IP_ADAPTER_UNICAST_ADDRESS*)
@ -1061,7 +970,6 @@ int uv_os_homedir(char* buffer, size_t* size) {
int uv_os_tmpdir(char* buffer, size_t* size) { int uv_os_tmpdir(char* buffer, size_t* size) {
wchar_t *path; wchar_t *path;
DWORD bufsize;
size_t len; size_t len;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
@ -1078,7 +986,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
if (path == NULL) { if (path == NULL) {
return UV_ENOMEM; return UV_ENOMEM;
} }
len = GetTempPathW(len, path); len = GetTempPathW(len, path);
if (len == 0) { if (len == 0) {
uv__free(path); uv__free(path);
@ -1093,34 +1001,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
path[len] = L'\0'; path[len] = L'\0';
} }
/* Check how much space we need */ return uv__copy_utf16_to_utf8(path, len, buffer, size);
bufsize = WideCharToMultiByte(CP_UTF8, 0, path, -1, NULL, 0, NULL, NULL);
if (bufsize == 0) {
uv__free(path);
return uv_translate_sys_error(GetLastError());
} else if (bufsize > *size) {
uv__free(path);
*size = bufsize;
return UV_ENOBUFS;
}
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
path,
-1,
buffer,
*size,
NULL,
NULL);
uv__free(path);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
*size = bufsize - 1;
return 0;
} }
@ -1131,95 +1012,71 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
* If utf16 is null terminated, utf16len can be set to -1, otherwise it must * If utf16 is null terminated, utf16len can be set to -1, otherwise it must
* be specified. * be specified.
*/ */
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8) { int uv__convert_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char** utf8) {
DWORD bufsize; size_t utf8_len = 0;
if (utf16 == NULL) if (utf16 == NULL)
return UV_EINVAL; return UV_EINVAL;
/* Check how much space we need */ *utf8 = NULL;
bufsize = WideCharToMultiByte(CP_UTF8, return uv_utf16_to_wtf8(utf16, utf16len, utf8, &utf8_len);
0,
utf16,
utf16len,
NULL,
0,
NULL,
NULL);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf16len is not -1 WideCharToMultiByte will not add it, so
* we do it ourselves always, just in case. */
*utf8 = uv__malloc(bufsize + 1);
if (*utf8 == NULL)
return UV_ENOMEM;
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
utf16,
utf16len,
*utf8,
bufsize,
NULL,
NULL);
if (bufsize == 0) {
uv__free(*utf8);
*utf8 = NULL;
return uv_translate_sys_error(GetLastError());
}
(*utf8)[bufsize] = '\0';
return 0;
} }
/* /*
* Converts a UTF-8 string into a UTF-16 one. The resulting string is * Converts a UTF-8 string into a UTF-16 one. The resulting string is
* null-terminated. * null-terminated.
*
* If utf8 is null terminated, utf8len can be set to -1, otherwise it must
* be specified.
*/ */
int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16) { int uv__convert_utf8_to_utf16(const char* utf8, WCHAR** utf16) {
int bufsize; int bufsize;
if (utf8 == NULL) if (utf8 == NULL)
return UV_EINVAL; return UV_EINVAL;
/* Check how much space we need */ /* Check how much space we need (including NUL). */
bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, NULL, 0); bufsize = uv_wtf8_length_as_utf16(utf8);
if (bufsize < 0)
return UV__EINVAL;
if (bufsize == 0) /* Allocate the destination buffer. */
return uv_translate_sys_error(GetLastError()); *utf16 = uv__malloc(sizeof(WCHAR) * bufsize);
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf8len is not -1 MultiByteToWideChar will not add it, so
* we do it ourselves always, just in case. */
*utf16 = uv__malloc(sizeof(WCHAR) * (bufsize + 1));
if (*utf16 == NULL) if (*utf16 == NULL)
return UV_ENOMEM; return UV_ENOMEM;
/* Convert to UTF-16 */ /* Convert to UTF-16 */
bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, *utf16, bufsize); uv_wtf8_to_utf16(utf8, *utf16, bufsize);
if (bufsize == 0) {
uv__free(*utf16);
*utf16 = NULL;
return uv_translate_sys_error(GetLastError());
}
(*utf16)[bufsize] = L'\0';
return 0; return 0;
} }
/*
* Converts a UTF-16 string into a UTF-8 one in an existing buffer. The
* resulting string is null-terminated.
*
* If utf16 is null terminated, utf16len can be set to -1, otherwise it must
* be specified.
*/
int uv__copy_utf16_to_utf8(const WCHAR* utf16buffer, size_t utf16len, char* utf8, size_t *size) {
int r;
if (utf8 == NULL || size == NULL)
return UV_EINVAL;
if (*size == 0) {
*size = uv_utf16_length_as_wtf8(utf16buffer, utf16len);
r = UV_ENOBUFS;
} else {
*size -= 1; /* Reserve space for NUL. */
r = uv_utf16_to_wtf8(utf16buffer, utf16len, &utf8, size);
}
if (r == UV_ENOBUFS)
*size += 1; /* Add space for NUL. */
return r;
}
static int uv__getpwuid_r(uv_passwd_t* pwd) { static int uv__getpwuid_r(uv_passwd_t* pwd) {
HANDLE token; HANDLE token;
wchar_t username[UNLEN + 1]; wchar_t username[UNLEN + 1];
@ -1384,14 +1241,13 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
wchar_t* var; wchar_t* var;
DWORD varlen; DWORD varlen;
wchar_t* name_w; wchar_t* name_w;
DWORD bufsize;
size_t len; size_t len;
int r; int r;
if (name == NULL || buffer == NULL || size == NULL || *size == 0) if (name == NULL || buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL; return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w); r = uv__convert_utf8_to_utf16(name, &name_w);
if (r != 0) if (r != 0)
return r; return r;
@ -1432,35 +1288,7 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
} }
} }
/* Check how much space we need */ r = uv__copy_utf16_to_utf8(var, len, buffer, size);
bufsize = WideCharToMultiByte(CP_UTF8, 0, var, -1, NULL, 0, NULL, NULL);
if (bufsize == 0) {
r = uv_translate_sys_error(GetLastError());
goto fail;
} else if (bufsize > *size) {
*size = bufsize;
r = UV_ENOBUFS;
goto fail;
}
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
var,
-1,
buffer,
*size,
NULL,
NULL);
if (bufsize == 0) {
r = uv_translate_sys_error(GetLastError());
goto fail;
}
*size = bufsize - 1;
r = 0;
fail: fail:
@ -1482,12 +1310,12 @@ int uv_os_setenv(const char* name, const char* value) {
if (name == NULL || value == NULL) if (name == NULL || value == NULL)
return UV_EINVAL; return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w); r = uv__convert_utf8_to_utf16(name, &name_w);
if (r != 0) if (r != 0)
return r; return r;
r = uv__convert_utf8_to_utf16(value, -1, &value_w); r = uv__convert_utf8_to_utf16(value, &value_w);
if (r != 0) { if (r != 0) {
uv__free(name_w); uv__free(name_w);
@ -1512,7 +1340,7 @@ int uv_os_unsetenv(const char* name) {
if (name == NULL) if (name == NULL)
return UV_EINVAL; return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w); r = uv__convert_utf8_to_utf16(name, &name_w);
if (r != 0) if (r != 0)
return r; return r;
@ -1529,9 +1357,6 @@ int uv_os_unsetenv(const char* name) {
int uv_os_gethostname(char* buffer, size_t* size) { int uv_os_gethostname(char* buffer, size_t* size) {
WCHAR buf[UV_MAXHOSTNAMESIZE]; WCHAR buf[UV_MAXHOSTNAMESIZE];
size_t len;
char* utf8_str;
int convert_result;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL; return UV_EINVAL;
@ -1544,22 +1369,7 @@ int uv_os_gethostname(char* buffer, size_t* size) {
if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) != 0) if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) != 0)
return uv_translate_sys_error(WSAGetLastError()); return uv_translate_sys_error(WSAGetLastError());
convert_result = uv__convert_utf16_to_utf8(buf, -1, &utf8_str); return uv__copy_utf16_to_utf8(buf, -1, buffer, size);
if (convert_result != 0)
return convert_result;
len = strlen(utf8_str);
if (len >= *size) {
*size = len + 1;
uv__free(utf8_str);
return UV_ENOBUFS;
}
memcpy(buffer, utf8_str, len + 1);
uv__free(utf8_str);
*size = len;
return 0;
} }
@ -1665,7 +1475,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
HKEY registry_key; HKEY registry_key;
WCHAR product_name_w[256]; WCHAR product_name_w[256];
DWORD product_name_w_size; DWORD product_name_w_size;
int version_size; size_t version_size;
int processor_level; int processor_level;
int r; int r;
@ -1696,7 +1506,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0, 0,
KEY_QUERY_VALUE, KEY_QUERY_VALUE | KEY_WOW64_64KEY,
&registry_key); &registry_key);
if (r == ERROR_SUCCESS) { if (r == ERROR_SUCCESS) {
@ -1727,37 +1537,29 @@ int uv_os_uname(uv_utsname_t* buffer) {
} }
} }
version_size = WideCharToMultiByte(CP_UTF8, version_size = sizeof(buffer->version);
0, r = uv__copy_utf16_to_utf8(product_name_w,
product_name_w, -1,
-1, buffer->version,
buffer->version, &version_size);
sizeof(buffer->version), if (r)
NULL,
NULL);
if (version_size == 0) {
r = uv_translate_sys_error(GetLastError());
goto error; goto error;
}
} }
} }
/* Append service pack information to the version if present. */ /* Append service pack information to the version if present. */
if (os_info.szCSDVersion[0] != L'\0') { if (os_info.szCSDVersion[0] != L'\0') {
if (version_size > 0) if (version_size > 0)
buffer->version[version_size - 1] = ' '; buffer->version[version_size++] = ' ';
if (WideCharToMultiByte(CP_UTF8, version_size = sizeof(buffer->version) - version_size;
0, r = uv__copy_utf16_to_utf8(os_info.szCSDVersion,
os_info.szCSDVersion, -1,
-1, buffer->version +
buffer->version + version_size, sizeof(buffer->version) - version_size,
sizeof(buffer->version) - version_size, &version_size);
NULL, if (r)
NULL) == 0) {
r = uv_translate_sys_error(GetLastError());
goto error; goto error;
}
} }
/* Populate the sysname field. */ /* Populate the sysname field. */

View File

@ -71,21 +71,21 @@ static int test_async_pummel(int nthreads) {
tids = calloc(nthreads, sizeof(tids[0])); tids = calloc(nthreads, sizeof(tids[0]));
ASSERT_NOT_NULL(tids); ASSERT_NOT_NULL(tids);
ASSERT(0 == uv_async_init(uv_default_loop(), &handle, async_cb)); ASSERT_OK(uv_async_init(uv_default_loop(), &handle, async_cb));
ACCESS_ONCE(const char*, handle.data) = running; ACCESS_ONCE(const char*, handle.data) = running;
for (i = 0; i < nthreads; i++) for (i = 0; i < nthreads; i++)
ASSERT(0 == uv_thread_create(tids + i, pummel, &handle)); ASSERT_OK(uv_thread_create(tids + i, pummel, &handle));
time = uv_hrtime(); time = uv_hrtime();
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
time = uv_hrtime() - time; time = uv_hrtime() - time;
done = 1; done = 1;
for (i = 0; i < nthreads; i++) for (i = 0; i < nthreads; i++)
ASSERT(0 == uv_thread_join(tids + i)); ASSERT_OK(uv_thread_join(tids + i));
printf("async_pummel_%d: %s callbacks in %.2f seconds (%s/sec)\n", printf("async_pummel_%d: %s callbacks in %.2f seconds (%s/sec)\n",
nthreads, nthreads,

View File

@ -43,7 +43,7 @@ struct ctx {
static void worker_async_cb(uv_async_t* handle) { static void worker_async_cb(uv_async_t* handle) {
struct ctx* ctx = container_of(handle, struct ctx, worker_async); struct ctx* ctx = container_of(handle, struct ctx, worker_async);
ASSERT(0 == uv_async_send(&ctx->main_async)); ASSERT_OK(uv_async_send(&ctx->main_async));
ctx->worker_sent++; ctx->worker_sent++;
ctx->worker_seen++; ctx->worker_seen++;
@ -55,7 +55,7 @@ static void worker_async_cb(uv_async_t* handle) {
static void main_async_cb(uv_async_t* handle) { static void main_async_cb(uv_async_t* handle) {
struct ctx* ctx = container_of(handle, struct ctx, main_async); struct ctx* ctx = container_of(handle, struct ctx, main_async);
ASSERT(0 == uv_async_send(&ctx->worker_async)); ASSERT_OK(uv_async_send(&ctx->worker_async));
ctx->main_sent++; ctx->main_sent++;
ctx->main_seen++; ctx->main_seen++;
@ -66,8 +66,8 @@ static void main_async_cb(uv_async_t* handle) {
static void worker(void* arg) { static void worker(void* arg) {
struct ctx* ctx = arg; struct ctx* ctx = arg;
ASSERT(0 == uv_async_send(&ctx->main_async)); ASSERT_OK(uv_async_send(&ctx->main_async));
ASSERT(0 == uv_run(&ctx->loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(&ctx->loop, UV_RUN_DEFAULT));
uv_loop_close(&ctx->loop); uv_loop_close(&ctx->loop);
} }
@ -85,29 +85,29 @@ static int test_async(int nthreads) {
for (i = 0; i < nthreads; i++) { for (i = 0; i < nthreads; i++) {
ctx = threads + i; ctx = threads + i;
ctx->nthreads = nthreads; ctx->nthreads = nthreads;
ASSERT(0 == uv_loop_init(&ctx->loop)); ASSERT_OK(uv_loop_init(&ctx->loop));
ASSERT(0 == uv_async_init(&ctx->loop, &ctx->worker_async, worker_async_cb)); ASSERT_OK(uv_async_init(&ctx->loop, &ctx->worker_async, worker_async_cb));
ASSERT(0 == uv_async_init(uv_default_loop(), ASSERT_OK(uv_async_init(uv_default_loop(),
&ctx->main_async, &ctx->main_async,
main_async_cb)); main_async_cb));
ASSERT(0 == uv_thread_create(&ctx->thread, worker, ctx)); ASSERT_OK(uv_thread_create(&ctx->thread, worker, ctx));
} }
time = uv_hrtime(); time = uv_hrtime();
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
for (i = 0; i < nthreads; i++) for (i = 0; i < nthreads; i++)
ASSERT(0 == uv_thread_join(&threads[i].thread)); ASSERT_OK(uv_thread_join(&threads[i].thread));
time = uv_hrtime() - time; time = uv_hrtime() - time;
for (i = 0; i < nthreads; i++) { for (i = 0; i < nthreads; i++) {
ctx = threads + i; ctx = threads + i;
ASSERT(ctx->worker_sent == NUM_PINGS); ASSERT_EQ(ctx->worker_sent, NUM_PINGS);
ASSERT(ctx->worker_seen == NUM_PINGS); ASSERT_EQ(ctx->worker_seen, NUM_PINGS);
ASSERT(ctx->main_sent == (unsigned int) NUM_PINGS); ASSERT_EQ(ctx->main_sent, (unsigned int) NUM_PINGS);
ASSERT(ctx->main_seen == (unsigned int) NUM_PINGS); ASSERT_EQ(ctx->main_seen, (unsigned int) NUM_PINGS);
} }
printf("async%d: %.2f sec (%s/sec)\n", printf("async%d: %.2f sec (%s/sec)\n",

View File

@ -43,7 +43,7 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle);
static void getaddrinfo_cb(uv_getaddrinfo_t* handle, int status, static void getaddrinfo_cb(uv_getaddrinfo_t* handle, int status,
struct addrinfo* res) { struct addrinfo* res) {
ASSERT(status == 0); ASSERT_OK(status);
calls_completed++; calls_completed++;
if (calls_initiated < TOTAL_CALLS) { if (calls_initiated < TOTAL_CALLS) {
getaddrinfo_initiate(handle); getaddrinfo_initiate(handle);
@ -59,7 +59,7 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
calls_initiated++; calls_initiated++;
r = uv_getaddrinfo(loop, handle, &getaddrinfo_cb, name, NULL, NULL); r = uv_getaddrinfo(loop, handle, &getaddrinfo_cb, name, NULL, NULL);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -80,8 +80,8 @@ BENCHMARK_IMPL(getaddrinfo) {
uv_update_time(loop); uv_update_time(loop);
end_time = uv_now(loop); end_time = uv_now(loop);
ASSERT(calls_initiated == TOTAL_CALLS); ASSERT_EQ(calls_initiated, TOTAL_CALLS);
ASSERT(calls_completed == TOTAL_CALLS); ASSERT_EQ(calls_completed, TOTAL_CALLS);
fprintf(stderr, "getaddrinfo: %.0f req/s\n", fprintf(stderr, "getaddrinfo: %.0f req/s\n",
(double) calls_completed / (double) (end_time - start_time) * 1000.0); (double) calls_completed / (double) (end_time - start_time) * 1000.0);

View File

@ -74,7 +74,7 @@ BENCHMARK_IMPL(loop_count) {
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ns = uv_hrtime() - ns; ns = uv_hrtime() - ns;
ASSERT(ticks == NUM_TICKS); ASSERT_UINT64_EQ(ticks, NUM_TICKS);
fprintf(stderr, "loop_count: %d ticks in %.2fs (%.0f/s)\n", fprintf(stderr, "loop_count: %d ticks in %.2fs (%.0f/s)\n",
NUM_TICKS, NUM_TICKS,

View File

@ -60,7 +60,7 @@ static void timer_cb(uv_timer_t* handle) {
unsigned i; unsigned i;
done = 1; done = 1;
ASSERT(0 == uv_thread_join(&thread_id)); ASSERT_OK(uv_thread_join(&thread_id));
for (i = 0; i < ARRAY_SIZE(container->async_handles); i++) { for (i = 0; i < ARRAY_SIZE(container->async_handles); i++) {
uv_async_t* handle = container->async_handles + i; uv_async_t* handle = container->async_handles + i;
@ -93,14 +93,14 @@ BENCHMARK_IMPL(million_async) {
for (i = 0; i < ARRAY_SIZE(container->async_handles); i++) { for (i = 0; i < ARRAY_SIZE(container->async_handles); i++) {
handle = container->async_handles + i; handle = container->async_handles + i;
ASSERT(0 == uv_async_init(loop, handle, async_cb)); ASSERT_OK(uv_async_init(loop, handle, async_cb));
handle->data = NULL; handle->data = NULL;
} }
ASSERT(0 == uv_timer_init(loop, &timer_handle)); ASSERT_OK(uv_timer_init(loop, &timer_handle));
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, timeout, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, timeout, 0));
ASSERT(0 == uv_thread_create(&thread_id, thread_cb, NULL)); ASSERT_OK(uv_thread_create(&thread_id, thread_cb, NULL));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
printf("%s async events in %.1f seconds (%s/s, %s unique handles seen)\n", printf("%s async events in %.1f seconds (%s/s, %s unique handles seen)\n",
fmt(&fmtbuf[0], container->async_events), fmt(&fmtbuf[0], container->async_events),
timeout / 1000., timeout / 1000.,

View File

@ -57,22 +57,22 @@ BENCHMARK_IMPL(million_timers) {
before_all = uv_hrtime(); before_all = uv_hrtime();
for (i = 0; i < NUM_TIMERS; i++) { for (i = 0; i < NUM_TIMERS; i++) {
if (i % 1000 == 0) timeout++; if (i % 1000 == 0) timeout++;
ASSERT(0 == uv_timer_init(loop, timers + i)); ASSERT_OK(uv_timer_init(loop, timers + i));
ASSERT(0 == uv_timer_start(timers + i, timer_cb, timeout, 0)); ASSERT_OK(uv_timer_start(timers + i, timer_cb, timeout, 0));
} }
before_run = uv_hrtime(); before_run = uv_hrtime();
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
after_run = uv_hrtime(); after_run = uv_hrtime();
for (i = 0; i < NUM_TIMERS; i++) for (i = 0; i < NUM_TIMERS; i++)
uv_close((uv_handle_t*) (timers + i), close_cb); uv_close((uv_handle_t*) (timers + i), close_cb);
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
after_all = uv_hrtime(); after_all = uv_hrtime();
ASSERT(timer_cb_called == NUM_TIMERS); ASSERT_EQ(timer_cb_called, NUM_TIMERS);
ASSERT(close_cb_called == NUM_TIMERS); ASSERT_EQ(close_cb_called, NUM_TIMERS);
free(timers); free(timers);
fprintf(stderr, "%.2f seconds total\n", (after_all - before_all) / 1e9); fprintf(stderr, "%.2f seconds total\n", (after_all - before_all) / 1e9);

View File

@ -117,19 +117,19 @@ static void ipc_connection_cb(uv_stream_t* ipc_pipe, int status) {
ASSERT_NOT_NULL(pc); ASSERT_NOT_NULL(pc);
if (ipc_pipe->type == UV_TCP) if (ipc_pipe->type == UV_TCP)
ASSERT(0 == uv_tcp_init(loop, (uv_tcp_t*) &pc->peer_handle)); ASSERT_OK(uv_tcp_init(loop, (uv_tcp_t*) &pc->peer_handle));
else if (ipc_pipe->type == UV_NAMED_PIPE) else if (ipc_pipe->type == UV_NAMED_PIPE)
ASSERT(0 == uv_pipe_init(loop, (uv_pipe_t*) &pc->peer_handle, 1)); ASSERT_OK(uv_pipe_init(loop, (uv_pipe_t*) &pc->peer_handle, 1));
else else
ASSERT(0); ASSERT(0);
ASSERT(0 == uv_accept(ipc_pipe, (uv_stream_t*) &pc->peer_handle)); ASSERT_OK(uv_accept(ipc_pipe, (uv_stream_t*) &pc->peer_handle));
ASSERT(0 == uv_write2(&pc->write_req, ASSERT_OK(uv_write2(&pc->write_req,
(uv_stream_t*) &pc->peer_handle, (uv_stream_t*) &pc->peer_handle,
&buf, &buf,
1, 1,
(uv_stream_t*) &sc->server_handle, (uv_stream_t*) &sc->server_handle,
ipc_write_cb)); ipc_write_cb));
if (--sc->num_connects == 0) if (--sc->num_connects == 0)
uv_close((uv_handle_t*) ipc_pipe, NULL); uv_close((uv_handle_t*) ipc_pipe, NULL);
@ -153,10 +153,10 @@ static void ipc_close_cb(uv_handle_t* handle) {
static void ipc_connect_cb(uv_connect_t* req, int status) { static void ipc_connect_cb(uv_connect_t* req, int status) {
struct ipc_client_ctx* ctx; struct ipc_client_ctx* ctx;
ctx = container_of(req, struct ipc_client_ctx, connect_req); ctx = container_of(req, struct ipc_client_ctx, connect_req);
ASSERT(0 == status); ASSERT_OK(status);
ASSERT(0 == uv_read_start((uv_stream_t*) &ctx->ipc_pipe, ASSERT_OK(uv_read_start((uv_stream_t*) &ctx->ipc_pipe,
ipc_alloc_cb, ipc_alloc_cb,
ipc_read_cb)); ipc_read_cb));
} }
@ -182,16 +182,16 @@ static void ipc_read_cb(uv_stream_t* handle,
ctx = container_of(ipc_pipe, struct ipc_client_ctx, ipc_pipe); ctx = container_of(ipc_pipe, struct ipc_client_ctx, ipc_pipe);
loop = ipc_pipe->loop; loop = ipc_pipe->loop;
ASSERT(1 == uv_pipe_pending_count(ipc_pipe)); ASSERT_EQ(1, uv_pipe_pending_count(ipc_pipe));
type = uv_pipe_pending_type(ipc_pipe); type = uv_pipe_pending_type(ipc_pipe);
if (type == UV_TCP) if (type == UV_TCP)
ASSERT(0 == uv_tcp_init(loop, (uv_tcp_t*) ctx->server_handle)); ASSERT_OK(uv_tcp_init(loop, (uv_tcp_t*) ctx->server_handle));
else if (type == UV_NAMED_PIPE) else if (type == UV_NAMED_PIPE)
ASSERT(0 == uv_pipe_init(loop, (uv_pipe_t*) ctx->server_handle, 0)); ASSERT_OK(uv_pipe_init(loop, (uv_pipe_t*) ctx->server_handle, 0));
else else
ASSERT(0); ASSERT(0);
ASSERT(0 == uv_accept(handle, ctx->server_handle)); ASSERT_OK(uv_accept(handle, ctx->server_handle));
uv_close((uv_handle_t*) &ctx->ipc_pipe, NULL); uv_close((uv_handle_t*) &ctx->ipc_pipe, NULL);
} }
@ -211,10 +211,10 @@ static void send_listen_handles(uv_handle_type type,
ctx.num_connects = num_servers; ctx.num_connects = num_servers;
if (type == UV_TCP) { if (type == UV_TCP) {
ASSERT(0 == uv_tcp_init(loop, (uv_tcp_t*) &ctx.server_handle)); ASSERT_OK(uv_tcp_init(loop, (uv_tcp_t*) &ctx.server_handle));
ASSERT(0 == uv_tcp_bind((uv_tcp_t*) &ctx.server_handle, ASSERT_OK(uv_tcp_bind((uv_tcp_t*) &ctx.server_handle,
(const struct sockaddr*) &listen_addr, (const struct sockaddr*) &listen_addr,
0)); 0));
} }
else else
ASSERT(0); ASSERT(0);
@ -223,16 +223,16 @@ static void send_listen_handles(uv_handle_type type,
* If we accept a connection then the connected pipe must be initialized * If we accept a connection then the connected pipe must be initialized
* with ipc=1. * with ipc=1.
*/ */
ASSERT(0 == uv_pipe_init(loop, &ctx.ipc_pipe, 0)); ASSERT_OK(uv_pipe_init(loop, &ctx.ipc_pipe, 0));
ASSERT(0 == uv_pipe_bind(&ctx.ipc_pipe, IPC_PIPE_NAME)); ASSERT_OK(uv_pipe_bind(&ctx.ipc_pipe, IPC_PIPE_NAME));
ASSERT(0 == uv_listen((uv_stream_t*) &ctx.ipc_pipe, 128, ipc_connection_cb)); ASSERT_OK(uv_listen((uv_stream_t*) &ctx.ipc_pipe, 128, ipc_connection_cb));
for (i = 0; i < num_servers; i++) for (i = 0; i < num_servers; i++)
uv_sem_post(&servers[i].semaphore); uv_sem_post(&servers[i].semaphore);
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
uv_close((uv_handle_t*) &ctx.server_handle, NULL); uv_close((uv_handle_t*) &ctx.server_handle, NULL);
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
for (i = 0; i < num_servers; i++) for (i = 0; i < num_servers; i++)
uv_sem_wait(&servers[i].semaphore); uv_sem_wait(&servers[i].semaphore);
@ -245,12 +245,12 @@ static void get_listen_handle(uv_loop_t* loop, uv_stream_t* server_handle) {
ctx.server_handle = server_handle; ctx.server_handle = server_handle;
ctx.server_handle->data = "server handle"; ctx.server_handle->data = "server handle";
ASSERT(0 == uv_pipe_init(loop, &ctx.ipc_pipe, 1)); ASSERT_OK(uv_pipe_init(loop, &ctx.ipc_pipe, 1));
uv_pipe_connect(&ctx.connect_req, uv_pipe_connect(&ctx.connect_req,
&ctx.ipc_pipe, &ctx.ipc_pipe,
IPC_PIPE_NAME, IPC_PIPE_NAME,
ipc_connect_cb); ipc_connect_cb);
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
} }
@ -259,9 +259,9 @@ static void server_cb(void *arg) {
uv_loop_t loop; uv_loop_t loop;
ctx = arg; ctx = arg;
ASSERT(0 == uv_loop_init(&loop)); ASSERT_OK(uv_loop_init(&loop));
ASSERT(0 == uv_async_init(&loop, &ctx->async_handle, sv_async_cb)); ASSERT_OK(uv_async_init(&loop, &ctx->async_handle, sv_async_cb));
uv_unref((uv_handle_t*) &ctx->async_handle); uv_unref((uv_handle_t*) &ctx->async_handle);
/* Wait until the main thread is ready. */ /* Wait until the main thread is ready. */
@ -270,10 +270,10 @@ static void server_cb(void *arg) {
uv_sem_post(&ctx->semaphore); uv_sem_post(&ctx->semaphore);
/* Now start the actual benchmark. */ /* Now start the actual benchmark. */
ASSERT(0 == uv_listen((uv_stream_t*) &ctx->server_handle, ASSERT_OK(uv_listen((uv_stream_t*) &ctx->server_handle,
128, 128,
sv_connection_cb)); sv_connection_cb));
ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(&loop, UV_RUN_DEFAULT));
uv_loop_close(&loop); uv_loop_close(&loop);
} }
@ -292,20 +292,20 @@ static void sv_connection_cb(uv_stream_t* server_handle, int status) {
struct server_ctx* ctx; struct server_ctx* ctx;
ctx = container_of(server_handle, struct server_ctx, server_handle); ctx = container_of(server_handle, struct server_ctx, server_handle);
ASSERT(status == 0); ASSERT_OK(status);
storage = malloc(sizeof(*storage)); storage = malloc(sizeof(*storage));
ASSERT_NOT_NULL(storage); ASSERT_NOT_NULL(storage);
if (server_handle->type == UV_TCP) if (server_handle->type == UV_TCP)
ASSERT(0 == uv_tcp_init(server_handle->loop, (uv_tcp_t*) storage)); ASSERT_OK(uv_tcp_init(server_handle->loop, (uv_tcp_t*) storage));
else if (server_handle->type == UV_NAMED_PIPE) else if (server_handle->type == UV_NAMED_PIPE)
ASSERT(0 == uv_pipe_init(server_handle->loop, (uv_pipe_t*) storage, 0)); ASSERT_OK(uv_pipe_init(server_handle->loop, (uv_pipe_t*) storage, 0));
else else
ASSERT(0); ASSERT(0);
ASSERT(0 == uv_accept(server_handle, (uv_stream_t*) storage)); ASSERT_OK(uv_accept(server_handle, (uv_stream_t*) storage));
ASSERT(0 == uv_read_start((uv_stream_t*) storage, sv_alloc_cb, sv_read_cb)); ASSERT_OK(uv_read_start((uv_stream_t*) storage, sv_alloc_cb, sv_read_cb));
ctx->num_connects++; ctx->num_connects++;
} }
@ -322,7 +322,7 @@ static void sv_alloc_cb(uv_handle_t* handle,
static void sv_read_cb(uv_stream_t* handle, static void sv_read_cb(uv_stream_t* handle,
ssize_t nread, ssize_t nread,
const uv_buf_t* buf) { const uv_buf_t* buf) {
ASSERT(nread == UV_EOF); ASSERT_EQ(nread, UV_EOF);
uv_close((uv_handle_t*) handle, (uv_close_cb) free); uv_close((uv_handle_t*) handle, (uv_close_cb) free);
} }
@ -330,7 +330,7 @@ static void sv_read_cb(uv_stream_t* handle,
static void cl_connect_cb(uv_connect_t* req, int status) { static void cl_connect_cb(uv_connect_t* req, int status) {
struct client_ctx* ctx = container_of(req, struct client_ctx, connect_req); struct client_ctx* ctx = container_of(req, struct client_ctx, connect_req);
uv_idle_start(&ctx->idle_handle, cl_idle_cb); uv_idle_start(&ctx->idle_handle, cl_idle_cb);
ASSERT(0 == status); ASSERT_OK(status);
} }
@ -351,11 +351,11 @@ static void cl_close_cb(uv_handle_t* handle) {
return; return;
} }
ASSERT(0 == uv_tcp_init(handle->loop, (uv_tcp_t*) &ctx->client_handle)); ASSERT_OK(uv_tcp_init(handle->loop, (uv_tcp_t*) &ctx->client_handle));
ASSERT(0 == uv_tcp_connect(&ctx->connect_req, ASSERT_OK(uv_tcp_connect(&ctx->connect_req,
(uv_tcp_t*) &ctx->client_handle, (uv_tcp_t*) &ctx->client_handle,
(const struct sockaddr*) &listen_addr, (const struct sockaddr*) &listen_addr,
cl_connect_cb)); cl_connect_cb));
} }
@ -367,7 +367,7 @@ static int test_tcp(unsigned int num_servers, unsigned int num_clients) {
unsigned int i; unsigned int i;
double time; double time;
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &listen_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &listen_addr));
loop = uv_default_loop(); loop = uv_default_loop();
servers = calloc(num_servers, sizeof(servers[0])); servers = calloc(num_servers, sizeof(servers[0]));
@ -381,8 +381,8 @@ static int test_tcp(unsigned int num_servers, unsigned int num_clients) {
*/ */
for (i = 0; i < num_servers; i++) { for (i = 0; i < num_servers; i++) {
struct server_ctx* ctx = servers + i; struct server_ctx* ctx = servers + i;
ASSERT(0 == uv_sem_init(&ctx->semaphore, 0)); ASSERT_OK(uv_sem_init(&ctx->semaphore, 0));
ASSERT(0 == uv_thread_create(&ctx->thread_id, server_cb, ctx)); ASSERT_OK(uv_thread_create(&ctx->thread_id, server_cb, ctx));
} }
send_listen_handles(UV_TCP, num_servers, servers); send_listen_handles(UV_TCP, num_servers, servers);
@ -392,17 +392,17 @@ static int test_tcp(unsigned int num_servers, unsigned int num_clients) {
ctx->num_connects = NUM_CONNECTS / num_clients; ctx->num_connects = NUM_CONNECTS / num_clients;
handle = (uv_tcp_t*) &ctx->client_handle; handle = (uv_tcp_t*) &ctx->client_handle;
handle->data = "client handle"; handle->data = "client handle";
ASSERT(0 == uv_tcp_init(loop, handle)); ASSERT_OK(uv_tcp_init(loop, handle));
ASSERT(0 == uv_tcp_connect(&ctx->connect_req, ASSERT_OK(uv_tcp_connect(&ctx->connect_req,
handle, handle,
(const struct sockaddr*) &listen_addr, (const struct sockaddr*) &listen_addr,
cl_connect_cb)); cl_connect_cb));
ASSERT(0 == uv_idle_init(loop, &ctx->idle_handle)); ASSERT_OK(uv_idle_init(loop, &ctx->idle_handle));
} }
{ {
uint64_t t = uv_hrtime(); uint64_t t = uv_hrtime();
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
t = uv_hrtime() - t; t = uv_hrtime() - t;
time = t / 1e9; time = t / 1e9;
} }
@ -410,7 +410,7 @@ static int test_tcp(unsigned int num_servers, unsigned int num_clients) {
for (i = 0; i < num_servers; i++) { for (i = 0; i < num_servers; i++) {
struct server_ctx* ctx = servers + i; struct server_ctx* ctx = servers + i;
uv_async_send(&ctx->async_handle); uv_async_send(&ctx->async_handle);
ASSERT(0 == uv_thread_join(&ctx->thread_id)); ASSERT_OK(uv_thread_join(&ctx->thread_id));
uv_sem_destroy(&ctx->semaphore); uv_sem_destroy(&ctx->semaphore);
} }

View File

@ -90,7 +90,7 @@ static void pinger_close_cb(uv_handle_t* handle) {
static void pinger_write_cb(uv_write_t* req, int status) { static void pinger_write_cb(uv_write_t* req, int status) {
ASSERT(status == 0); ASSERT_OK(status);
free(req); free(req);
} }
@ -110,14 +110,14 @@ static void pinger_write_ping(pinger_t* pinger) {
static void pinger_shutdown_cb(uv_shutdown_t* req, int status) { static void pinger_shutdown_cb(uv_shutdown_t* req, int status) {
ASSERT(status == 0); ASSERT_OK(status);
pinger_shutdown_cb_called++; pinger_shutdown_cb_called++;
/* /*
* The close callback has not been triggered yet. We must wait for EOF * The close callback has not been triggered yet. We must wait for EOF
* until we close the connection. * until we close the connection.
*/ */
ASSERT(completed_pingers == 0); ASSERT_OK(completed_pingers);
} }
@ -130,13 +130,13 @@ static void pinger_read_cb(uv_stream_t* tcp,
pinger = (pinger_t*)tcp->data; pinger = (pinger_t*)tcp->data;
if (nread < 0) { if (nread < 0) {
ASSERT(nread == UV_EOF); ASSERT_EQ(nread, UV_EOF);
if (buf->base) { if (buf->base) {
buf_free(buf); buf_free(buf);
} }
ASSERT(pinger_shutdown_cb_called == 1); ASSERT_EQ(1, pinger_shutdown_cb_called);
uv_close((uv_handle_t*)tcp, pinger_close_cb); uv_close((uv_handle_t*)tcp, pinger_close_cb);
return; return;
@ -144,7 +144,7 @@ static void pinger_read_cb(uv_stream_t* tcp,
/* Now we count the pings */ /* Now we count the pings */
for (i = 0; i < nread; i++) { for (i = 0; i < nread; i++) {
ASSERT(buf->base[i] == PING[pinger->state]); ASSERT_EQ(buf->base[i], PING[pinger->state]);
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1); pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
if (pinger->state == 0) { if (pinger->state == 0) {
pinger->pongs++; pinger->pongs++;
@ -166,7 +166,7 @@ static void pinger_read_cb(uv_stream_t* tcp,
static void pinger_connect_cb(uv_connect_t* req, int status) { static void pinger_connect_cb(uv_connect_t* req, int status) {
pinger_t *pinger = (pinger_t*)req->handle->data; pinger_t *pinger = (pinger_t*)req->handle->data;
ASSERT(status == 0); ASSERT_OK(status);
pinger_write_ping(pinger); pinger_write_ping(pinger);
@ -182,8 +182,8 @@ static void pinger_new(void) {
pinger_t *pinger; pinger_t *pinger;
int r; int r;
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &client_addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", 0, &client_addr));
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr));
pinger = malloc(sizeof(*pinger)); pinger = malloc(sizeof(*pinger));
pinger->state = 0; pinger->state = 0;
pinger->pongs = 0; pinger->pongs = 0;
@ -194,9 +194,9 @@ static void pinger_new(void) {
pinger->tcp.data = pinger; pinger->tcp.data = pinger;
ASSERT(0 == uv_tcp_bind(&pinger->tcp, ASSERT_OK(uv_tcp_bind(&pinger->tcp,
(const struct sockaddr*) &client_addr, (const struct sockaddr*) &client_addr,
0)); 0));
r = uv_tcp_connect(&pinger->connect_req, r = uv_tcp_connect(&pinger->connect_req,
&pinger->tcp, &pinger->tcp,
@ -214,7 +214,7 @@ BENCHMARK_IMPL(ping_pongs) {
pinger_new(); pinger_new();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(completed_pingers == 1); ASSERT_EQ(1, completed_pingers);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;

View File

@ -95,11 +95,11 @@ static void pinger_read_cb(uv_udp_t* udp,
pinger = (pinger_t*)udp->data; pinger = (pinger_t*)udp->data;
/* No data here means something went wrong */ /* No data here means something went wrong */
ASSERT(nread > 0); ASSERT_GT(nread, 0);
/* Now we count the pings */ /* Now we count the pings */
for (i = 0; i < nread; i++) { for (i = 0; i < nread; i++) {
ASSERT(buf->base[i] == PING[pinger->state]); ASSERT_EQ(buf->base[i], PING[pinger->state]);
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1); pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
if (pinger->state == 0) { if (pinger->state == 0) {
pinger->pongs++; pinger->pongs++;
@ -119,15 +119,15 @@ static void udp_pinger_new(void) {
pinger_t* pinger = malloc(sizeof(*pinger)); pinger_t* pinger = malloc(sizeof(*pinger));
int r; int r;
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &pinger->server_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &pinger->server_addr));
pinger->state = 0; pinger->state = 0;
pinger->pongs = 0; pinger->pongs = 0;
/* Try to do NUM_PINGS ping-pongs (connection-less). */ /* Try to do NUM_PINGS ping-pongs (connection-less). */
r = uv_udp_init(loop, &pinger->udp); r = uv_udp_init(loop, &pinger->udp);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_udp_bind(&pinger->udp, (const struct sockaddr*) &pinger->server_addr, 0); r = uv_udp_bind(&pinger->udp, (const struct sockaddr*) &pinger->server_addr, 0);
ASSERT(r == 0); ASSERT_OK(r);
pinger->udp.data = pinger; pinger->udp.data = pinger;
@ -148,7 +148,7 @@ static int ping_udp(unsigned pingers) {
udp_pinger_new(); udp_pinger_new();
} }
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(completed_pingers >= 1); ASSERT_GE(completed_pingers, 1);
fprintf(stderr, "ping_pongs: %d pingers, ~ %lu roundtrips/s\n", fprintf(stderr, "ping_pongs: %d pingers, ~ %lu roundtrips/s\n",
completed_pingers, completed_pings / (TIME/1000)); completed_pingers, completed_pings / (TIME/1000));

View File

@ -115,7 +115,7 @@ static void connect_cb(uv_connect_t* req, int status) {
} }
ASSERT_NOT_NULL(req); ASSERT_NOT_NULL(req);
ASSERT(status == 0); ASSERT_OK(status);
conn = (conn_rec*)req->data; conn = (conn_rec*)req->data;
ASSERT_NOT_NULL(conn); ASSERT_NOT_NULL(conn);
@ -125,13 +125,13 @@ static void connect_cb(uv_connect_t* req, int status) {
#endif #endif
r = uv_read_start(&conn->stream, alloc_cb, read_cb); r = uv_read_start(&conn->stream, alloc_cb, read_cb);
ASSERT(r == 0); ASSERT_OK(r);
buf.base = buffer; buf.base = buffer;
buf.len = sizeof(buffer) - 1; buf.len = sizeof(buffer) - 1;
r = uv_write(&conn->write_req, &conn->stream, &buf, 1, after_write); r = uv_write(&conn->write_req, &conn->stream, &buf, 1, after_write);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -200,9 +200,9 @@ static void tcp_make_connect(conn_rec* p) {
tp = (tcp_conn_rec*) p; tp = (tcp_conn_rec*) p;
r = uv_tcp_init(loop, (uv_tcp_t*)&p->stream); r = uv_tcp_init(loop, (uv_tcp_t*)&p->stream);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
r = uv_tcp_connect(&tp->conn_req, r = uv_tcp_connect(&tp->conn_req,
(uv_tcp_t*) &p->stream, (uv_tcp_t*) &p->stream,
@ -227,7 +227,7 @@ static void pipe_make_connect(conn_rec* p) {
int r; int r;
r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream, 0); r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream, 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_pipe_connect(&((pipe_conn_rec*) p)->conn_req, uv_pipe_connect(&((pipe_conn_rec*) p)->conn_req,
(uv_pipe_t*) &p->stream, (uv_pipe_t*) &p->stream,

View File

@ -159,9 +159,9 @@ static void start_stats_collection(void) {
/* Show-stats timer */ /* Show-stats timer */
stats_left = STATS_COUNT; stats_left = STATS_COUNT;
r = uv_timer_init(loop, &timer_handle); r = uv_timer_init(loop, &timer_handle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer_handle, show_stats, STATS_INTERVAL, STATS_INTERVAL); r = uv_timer_start(&timer_handle, show_stats, STATS_INTERVAL, STATS_INTERVAL);
ASSERT(r == 0); ASSERT_OK(r);
uv_update_time(loop); uv_update_time(loop);
start_time = uv_now(loop); start_time = uv_now(loop);
@ -170,7 +170,7 @@ static void start_stats_collection(void) {
static void read_cb(uv_stream_t* stream, ssize_t bytes, const uv_buf_t* buf) { static void read_cb(uv_stream_t* stream, ssize_t bytes, const uv_buf_t* buf) {
if (nrecv_total == 0) { if (nrecv_total == 0) {
ASSERT(start_time == 0); ASSERT_OK(start_time);
uv_update_time(loop); uv_update_time(loop);
start_time = uv_now(loop); start_time = uv_now(loop);
} }
@ -188,7 +188,7 @@ static void read_cb(uv_stream_t* stream, ssize_t bytes, const uv_buf_t* buf) {
static void write_cb(uv_write_t* req, int status) { static void write_cb(uv_write_t* req, int status) {
ASSERT(status == 0); ASSERT_OK(status);
req_free((uv_req_t*) req); req_free((uv_req_t*) req);
@ -209,7 +209,7 @@ static void do_write(uv_stream_t* stream) {
req = (uv_write_t*) req_alloc(); req = (uv_write_t*) req_alloc();
r = uv_write(req, stream, &buf, 1, write_cb); r = uv_write(req, stream, &buf, 1, write_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -220,7 +220,7 @@ static void connect_cb(uv_connect_t* req, int status) {
fprintf(stderr, "%s", uv_strerror(status)); fprintf(stderr, "%s", uv_strerror(status));
fflush(stderr); fflush(stderr);
} }
ASSERT(status == 0); ASSERT_OK(status);
write_sockets++; write_sockets++;
req_free((uv_req_t*) req); req_free((uv_req_t*) req);
@ -253,19 +253,19 @@ static void maybe_connect_some(void) {
tcp = &tcp_write_handles[max_connect_socket++]; tcp = &tcp_write_handles[max_connect_socket++];
r = uv_tcp_init(loop, tcp); r = uv_tcp_init(loop, tcp);
ASSERT(r == 0); ASSERT_OK(r);
req = (uv_connect_t*) req_alloc(); req = (uv_connect_t*) req_alloc();
r = uv_tcp_connect(req, r = uv_tcp_connect(req,
tcp, tcp,
(const struct sockaddr*) &connect_addr, (const struct sockaddr*) &connect_addr,
connect_cb); connect_cb);
ASSERT(r == 0); ASSERT_OK(r);
} else { } else {
pipe = &pipe_write_handles[max_connect_socket++]; pipe = &pipe_write_handles[max_connect_socket++];
r = uv_pipe_init(loop, pipe, 0); r = uv_pipe_init(loop, pipe, 0);
ASSERT(r == 0); ASSERT_OK(r);
req = (uv_connect_t*) req_alloc(); req = (uv_connect_t*) req_alloc();
uv_pipe_connect(req, pipe, TEST_PIPENAME, connect_cb); uv_pipe_connect(req, pipe, TEST_PIPENAME, connect_cb);
@ -278,24 +278,24 @@ static void connection_cb(uv_stream_t* s, int status) {
uv_stream_t* stream; uv_stream_t* stream;
int r; int r;
ASSERT(server == s); ASSERT_PTR_EQ(server, s);
ASSERT(status == 0); ASSERT_OK(status);
if (type == TCP) { if (type == TCP) {
stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t)); stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t));
r = uv_tcp_init(loop, (uv_tcp_t*)stream); r = uv_tcp_init(loop, (uv_tcp_t*)stream);
ASSERT(r == 0); ASSERT_OK(r);
} else { } else {
stream = (uv_stream_t*)malloc(sizeof(uv_pipe_t)); stream = (uv_stream_t*)malloc(sizeof(uv_pipe_t));
r = uv_pipe_init(loop, (uv_pipe_t*)stream, 0); r = uv_pipe_init(loop, (uv_pipe_t*)stream, 0);
ASSERT(r == 0); ASSERT_OK(r);
} }
r = uv_accept(s, stream); r = uv_accept(s, stream);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_read_start(stream, buf_alloc, read_cb); r = uv_read_start(stream, buf_alloc, read_cb);
ASSERT(r == 0); ASSERT_OK(r);
read_sockets++; read_sockets++;
max_read_sockets++; max_read_sockets++;
@ -379,16 +379,16 @@ HELPER_IMPL(tcp_pump_server) {
type = TCP; type = TCP;
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &listen_addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", TEST_PORT, &listen_addr));
/* Server */ /* Server */
server = (uv_stream_t*)&tcpServer; server = (uv_stream_t*)&tcpServer;
r = uv_tcp_init(loop, &tcpServer); r = uv_tcp_init(loop, &tcpServer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_tcp_bind(&tcpServer, (const struct sockaddr*) &listen_addr, 0); r = uv_tcp_bind(&tcpServer, (const struct sockaddr*) &listen_addr, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_listen((uv_stream_t*)&tcpServer, MAX_WRITE_HANDLES, connection_cb); r = uv_listen((uv_stream_t*)&tcpServer, MAX_WRITE_HANDLES, connection_cb);
ASSERT(r == 0); ASSERT_OK(r);
notify_parent_process(); notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
@ -406,11 +406,11 @@ HELPER_IMPL(pipe_pump_server) {
/* Server */ /* Server */
server = (uv_stream_t*)&pipeServer; server = (uv_stream_t*)&pipeServer;
r = uv_pipe_init(loop, &pipeServer, 0); r = uv_pipe_init(loop, &pipeServer, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_pipe_bind(&pipeServer, TEST_PIPENAME); r = uv_pipe_bind(&pipeServer, TEST_PIPENAME);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_listen((uv_stream_t*)&pipeServer, MAX_WRITE_HANDLES, connection_cb); r = uv_listen((uv_stream_t*)&pipeServer, MAX_WRITE_HANDLES, connection_cb);
ASSERT(r == 0); ASSERT_OK(r);
notify_parent_process(); notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
@ -421,13 +421,13 @@ HELPER_IMPL(pipe_pump_server) {
static void tcp_pump(int n) { static void tcp_pump(int n) {
ASSERT(n <= MAX_WRITE_HANDLES); ASSERT_LE(n, MAX_WRITE_HANDLES);
TARGET_CONNECTIONS = n; TARGET_CONNECTIONS = n;
type = TCP; type = TCP;
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &connect_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &connect_addr));
/* Start making connections */ /* Start making connections */
maybe_connect_some(); maybe_connect_some();
@ -439,7 +439,7 @@ static void tcp_pump(int n) {
static void pipe_pump(int n) { static void pipe_pump(int n) {
ASSERT(n <= MAX_WRITE_HANDLES); ASSERT_LE(n, MAX_WRITE_HANDLES);
TARGET_CONNECTIONS = n; TARGET_CONNECTIONS = n;
type = PIPE; type = PIPE;

View File

@ -40,7 +40,7 @@ static void work_cb(uv_work_t* req) {
static void after_work_cb(uv_work_t* req, int status) { static void after_work_cb(uv_work_t* req, int status) {
events++; events++;
if (!done) if (!done)
ASSERT_EQ(0, uv_queue_work(req->loop, req, work_cb, after_work_cb)); ASSERT_OK(uv_queue_work(req->loop, req, work_cb, after_work_cb));
} }
static void timer_cb(uv_timer_t* handle) { done = 1; } static void timer_cb(uv_timer_t* handle) { done = 1; }
@ -55,11 +55,11 @@ BENCHMARK_IMPL(queue_work) {
loop = uv_default_loop(); loop = uv_default_loop();
timeout = 5000; timeout = 5000;
ASSERT_EQ(0, uv_timer_init(loop, &timer_handle)); ASSERT_OK(uv_timer_init(loop, &timer_handle));
ASSERT_EQ(0, uv_timer_start(&timer_handle, timer_cb, timeout, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, timeout, 0));
ASSERT_EQ(0, uv_queue_work(loop, &work, work_cb, after_work_cb)); ASSERT_OK(uv_queue_work(loop, &work, work_cb, after_work_cb));
ASSERT_EQ(0, uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
printf("%s async jobs in %.1f seconds (%s/s)\n", printf("%s async jobs in %.1f seconds (%s/s)\n",
fmt(&fmtbuf[0], events), fmt(&fmtbuf[0], events),

View File

@ -58,7 +58,7 @@ static void maybe_spawn(void) {
static void process_close_cb(uv_handle_t* handle) { static void process_close_cb(uv_handle_t* handle) {
ASSERT(process_open == 1); ASSERT_EQ(1, process_open);
process_open = 0; process_open = 0;
maybe_spawn(); maybe_spawn();
} }
@ -67,8 +67,8 @@ static void process_close_cb(uv_handle_t* handle) {
static void exit_cb(uv_process_t* process, static void exit_cb(uv_process_t* process,
int64_t exit_status, int64_t exit_status,
int term_signal) { int term_signal) {
ASSERT(exit_status == 42); ASSERT_EQ(42, exit_status);
ASSERT(term_signal == 0); ASSERT_OK(term_signal);
uv_close((uv_handle_t*)process, process_close_cb); uv_close((uv_handle_t*)process, process_close_cb);
} }
@ -82,7 +82,7 @@ static void on_alloc(uv_handle_t* handle,
static void pipe_close_cb(uv_handle_t* pipe) { static void pipe_close_cb(uv_handle_t* pipe) {
ASSERT(pipe_open == 1); ASSERT_EQ(1, pipe_open);
pipe_open = 0; pipe_open = 0;
maybe_spawn(); maybe_spawn();
} }
@ -90,7 +90,7 @@ static void pipe_close_cb(uv_handle_t* pipe) {
static void on_read(uv_stream_t* pipe, ssize_t nread, const uv_buf_t* buf) { static void on_read(uv_stream_t* pipe, ssize_t nread, const uv_buf_t* buf) {
if (nread > 0) { if (nread > 0) {
ASSERT(pipe_open == 1); ASSERT_EQ(1, pipe_open);
output_used += nread; output_used += nread;
} else if (nread < 0) { } else if (nread < 0) {
if (nread == UV_EOF) { if (nread == UV_EOF) {
@ -104,8 +104,8 @@ static void spawn(void) {
uv_stdio_container_t stdio[2]; uv_stdio_container_t stdio[2];
int r; int r;
ASSERT(process_open == 0); ASSERT_OK(process_open);
ASSERT(pipe_open == 0); ASSERT_OK(pipe_open);
args[0] = exepath; args[0] = exepath;
args[1] = "spawn_helper"; args[1] = "spawn_helper";
@ -123,14 +123,14 @@ static void spawn(void) {
options.stdio[1].data.stream = (uv_stream_t*)&out; options.stdio[1].data.stream = (uv_stream_t*)&out;
r = uv_spawn(loop, &process, &options); r = uv_spawn(loop, &process, &options);
ASSERT(r == 0); ASSERT_OK(r);
process_open = 1; process_open = 1;
pipe_open = 1; pipe_open = 1;
output_used = 0; output_used = 0;
r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read); r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -141,7 +141,7 @@ BENCHMARK_IMPL(spawn) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_exepath(exepath, &exepath_size); r = uv_exepath(exepath, &exepath_size);
ASSERT(r == 0); ASSERT_OK(r);
exepath[exepath_size] = '\0'; exepath[exepath_size] = '\0';
uv_update_time(loop); uv_update_time(loop);
@ -150,7 +150,7 @@ BENCHMARK_IMPL(spawn) {
spawn(); spawn();
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
uv_update_time(loop); uv_update_time(loop);
end_time = uv_now(loop); end_time = uv_now(loop);

View File

@ -55,16 +55,16 @@ static void connect_cb(uv_connect_t* req, int status) {
int i; int i;
int r; int r;
ASSERT(req->handle == (uv_stream_t*)&tcp_client); ASSERT_PTR_EQ(req->handle, (uv_stream_t*)&tcp_client);
for (i = 0; i < NUM_WRITE_REQS; i++) { for (i = 0; i < NUM_WRITE_REQS; i++) {
w = &write_reqs[i]; w = &write_reqs[i];
r = uv_write(&w->req, req->handle, &w->buf, 1, write_cb); r = uv_write(&w->req, req->handle, &w->buf, 1, write_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
r = uv_shutdown(&shutdown_req, req->handle, shutdown_cb); r = uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
ASSERT(r == 0); ASSERT_OK(r);
connect_cb_called++; connect_cb_called++;
} }
@ -72,14 +72,14 @@ static void connect_cb(uv_connect_t* req, int status) {
static void write_cb(uv_write_t* req, int status) { static void write_cb(uv_write_t* req, int status) {
ASSERT_NOT_NULL(req); ASSERT_NOT_NULL(req);
ASSERT(status == 0); ASSERT_OK(status);
write_cb_called++; write_cb_called++;
} }
static void shutdown_cb(uv_shutdown_t* req, int status) { static void shutdown_cb(uv_shutdown_t* req, int status) {
ASSERT(req->handle == (uv_stream_t*)&tcp_client); ASSERT_PTR_EQ(req->handle, (uv_stream_t*)&tcp_client);
ASSERT(req->handle->write_queue_size == 0); ASSERT_OK(req->handle->write_queue_size);
uv_close((uv_handle_t*)req->handle, close_cb); uv_close((uv_handle_t*)req->handle, close_cb);
free(write_reqs); free(write_reqs);
@ -89,7 +89,7 @@ static void shutdown_cb(uv_shutdown_t* req, int status) {
static void close_cb(uv_handle_t* handle) { static void close_cb(uv_handle_t* handle) {
ASSERT(handle == (uv_handle_t*)&tcp_client); ASSERT_PTR_EQ(handle, (uv_handle_t*)&tcp_client);
close_cb_called++; close_cb_called++;
} }
@ -112,28 +112,28 @@ BENCHMARK_IMPL(tcp_write_batch) {
} }
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
r = uv_tcp_init(loop, &tcp_client); r = uv_tcp_init(loop, &tcp_client);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_tcp_connect(&connect_req, r = uv_tcp_connect(&connect_req,
&tcp_client, &tcp_client,
(const struct sockaddr*) &addr, (const struct sockaddr*) &addr,
connect_cb); connect_cb);
ASSERT(r == 0); ASSERT_OK(r);
start = uv_hrtime(); start = uv_hrtime();
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
stop = uv_hrtime(); stop = uv_hrtime();
ASSERT(connect_cb_called == 1); ASSERT_EQ(1, connect_cb_called);
ASSERT(write_cb_called == NUM_WRITE_REQS); ASSERT_EQ(write_cb_called, NUM_WRITE_REQS);
ASSERT(shutdown_cb_called == 1); ASSERT_EQ(1, shutdown_cb_called);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
printf("%ld write requests in %.2fs.\n", printf("%ld write requests in %.2fs.\n",
(long)NUM_WRITE_REQS, (long)NUM_WRITE_REQS,

View File

@ -31,7 +31,7 @@ static volatile int num_threads;
static void thread_entry(void* arg) { static void thread_entry(void* arg) {
ASSERT(arg == (void *) 42); ASSERT_PTR_EQ(arg, (void *) 42);
num_threads++; num_threads++;
/* FIXME write barrier? */ /* FIXME write barrier? */
} }
@ -47,15 +47,15 @@ BENCHMARK_IMPL(thread_create) {
for (i = 0; i < NUM_THREADS; i++) { for (i = 0; i < NUM_THREADS; i++) {
r = uv_thread_create(&tid, thread_entry, (void *) 42); r = uv_thread_create(&tid, thread_entry, (void *) 42);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_thread_join(&tid); r = uv_thread_join(&tid);
ASSERT(r == 0); ASSERT_OK(r);
} }
duration = (uv_hrtime() - start_time) / 1e9; duration = (uv_hrtime() - start_time) / 1e9;
ASSERT(num_threads == NUM_THREADS); ASSERT_EQ(num_threads, NUM_THREADS);
printf("%d threads created in %.2f seconds (%.0f/s)\n", printf("%d threads created in %.2f seconds (%.0f/s)\n",
NUM_THREADS, duration, NUM_THREADS / duration); NUM_THREADS, duration, NUM_THREADS / duration);

View File

@ -63,7 +63,7 @@ static void alloc_cb(uv_handle_t* handle,
size_t suggested_size, size_t suggested_size,
uv_buf_t* buf) { uv_buf_t* buf) {
static char slab[65536]; static char slab[65536];
ASSERT(suggested_size <= sizeof(slab)); ASSERT_LE(suggested_size, sizeof(slab));
buf->base = slab; buf->base = slab;
buf->len = sizeof(slab); buf->len = sizeof(slab);
} }
@ -75,7 +75,7 @@ static void send_cb(uv_udp_send_t* req, int status) {
ASSERT_NOT_NULL(req); ASSERT_NOT_NULL(req);
if (status != 0) { if (status != 0) {
ASSERT(status == UV_ECANCELED); ASSERT_EQ(status, UV_ECANCELED);
return; return;
} }
@ -83,7 +83,7 @@ static void send_cb(uv_udp_send_t* req, int status) {
return; return;
s = container_of(req, struct sender_state, send_req); s = container_of(req, struct sender_state, send_req);
ASSERT(req->handle == &s->udp_handle); ASSERT_PTR_EQ(req->handle, &s->udp_handle);
if (timed) if (timed)
goto send; goto send;
@ -96,12 +96,12 @@ static void send_cb(uv_udp_send_t* req, int status) {
packet_counter--; packet_counter--;
send: send:
ASSERT(0 == uv_udp_send(&s->send_req, ASSERT_OK(uv_udp_send(&s->send_req,
&s->udp_handle, &s->udp_handle,
bufs, bufs,
ARRAY_SIZE(bufs), ARRAY_SIZE(bufs),
(const struct sockaddr*) &s->addr, (const struct sockaddr*) &s->addr,
send_cb)); send_cb));
send_cb_called++; send_cb_called++;
} }
@ -115,11 +115,11 @@ static void recv_cb(uv_udp_t* handle,
return; return;
if (nread < 0) { if (nread < 0) {
ASSERT(nread == UV_ECANCELED); ASSERT_EQ(nread, UV_ECANCELED);
return; return;
} }
ASSERT(addr->sa_family == AF_INET); ASSERT_EQ(addr->sa_family, AF_INET);
ASSERT(!memcmp(buf->base, EXPECTED, nread)); ASSERT(!memcmp(buf->base, EXPECTED, nread));
recv_cb_called++; recv_cb_called++;
@ -153,8 +153,8 @@ static int pummel(unsigned int n_senders,
uv_loop_t* loop; uv_loop_t* loop;
unsigned int i; unsigned int i;
ASSERT(n_senders <= ARRAY_SIZE(senders)); ASSERT_LE(n_senders, ARRAY_SIZE(senders));
ASSERT(n_receivers <= ARRAY_SIZE(receivers)); ASSERT_LE(n_receivers, ARRAY_SIZE(receivers));
loop = uv_default_loop(); loop = uv_default_loop();
@ -162,8 +162,8 @@ static int pummel(unsigned int n_senders,
n_receivers_ = n_receivers; n_receivers_ = n_receivers;
if (timeout) { if (timeout) {
ASSERT(0 == uv_timer_init(loop, &timer_handle)); ASSERT_OK(uv_timer_init(loop, &timer_handle));
ASSERT(0 == uv_timer_start(&timer_handle, timeout_cb, timeout, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timeout_cb, timeout, 0));
/* Timer should not keep loop alive. */ /* Timer should not keep loop alive. */
uv_unref((uv_handle_t*)&timer_handle); uv_unref((uv_handle_t*)&timer_handle);
timed = 1; timed = 1;
@ -172,10 +172,10 @@ static int pummel(unsigned int n_senders,
for (i = 0; i < n_receivers; i++) { for (i = 0; i < n_receivers; i++) {
struct receiver_state* s = receivers + i; struct receiver_state* s = receivers + i;
struct sockaddr_in addr; struct sockaddr_in addr;
ASSERT(0 == uv_ip4_addr("0.0.0.0", BASE_PORT + i, &addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", BASE_PORT + i, &addr));
ASSERT(0 == uv_udp_init(loop, &s->udp_handle)); ASSERT_OK(uv_udp_init(loop, &s->udp_handle));
ASSERT(0 == uv_udp_bind(&s->udp_handle, (const struct sockaddr*) &addr, 0)); ASSERT_OK(uv_udp_bind(&s->udp_handle, (const struct sockaddr*) &addr, 0));
ASSERT(0 == uv_udp_recv_start(&s->udp_handle, alloc_cb, recv_cb)); ASSERT_OK(uv_udp_recv_start(&s->udp_handle, alloc_cb, recv_cb));
uv_unref((uv_handle_t*)&s->udp_handle); uv_unref((uv_handle_t*)&s->udp_handle);
} }
@ -187,20 +187,20 @@ static int pummel(unsigned int n_senders,
for (i = 0; i < n_senders; i++) { for (i = 0; i < n_senders; i++) {
struct sender_state* s = senders + i; struct sender_state* s = senders + i;
ASSERT(0 == uv_ip4_addr("127.0.0.1", ASSERT_OK(uv_ip4_addr("127.0.0.1",
BASE_PORT + (i % n_receivers), BASE_PORT + (i % n_receivers),
&s->addr)); &s->addr));
ASSERT(0 == uv_udp_init(loop, &s->udp_handle)); ASSERT_OK(uv_udp_init(loop, &s->udp_handle));
ASSERT(0 == uv_udp_send(&s->send_req, ASSERT_OK(uv_udp_send(&s->send_req,
&s->udp_handle, &s->udp_handle,
bufs, bufs,
ARRAY_SIZE(bufs), ARRAY_SIZE(bufs),
(const struct sockaddr*) &s->addr, (const struct sockaddr*) &s->addr,
send_cb)); send_cb));
} }
duration = uv_hrtime(); duration = uv_hrtime();
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
duration = uv_hrtime() - duration; duration = uv_hrtime() - duration;
/* convert from nanoseconds to milliseconds */ /* convert from nanoseconds to milliseconds */
duration = duration / (uint64_t) 1e6; duration = duration / (uint64_t) 1e6;

View File

@ -43,20 +43,20 @@ static void connection_cb(uv_stream_t* stream, int status) {
conn_rec* conn; conn_rec* conn;
int r; int r;
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(stream == (uv_stream_t*)&tcp_server); ASSERT_PTR_EQ(stream, (uv_stream_t*)&tcp_server);
conn = malloc(sizeof *conn); conn = malloc(sizeof *conn);
ASSERT_NOT_NULL(conn); ASSERT_NOT_NULL(conn);
r = uv_tcp_init(stream->loop, &conn->handle); r = uv_tcp_init(stream->loop, &conn->handle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_accept(stream, (uv_stream_t*)&conn->handle); r = uv_accept(stream, (uv_stream_t*)&conn->handle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_read_start((uv_stream_t*)&conn->handle, alloc_cb, read_cb); r = uv_read_start((uv_stream_t*)&conn->handle, alloc_cb, read_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -76,12 +76,12 @@ static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
if (nread >= 0) if (nread >= 0)
return; return;
ASSERT(nread == UV_EOF); ASSERT_EQ(nread, UV_EOF);
conn = container_of(stream, conn_rec, handle); conn = container_of(stream, conn_rec, handle);
r = uv_shutdown(&conn->shutdown_req, stream, shutdown_cb); r = uv_shutdown(&conn->shutdown_req, stream, shutdown_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -103,16 +103,16 @@ HELPER_IMPL(tcp4_blackhole_server) {
int r; int r;
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
r = uv_tcp_init(loop, &tcp_server); r = uv_tcp_init(loop, &tcp_server);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_listen((uv_stream_t*)&tcp_server, 128, connection_cb); r = uv_listen((uv_stream_t*)&tcp_server, 128, connection_cb);
ASSERT(r == 0); ASSERT_OK(r);
notify_parent_process(); notify_parent_process();
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);

View File

@ -65,14 +65,14 @@ static void after_write(uv_write_t* req, int status) {
static void after_shutdown(uv_shutdown_t* req, int status) { static void after_shutdown(uv_shutdown_t* req, int status) {
ASSERT_EQ(status, 0); ASSERT_OK(status);
uv_close((uv_handle_t*) req->handle, on_close); uv_close((uv_handle_t*) req->handle, on_close);
free(req); free(req);
} }
static void on_shutdown(uv_shutdown_t* req, int status) { static void on_shutdown(uv_shutdown_t* req, int status) {
ASSERT_EQ(status, 0); ASSERT_OK(status);
free(req); free(req);
} }
@ -92,7 +92,7 @@ static void after_read(uv_stream_t* handle,
free(buf->base); free(buf->base);
sreq = malloc(sizeof* sreq); sreq = malloc(sizeof* sreq);
if (uv_is_writable(handle)) { if (uv_is_writable(handle)) {
ASSERT_EQ(0, uv_shutdown(sreq, handle, after_shutdown)); ASSERT_OK(uv_shutdown(sreq, handle, after_shutdown));
} }
return; return;
} }
@ -118,7 +118,7 @@ static void after_read(uv_stream_t* handle,
if (i + 2 < nread && buf->base[i + 2] == 'H') if (i + 2 < nread && buf->base[i + 2] == 'H')
reset = 1; reset = 1;
if (reset && handle->type == UV_TCP) if (reset && handle->type == UV_TCP)
ASSERT_EQ(0, uv_tcp_close_reset((uv_tcp_t*) handle, on_close)); ASSERT_OK(uv_tcp_close_reset((uv_tcp_t*) handle, on_close));
else if (shutdown) else if (shutdown)
break; break;
else else
@ -141,7 +141,7 @@ static void after_read(uv_stream_t* handle,
} }
if (shutdown) if (shutdown)
ASSERT_EQ(0, uv_shutdown(malloc(sizeof* sreq), handle, on_shutdown)); ASSERT_OK(uv_shutdown(malloc(sizeof* sreq), handle, on_shutdown));
} }
@ -173,21 +173,21 @@ static void on_connection(uv_stream_t* server, int status) {
if (status != 0) { if (status != 0) {
fprintf(stderr, "Connect error %s\n", uv_err_name(status)); fprintf(stderr, "Connect error %s\n", uv_err_name(status));
} }
ASSERT(status == 0); ASSERT_OK(status);
switch (serverType) { switch (serverType) {
case TCP: case TCP:
stream = malloc(sizeof(uv_tcp_t)); stream = malloc(sizeof(uv_tcp_t));
ASSERT_NOT_NULL(stream); ASSERT_NOT_NULL(stream);
r = uv_tcp_init(loop, (uv_tcp_t*)stream); r = uv_tcp_init(loop, (uv_tcp_t*)stream);
ASSERT(r == 0); ASSERT_OK(r);
break; break;
case PIPE: case PIPE:
stream = malloc(sizeof(uv_pipe_t)); stream = malloc(sizeof(uv_pipe_t));
ASSERT_NOT_NULL(stream); ASSERT_NOT_NULL(stream);
r = uv_pipe_init(loop, (uv_pipe_t*)stream, 0); r = uv_pipe_init(loop, (uv_pipe_t*)stream, 0);
ASSERT(r == 0); ASSERT_OK(r);
break; break;
default: default:
@ -199,15 +199,15 @@ static void on_connection(uv_stream_t* server, int status) {
stream->data = server; stream->data = server;
r = uv_accept(server, stream); r = uv_accept(server, stream);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_read_start(stream, echo_alloc, after_read); r = uv_read_start(stream, echo_alloc, after_read);
ASSERT(r == 0); ASSERT_OK(r);
} }
static void on_server_close(uv_handle_t* handle) { static void on_server_close(uv_handle_t* handle) {
ASSERT(handle == server); ASSERT_PTR_EQ(handle, server);
} }
static uv_udp_send_t* send_alloc(void) { static uv_udp_send_t* send_alloc(void) {
@ -221,7 +221,7 @@ static uv_udp_send_t* send_alloc(void) {
static void on_send(uv_udp_send_t* req, int status) { static void on_send(uv_udp_send_t* req, int status) {
ASSERT_NOT_NULL(req); ASSERT_NOT_NULL(req);
ASSERT(status == 0); ASSERT_OK(status);
req->data = send_freelist; req->data = send_freelist;
send_freelist = req; send_freelist = req;
} }
@ -239,20 +239,20 @@ static void on_recv(uv_udp_t* handle,
return; return;
} }
ASSERT(nread > 0); ASSERT_GT(nread, 0);
ASSERT(addr->sa_family == AF_INET); ASSERT_EQ(addr->sa_family, AF_INET);
req = send_alloc(); req = send_alloc();
ASSERT_NOT_NULL(req); ASSERT_NOT_NULL(req);
sndbuf = uv_buf_init(rcvbuf->base, nread); sndbuf = uv_buf_init(rcvbuf->base, nread);
ASSERT(0 <= uv_udp_send(req, handle, &sndbuf, 1, addr, on_send)); ASSERT_LE(0, uv_udp_send(req, handle, &sndbuf, 1, addr, on_send));
} }
static int tcp4_echo_start(int port) { static int tcp4_echo_start(int port) {
struct sockaddr_in addr; struct sockaddr_in addr;
int r; int r;
ASSERT(0 == uv_ip4_addr("127.0.0.1", port, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", port, &addr));
server = (uv_handle_t*)&tcpServer; server = (uv_handle_t*)&tcpServer;
serverType = TCP; serverType = TCP;
@ -286,7 +286,7 @@ static int tcp6_echo_start(int port) {
struct sockaddr_in6 addr6; struct sockaddr_in6 addr6;
int r; int r;
ASSERT(0 == uv_ip6_addr("::1", port, &addr6)); ASSERT_OK(uv_ip6_addr("::1", port, &addr6));
server = (uv_handle_t*)&tcpServer; server = (uv_handle_t*)&tcpServer;
serverType = TCP; serverType = TCP;
@ -321,7 +321,7 @@ static int udp4_echo_start(int port) {
struct sockaddr_in addr; struct sockaddr_in addr;
int r; int r;
ASSERT(0 == uv_ip4_addr("127.0.0.1", port, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", port, &addr));
server = (uv_handle_t*)&udpServer; server = (uv_handle_t*)&udpServer;
serverType = UDP; serverType = UDP;

View File

@ -145,7 +145,7 @@ static int maybe_run_test(int argc, char **argv) {
if (strcmp(argv[1], "spawn_helper3") == 0) { if (strcmp(argv[1], "spawn_helper3") == 0) {
char buffer[256]; char buffer[256];
notify_parent_process(); notify_parent_process();
ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin)); ASSERT_PTR_EQ(buffer, fgets(buffer, sizeof(buffer) - 1, stdin));
buffer[sizeof(buffer) - 1] = '\0'; buffer[sizeof(buffer) - 1] = '\0';
fputs(buffer, stdout); fputs(buffer, stdout);
return 1; return 1;
@ -183,10 +183,10 @@ static int maybe_run_test(int argc, char **argv) {
notify_parent_process(); notify_parent_process();
r = fprintf(stdout, "hello world\n"); r = fprintf(stdout, "hello world\n");
ASSERT(r > 0); ASSERT_GT(r, 0);
r = fprintf(stderr, "hello errworld\n"); r = fprintf(stderr, "hello errworld\n");
ASSERT(r > 0); ASSERT_GT(r, 0);
return 1; return 1;
} }
@ -202,7 +202,7 @@ static int maybe_run_test(int argc, char **argv) {
ASSERT_NOT_NULL(test); ASSERT_NOT_NULL(test);
r = fprintf(stdout, "%s", test); r = fprintf(stdout, "%s", test);
ASSERT(r > 0); ASSERT_GT(r, 0);
return 1; return 1;
} }
@ -216,23 +216,24 @@ static int maybe_run_test(int argc, char **argv) {
sCompareObjectHandles pCompareObjectHandles; /* function introduced in Windows 10 */ sCompareObjectHandles pCompareObjectHandles; /* function introduced in Windows 10 */
#endif #endif
notify_parent_process(); notify_parent_process();
ASSERT(sizeof(closed_fd) == read(0, &closed_fd, sizeof(closed_fd))); ASSERT_EQ(sizeof(closed_fd), read(0, &closed_fd, sizeof(closed_fd)));
ASSERT(sizeof(open_fd) == read(0, &open_fd, sizeof(open_fd))); ASSERT_EQ(sizeof(open_fd), read(0, &open_fd, sizeof(open_fd)));
#ifdef _WIN32 #ifdef _WIN32
ASSERT((intptr_t) closed_fd > 0); ASSERT_GT((intptr_t) closed_fd, 0);
ASSERT((intptr_t) open_fd > 0); ASSERT_GT((intptr_t) open_fd, 0);
ASSERT(0 != GetHandleInformation(open_fd, &flags)); ASSERT_NE(0, GetHandleInformation(open_fd, &flags));
kernelbase_module = GetModuleHandleA("kernelbase.dll"); kernelbase_module = GetModuleHandleA("kernelbase.dll");
pCompareObjectHandles = (sCompareObjectHandles) pCompareObjectHandles = (sCompareObjectHandles)
GetProcAddress(kernelbase_module, "CompareObjectHandles"); GetProcAddress(kernelbase_module, "CompareObjectHandles");
ASSERT(pCompareObjectHandles == NULL || !pCompareObjectHandles(open_fd, closed_fd)); ASSERT_NE(pCompareObjectHandles == NULL || \
!pCompareObjectHandles(open_fd, closed_fd), 0);
#else #else
ASSERT(open_fd > 2); ASSERT_GT(open_fd, 2);
ASSERT(closed_fd > 2); ASSERT_GT(closed_fd, 2);
# if defined(__PASE__) /* On IBMi PASE, write() returns 1 */ # if defined(__PASE__) /* On IBMi PASE, write() returns 1 */
ASSERT(1 == write(closed_fd, "x", 1)); ASSERT_EQ(1, write(closed_fd, "x", 1));
# else # else
ASSERT(-1 == write(closed_fd, "x", 1)); ASSERT_EQ(-1, write(closed_fd, "x", 1));
# endif /* !__PASE__ */ # endif /* !__PASE__ */
#endif #endif
return 1; return 1;
@ -249,8 +250,8 @@ static int maybe_run_test(int argc, char **argv) {
uv_uid_t uid = atoi(argv[2]); uv_uid_t uid = atoi(argv[2]);
uv_gid_t gid = atoi(argv[3]); uv_gid_t gid = atoi(argv[3]);
ASSERT(uid == getuid()); ASSERT_EQ(uid, getuid());
ASSERT(gid == getgid()); ASSERT_EQ(gid, getgid());
notify_parent_process(); notify_parent_process();
return 1; return 1;

View File

@ -185,7 +185,7 @@ int process_wait(process_info_t *vec, int n, int timeout) {
if (n == 0) if (n == 0)
return 0; return 0;
ASSERT(n <= MAXIMUM_WAIT_OBJECTS); ASSERT_LE(n, MAXIMUM_WAIT_OBJECTS);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
handles[i] = vec[i].process; handles[i] = vec[i].process;
@ -245,7 +245,7 @@ int process_read_last_line(process_info_t *p,
DWORD start; DWORD start;
OVERLAPPED overlapped; OVERLAPPED overlapped;
ASSERT(buffer_len > 0); ASSERT_GT(buffer_len, 0);
size = GetFileSize(p->stdio_out, NULL); size = GetFileSize(p->stdio_out, NULL);
if (size == INVALID_FILE_SIZE) if (size == INVALID_FILE_SIZE)

View File

@ -244,13 +244,16 @@ typedef enum {
#define ASSERT_PTR_NE(a, b) \ #define ASSERT_PTR_NE(a, b) \
ASSERT_BASE(a, !=, b, void*, "p") 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 /* This macro cleans up the event loop. This is used to avoid valgrind
* warnings about memory being "leaked" by the event loop. * warnings about memory being "leaked" by the event loop.
*/ */
#define MAKE_VALGRIND_HAPPY(loop) \ #define MAKE_VALGRIND_HAPPY(loop) \
do { \ do { \
close_loop(loop); \ close_loop(loop); \
ASSERT(0 == uv_loop_close(loop)); \ ASSERT_EQ(0, uv_loop_close(loop)); \
uv_library_shutdown(); \ uv_library_shutdown(); \
} while (0) } while (0)

View File

@ -45,39 +45,39 @@ TEST_IMPL(active) {
uv_timer_t timer; uv_timer_t timer;
r = uv_timer_init(uv_default_loop(), &timer); r = uv_timer_init(uv_default_loop(), &timer);
ASSERT(r == 0); ASSERT_OK(r);
/* uv_is_active() and uv_is_closing() should always return either 0 or 1. */ /* uv_is_active() and uv_is_closing() should always return either 0 or 1. */
ASSERT(0 == uv_is_active((uv_handle_t*) &timer)); ASSERT_OK(uv_is_active((uv_handle_t*) &timer));
ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
r = uv_timer_start(&timer, timer_cb, 1000, 0); r = uv_timer_start(&timer, timer_cb, 1000, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(1 == uv_is_active((uv_handle_t*) &timer)); ASSERT_EQ(1, uv_is_active((uv_handle_t*) &timer));
ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
r = uv_timer_stop(&timer); r = uv_timer_stop(&timer);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(0 == uv_is_active((uv_handle_t*) &timer)); ASSERT_OK(uv_is_active((uv_handle_t*) &timer));
ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
r = uv_timer_start(&timer, timer_cb, 1000, 0); r = uv_timer_start(&timer, timer_cb, 1000, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(1 == uv_is_active((uv_handle_t*) &timer)); ASSERT_EQ(1, uv_is_active((uv_handle_t*) &timer));
ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
uv_close((uv_handle_t*) &timer, close_cb); uv_close((uv_handle_t*) &timer, close_cb);
ASSERT(0 == uv_is_active((uv_handle_t*) &timer)); ASSERT_OK(uv_is_active((uv_handle_t*) &timer));
ASSERT(1 == uv_is_closing((uv_handle_t*) &timer)); ASSERT_EQ(1, uv_is_closing((uv_handle_t*) &timer));
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;

View File

@ -36,7 +36,7 @@ static void thread_cb(void* dummy) {
static void check_cb(uv_check_t* handle) { static void check_cb(uv_check_t* handle) {
ASSERT(check_cb_called == 0); ASSERT_OK(check_cb_called);
uv_close((uv_handle_t*) &async_handle, NULL); uv_close((uv_handle_t*) &async_handle, NULL);
uv_close((uv_handle_t*) &check_handle, NULL); uv_close((uv_handle_t*) &check_handle, NULL);
check_cb_called++; check_cb_called++;
@ -52,13 +52,13 @@ TEST_IMPL(async_null_cb) {
*/ */
memset(&async_handle, 0xff, sizeof(async_handle)); memset(&async_handle, 0xff, sizeof(async_handle));
ASSERT(0 == uv_async_init(uv_default_loop(), &async_handle, NULL)); ASSERT_OK(uv_async_init(uv_default_loop(), &async_handle, NULL));
ASSERT(0 == uv_check_init(uv_default_loop(), &check_handle)); ASSERT_OK(uv_check_init(uv_default_loop(), &check_handle));
ASSERT(0 == uv_check_start(&check_handle, check_cb)); ASSERT_OK(uv_check_start(&check_handle, check_cb));
ASSERT(0 == uv_thread_create(&thread, thread_cb, NULL)); ASSERT_OK(uv_thread_create(&thread, thread_cb, NULL));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(0 == uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
ASSERT(1 == check_cb_called); ASSERT_EQ(1, check_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
} }

View File

@ -49,7 +49,7 @@ static void thread_cb(void *arg) {
} }
r = uv_async_send(&async); r = uv_async_send(&async);
ASSERT(r == 0); ASSERT_OK(r);
/* Work around a bug in Valgrind. /* Work around a bug in Valgrind.
* *
@ -78,7 +78,7 @@ static void close_cb(uv_handle_t* handle) {
static void async_cb(uv_async_t* handle) { static void async_cb(uv_async_t* handle) {
int n; int n;
ASSERT(handle == &async); ASSERT_PTR_EQ(handle, &async);
uv_mutex_lock(&mutex); uv_mutex_lock(&mutex);
n = ++async_cb_called; n = ++async_cb_called;
@ -94,13 +94,13 @@ static void async_cb(uv_async_t* handle) {
static void prepare_cb(uv_prepare_t* handle) { static void prepare_cb(uv_prepare_t* handle) {
int r; int r;
ASSERT(handle == &prepare); ASSERT_PTR_EQ(handle, &prepare);
if (prepare_cb_called++) if (prepare_cb_called++)
return; return;
r = uv_thread_create(&thread, thread_cb, NULL); r = uv_thread_create(&thread, thread_cb, NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_mutex_unlock(&mutex); uv_mutex_unlock(&mutex);
} }
@ -109,25 +109,25 @@ TEST_IMPL(async) {
int r; int r;
r = uv_mutex_init(&mutex); r = uv_mutex_init(&mutex);
ASSERT(r == 0); ASSERT_OK(r);
uv_mutex_lock(&mutex); uv_mutex_lock(&mutex);
r = uv_prepare_init(uv_default_loop(), &prepare); r = uv_prepare_init(uv_default_loop(), &prepare);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_prepare_start(&prepare, prepare_cb); r = uv_prepare_start(&prepare, prepare_cb);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_async_init(uv_default_loop(), &async, async_cb); r = uv_async_init(uv_default_loop(), &async, async_cb);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(prepare_cb_called > 0); ASSERT_GT(prepare_cb_called, 0);
ASSERT(async_cb_called == 3); ASSERT_EQ(3, async_cb_called);
ASSERT(close_cb_called == 2); ASSERT_EQ(2, close_cb_called);
ASSERT(0 == uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;

View File

@ -53,13 +53,13 @@ TEST_IMPL(barrier_1) {
memset(&wc, 0, sizeof(wc)); memset(&wc, 0, sizeof(wc));
wc.niter = 1; wc.niter = 1;
ASSERT_EQ(0, uv_barrier_init(&wc.barrier, 2)); ASSERT_OK(uv_barrier_init(&wc.barrier, 2));
ASSERT_EQ(0, uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
uv_sleep(100); uv_sleep(100);
wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier); wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier);
ASSERT_EQ(0, uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
uv_barrier_destroy(&wc.barrier); uv_barrier_destroy(&wc.barrier);
ASSERT_EQ(1, (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval)); ASSERT_EQ(1, (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval));
@ -76,12 +76,12 @@ TEST_IMPL(barrier_2) {
wc.delay = 100; wc.delay = 100;
wc.niter = 1; wc.niter = 1;
ASSERT_EQ(0, uv_barrier_init(&wc.barrier, 2)); ASSERT_OK(uv_barrier_init(&wc.barrier, 2));
ASSERT_EQ(0, uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier); wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier);
ASSERT_EQ(0, uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
uv_barrier_destroy(&wc.barrier); uv_barrier_destroy(&wc.barrier);
ASSERT_EQ(1, (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval)); ASSERT_EQ(1, (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval));
@ -98,13 +98,13 @@ TEST_IMPL(barrier_3) {
memset(&wc, 0, sizeof(wc)); memset(&wc, 0, sizeof(wc));
wc.niter = 5; wc.niter = 5;
ASSERT_EQ(0, uv_barrier_init(&wc.barrier, 2)); ASSERT_OK(uv_barrier_init(&wc.barrier, 2));
ASSERT_EQ(0, uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
for (i = 0; i < wc.niter; i++) for (i = 0; i < wc.niter; i++)
wc.main_barrier_wait_rval += uv_barrier_wait(&wc.barrier); wc.main_barrier_wait_rval += uv_barrier_wait(&wc.barrier);
ASSERT_EQ(0, uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
uv_barrier_destroy(&wc.barrier); uv_barrier_destroy(&wc.barrier);
ASSERT_EQ(wc.niter, wc.main_barrier_wait_rval + wc.worker_barrier_wait_rval); ASSERT_EQ(wc.niter, wc.main_barrier_wait_rval + wc.worker_barrier_wait_rval);
@ -133,10 +133,10 @@ TEST_IMPL(barrier_serial_thread) {
uv_barrier_t barrier; uv_barrier_t barrier;
unsigned i; unsigned i;
ASSERT_EQ(0, uv_barrier_init(&barrier, ARRAY_SIZE(threads) + 1)); ASSERT_OK(uv_barrier_init(&barrier, ARRAY_SIZE(threads) + 1));
for (i = 0; i < ARRAY_SIZE(threads); ++i) for (i = 0; i < ARRAY_SIZE(threads); ++i)
ASSERT_EQ(0, uv_thread_create(&threads[i], serial_worker, &barrier)); ASSERT_OK(uv_thread_create(&threads[i], serial_worker, &barrier));
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
uv_barrier_wait(&barrier); uv_barrier_wait(&barrier);
@ -144,7 +144,7 @@ TEST_IMPL(barrier_serial_thread) {
uv_barrier_destroy(&barrier); uv_barrier_destroy(&barrier);
for (i = 0; i < ARRAY_SIZE(threads); ++i) for (i = 0; i < ARRAY_SIZE(threads); ++i)
ASSERT_EQ(0, uv_thread_join(&threads[i])); ASSERT_OK(uv_thread_join(&threads[i]));
return 0; return 0;
} }
@ -153,7 +153,7 @@ TEST_IMPL(barrier_serial_thread) {
TEST_IMPL(barrier_serial_thread_single) { TEST_IMPL(barrier_serial_thread_single) {
uv_barrier_t barrier; uv_barrier_t barrier;
ASSERT_EQ(0, uv_barrier_init(&barrier, 1)); ASSERT_OK(uv_barrier_init(&barrier, 1));
ASSERT_LT(0, uv_barrier_wait(&barrier)); ASSERT_LT(0, uv_barrier_wait(&barrier));
uv_barrier_destroy(&barrier); uv_barrier_destroy(&barrier);
return 0; return 0;

View File

@ -60,7 +60,7 @@ static void close_cb(uv_handle_t* handle) {
static void shutdown_cb(uv_shutdown_t* req, int status) { static void shutdown_cb(uv_shutdown_t* req, int status) {
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(nested == 0 && "shutdown_cb must be called from a fresh stack"); ASSERT(nested == 0 && "shutdown_cb must be called from a fresh stack");
shutdown_cb_called++; shutdown_cb_called++;
@ -77,7 +77,7 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
return; return;
} else if (nread < 0) { } else if (nread < 0) {
ASSERT(nread == UV_EOF); ASSERT_EQ(nread, UV_EOF);
nested++; nested++;
uv_close((uv_handle_t*)tcp, close_cb); uv_close((uv_handle_t*)tcp, close_cb);
@ -105,7 +105,7 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
static void timer_cb(uv_timer_t* handle) { static void timer_cb(uv_timer_t* handle) {
ASSERT(handle == &timer); ASSERT_PTR_EQ(handle, &timer);
ASSERT(nested == 0 && "timer_cb must be called from a fresh stack"); ASSERT(nested == 0 && "timer_cb must be called from a fresh stack");
puts("Timeout complete. Now read data..."); puts("Timeout complete. Now read data...");
@ -125,7 +125,7 @@ static void timer_cb(uv_timer_t* handle) {
static void write_cb(uv_write_t* req, int status) { static void write_cb(uv_write_t* req, int status) {
int r; int r;
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(nested == 0 && "write_cb must be called from a fresh stack"); ASSERT(nested == 0 && "write_cb must be called from a fresh stack");
puts("Data written. 500ms timeout..."); puts("Data written. 500ms timeout...");
@ -136,9 +136,9 @@ static void write_cb(uv_write_t* req, int status) {
* for the backend to use dirty stack for calling read_cb. */ * for the backend to use dirty stack for calling read_cb. */
nested++; nested++;
r = uv_timer_init(uv_default_loop(), &timer); r = uv_timer_init(uv_default_loop(), &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, timer_cb, 500, 0); r = uv_timer_start(&timer, timer_cb, 500, 0);
ASSERT(r == 0); ASSERT_OK(r);
nested--; nested--;
write_cb_called++; write_cb_called++;
@ -150,7 +150,7 @@ static void connect_cb(uv_connect_t* req, int status) {
puts("Connected. Write some data to echo server..."); puts("Connected. Write some data to echo server...");
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(nested == 0 && "connect_cb must be called from a fresh stack"); ASSERT(nested == 0 && "connect_cb must be called from a fresh stack");
nested++; nested++;
@ -171,7 +171,7 @@ static void connect_cb(uv_connect_t* req, int status) {
TEST_IMPL(callback_stack) { TEST_IMPL(callback_stack) {
struct sockaddr_in addr; struct sockaddr_in addr;
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
if (uv_tcp_init(uv_default_loop(), &client)) { if (uv_tcp_init(uv_default_loop(), &client)) {
FATAL("uv_tcp_init failed"); FATAL("uv_tcp_init failed");
@ -191,13 +191,18 @@ TEST_IMPL(callback_stack) {
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(nested == 0); ASSERT_OK(nested);
ASSERT(connect_cb_called == 1 && "connect_cb must be called exactly once"); ASSERT_NE(connect_cb_called == 1 && \
ASSERT(write_cb_called == 1 && "write_cb must be called exactly once"); "connect_cb must be called exactly once", 0);
ASSERT(timer_cb_called == 1 && "timer_cb must be called exactly once"); ASSERT_NE(write_cb_called == 1 && "write_cb must be called exactly once",
ASSERT(bytes_received == sizeof MESSAGE); 0);
ASSERT(shutdown_cb_called == 1 && "shutdown_cb must be called exactly once"); ASSERT_NE(timer_cb_called == 1 && "timer_cb must be called exactly once",
ASSERT(close_cb_called == 2 && "close_cb must be called exactly twice"); 0);
ASSERT_EQ(bytes_received, sizeof MESSAGE);
ASSERT_NE(shutdown_cb_called == 1 && \
"shutdown_cb must be called exactly once", 0);
ASSERT_NE(close_cb_called == 2 && "close_cb must be called exactly twice",
0);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;

View File

@ -36,11 +36,11 @@ static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
static void read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static void read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
switch (++read_cb_called) { switch (++read_cb_called) {
case 1: case 1:
ASSERT(nread == 1); ASSERT_EQ(1, nread);
uv_read_stop(handle); uv_read_stop(handle);
break; break;
case 2: case 2:
ASSERT(nread == UV_EOF); ASSERT_EQ(nread, UV_EOF);
uv_close((uv_handle_t *) handle, NULL); uv_close((uv_handle_t *) handle, NULL);
break; break;
default: default:
@ -55,29 +55,29 @@ TEST_IMPL(close_fd) {
uv_file fd[2]; uv_file fd[2];
bufs[0] = uv_buf_init("", 1); bufs[0] = uv_buf_init("", 1);
ASSERT(0 == uv_pipe(fd, 0, 0)); ASSERT_OK(uv_pipe(fd, 0, 0));
ASSERT(0 == uv_pipe_init(uv_default_loop(), &pipe_handle, 0)); ASSERT_OK(uv_pipe_init(uv_default_loop(), &pipe_handle, 0));
ASSERT(0 == uv_pipe_open(&pipe_handle, fd[0])); ASSERT_OK(uv_pipe_open(&pipe_handle, fd[0]));
/* uv_pipe_open() takes ownership of the file descriptor. */ /* uv_pipe_open() takes ownership of the file descriptor. */
fd[0] = -1; fd[0] = -1;
ASSERT(1 == uv_fs_write(NULL, &req, fd[1], bufs, 1, -1, NULL)); ASSERT_EQ(1, uv_fs_write(NULL, &req, fd[1], bufs, 1, -1, NULL));
ASSERT(1 == req.result); ASSERT_EQ(1, req.result);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
#ifdef _WIN32 #ifdef _WIN32
ASSERT(0 == _close(fd[1])); ASSERT_OK(_close(fd[1]));
#else #else
ASSERT(0 == close(fd[1])); ASSERT_OK(close(fd[1]));
#endif #endif
fd[1] = -1; fd[1] = -1;
ASSERT(0 == uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb)); ASSERT_OK(uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(1 == read_cb_called); ASSERT_EQ(1, read_cb_called);
ASSERT(0 == uv_is_active((const uv_handle_t *) &pipe_handle)); ASSERT_OK(uv_is_active((const uv_handle_t *) &pipe_handle));
ASSERT(0 == uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb)); ASSERT_OK(uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(2 == read_cb_called); ASSERT_EQ(2, read_cb_called);
ASSERT(0 != uv_is_closing((const uv_handle_t *) &pipe_handle)); ASSERT_NE(0, uv_is_closing((const uv_handle_t *) &pipe_handle));
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;

View File

@ -39,9 +39,9 @@ static void close_cb(uv_handle_t* handle) {
/* check_cb should run before any close_cb */ /* check_cb should run before any close_cb */
static void check_cb(uv_check_t* handle) { static void check_cb(uv_check_t* handle) {
ASSERT(check_cb_called == 0); ASSERT_OK(check_cb_called);
ASSERT(timer_cb_called == 1); ASSERT_EQ(1, timer_cb_called);
ASSERT(close_cb_called == 0); ASSERT_OK(close_cb_called);
uv_close((uv_handle_t*) handle, close_cb); uv_close((uv_handle_t*) handle, close_cb);
uv_close((uv_handle_t*) &timer_handle2, close_cb); uv_close((uv_handle_t*) &timer_handle2, close_cb);
check_cb_called++; check_cb_called++;
@ -65,15 +65,15 @@ TEST_IMPL(close_order) {
uv_timer_init(loop, &timer_handle2); uv_timer_init(loop, &timer_handle2);
uv_timer_start(&timer_handle2, timer_cb, 100000, 0); uv_timer_start(&timer_handle2, timer_cb, 100000, 0);
ASSERT(check_cb_called == 0); ASSERT_OK(check_cb_called);
ASSERT(close_cb_called == 0); ASSERT_OK(close_cb_called);
ASSERT(timer_cb_called == 0); ASSERT_OK(timer_cb_called);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(check_cb_called == 1); ASSERT_EQ(1, check_cb_called);
ASSERT(close_cb_called == 3); ASSERT_EQ(3, close_cb_called);
ASSERT(timer_cb_called == 1); ASSERT_EQ(1, timer_cb_called);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;

View File

@ -55,10 +55,10 @@ void worker_config_init(worker_config* wc,
wc->use_broadcast = use_broadcast; wc->use_broadcast = use_broadcast;
/* Init. */ /* Init. */
ASSERT(0 == uv_sem_init(&wc->sem_waiting, 0)); ASSERT_OK(uv_sem_init(&wc->sem_waiting, 0));
ASSERT(0 == uv_sem_init(&wc->sem_signaled, 0)); ASSERT_OK(uv_sem_init(&wc->sem_signaled, 0));
ASSERT(0 == uv_cond_init(&wc->cond)); ASSERT_OK(uv_cond_init(&wc->cond));
ASSERT(0 == uv_mutex_init(&wc->mutex)); ASSERT_OK(uv_mutex_init(&wc->mutex));
} }
void worker_config_destroy(worker_config* wc) { void worker_config_destroy(worker_config* wc) {
@ -87,7 +87,7 @@ static void condvar_signal(worker_config* c, int* flag) {
uv_mutex_lock(&c->mutex); uv_mutex_lock(&c->mutex);
/* Help waiter differentiate between spurious and legitimate wakeup. */ /* Help waiter differentiate between spurious and legitimate wakeup. */
ASSERT(*flag == 0); ASSERT_OK(*flag);
*flag = 1; *flag = 1;
if (c->use_broadcast) if (c->use_broadcast)
@ -113,7 +113,7 @@ static int condvar_wait(worker_config* c, const int* flag) {
do { do {
uv_cond_wait(&c->cond, &c->mutex); uv_cond_wait(&c->cond, &c->mutex);
} while (*flag == 0); } while (*flag == 0);
ASSERT(*flag == 1); ASSERT_EQ(1, *flag);
uv_mutex_unlock(&c->mutex); uv_mutex_unlock(&c->mutex);
@ -130,13 +130,13 @@ TEST_IMPL(condvar_1) {
/* Helper signal-then-wait. */ /* Helper signal-then-wait. */
worker_config_init(&wc, 0, condvar_signal, condvar_wait); worker_config_init(&wc, 0, condvar_signal, condvar_wait);
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
/* We wait-then-signal. */ /* We wait-then-signal. */
ASSERT(0 == wc.wait_cond(&wc, &wc.posted_1)); ASSERT_OK(wc.wait_cond(&wc, &wc.posted_1));
wc.signal_cond(&wc, &wc.posted_2); wc.signal_cond(&wc, &wc.posted_2);
ASSERT(0 == uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
worker_config_destroy(&wc); worker_config_destroy(&wc);
return 0; return 0;
@ -149,13 +149,13 @@ TEST_IMPL(condvar_2) {
/* Helper to signal-then-wait. */ /* Helper to signal-then-wait. */
worker_config_init(&wc, 1, condvar_signal, condvar_wait); worker_config_init(&wc, 1, condvar_signal, condvar_wait);
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
/* We wait-then-signal. */ /* We wait-then-signal. */
ASSERT(0 == wc.wait_cond(&wc, &wc.posted_1)); ASSERT_OK(wc.wait_cond(&wc, &wc.posted_1));
wc.signal_cond(&wc, &wc.posted_2); wc.signal_cond(&wc, &wc.posted_2);
ASSERT(0 == uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
worker_config_destroy(&wc); worker_config_destroy(&wc);
return 0; return 0;
@ -176,9 +176,9 @@ static int condvar_timedwait(worker_config* c, const int* flag) {
/* Wait until I get a non-spurious signal. */ /* Wait until I get a non-spurious signal. */
do { do {
r = uv_cond_timedwait(&c->cond, &c->mutex, (uint64_t)(1 * 1e9)); /* 1 s */ r = uv_cond_timedwait(&c->cond, &c->mutex, (uint64_t)(1 * 1e9)); /* 1 s */
ASSERT(r == 0); /* Should not time out. */ ASSERT_OK(r); /* Should not time out. */
} while (*flag == 0); } while (*flag == 0);
ASSERT(*flag == 1); ASSERT_EQ(1, *flag);
uv_mutex_unlock(&c->mutex); uv_mutex_unlock(&c->mutex);
@ -194,13 +194,13 @@ TEST_IMPL(condvar_3) {
/* Helper to signal-then-wait. */ /* Helper to signal-then-wait. */
worker_config_init(&wc, 0, condvar_signal, condvar_timedwait); worker_config_init(&wc, 0, condvar_signal, condvar_timedwait);
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
/* We wait-then-signal. */ /* We wait-then-signal. */
wc.wait_cond(&wc, &wc.posted_1); wc.wait_cond(&wc, &wc.posted_1);
wc.signal_cond(&wc, &wc.posted_2); wc.signal_cond(&wc, &wc.posted_2);
ASSERT(0 == uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
worker_config_destroy(&wc); worker_config_destroy(&wc);
return 0; return 0;
@ -213,13 +213,13 @@ TEST_IMPL(condvar_4) {
/* Helper to signal-then-wait. */ /* Helper to signal-then-wait. */
worker_config_init(&wc, 1, condvar_signal, condvar_timedwait); worker_config_init(&wc, 1, condvar_signal, condvar_timedwait);
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); ASSERT_OK(uv_thread_create(&thread, worker, &wc));
/* We wait-then-signal. */ /* We wait-then-signal. */
wc.wait_cond(&wc, &wc.posted_1); wc.wait_cond(&wc, &wc.posted_1);
wc.signal_cond(&wc, &wc.posted_2); wc.signal_cond(&wc, &wc.posted_2);
ASSERT(0 == uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
worker_config_destroy(&wc); worker_config_destroy(&wc);
return 0; return 0;

View File

@ -23,11 +23,11 @@
#include "task.h" #include "task.h"
static void connect_4(uv_connect_t* req, int status) { static void connect_4(uv_connect_t* req, int status) {
ASSERT(status != UV_EADDRNOTAVAIL); ASSERT_NE(status, UV_EADDRNOTAVAIL);
} }
static void connect_6(uv_connect_t* req, int status) { static void connect_6(uv_connect_t* req, int status) {
ASSERT(status != UV_EADDRNOTAVAIL); ASSERT_NE(status, UV_EADDRNOTAVAIL);
} }
TEST_IMPL(connect_unspecified) { TEST_IMPL(connect_unspecified) {
@ -41,23 +41,23 @@ TEST_IMPL(connect_unspecified) {
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(uv_tcp_init(loop, &socket4) == 0); ASSERT_OK(uv_tcp_init(loop, &socket4));
ASSERT(uv_ip4_addr("0.0.0.0", TEST_PORT, &addr4) == 0); ASSERT_OK(uv_ip4_addr("0.0.0.0", TEST_PORT, &addr4));
ASSERT(uv_tcp_connect(&connect4, ASSERT_OK(uv_tcp_connect(&connect4,
&socket4, &socket4,
(const struct sockaddr*) &addr4, (const struct sockaddr*) &addr4,
connect_4) == 0); connect_4));
if (can_ipv6()) { if (can_ipv6()) {
ASSERT(uv_tcp_init(loop, &socket6) == 0); ASSERT_OK(uv_tcp_init(loop, &socket6));
ASSERT(uv_ip6_addr("::", TEST_PORT, &addr6) == 0); ASSERT_OK(uv_ip6_addr("::", TEST_PORT, &addr6));
ASSERT(uv_tcp_connect(&connect6, ASSERT_OK(uv_tcp_connect(&connect6,
&socket6, &socket6,
(const struct sockaddr*) &addr6, (const struct sockaddr*) &addr6,
connect_6) == 0); connect_6));
} }
ASSERT(uv_run(loop, UV_RUN_DEFAULT) == 0); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;

View File

@ -54,8 +54,8 @@ static void timer_cb(uv_timer_t* handle) {
* but libuv hasn't automatically closed the socket. The user must * but libuv hasn't automatically closed the socket. The user must
* uv_close the handle manually. * uv_close the handle manually.
*/ */
ASSERT(close_cb_calls == 0); ASSERT_OK(close_cb_calls);
ASSERT(connect_cb_calls == 1); ASSERT_EQ(1, connect_cb_calls);
/* Close the tcp handle. */ /* Close the tcp handle. */
uv_close((uv_handle_t*)&tcp, on_close); uv_close((uv_handle_t*)&tcp, on_close);
@ -66,22 +66,22 @@ static void timer_cb(uv_timer_t* handle) {
static void on_connect_with_close(uv_connect_t *req, int status) { static void on_connect_with_close(uv_connect_t *req, int status) {
ASSERT((uv_stream_t*) &tcp == req->handle); ASSERT_PTR_EQ((uv_stream_t*) &tcp, req->handle);
ASSERT(status == UV_ECONNREFUSED); ASSERT_EQ(status, UV_ECONNREFUSED);
connect_cb_calls++; connect_cb_calls++;
ASSERT(close_cb_calls == 0); ASSERT_OK(close_cb_calls);
uv_close((uv_handle_t*)req->handle, on_close); uv_close((uv_handle_t*)req->handle, on_close);
} }
static void on_connect_without_close(uv_connect_t *req, int status) { static void on_connect_without_close(uv_connect_t *req, int status) {
ASSERT(status == UV_ECONNREFUSED); ASSERT_EQ(status, UV_ECONNREFUSED);
connect_cb_calls++; connect_cb_calls++;
uv_timer_start(&timer, timer_cb, 100, 0); uv_timer_start(&timer, timer_cb, 100, 0);
ASSERT(close_cb_calls == 0); ASSERT_OK(close_cb_calls);
} }
@ -89,10 +89,10 @@ static void connection_fail(uv_connect_cb connect_cb) {
struct sockaddr_in client_addr, server_addr; struct sockaddr_in client_addr, server_addr;
int r; int r;
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &client_addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", 0, &client_addr));
/* There should be no servers listening on this port. */ /* There should be no servers listening on this port. */
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr));
/* Try to connect to the server and do NUM_PINGS ping-pongs. */ /* Try to connect to the server and do NUM_PINGS ping-pongs. */
r = uv_tcp_init(uv_default_loop(), &tcp); r = uv_tcp_init(uv_default_loop(), &tcp);
@ -100,7 +100,7 @@ static void connection_fail(uv_connect_cb connect_cb) {
/* We are never doing multiple reads/connects at a time anyway. so these /* We are never doing multiple reads/connects at a time anyway. so these
* handles can be pre-initialized. */ * handles can be pre-initialized. */
ASSERT(0 == uv_tcp_bind(&tcp, (const struct sockaddr*) &client_addr, 0)); ASSERT_OK(uv_tcp_bind(&tcp, (const struct sockaddr*) &client_addr, 0));
r = uv_tcp_connect(&req, r = uv_tcp_connect(&req,
&tcp, &tcp,
@ -110,8 +110,8 @@ static void connection_fail(uv_connect_cb connect_cb) {
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(connect_cb_calls == 1); ASSERT_EQ(1, connect_cb_calls);
ASSERT(close_cb_calls == 1); ASSERT_EQ(1, close_cb_calls);
} }
@ -127,8 +127,8 @@ TEST_IMPL(connection_fail) {
connection_fail(on_connect_with_close); connection_fail(on_connect_with_close);
ASSERT(timer_close_cb_calls == 0); ASSERT_OK(timer_close_cb_calls);
ASSERT(timer_cb_calls == 0); ASSERT_OK(timer_cb_calls);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
@ -149,12 +149,12 @@ TEST_IMPL(connection_fail_doesnt_auto_close) {
int r; int r;
r = uv_timer_init(uv_default_loop(), &timer); r = uv_timer_init(uv_default_loop(), &timer);
ASSERT(r == 0); ASSERT_OK(r);
connection_fail(on_connect_without_close); connection_fail(on_connect_without_close);
ASSERT(timer_close_cb_calls == 1); ASSERT_EQ(1, timer_close_cb_calls);
ASSERT(timer_cb_calls == 1); ASSERT_EQ(1, timer_cb_calls);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;

View File

@ -34,24 +34,24 @@ TEST_IMPL(cwd_and_chdir) {
size1 = 1; size1 = 1;
err = uv_cwd(buffer_orig, &size1); err = uv_cwd(buffer_orig, &size1);
ASSERT(err == UV_ENOBUFS); ASSERT_EQ(err, UV_ENOBUFS);
ASSERT(size1 > 1); ASSERT_GT(size1, 1);
size1 = sizeof buffer_orig; size1 = sizeof buffer_orig;
err = uv_cwd(buffer_orig, &size1); err = uv_cwd(buffer_orig, &size1);
ASSERT(err == 0); ASSERT_OK(err);
ASSERT(size1 > 0); ASSERT_GT(size1, 0);
ASSERT(buffer_orig[size1] != '/'); ASSERT_NE(buffer_orig[size1], '/');
err = uv_chdir(buffer_orig); err = uv_chdir(buffer_orig);
ASSERT(err == 0); ASSERT_OK(err);
size2 = sizeof buffer_new; size2 = sizeof buffer_new;
err = uv_cwd(buffer_new, &size2); err = uv_cwd(buffer_new, &size2);
ASSERT(err == 0); ASSERT_OK(err);
ASSERT(size1 == size2); ASSERT_EQ(size1, size2);
ASSERT(strcmp(buffer_orig, buffer_new) == 0); ASSERT_OK(strcmp(buffer_orig, buffer_new));
return 0; return 0;
} }

View File

@ -39,19 +39,19 @@ TEST_IMPL(default_loop_close) {
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT_NOT_NULL(loop); ASSERT_NOT_NULL(loop);
ASSERT(0 == uv_timer_init(loop, &timer_handle)); ASSERT_OK(uv_timer_init(loop, &timer_handle));
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 1, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, 1, 0));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
ASSERT(1 == timer_cb_called); ASSERT_EQ(1, timer_cb_called);
ASSERT(0 == uv_loop_close(loop)); ASSERT_OK(uv_loop_close(loop));
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT_NOT_NULL(loop); ASSERT_NOT_NULL(loop);
ASSERT(0 == uv_timer_init(loop, &timer_handle)); ASSERT_OK(uv_timer_init(loop, &timer_handle));
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 1, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, 1, 0));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
ASSERT(2 == timer_cb_called); ASSERT_EQ(2, timer_cb_called);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;

View File

@ -54,11 +54,11 @@ static void do_accept(uv_timer_t* timer_handle) {
ASSERT_NOT_NULL(accepted_handle); ASSERT_NOT_NULL(accepted_handle);
r = uv_tcp_init(uv_default_loop(), accepted_handle); r = uv_tcp_init(uv_default_loop(), accepted_handle);
ASSERT(r == 0); ASSERT_OK(r);
server = (uv_tcp_t*)timer_handle->data; server = (uv_tcp_t*)timer_handle->data;
r = uv_accept((uv_stream_t*)server, (uv_stream_t*)accepted_handle); r = uv_accept((uv_stream_t*)server, (uv_stream_t*)accepted_handle);
ASSERT(r == 0); ASSERT_OK(r);
do_accept_called++; do_accept_called++;
@ -79,19 +79,19 @@ static void connection_cb(uv_stream_t* tcp, int status) {
int r; int r;
uv_timer_t* timer_handle; uv_timer_t* timer_handle;
ASSERT(status == 0); ASSERT_OK(status);
timer_handle = (uv_timer_t*)malloc(sizeof *timer_handle); timer_handle = (uv_timer_t*)malloc(sizeof *timer_handle);
ASSERT_NOT_NULL(timer_handle); ASSERT_NOT_NULL(timer_handle);
/* Accept the client after 1 second */ /* Accept the client after 1 second */
r = uv_timer_init(uv_default_loop(), timer_handle); r = uv_timer_init(uv_default_loop(), timer_handle);
ASSERT(r == 0); ASSERT_OK(r);
timer_handle->data = tcp; timer_handle->data = tcp;
r = uv_timer_start(timer_handle, do_accept, 1000, 0); r = uv_timer_start(timer_handle, do_accept, 1000, 0);
ASSERT(r == 0); ASSERT_OK(r);
connection_cb_called++; connection_cb_called++;
} }
@ -102,16 +102,16 @@ static void start_server(void) {
uv_tcp_t* server = (uv_tcp_t*)malloc(sizeof *server); uv_tcp_t* server = (uv_tcp_t*)malloc(sizeof *server);
int r; int r;
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_NOT_NULL(server); ASSERT_NOT_NULL(server);
r = uv_tcp_init(uv_default_loop(), server); r = uv_tcp_init(uv_default_loop(), server);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_tcp_bind(server, (const struct sockaddr*) &addr, 0); r = uv_tcp_bind(server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_listen((uv_stream_t*)server, 128, connection_cb); r = uv_listen((uv_stream_t*)server, 128, connection_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -123,10 +123,10 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
} }
if (nread >= 0) { if (nread >= 0) {
ASSERT(nread == 0); ASSERT_OK(nread);
} else { } else {
ASSERT_NOT_NULL(tcp); ASSERT_NOT_NULL(tcp);
ASSERT(nread == UV_EOF); ASSERT_EQ(nread, UV_EOF);
uv_close((uv_handle_t*)tcp, close_cb); uv_close((uv_handle_t*)tcp, close_cb);
} }
} }
@ -136,12 +136,12 @@ static void connect_cb(uv_connect_t* req, int status) {
int r; int r;
ASSERT_NOT_NULL(req); ASSERT_NOT_NULL(req);
ASSERT(status == 0); ASSERT_OK(status);
/* Not that the server will send anything, but otherwise we'll never know /* Not that the server will send anything, but otherwise we'll never know
* when the server closes the connection. */ * when the server closes the connection. */
r = uv_read_start((uv_stream_t*)(req->handle), alloc_cb, read_cb); r = uv_read_start((uv_stream_t*)(req->handle), alloc_cb, read_cb);
ASSERT(r == 0); ASSERT_OK(r);
connect_cb_called++; connect_cb_called++;
@ -155,18 +155,18 @@ static void client_connect(void) {
uv_connect_t* connect_req = malloc(sizeof *connect_req); uv_connect_t* connect_req = malloc(sizeof *connect_req);
int r; int r;
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
ASSERT_NOT_NULL(client); ASSERT_NOT_NULL(client);
ASSERT_NOT_NULL(connect_req); ASSERT_NOT_NULL(connect_req);
r = uv_tcp_init(uv_default_loop(), client); r = uv_tcp_init(uv_default_loop(), client);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_tcp_connect(connect_req, r = uv_tcp_connect(connect_req,
client, client,
(const struct sockaddr*) &addr, (const struct sockaddr*) &addr,
connect_cb); connect_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -179,10 +179,10 @@ TEST_IMPL(delayed_accept) {
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(connection_cb_called == 2); ASSERT_EQ(2, connection_cb_called);
ASSERT(do_accept_called == 2); ASSERT_EQ(2, do_accept_called);
ASSERT(connect_cb_called == 2); ASSERT_EQ(2, connect_cb_called);
ASSERT(close_cb_called == 7); ASSERT_EQ(7, close_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;

View File

@ -38,7 +38,7 @@ TEST_IMPL(dlerror) {
ASSERT_NOT_NULL(strstr(msg, dlerror_no_error)); ASSERT_NOT_NULL(strstr(msg, dlerror_no_error));
r = uv_dlopen(path, &lib); r = uv_dlopen(path, &lib);
ASSERT(r == -1); ASSERT_EQ(r, -1);
msg = uv_dlerror(&lib); msg = uv_dlerror(&lib);
ASSERT_NOT_NULL(msg); ASSERT_NOT_NULL(msg);

View File

@ -48,13 +48,13 @@ struct thread_ctx {
static void thread_main(void* arg) { static void thread_main(void* arg) {
int nwritten; int nwritten;
ASSERT(0 == kill(getpid(), SIGUSR1)); ASSERT_OK(kill(getpid(), SIGUSR1));
do do
nwritten = write(pipe_fds[1], test_buf, sizeof(test_buf)); nwritten = write(pipe_fds[1], test_buf, sizeof(test_buf));
while (nwritten == -1 && errno == EINTR); while (nwritten == -1 && errno == EINTR);
ASSERT(nwritten == sizeof(test_buf)); ASSERT_EQ(nwritten, sizeof(test_buf));
} }
static void sig_func(uv_signal_t* handle, int signum) { static void sig_func(uv_signal_t* handle, int signum) {
@ -70,24 +70,24 @@ TEST_IMPL(eintr_handling) {
iov = uv_buf_init(buf, sizeof(buf)); iov = uv_buf_init(buf, sizeof(buf));
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_signal_init(loop, &signal)); ASSERT_OK(uv_signal_init(loop, &signal));
ASSERT(0 == uv_signal_start(&signal, sig_func, SIGUSR1)); ASSERT_OK(uv_signal_start(&signal, sig_func, SIGUSR1));
ASSERT(0 == pipe(pipe_fds)); ASSERT_OK(pipe(pipe_fds));
ASSERT(0 == uv_thread_create(&thread, thread_main, &ctx)); ASSERT_OK(uv_thread_create(&thread, thread_main, &ctx));
nread = uv_fs_read(loop, &read_req, pipe_fds[0], &iov, 1, -1, NULL); nread = uv_fs_read(loop, &read_req, pipe_fds[0], &iov, 1, -1, NULL);
ASSERT(nread == sizeof(test_buf)); ASSERT_EQ(nread, sizeof(test_buf));
ASSERT(0 == strcmp(buf, test_buf)); ASSERT_OK(strcmp(buf, test_buf));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
ASSERT(0 == close(pipe_fds[0])); ASSERT_OK(close(pipe_fds[0]));
ASSERT(0 == close(pipe_fds[1])); ASSERT_OK(close(pipe_fds[1]));
uv_close((uv_handle_t*) &signal, NULL); uv_close((uv_handle_t*) &signal, NULL);
ASSERT_EQ(0, uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;

View File

@ -36,7 +36,7 @@ static uv_barrier_t barrier;
static void thread_main(void* arg) { static void thread_main(void* arg) {
ASSERT_LE(0, uv_barrier_wait(&barrier)); ASSERT_LE(0, uv_barrier_wait(&barrier));
uv_sleep(250); uv_sleep(250);
ASSERT_EQ(0, uv_async_send(&async)); ASSERT_OK(uv_async_send(&async));
} }
@ -50,9 +50,9 @@ TEST_IMPL(embed) {
uv_loop_t* loop; uv_loop_t* loop;
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT_EQ(0, uv_async_init(loop, &async, async_cb)); ASSERT_OK(uv_async_init(loop, &async, async_cb));
ASSERT_EQ(0, uv_barrier_init(&barrier, 2)); ASSERT_OK(uv_barrier_init(&barrier, 2));
ASSERT_EQ(0, uv_thread_create(&thread, thread_main, NULL)); ASSERT_OK(uv_thread_create(&thread, thread_main, NULL));
ASSERT_LE(0, uv_barrier_wait(&barrier)); ASSERT_LE(0, uv_barrier_wait(&barrier));
while (uv_loop_alive(loop)) { while (uv_loop_alive(loop)) {
@ -71,7 +71,7 @@ TEST_IMPL(embed) {
#endif #endif
} }
ASSERT_EQ(0, uv_thread_join(&thread)); ASSERT_OK(uv_thread_join(&thread));
uv_barrier_destroy(&barrier); uv_barrier_destroy(&barrier);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);

View File

@ -54,37 +54,37 @@ TEST_IMPL(emfile) {
/* Lower the file descriptor limit and use up all fds save one. */ /* Lower the file descriptor limit and use up all fds save one. */
limits.rlim_cur = limits.rlim_max = maxfd + 1; limits.rlim_cur = limits.rlim_max = maxfd + 1;
if (setrlimit(RLIMIT_NOFILE, &limits)) { if (setrlimit(RLIMIT_NOFILE, &limits)) {
ASSERT(errno == EPERM); /* Valgrind blocks the setrlimit() call. */ ASSERT_EQ(errno, EPERM); /* Valgrind blocks the setrlimit() call. */
RETURN_SKIP("setrlimit(RLIMIT_NOFILE) failed, running under valgrind?"); RETURN_SKIP("setrlimit(RLIMIT_NOFILE) failed, running under valgrind?");
} }
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
ASSERT(0 == uv_tcp_init(loop, &server_handle)); ASSERT_OK(uv_tcp_init(loop, &server_handle));
ASSERT(0 == uv_tcp_init(loop, &client_handle)); ASSERT_OK(uv_tcp_init(loop, &client_handle));
ASSERT(0 == uv_tcp_bind(&server_handle, (const struct sockaddr*) &addr, 0)); ASSERT_OK(uv_tcp_bind(&server_handle, (const struct sockaddr*) &addr, 0));
ASSERT(0 == uv_listen((uv_stream_t*) &server_handle, 8, connection_cb)); ASSERT_OK(uv_listen((uv_stream_t*) &server_handle, 8, connection_cb));
/* Remember the first one so we can clean up afterwards. */ /* Remember the first one so we can clean up afterwards. */
do do
first_fd = dup(0); first_fd = dup(0);
while (first_fd == -1 && errno == EINTR); while (first_fd == -1 && errno == EINTR);
ASSERT(first_fd > 0); ASSERT_GT(first_fd, 0);
while (dup(0) != -1 || errno == EINTR); while (dup(0) != -1 || errno == EINTR);
ASSERT(errno == EMFILE); ASSERT_EQ(errno, EMFILE);
close(maxfd); close(maxfd);
/* Now connect and use up the last available file descriptor. The EMFILE /* Now connect and use up the last available file descriptor. The EMFILE
* handling logic in src/unix/stream.c should ensure that connect_cb() runs * handling logic in src/unix/stream.c should ensure that connect_cb() runs
* whereas connection_cb() should *not* run. * whereas connection_cb() should *not* run.
*/ */
ASSERT(0 == uv_tcp_connect(&connect_req, ASSERT_OK(uv_tcp_connect(&connect_req,
&client_handle, &client_handle,
(const struct sockaddr*) &addr, (const struct sockaddr*) &addr,
connect_cb)); connect_cb));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
ASSERT(1 == connect_cb_called); ASSERT_EQ(1, connect_cb_called);
/* Close the dups again. Ignore errors in the unlikely event that the /* Close the dups again. Ignore errors in the unlikely event that the
* file descriptors were not contiguous. * file descriptors were not contiguous.
@ -108,7 +108,7 @@ static void connect_cb(uv_connect_t* req, int status) {
/* |status| should equal 0 because the connection should have been accepted, /* |status| should equal 0 because the connection should have been accepted,
* it's just that the server immediately closes it again. * it's just that the server immediately closes it again.
*/ */
ASSERT(0 == status); ASSERT_OK(status);
connect_cb_called += 1; connect_cb_called += 1;
uv_close((uv_handle_t*) &server_handle, NULL); uv_close((uv_handle_t*) &server_handle, NULL);
uv_close((uv_handle_t*) &client_handle, NULL); uv_close((uv_handle_t*) &client_handle, NULL);

View File

@ -35,83 +35,83 @@ TEST_IMPL(env_vars) {
/* Reject invalid inputs when setting an environment variable */ /* Reject invalid inputs when setting an environment variable */
r = uv_os_setenv(NULL, "foo"); r = uv_os_setenv(NULL, "foo");
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_os_setenv(name, NULL); r = uv_os_setenv(name, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_os_setenv(NULL, NULL); r = uv_os_setenv(NULL, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
/* Reject invalid inputs when retrieving an environment variable */ /* Reject invalid inputs when retrieving an environment variable */
size = BUF_SIZE; size = BUF_SIZE;
r = uv_os_getenv(NULL, buf, &size); r = uv_os_getenv(NULL, buf, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_os_getenv(name, NULL, &size); r = uv_os_getenv(name, NULL, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_os_getenv(name, buf, NULL); r = uv_os_getenv(name, buf, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
size = 0; size = 0;
r = uv_os_getenv(name, buf, &size); r = uv_os_getenv(name, buf, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
/* Reject invalid inputs when deleting an environment variable */ /* Reject invalid inputs when deleting an environment variable */
r = uv_os_unsetenv(NULL); r = uv_os_unsetenv(NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
/* Successfully set an environment variable */ /* Successfully set an environment variable */
r = uv_os_setenv(name, "123456789"); r = uv_os_setenv(name, "123456789");
ASSERT(r == 0); ASSERT_OK(r);
/* Successfully read an environment variable */ /* Successfully read an environment variable */
size = BUF_SIZE; size = BUF_SIZE;
buf[0] = '\0'; buf[0] = '\0';
r = uv_os_getenv(name, buf, &size); r = uv_os_getenv(name, buf, &size);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(strcmp(buf, "123456789") == 0); ASSERT_OK(strcmp(buf, "123456789"));
ASSERT(size == BUF_SIZE - 1); ASSERT_EQ(size, BUF_SIZE - 1);
/* Return UV_ENOBUFS if the buffer cannot hold the environment variable */ /* Return UV_ENOBUFS if the buffer cannot hold the environment variable */
size = BUF_SIZE - 1; size = BUF_SIZE - 1;
buf[0] = '\0'; buf[0] = '\0';
r = uv_os_getenv(name, buf, &size); r = uv_os_getenv(name, buf, &size);
ASSERT(r == UV_ENOBUFS); ASSERT_EQ(r, UV_ENOBUFS);
ASSERT(size == BUF_SIZE); ASSERT_EQ(size, BUF_SIZE);
/* Successfully delete an environment variable */ /* Successfully delete an environment variable */
r = uv_os_unsetenv(name); r = uv_os_unsetenv(name);
ASSERT(r == 0); ASSERT_OK(r);
/* Return UV_ENOENT retrieving an environment variable that does not exist */ /* Return UV_ENOENT retrieving an environment variable that does not exist */
r = uv_os_getenv(name, buf, &size); r = uv_os_getenv(name, buf, &size);
ASSERT(r == UV_ENOENT); ASSERT_EQ(r, UV_ENOENT);
/* Successfully delete an environment variable that does not exist */ /* Successfully delete an environment variable that does not exist */
r = uv_os_unsetenv(name); r = uv_os_unsetenv(name);
ASSERT(r == 0); ASSERT_OK(r);
/* Setting an environment variable to the empty string does not delete it. */ /* Setting an environment variable to the empty string does not delete it. */
r = uv_os_setenv(name, ""); r = uv_os_setenv(name, "");
ASSERT(r == 0); ASSERT_OK(r);
size = BUF_SIZE; size = BUF_SIZE;
r = uv_os_getenv(name, buf, &size); r = uv_os_getenv(name, buf, &size);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(size == 0); ASSERT_OK(size);
ASSERT(strlen(buf) == 0); ASSERT_OK(strlen(buf));
/* Check getting all env variables. */ /* Check getting all env variables. */
r = uv_os_setenv(name, "123456789"); r = uv_os_setenv(name, "123456789");
ASSERT(r == 0); ASSERT_OK(r);
r = uv_os_setenv(name2, ""); r = uv_os_setenv(name2, "");
ASSERT(r == 0); ASSERT_OK(r);
#ifdef _WIN32 #ifdef _WIN32
/* Create a special environment variable on Windows in case there are no /* Create a special environment variable on Windows in case there are no
naturally occurring ones. */ naturally occurring ones. */
r = uv_os_setenv("=Z:", "\\"); r = uv_os_setenv("=Z:", "\\");
ASSERT(r == 0); ASSERT_OK(r);
#endif #endif
r = uv_os_environ(&envitems, &envcount); r = uv_os_environ(&envitems, &envcount);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(envcount > 0); ASSERT_GT(envcount, 0);
found = 0; found = 0;
found_win_special = 0; found_win_special = 0;
@ -120,16 +120,16 @@ TEST_IMPL(env_vars) {
/* printf("Env: %s = %s\n", envitems[i].name, envitems[i].value); */ /* printf("Env: %s = %s\n", envitems[i].name, envitems[i].value); */
if (strcmp(envitems[i].name, name) == 0) { if (strcmp(envitems[i].name, name) == 0) {
found++; found++;
ASSERT(strcmp(envitems[i].value, "123456789") == 0); ASSERT_OK(strcmp(envitems[i].value, "123456789"));
} else if (strcmp(envitems[i].name, name2) == 0) { } else if (strcmp(envitems[i].name, name2) == 0) {
found++; found++;
ASSERT(strlen(envitems[i].value) == 0); ASSERT_OK(strlen(envitems[i].value));
} else if (envitems[i].name[0] == '=') { } else if (envitems[i].name[0] == '=') {
found_win_special++; found_win_special++;
} }
} }
ASSERT(found == 2); ASSERT_EQ(2, found);
#ifdef _WIN32 #ifdef _WIN32
ASSERT_GT(found_win_special, 0); ASSERT_GT(found_win_special, 0);
#else #else
@ -140,10 +140,10 @@ TEST_IMPL(env_vars) {
uv_os_free_environ(envitems, envcount); uv_os_free_environ(envitems, envcount);
r = uv_os_unsetenv(name); r = uv_os_unsetenv(name);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_os_unsetenv(name2); r = uv_os_unsetenv(name2);
ASSERT(r == 0); ASSERT_OK(r);
for (i = 1; i <= 4; i++) { for (i = 1; i <= 4; i++) {
size_t n; size_t n;
@ -158,14 +158,14 @@ TEST_IMPL(env_vars) {
memset(p, 'x', n); memset(p, 'x', n);
p[n] = '\0'; p[n] = '\0';
ASSERT_EQ(0, uv_os_setenv(name, p)); ASSERT_OK(uv_os_setenv(name, p));
ASSERT_EQ(0, uv_os_getenv(name, p, &size)); ASSERT_OK(uv_os_getenv(name, p, &size));
ASSERT_EQ(n, size); ASSERT_EQ(n, size);
for (n = 0; n < size; n++) for (n = 0; n < size; n++)
ASSERT_EQ('x', p[n]); ASSERT_EQ('x', p[n]);
ASSERT_EQ(0, uv_os_unsetenv(name)); ASSERT_OK(uv_os_unsetenv(name));
free(p); free(p);
} }

View File

@ -51,8 +51,8 @@ TEST_IMPL(error_message) {
} }
ASSERT_NULL(strstr(uv_strerror(UV_EINVAL), "Success")); ASSERT_NULL(strstr(uv_strerror(UV_EINVAL), "Success"));
ASSERT(strcmp(uv_strerror(1337), "Unknown error") == 0); ASSERT_OK(strcmp(uv_strerror(1337), "Unknown error"));
ASSERT(strcmp(uv_strerror(-1337), "Unknown error") == 0); ASSERT_OK(strcmp(uv_strerror(-1337), "Unknown error"));
ASSERT_NULL(strstr(uv_strerror_r(UV_EINVAL, buf, sizeof(buf)), "Success")); ASSERT_NULL(strstr(uv_strerror_r(UV_EINVAL, buf, sizeof(buf)), "Success"));
ASSERT_NOT_NULL(strstr(uv_strerror_r(1337, buf, sizeof(buf)), "1337")); ASSERT_NOT_NULL(strstr(uv_strerror_r(1337, buf, sizeof(buf)), "1337"));
@ -64,19 +64,19 @@ TEST_IMPL(error_message) {
TEST_IMPL(sys_error) { TEST_IMPL(sys_error) {
#if defined(_WIN32) #if defined(_WIN32)
ASSERT(uv_translate_sys_error(ERROR_NOACCESS) == UV_EACCES); ASSERT_EQ(uv_translate_sys_error(ERROR_NOACCESS), UV_EACCES);
ASSERT(uv_translate_sys_error(ERROR_ELEVATION_REQUIRED) == UV_EACCES); ASSERT_EQ(uv_translate_sys_error(ERROR_ELEVATION_REQUIRED), UV_EACCES);
ASSERT(uv_translate_sys_error(WSAEADDRINUSE) == UV_EADDRINUSE); ASSERT_EQ(uv_translate_sys_error(WSAEADDRINUSE), UV_EADDRINUSE);
ASSERT(uv_translate_sys_error(ERROR_BAD_PIPE) == UV_EPIPE); ASSERT_EQ(uv_translate_sys_error(ERROR_BAD_PIPE), UV_EPIPE);
#else #else
ASSERT(uv_translate_sys_error(EPERM) == UV_EPERM); ASSERT_EQ(uv_translate_sys_error(EPERM), UV_EPERM);
ASSERT(uv_translate_sys_error(EPIPE) == UV_EPIPE); ASSERT_EQ(uv_translate_sys_error(EPIPE), UV_EPIPE);
ASSERT(uv_translate_sys_error(EINVAL) == UV_EINVAL); ASSERT_EQ(uv_translate_sys_error(EINVAL), UV_EINVAL);
#endif #endif
ASSERT(uv_translate_sys_error(UV_EINVAL) == UV_EINVAL); ASSERT_EQ(uv_translate_sys_error(UV_EINVAL), UV_EINVAL);
ASSERT(uv_translate_sys_error(UV_ERANGE) == UV_ERANGE); ASSERT_EQ(uv_translate_sys_error(UV_ERANGE), UV_ERANGE);
ASSERT(uv_translate_sys_error(UV_EACCES) == UV_EACCES); ASSERT_EQ(uv_translate_sys_error(UV_EACCES), UV_EACCES);
ASSERT(uv_translate_sys_error(0) == 0); ASSERT_OK(uv_translate_sys_error(0));
return 0; return 0;
} }

View File

@ -51,12 +51,12 @@ static char socket_cb_read_buf[1024];
static void socket_cb(uv_poll_t* poll, int status, int events) { static void socket_cb(uv_poll_t* poll, int status, int events) {
ssize_t cnt; ssize_t cnt;
socket_cb_called++; socket_cb_called++;
ASSERT(0 == status); ASSERT_OK(status);
printf("Socket cb got events %d\n", events); printf("Socket cb got events %d\n", events);
ASSERT(UV_READABLE == (events & UV_READABLE)); ASSERT_EQ(UV_READABLE, (events & UV_READABLE));
if (socket_cb_read_fd) { if (socket_cb_read_fd) {
cnt = read(socket_cb_read_fd, socket_cb_read_buf, socket_cb_read_size); cnt = read(socket_cb_read_fd, socket_cb_read_buf, socket_cb_read_size);
ASSERT(cnt == socket_cb_read_size); ASSERT_EQ(cnt, socket_cb_read_size);
} }
uv_close((uv_handle_t*) poll, NULL); uv_close((uv_handle_t*) poll, NULL);
} }
@ -66,15 +66,15 @@ static void run_timer_loop_once(void) {
uv_loop_t loop; uv_loop_t loop;
uv_timer_t timer_handle; uv_timer_t timer_handle;
ASSERT_EQ(0, uv_loop_init(&loop)); ASSERT_OK(uv_loop_init(&loop));
timer_cb_called = 0; /* Reset for the child. */ timer_cb_called = 0; /* Reset for the child. */
ASSERT(0 == uv_timer_init(&loop, &timer_handle)); ASSERT_OK(uv_timer_init(&loop, &timer_handle));
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 1, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, 1, 0));
ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(&loop, UV_RUN_DEFAULT));
ASSERT(1 == timer_cb_called); ASSERT_EQ(1, timer_cb_called);
ASSERT_EQ(0, uv_loop_close(&loop)); ASSERT_OK(uv_loop_close(&loop));
} }
@ -87,10 +87,10 @@ static void assert_wait_child(pid_t child_pid) {
if (waited_pid == -1) { if (waited_pid == -1) {
perror("Failed to wait"); perror("Failed to wait");
} }
ASSERT(child_pid == waited_pid); ASSERT_EQ(child_pid, waited_pid);
ASSERT(WIFEXITED(child_stat)); /* Clean exit, not a signal. */ ASSERT(WIFEXITED(child_stat)); /* Clean exit, not a signal. */
ASSERT(!WIFSIGNALED(child_stat)); ASSERT(!WIFSIGNALED(child_stat));
ASSERT(0 == WEXITSTATUS(child_stat)); ASSERT_OK(WEXITSTATUS(child_stat));
} }
@ -109,14 +109,14 @@ TEST_IMPL(fork_timer) {
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
assert_wait_child(child_pid); assert_wait_child(child_pid);
} else { } else {
/* child */ /* child */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
run_timer_loop_once(); run_timer_loop_once();
} }
@ -135,30 +135,30 @@ TEST_IMPL(fork_socketpair) {
/* Prime the loop. */ /* Prime the loop. */
run_timer_loop_once(); run_timer_loop_once();
ASSERT(0 == socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds)); ASSERT_OK(socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds));
/* Create the server watcher in the parent, use it in the child. */ /* Create the server watcher in the parent, use it in the child. */
ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_handle, socket_fds[0])); ASSERT_OK(uv_poll_init(uv_default_loop(), &poll_handle, socket_fds[0]));
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
child_pid = -1; child_pid = -1;
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
ASSERT(3 == send(socket_fds[1], "hi\n", 3, 0)); ASSERT_EQ(3, send(socket_fds[1], "hi\n", 3, 0));
assert_wait_child(child_pid); assert_wait_child(child_pid);
} else { } else {
/* child */ /* child */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
ASSERT(0 == socket_cb_called); ASSERT_OK(socket_cb_called);
ASSERT(0 == uv_poll_start(&poll_handle, UV_READABLE, socket_cb)); ASSERT_OK(uv_poll_start(&poll_handle, UV_READABLE, socket_cb));
printf("Going to run the loop in the child\n"); printf("Going to run the loop in the child\n");
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(1 == socket_cb_called); ASSERT_EQ(1, socket_cb_called);
} }
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
@ -176,57 +176,57 @@ TEST_IMPL(fork_socketpair_started) {
char sync_buf[1]; char sync_buf[1];
uv_poll_t poll_handle; uv_poll_t poll_handle;
ASSERT(0 == pipe(sync_pipe)); ASSERT_OK(pipe(sync_pipe));
/* Prime the loop. */ /* Prime the loop. */
run_timer_loop_once(); run_timer_loop_once();
ASSERT(0 == socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds)); ASSERT_OK(socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds));
/* Create and start the server watcher in the parent, use it in the child. */ /* Create and start the server watcher in the parent, use it in the child. */
ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_handle, socket_fds[0])); ASSERT_OK(uv_poll_init(uv_default_loop(), &poll_handle, socket_fds[0]));
ASSERT(0 == uv_poll_start(&poll_handle, UV_READABLE, socket_cb)); ASSERT_OK(uv_poll_start(&poll_handle, UV_READABLE, socket_cb));
/* Run the loop AFTER the poll watcher is registered to make sure it /* Run the loop AFTER the poll watcher is registered to make sure it
gets passed to the kernel. Use NOWAIT and expect a non-zero gets passed to the kernel. Use NOWAIT and expect a non-zero
return to prove the poll watcher is active. return to prove the poll watcher is active.
*/ */
ASSERT(1 == uv_run(uv_default_loop(), UV_RUN_NOWAIT)); ASSERT_EQ(1, uv_run(uv_default_loop(), UV_RUN_NOWAIT));
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
child_pid = -1; child_pid = -1;
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
ASSERT(0 == uv_poll_stop(&poll_handle)); ASSERT_OK(uv_poll_stop(&poll_handle));
uv_close((uv_handle_t*)&poll_handle, NULL); uv_close((uv_handle_t*)&poll_handle, NULL);
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(0 == socket_cb_called); ASSERT_OK(socket_cb_called);
ASSERT(1 == write(sync_pipe[1], "1", 1)); /* alert child */ ASSERT_EQ(1, write(sync_pipe[1], "1", 1)); /* alert child */
ASSERT(3 == send(socket_fds[1], "hi\n", 3, 0)); ASSERT_EQ(3, send(socket_fds[1], "hi\n", 3, 0));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(0 == socket_cb_called); ASSERT_OK(socket_cb_called);
assert_wait_child(child_pid); assert_wait_child(child_pid);
} else { } else {
/* child */ /* child */
printf("Child is %d\n", getpid()); printf("Child is %d\n", getpid());
ASSERT(1 == read(sync_pipe[0], sync_buf, 1)); /* wait for parent */ ASSERT_EQ(1, read(sync_pipe[0], sync_buf, 1)); /* wait for parent */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
ASSERT(0 == socket_cb_called); ASSERT_OK(socket_cb_called);
printf("Going to run the loop in the child\n"); printf("Going to run the loop in the child\n");
socket_cb_read_fd = socket_fds[0]; socket_cb_read_fd = socket_fds[0];
socket_cb_read_size = 3; socket_cb_read_size = 3;
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(1 == socket_cb_called); ASSERT_EQ(1, socket_cb_called);
printf("Buf %s\n", socket_cb_read_buf); printf("Buf %s\n", socket_cb_read_buf);
ASSERT(0 == strcmp("hi\n", socket_cb_read_buf)); ASSERT_OK(strcmp("hi\n", socket_cb_read_buf));
} }
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
@ -253,41 +253,43 @@ TEST_IMPL(fork_signal_to_child) {
fork_signal_cb_called = 0; /* reset */ fork_signal_cb_called = 0; /* reset */
ASSERT(0 == pipe(sync_pipe)); ASSERT_OK(pipe(sync_pipe));
/* Prime the loop. */ /* Prime the loop. */
run_timer_loop_once(); run_timer_loop_once();
ASSERT(0 == uv_signal_init(uv_default_loop(), &signal_handle)); ASSERT_OK(uv_signal_init(uv_default_loop(), &signal_handle));
ASSERT(0 == uv_signal_start(&signal_handle, fork_signal_to_child_cb, SIGUSR1)); ASSERT_OK(uv_signal_start(&signal_handle,
fork_signal_to_child_cb,
SIGUSR1));
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
child_pid = -1; child_pid = -1;
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
ASSERT(1 == read(sync_pipe[0], sync_buf, 1)); /* wait for child */ ASSERT_EQ(1, read(sync_pipe[0], sync_buf, 1)); /* wait for child */
ASSERT(0 == kill(child_pid, SIGUSR1)); ASSERT_OK(kill(child_pid, SIGUSR1));
/* Run the loop, make sure we don't get the signal. */ /* Run the loop, make sure we don't get the signal. */
printf("Running loop in parent\n"); printf("Running loop in parent\n");
uv_unref((uv_handle_t*)&signal_handle); uv_unref((uv_handle_t*)&signal_handle);
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_NOWAIT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_NOWAIT));
ASSERT(0 == fork_signal_cb_called); ASSERT_OK(fork_signal_cb_called);
printf("Waiting for child in parent\n"); printf("Waiting for child in parent\n");
assert_wait_child(child_pid); assert_wait_child(child_pid);
} else { } else {
/* child */ /* child */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
ASSERT(1 == write(sync_pipe[1], "1", 1)); /* alert parent */ ASSERT_EQ(1, write(sync_pipe[1], "1", 1)); /* alert parent */
/* Get the signal. */ /* Get the signal. */
ASSERT(0 != uv_loop_alive(uv_default_loop())); ASSERT_NE(0, uv_loop_alive(uv_default_loop()));
printf("Running loop in child\n"); printf("Running loop in child\n");
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_ONCE)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_ONCE));
ASSERT(SIGUSR1 == fork_signal_cb_called); ASSERT_EQ(SIGUSR1, fork_signal_cb_called);
} }
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
@ -308,47 +310,49 @@ TEST_IMPL(fork_signal_to_child_closed) {
fork_signal_cb_called = 0; /* reset */ fork_signal_cb_called = 0; /* reset */
ASSERT(0 == pipe(sync_pipe)); ASSERT_OK(pipe(sync_pipe));
ASSERT(0 == pipe(sync_pipe2)); ASSERT_OK(pipe(sync_pipe2));
/* Prime the loop. */ /* Prime the loop. */
run_timer_loop_once(); run_timer_loop_once();
ASSERT(0 == uv_signal_init(uv_default_loop(), &signal_handle)); ASSERT_OK(uv_signal_init(uv_default_loop(), &signal_handle));
ASSERT(0 == uv_signal_start(&signal_handle, fork_signal_to_child_cb, SIGUSR1)); ASSERT_OK(uv_signal_start(&signal_handle,
fork_signal_to_child_cb,
SIGUSR1));
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
child_pid = -1; child_pid = -1;
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
printf("Wating on child in parent\n"); printf("Wating on child in parent\n");
ASSERT(1 == read(sync_pipe[0], sync_buf, 1)); /* wait for child */ ASSERT_EQ(1, read(sync_pipe[0], sync_buf, 1)); /* wait for child */
printf("Parent killing child\n"); printf("Parent killing child\n");
ASSERT(0 == kill(child_pid, SIGUSR1)); ASSERT_OK(kill(child_pid, SIGUSR1));
/* Run the loop, make sure we don't get the signal. */ /* Run the loop, make sure we don't get the signal. */
printf("Running loop in parent\n"); printf("Running loop in parent\n");
uv_unref((uv_handle_t*)&signal_handle); /* so the loop can exit; uv_unref((uv_handle_t*)&signal_handle); /* so the loop can exit;
we *shouldn't* get any signals */ we *shouldn't* get any signals */
run_timer_loop_once(); /* but while we share a pipe, we do, so run_timer_loop_once(); /* but while we share a pipe, we do, so
have something active. */ have something active. */
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_ONCE)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_ONCE));
printf("Signal in parent %d\n", fork_signal_cb_called); printf("Signal in parent %d\n", fork_signal_cb_called);
ASSERT(0 == fork_signal_cb_called); ASSERT_OK(fork_signal_cb_called);
ASSERT(1 == write(sync_pipe2[1], "1", 1)); /* alert child */ ASSERT_EQ(1, write(sync_pipe2[1], "1", 1)); /* alert child */
printf("Waiting for child in parent\n"); printf("Waiting for child in parent\n");
assert_wait_child(child_pid); assert_wait_child(child_pid);
} else { } else {
/* Child. Our signal handler should still be installed. */ /* Child. Our signal handler should still be installed. */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
printf("Checking loop in child\n"); printf("Checking loop in child\n");
ASSERT(0 != uv_loop_alive(uv_default_loop())); ASSERT_NE(0, uv_loop_alive(uv_default_loop()));
printf("Alerting parent in child\n"); printf("Alerting parent in child\n");
ASSERT(1 == write(sync_pipe[1], "1", 1)); /* alert parent */ ASSERT_EQ(1, write(sync_pipe[1], "1", 1)); /* alert parent */
/* Don't run the loop. Wait for the parent to call us */ /* Don't run the loop. Wait for the parent to call us */
printf("Waiting on parent in child\n"); printf("Waiting on parent in child\n");
/* Wait for parent. read may fail if the parent tripped an ASSERT /* Wait for parent. read may fail if the parent tripped an ASSERT
@ -356,7 +360,7 @@ TEST_IMPL(fork_signal_to_child_closed) {
*/ */
r = read(sync_pipe2[0], sync_buf, 1); r = read(sync_pipe2[0], sync_buf, 1);
ASSERT(-1 <= r && r <= 1); ASSERT(-1 <= r && r <= 1);
ASSERT(0 == fork_signal_cb_called); ASSERT_OK(fork_signal_cb_called);
printf("Exiting child \n"); printf("Exiting child \n");
/* Note that we're deliberately not running the loop /* Note that we're deliberately not running the loop
* in the child, and also not closing the loop's handles, * in the child, and also not closing the loop's handles,
@ -371,6 +375,47 @@ TEST_IMPL(fork_signal_to_child_closed) {
return 0; return 0;
} }
static void fork_signal_cb(uv_signal_t* h, int s) {
fork_signal_cb_called = s;
}
static void empty_close_cb(uv_handle_t* h){}
TEST_IMPL(fork_close_signal_in_child) {
uv_loop_t loop;
uv_signal_t signal_handle;
pid_t child_pid;
ASSERT_OK(uv_loop_init(&loop));
ASSERT_OK(uv_signal_init(&loop, &signal_handle));
ASSERT_OK(uv_signal_start(&signal_handle, &fork_signal_cb, SIGHUP));
ASSERT_OK(kill(getpid(), SIGHUP));
child_pid = fork();
ASSERT_NE(child_pid, -1);
ASSERT_OK(fork_signal_cb_called);
if (!child_pid) {
uv_loop_fork(&loop);
uv_close((uv_handle_t*)&signal_handle, &empty_close_cb);
uv_run(&loop, UV_RUN_DEFAULT);
/* Child doesn't receive the signal */
ASSERT_OK(fork_signal_cb_called);
} else {
/* Parent. Runing once to receive the signal */
uv_run(&loop, UV_RUN_ONCE);
ASSERT_EQ(SIGHUP, fork_signal_cb_called);
/* loop should stop after closing the only handle */
uv_close((uv_handle_t*)&signal_handle, &empty_close_cb);
ASSERT_OK(uv_run(&loop, UV_RUN_DEFAULT));
assert_wait_child(child_pid);
}
MAKE_VALGRIND_HAPPY(&loop);
return 0;
}
static void create_file(const char* name) { static void create_file(const char* name) {
int r; int r;
@ -378,11 +423,11 @@ static void create_file(const char* name) {
uv_fs_t req; uv_fs_t req;
r = uv_fs_open(NULL, &req, name, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR, NULL); r = uv_fs_open(NULL, &req, name, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_close(NULL, &req, file, NULL); r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
} }
@ -394,17 +439,17 @@ static void touch_file(const char* name) {
uv_buf_t buf; uv_buf_t buf;
r = uv_fs_open(NULL, &req, name, O_RDWR, 0, NULL); r = uv_fs_open(NULL, &req, name, O_RDWR, 0, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
buf = uv_buf_init("foo", 4); buf = uv_buf_init("foo", 4);
r = uv_fs_write(NULL, &req, file, &buf, 1, -1, NULL); r = uv_fs_write(NULL, &req, file, &buf, 1, -1, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_close(NULL, &req, file, NULL); r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
} }
@ -424,11 +469,11 @@ static void fs_event_cb_file_current_dir(uv_fs_event_t* handle,
const char* filename, const char* filename,
int events, int events,
int status) { int status) {
ASSERT(fs_event_cb_called == 0); ASSERT_OK(fs_event_cb_called);
++fs_event_cb_called; ++fs_event_cb_called;
ASSERT(status == 0); ASSERT_OK(status);
#if defined(__APPLE__) || defined(__linux__) #if defined(__APPLE__) || defined(__linux__)
ASSERT(strcmp(filename, "watch_file") == 0); ASSERT_OK(strcmp(filename, "watch_file"));
#else #else
ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0); ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0);
#endif #endif
@ -446,28 +491,28 @@ static void assert_watch_file_current_dir(uv_loop_t* const loop, int file_or_dir
create_file("watch_file"); create_file("watch_file");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
/* watching a dir is the only way to get fsevents involved on apple /* watching a dir is the only way to get fsevents involved on apple
platforms */ platforms */
r = uv_fs_event_start(&fs_event, r = uv_fs_event_start(&fs_event,
fs_event_cb_file_current_dir, fs_event_cb_file_current_dir,
file_or_dir == 1 ? "." : "watch_file", file_or_dir == 1 ? "." : "watch_file",
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, timer_cb_touch, 100, 0); r = uv_timer_start(&timer, timer_cb_touch, 100, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(timer_cb_touch_called == 0); ASSERT_OK(timer_cb_touch_called);
ASSERT(fs_event_cb_called == 0); ASSERT_OK(fs_event_cb_called);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(timer_cb_touch_called == 1); ASSERT_EQ(1, timer_cb_touch_called);
ASSERT(fs_event_cb_called == 1); ASSERT_EQ(1, fs_event_cb_called);
/* Cleanup */ /* Cleanup */
remove("watch_file"); remove("watch_file");
@ -492,7 +537,7 @@ static int _do_fork_fs_events_child(int file_or_dir) {
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
@ -508,10 +553,10 @@ static int _do_fork_fs_events_child(int file_or_dir) {
uv_loop_init(&loop); uv_loop_init(&loop);
printf("Child first watch\n"); printf("Child first watch\n");
assert_watch_file_current_dir(&loop, file_or_dir); assert_watch_file_current_dir(&loop, file_or_dir);
ASSERT(0 == uv_loop_close(&loop)); ASSERT_OK(uv_loop_close(&loop));
printf("Child second watch default loop\n"); printf("Child second watch default loop\n");
/* Ee can watch in the default loop. */ /* Ee can watch in the default loop. */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
/* On some platforms (OS X), if we don't update the time now, /* On some platforms (OS X), if we don't update the time now,
* the timer cb fires before the event loop enters uv__io_poll, * the timer cb fires before the event loop enters uv__io_poll,
* instead of after, meaning we don't see the change! This may be * instead of after, meaning we don't see the change! This may be
@ -524,7 +569,7 @@ static int _do_fork_fs_events_child(int file_or_dir) {
especially important on Apple platforms where if we're not especially important on Apple platforms where if we're not
careful trying to touch the CFRunLoop, even just to shut it careful trying to touch the CFRunLoop, even just to shut it
down, that we allocated in the FS_TEST_DIR case would crash. */ down, that we allocated in the FS_TEST_DIR case would crash. */
ASSERT(0 == uv_loop_close(uv_default_loop())); ASSERT_OK(uv_loop_close(uv_default_loop()));
printf("Exiting child \n"); printf("Exiting child \n");
} }
@ -587,40 +632,40 @@ TEST_IMPL(fork_fs_events_file_parent_child) {
create_file("watch_file"); create_file("watch_file");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, r = uv_fs_event_start(&fs_event,
fs_event_cb_file_current_dir, fs_event_cb_file_current_dir,
"watch_file", "watch_file",
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
child_pid = -1; child_pid = -1;
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* parent */ /* parent */
assert_wait_child(child_pid); assert_wait_child(child_pid);
} else { } else {
/* child */ /* child */
printf("Running child\n"); printf("Running child\n");
ASSERT(0 == uv_loop_fork(loop)); ASSERT_OK(uv_loop_fork(loop));
r = uv_timer_start(&timer, timer_cb_touch, 100, 0); r = uv_timer_start(&timer, timer_cb_touch, 100, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(timer_cb_touch_called == 0); ASSERT_OK(timer_cb_touch_called);
ASSERT(fs_event_cb_called == 0); ASSERT_OK(fs_event_cb_called);
printf("Running loop in child \n"); printf("Running loop in child \n");
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(timer_cb_touch_called == 1); ASSERT_EQ(1, timer_cb_touch_called);
ASSERT(fs_event_cb_called == 1); ASSERT_EQ(1, fs_event_cb_called);
/* Cleanup */ /* Cleanup */
remove("watch_file"); remove("watch_file");
@ -646,7 +691,7 @@ static void work_cb(uv_work_t* req) {
static void after_work_cb(uv_work_t* req, int status) { static void after_work_cb(uv_work_t* req, int status) {
ASSERT(status == 0); ASSERT_OK(status);
after_work_cb_count++; after_work_cb_count++;
} }
@ -655,16 +700,16 @@ static void assert_run_work(uv_loop_t* const loop) {
uv_work_t work_req; uv_work_t work_req;
int r; int r;
ASSERT(work_cb_count == 0); ASSERT_OK(work_cb_count);
ASSERT(after_work_cb_count == 0); ASSERT_OK(after_work_cb_count);
printf("Queue in %d\n", getpid()); printf("Queue in %d\n", getpid());
r = uv_queue_work(loop, &work_req, work_cb, after_work_cb); r = uv_queue_work(loop, &work_req, work_cb, after_work_cb);
ASSERT(r == 0); ASSERT_OK(r);
printf("Running in %d\n", getpid()); printf("Running in %d\n", getpid());
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(work_cb_count == 1); ASSERT_EQ(1, work_cb_count);
ASSERT(after_work_cb_count == 1); ASSERT_EQ(1, after_work_cb_count);
/* cleanup */ /* cleanup */
work_cb_count = 0; work_cb_count = 0;
@ -691,7 +736,7 @@ TEST_IMPL(fork_threadpool_queue_work_simple) {
#else #else
child_pid = fork(); child_pid = fork();
#endif #endif
ASSERT(child_pid != -1); ASSERT_NE(child_pid, -1);
if (child_pid != 0) { if (child_pid != 0) {
/* Parent. We can still run work. */ /* Parent. We can still run work. */
@ -706,7 +751,7 @@ TEST_IMPL(fork_threadpool_queue_work_simple) {
uv_loop_close(&loop); uv_loop_close(&loop);
printf("Child second watch default loop\n"); printf("Child second watch default loop\n");
/* We can work in the default loop. */ /* We can work in the default loop. */
ASSERT(0 == uv_loop_fork(uv_default_loop())); ASSERT_OK(uv_loop_fork(uv_default_loop()));
assert_run_work(uv_default_loop()); assert_run_work(uv_default_loop());
printf("Exiting child \n"); printf("Exiting child \n");
} }

View File

@ -48,19 +48,19 @@ static void handle_result(uv_fs_t* req) {
uint64_t mode; uint64_t mode;
int r; int r;
ASSERT(req->fs_type == UV_FS_COPYFILE); ASSERT_EQ(req->fs_type, UV_FS_COPYFILE);
ASSERT(req->result == 0); ASSERT_OK(req->result);
/* Verify that the file size and mode are the same. */ /* Verify that the file size and mode are the same. */
r = uv_fs_stat(NULL, &stat_req, req->path, NULL); r = uv_fs_stat(NULL, &stat_req, req->path, NULL);
ASSERT(r == 0); ASSERT_OK(r);
size = stat_req.statbuf.st_size; size = stat_req.statbuf.st_size;
mode = stat_req.statbuf.st_mode; mode = stat_req.statbuf.st_mode;
uv_fs_req_cleanup(&stat_req); uv_fs_req_cleanup(&stat_req);
r = uv_fs_stat(NULL, &stat_req, dst, NULL); r = uv_fs_stat(NULL, &stat_req, dst, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(stat_req.statbuf.st_size == size); ASSERT_EQ(stat_req.statbuf.st_size, size);
ASSERT(stat_req.statbuf.st_mode == mode); ASSERT_EQ(stat_req.statbuf.st_mode, mode);
uv_fs_req_cleanup(&stat_req); uv_fs_req_cleanup(&stat_req);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
result_check_count++; result_check_count++;
@ -77,7 +77,7 @@ static void touch_file(const char* name, unsigned int size) {
r = uv_fs_open(NULL, &req, name, O_WRONLY | O_CREAT | O_TRUNC, r = uv_fs_open(NULL, &req, name, O_WRONLY | O_CREAT | O_TRUNC,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
ASSERT(r >= 0); ASSERT_GE(r, 0);
file = r; file = r;
buf = uv_buf_init("a", 1); buf = uv_buf_init("a", 1);
@ -86,12 +86,12 @@ static void touch_file(const char* name, unsigned int size) {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
r = uv_fs_write(NULL, &req, file, &buf, 1, i, NULL); r = uv_fs_write(NULL, &req, file, &buf, 1, i, NULL);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
ASSERT(r >= 0); ASSERT_GE(r, 0);
} }
r = uv_fs_close(NULL, &req, file, NULL); r = uv_fs_close(NULL, &req, file, NULL);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -105,102 +105,102 @@ TEST_IMPL(fs_copyfile) {
/* Fails with EINVAL if bad flags are passed. */ /* Fails with EINVAL if bad flags are passed. */
r = uv_fs_copyfile(NULL, &req, src, dst, -1, NULL); r = uv_fs_copyfile(NULL, &req, src, dst, -1, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
/* Fails with ENOENT if source does not exist. */ /* Fails with ENOENT if source does not exist. */
unlink(src); unlink(src);
unlink(dst); unlink(dst);
r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL);
ASSERT(req.result == UV_ENOENT); ASSERT_EQ(req.result, UV_ENOENT);
ASSERT(r == UV_ENOENT); ASSERT_EQ(r, UV_ENOENT);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
/* The destination should not exist. */ /* The destination should not exist. */
r = uv_fs_stat(NULL, &req, dst, NULL); r = uv_fs_stat(NULL, &req, dst, NULL);
ASSERT(r != 0); ASSERT(r);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
/* Succeeds if src and dst files are identical. */ /* Succeeds if src and dst files are identical. */
touch_file(src, 12); touch_file(src, 12);
r = uv_fs_copyfile(NULL, &req, src, src, 0, NULL); r = uv_fs_copyfile(NULL, &req, src, src, 0, NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
/* Verify that the src file did not get truncated. */ /* Verify that the src file did not get truncated. */
r = uv_fs_stat(NULL, &req, src, NULL); r = uv_fs_stat(NULL, &req, src, NULL);
ASSERT_EQ(r, 0); ASSERT_OK(r);
ASSERT_EQ(req.statbuf.st_size, 12); ASSERT_EQ(12, req.statbuf.st_size);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
unlink(src); unlink(src);
/* Copies file synchronously. Creates new file. */ /* Copies file synchronously. Creates new file. */
unlink(dst); unlink(dst);
r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL);
ASSERT(r == 0); ASSERT_OK(r);
handle_result(&req); handle_result(&req);
/* Copies a file of size zero. */ /* Copies a file of size zero. */
unlink(dst); unlink(dst);
touch_file(src, 0); touch_file(src, 0);
r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL);
ASSERT(r == 0); ASSERT_OK(r);
handle_result(&req); handle_result(&req);
/* Copies file synchronously. Overwrites existing file. */ /* Copies file synchronously. Overwrites existing file. */
r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL);
ASSERT(r == 0); ASSERT_OK(r);
handle_result(&req); handle_result(&req);
/* Fails to overwrites existing file. */ /* Fails to overwrites existing file. */
ASSERT_EQ(uv_fs_chmod(NULL, &req, dst, 0644, NULL), 0); ASSERT_OK(uv_fs_chmod(NULL, &req, dst, 0644, NULL));
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_EXCL, NULL); r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_EXCL, NULL);
ASSERT(r == UV_EEXIST); ASSERT_EQ(r, UV_EEXIST);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
/* Truncates when an existing destination is larger than the source file. */ /* Truncates when an existing destination is larger than the source file. */
ASSERT_EQ(uv_fs_chmod(NULL, &req, dst, 0644, NULL), 0); ASSERT_OK(uv_fs_chmod(NULL, &req, dst, 0644, NULL));
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
touch_file(src, 1); touch_file(src, 1);
r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL);
ASSERT_EQ(r, 0); ASSERT_OK(r);
handle_result(&req); handle_result(&req);
/* Copies a larger file. */ /* Copies a larger file. */
unlink(dst); unlink(dst);
touch_file(src, 4096 * 2); touch_file(src, 4096 * 2);
r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL);
ASSERT(r == 0); ASSERT_OK(r);
handle_result(&req); handle_result(&req);
unlink(src); unlink(src);
/* Copies file asynchronously */ /* Copies file asynchronously */
unlink(dst); unlink(dst);
r = uv_fs_copyfile(loop, &req, fixture, dst, 0, handle_result); r = uv_fs_copyfile(loop, &req, fixture, dst, 0, handle_result);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(result_check_count == 5); ASSERT_EQ(5, result_check_count);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(result_check_count == 6); ASSERT_EQ(6, result_check_count);
/* Ensure file is user-writable (not copied from src). */ /* Ensure file is user-writable (not copied from src). */
ASSERT_EQ(uv_fs_chmod(NULL, &req, dst, 0644, NULL), 0); ASSERT_OK(uv_fs_chmod(NULL, &req, dst, 0644, NULL));
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
/* If the flags are invalid, the loop should not be kept open */ /* If the flags are invalid, the loop should not be kept open */
unlink(dst); unlink(dst);
r = uv_fs_copyfile(loop, &req, fixture, dst, -1, fail_cb); r = uv_fs_copyfile(loop, &req, fixture, dst, -1, fail_cb);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
/* Copies file using UV_FS_COPYFILE_FICLONE. */ /* Copies file using UV_FS_COPYFILE_FICLONE. */
unlink(dst); unlink(dst);
r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_FICLONE, NULL); r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_FICLONE, NULL);
ASSERT(r == 0); ASSERT_OK(r);
handle_result(&req); handle_result(&req);
/* Copies file using UV_FS_COPYFILE_FICLONE_FORCE. */ /* Copies file using UV_FS_COPYFILE_FICLONE_FORCE. */
unlink(dst); unlink(dst);
r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_FICLONE_FORCE, r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_FICLONE_FORCE,
NULL); NULL);
ASSERT(r <= 0); ASSERT_LE(r, 0);
if (r == 0) if (r == 0)
handle_result(&req); handle_result(&req);
@ -213,8 +213,8 @@ TEST_IMPL(fs_copyfile) {
r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL); r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL);
/* On IBMi PASE, qsecofr users can overwrite read-only files */ /* On IBMi PASE, qsecofr users can overwrite read-only files */
# ifndef __PASE__ # ifndef __PASE__
ASSERT(req.result == UV_EACCES); ASSERT_EQ(req.result, UV_EACCES);
ASSERT(r == UV_EACCES); ASSERT_EQ(r, UV_EACCES);
# endif # endif
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
#endif #endif

View File

@ -81,11 +81,11 @@ static void create_file(const char* name) {
uv_fs_t req; uv_fs_t req;
r = uv_fs_open(NULL, &req, name, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR, NULL); r = uv_fs_open(NULL, &req, name, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_close(NULL, &req, file, NULL); r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
} }
@ -96,17 +96,17 @@ static void touch_file(const char* name) {
uv_buf_t buf; uv_buf_t buf;
r = uv_fs_open(NULL, &req, name, O_RDWR, 0, NULL); r = uv_fs_open(NULL, &req, name, O_RDWR, 0, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
buf = uv_buf_init("foo", 4); buf = uv_buf_init("foo", 4);
r = uv_fs_write(NULL, &req, file, &buf, 1, -1, NULL); r = uv_fs_write(NULL, &req, file, &buf, 1, -1, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_close(NULL, &req, file, NULL); r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
} }
@ -125,15 +125,15 @@ static void fail_cb(uv_fs_event_t* handle,
static void fs_event_cb_dir(uv_fs_event_t* handle, const char* filename, static void fs_event_cb_dir(uv_fs_event_t* handle, const char* filename,
int events, int status) { int events, int status) {
++fs_event_cb_called; ++fs_event_cb_called;
ASSERT(handle == &fs_event); ASSERT_PTR_EQ(handle, &fs_event);
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(events == UV_CHANGE); ASSERT_EQ(events, UV_CHANGE);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strcmp(filename, "file1") == 0); ASSERT_OK(strcmp(filename, "file1"));
#else #else
ASSERT(filename == NULL || strcmp(filename, "file1") == 0); ASSERT(filename == NULL || strcmp(filename, "file1") == 0);
#endif #endif
ASSERT(0 == uv_fs_event_stop(handle)); ASSERT_OK(uv_fs_event_stop(handle));
uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
} }
@ -148,7 +148,7 @@ static const char* fs_event_get_filename(int i) {
static void fs_event_create_files(uv_timer_t* handle) { static void fs_event_create_files(uv_timer_t* handle) {
/* Make sure we're not attempting to create files we do not intend */ /* Make sure we're not attempting to create files we do not intend */
ASSERT(fs_event_created < fs_event_file_count); ASSERT_LT(fs_event_created, fs_event_file_count);
/* Create the file */ /* Create the file */
create_file(fs_event_get_filename(fs_event_created)); create_file(fs_event_get_filename(fs_event_created));
@ -156,7 +156,7 @@ static void fs_event_create_files(uv_timer_t* handle) {
if (++fs_event_created < fs_event_file_count) { if (++fs_event_created < fs_event_file_count) {
/* Create another file on a different event loop tick. We do it this way /* Create another file on a different event loop tick. We do it this way
* to avoid fs events coalescing into one fs event. */ * to avoid fs events coalescing into one fs event. */
ASSERT_EQ(0, uv_timer_start(&timer, fs_event_create_files, 100, 0)); ASSERT_OK(uv_timer_start(&timer, fs_event_create_files, 100, 0));
} }
} }
@ -170,19 +170,19 @@ static void fs_event_unlink_files(uv_timer_t* handle) {
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
r = remove(fs_event_get_filename(i)); r = remove(fs_event_get_filename(i));
if (handle != NULL) if (handle != NULL)
ASSERT(r == 0); ASSERT_OK(r);
} }
} else { } else {
/* Make sure we're not attempting to remove files we do not intend */ /* Make sure we're not attempting to remove files we do not intend */
ASSERT(fs_event_removed < fs_event_file_count); ASSERT_LT(fs_event_removed, fs_event_file_count);
/* Remove the file */ /* Remove the file */
ASSERT(0 == remove(fs_event_get_filename(fs_event_removed))); ASSERT_OK(remove(fs_event_get_filename(fs_event_removed)));
if (++fs_event_removed < fs_event_file_count) { if (++fs_event_removed < fs_event_file_count) {
/* Remove another file on a different event loop tick. We do it this way /* Remove another file on a different event loop tick. We do it this way
* to avoid fs events coalescing into one fs event. */ * to avoid fs events coalescing into one fs event. */
ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files, 1, 0)); ASSERT_OK(uv_timer_start(&timer, fs_event_unlink_files, 1, 0));
} }
} }
} }
@ -192,19 +192,19 @@ static void fs_event_cb_dir_multi_file(uv_fs_event_t* handle,
int events, int events,
int status) { int status) {
fs_event_cb_called++; fs_event_cb_called++;
ASSERT(handle == &fs_event); ASSERT_PTR_EQ(handle, &fs_event);
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(events == UV_CHANGE || events == UV_RENAME); ASSERT(events == UV_CHANGE || events == UV_RENAME);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strncmp(filename, file_prefix, sizeof(file_prefix) - 1) == 0); ASSERT_OK(strncmp(filename, file_prefix, sizeof(file_prefix) - 1));
#else #else
ASSERT(filename == NULL || ASSERT_NE(filename == NULL ||
strncmp(filename, file_prefix, sizeof(file_prefix) - 1) == 0); strncmp(filename, file_prefix, sizeof(file_prefix) - 1) == 0, 0);
#endif #endif
if (fs_event_created + fs_event_removed == fs_event_file_count) { if (fs_event_created + fs_event_removed == fs_event_file_count) {
/* Once we've processed all create events, delete all files */ /* Once we've processed all create events, delete all files */
ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files, 1, 0)); ASSERT_OK(uv_timer_start(&timer, fs_event_unlink_files, 1, 0));
} else if (fs_event_cb_called == 2 * fs_event_file_count) { } else if (fs_event_cb_called == 2 * fs_event_file_count) {
/* Once we've processed all create and delete events, stop watching */ /* Once we've processed all create and delete events, stop watching */
uv_close((uv_handle_t*) &timer, close_cb); uv_close((uv_handle_t*) &timer, close_cb);
@ -224,7 +224,7 @@ static const char* fs_event_get_filename_in_subdir(int i) {
static void fs_event_create_files_in_subdir(uv_timer_t* handle) { static void fs_event_create_files_in_subdir(uv_timer_t* handle) {
/* Make sure we're not attempting to create files we do not intend */ /* Make sure we're not attempting to create files we do not intend */
ASSERT(fs_event_created < fs_event_file_count); ASSERT_LT(fs_event_created, fs_event_file_count);
/* Create the file */ /* Create the file */
create_file(fs_event_get_filename_in_subdir(fs_event_created)); create_file(fs_event_get_filename_in_subdir(fs_event_created));
@ -232,8 +232,7 @@ static void fs_event_create_files_in_subdir(uv_timer_t* handle) {
if (++fs_event_created < fs_event_file_count) { if (++fs_event_created < fs_event_file_count) {
/* Create another file on a different event loop tick. We do it this way /* Create another file on a different event loop tick. We do it this way
* to avoid fs events coalescing into one fs event. */ * to avoid fs events coalescing into one fs event. */
ASSERT_EQ(0, ASSERT_OK(uv_timer_start(&timer, fs_event_create_files_in_subdir, 100, 0));
uv_timer_start(&timer, fs_event_create_files_in_subdir, 100, 0));
} }
} }
@ -247,19 +246,22 @@ static void fs_event_unlink_files_in_subdir(uv_timer_t* handle) {
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
r = remove(fs_event_get_filename_in_subdir(i)); r = remove(fs_event_get_filename_in_subdir(i));
if (handle != NULL) if (handle != NULL)
ASSERT(r == 0); ASSERT_OK(r);
} }
} else { } else {
/* Make sure we're not attempting to remove files we do not intend */ /* Make sure we're not attempting to remove files we do not intend */
ASSERT(fs_event_removed < fs_event_file_count); ASSERT_LT(fs_event_removed, fs_event_file_count);
/* Remove the file */ /* Remove the file */
ASSERT(0 == remove(fs_event_get_filename_in_subdir(fs_event_removed))); ASSERT_OK(remove(fs_event_get_filename_in_subdir(fs_event_removed)));
if (++fs_event_removed < fs_event_file_count) { if (++fs_event_removed < fs_event_file_count) {
/* Remove another file on a different event loop tick. We do it this way /* Remove another file on a different event loop tick. We do it this way
* to avoid fs events coalescing into one fs event. */ * to avoid fs events coalescing into one fs event. */
ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files_in_subdir, 1, 0)); ASSERT_OK(uv_timer_start(&timer,
fs_event_unlink_files_in_subdir,
1,
0));
} }
} }
} }
@ -283,27 +285,30 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle,
return; return;
fs_multievent_cb_called++; fs_multievent_cb_called++;
ASSERT(handle == &fs_event); ASSERT_PTR_EQ(handle, &fs_event);
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(events == UV_CHANGE || events == UV_RENAME); ASSERT(events == UV_CHANGE || events == UV_RENAME);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strncmp(filename, ASSERT_OK(strncmp(filename,
file_prefix_in_subdir, file_prefix_in_subdir,
sizeof(file_prefix_in_subdir) - 1) == 0); sizeof(file_prefix_in_subdir) - 1));
#else #else
ASSERT(filename == NULL || ASSERT_NE(filename == NULL ||
strncmp(filename, strncmp(filename,
file_prefix_in_subdir, file_prefix_in_subdir,
sizeof(file_prefix_in_subdir) - 1) == 0); sizeof(file_prefix_in_subdir) - 1) == 0, 0);
#endif #endif
if (fs_event_created == fs_event_file_count && if (fs_event_created == fs_event_file_count &&
fs_multievent_cb_called == fs_event_created) { fs_multievent_cb_called == fs_event_created) {
/* Once we've processed all create events, delete all files */ /* Once we've processed all create events, delete all files */
ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files_in_subdir, 1, 0)); ASSERT_OK(uv_timer_start(&timer,
fs_event_unlink_files_in_subdir,
1,
0));
} else if (fs_multievent_cb_called == 2 * fs_event_file_count) { } else if (fs_multievent_cb_called == 2 * fs_event_file_count) {
/* Once we've processed all create and delete events, stop watching */ /* Once we've processed all create and delete events, stop watching */
ASSERT(fs_event_removed == fs_event_file_count); ASSERT_EQ(fs_event_removed, fs_event_file_count);
uv_close((uv_handle_t*) &timer, close_cb); uv_close((uv_handle_t*) &timer, close_cb);
uv_close((uv_handle_t*) handle, close_cb); uv_close((uv_handle_t*) handle, close_cb);
} }
@ -313,15 +318,15 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle,
static void fs_event_cb_file(uv_fs_event_t* handle, const char* filename, static void fs_event_cb_file(uv_fs_event_t* handle, const char* filename,
int events, int status) { int events, int status) {
++fs_event_cb_called; ++fs_event_cb_called;
ASSERT(handle == &fs_event); ASSERT_PTR_EQ(handle, &fs_event);
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(events == UV_CHANGE); ASSERT_EQ(events, UV_CHANGE);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strcmp(filename, "file2") == 0); ASSERT_OK(strcmp(filename, "file2"));
#else #else
ASSERT(filename == NULL || strcmp(filename, "file2") == 0); ASSERT(filename == NULL || strcmp(filename, "file2") == 0);
#endif #endif
ASSERT(0 == uv_fs_event_stop(handle)); ASSERT_OK(uv_fs_event_stop(handle));
uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
} }
@ -329,11 +334,11 @@ static void fs_event_cb_file_current_dir(uv_fs_event_t* handle,
const char* filename, int events, int status) { const char* filename, int events, int status) {
++fs_event_cb_called; ++fs_event_cb_called;
ASSERT(handle == &fs_event); ASSERT_PTR_EQ(handle, &fs_event);
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(events == UV_CHANGE); ASSERT_EQ(events, UV_CHANGE);
#if defined(__APPLE__) || defined(_WIN32) || defined(__linux__) #if defined(__APPLE__) || defined(_WIN32) || defined(__linux__)
ASSERT(strcmp(filename, "watch_file") == 0); ASSERT_OK(strcmp(filename, "watch_file"));
#else #else
ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0); ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0);
#endif #endif
@ -366,7 +371,7 @@ static void timer_cb_exact(uv_timer_t* handle) {
} else { } else {
uv_close((uv_handle_t*)handle, NULL); uv_close((uv_handle_t*)handle, NULL);
r = uv_fs_event_stop(&fs_event); r = uv_fs_event_stop(&fs_event);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &fs_event, NULL); uv_close((uv_handle_t*) &fs_event, NULL);
} }
@ -384,9 +389,9 @@ static void fs_event_cb_close(uv_fs_event_t* handle,
const char* filename, const char* filename,
int events, int events,
int status) { int status) {
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(fs_event_cb_called < 3); ASSERT_LT(fs_event_cb_called, 3);
++fs_event_cb_called; ++fs_event_cb_called;
if (fs_event_cb_called == 3) { if (fs_event_cb_called == 3) {
@ -400,6 +405,8 @@ TEST_IMPL(fs_event_watch_dir) {
RETURN_SKIP(NO_FS_EVENTS); RETURN_SKIP(NO_FS_EVENTS);
#elif defined(__MVS__) #elif defined(__MVS__)
RETURN_SKIP("Directory watching not supported on this platform."); RETURN_SKIP("Directory watching not supported on this platform.");
#elif defined(__APPLE__) && defined(__TSAN__)
RETURN_SKIP("Times out under TSAN.");
#endif #endif
uv_loop_t* loop = uv_default_loop(); uv_loop_t* loop = uv_default_loop();
@ -413,18 +420,18 @@ TEST_IMPL(fs_event_watch_dir) {
create_dir("watch_dir"); create_dir("watch_dir");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_cb_dir_multi_file, "watch_dir", 0); r = uv_fs_event_start(&fs_event, fs_event_cb_dir_multi_file, "watch_dir", 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, fs_event_create_files, 100, 0); r = uv_timer_start(&timer, fs_event_create_files, 100, 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fs_event_cb_called == fs_event_created + fs_event_removed); ASSERT_EQ(fs_event_cb_called, fs_event_created + fs_event_removed);
ASSERT(close_cb_called == 2); ASSERT_EQ(2, close_cb_called);
/* Cleanup */ /* Cleanup */
fs_event_unlink_files(NULL); fs_event_unlink_files(NULL);
@ -438,7 +445,9 @@ TEST_IMPL(fs_event_watch_dir) {
TEST_IMPL(fs_event_watch_dir_recursive) { TEST_IMPL(fs_event_watch_dir_recursive) {
#if defined(__APPLE__) || defined(_WIN32) #if defined(__APPLE__) && defined(__TSAN__)
RETURN_SKIP("Times out under TSAN.");
#elif defined(__APPLE__) || defined(_WIN32)
uv_loop_t* loop; uv_loop_t* loop;
int r; int r;
uv_fs_event_t fs_event_root; uv_fs_event_t fs_event_root;
@ -454,27 +463,27 @@ TEST_IMPL(fs_event_watch_dir_recursive) {
create_dir("watch_dir/subdir"); create_dir("watch_dir/subdir");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, r = uv_fs_event_start(&fs_event,
fs_event_cb_dir_multi_file_in_subdir, fs_event_cb_dir_multi_file_in_subdir,
"watch_dir", "watch_dir",
UV_FS_EVENT_RECURSIVE); UV_FS_EVENT_RECURSIVE);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, fs_event_create_files_in_subdir, 100, 0); r = uv_timer_start(&timer, fs_event_create_files_in_subdir, 100, 0);
ASSERT(r == 0); ASSERT_OK(r);
#ifndef _WIN32 #ifndef _WIN32
/* Also try to watch the root directory. /* Also try to watch the root directory.
* This will be noisier, so we're just checking for any couple events to happen. */ * This will be noisier, so we're just checking for any couple events to happen. */
r = uv_fs_event_init(loop, &fs_event_root); r = uv_fs_event_init(loop, &fs_event_root);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event_root, r = uv_fs_event_start(&fs_event_root,
fs_event_cb_close, fs_event_cb_close,
"/", "/",
UV_FS_EVENT_RECURSIVE); UV_FS_EVENT_RECURSIVE);
ASSERT(r == 0); ASSERT_OK(r);
#else #else
fs_event_cb_called += 3; fs_event_cb_called += 3;
close_cb_called += 1; close_cb_called += 1;
@ -483,9 +492,9 @@ TEST_IMPL(fs_event_watch_dir_recursive) {
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fs_multievent_cb_called == fs_event_created + fs_event_removed); ASSERT_EQ(fs_multievent_cb_called, fs_event_created + fs_event_removed);
ASSERT(fs_event_cb_called == 3); ASSERT_EQ(3, fs_event_cb_called);
ASSERT(close_cb_called == 3); ASSERT_EQ(3, close_cb_called);
/* Cleanup */ /* Cleanup */
fs_event_unlink_files_in_subdir(NULL); fs_event_unlink_files_in_subdir(NULL);
@ -522,19 +531,19 @@ TEST_IMPL(fs_event_watch_dir_short_path) {
has_shortnames = uv_fs_stat(NULL, &req, "watch_~1", NULL) != UV_ENOENT; has_shortnames = uv_fs_stat(NULL, &req, "watch_~1", NULL) != UV_ENOENT;
if (has_shortnames) { if (has_shortnames) {
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_cb_dir, "watch_~1", 0); r = uv_fs_event_start(&fs_event, fs_event_cb_dir, "watch_~1", 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, timer_cb_file, 100, 0); r = uv_timer_start(&timer, timer_cb_file, 100, 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fs_event_cb_called == 1); ASSERT_EQ(1, fs_event_cb_called);
ASSERT(timer_cb_called == 1); ASSERT_EQ(1, timer_cb_called);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
} }
/* Cleanup */ /* Cleanup */
@ -568,19 +577,19 @@ TEST_IMPL(fs_event_watch_file) {
create_file("watch_dir/file2"); create_file("watch_dir/file2");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_cb_file, "watch_dir/file2", 0); r = uv_fs_event_start(&fs_event, fs_event_cb_file, "watch_dir/file2", 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, timer_cb_file, 100, 100); r = uv_timer_start(&timer, timer_cb_file, 100, 100);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fs_event_cb_called == 1); ASSERT_EQ(1, fs_event_cb_called);
ASSERT(timer_cb_called == 2); ASSERT_EQ(2, timer_cb_called);
ASSERT(close_cb_called == 2); ASSERT_EQ(2, close_cb_called);
/* Cleanup */ /* Cleanup */
remove("watch_dir/file2"); remove("watch_dir/file2");
@ -624,16 +633,16 @@ TEST_IMPL(fs_event_watch_file_exact_path) {
#endif #endif
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir/file.jsx", 0); r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir/file.jsx", 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, timer_cb_exact, 100, 100); r = uv_timer_start(&timer, timer_cb_exact, 100, 100);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(timer_cb_exact_called == 2); ASSERT_EQ(2, timer_cb_exact_called);
/* Cleanup */ /* Cleanup */
remove("watch_dir/file.js"); remove("watch_dir/file.js");
@ -656,13 +665,13 @@ TEST_IMPL(fs_event_watch_file_twice) {
loop = uv_default_loop(); loop = uv_default_loop();
timer.data = watchers; timer.data = watchers;
ASSERT(0 == uv_fs_event_init(loop, watchers + 0)); ASSERT_OK(uv_fs_event_init(loop, watchers + 0));
ASSERT(0 == uv_fs_event_start(watchers + 0, fail_cb, path, 0)); ASSERT_OK(uv_fs_event_start(watchers + 0, fail_cb, path, 0));
ASSERT(0 == uv_fs_event_init(loop, watchers + 1)); ASSERT_OK(uv_fs_event_init(loop, watchers + 1));
ASSERT(0 == uv_fs_event_start(watchers + 1, fail_cb, path, 0)); ASSERT_OK(uv_fs_event_start(watchers + 1, fail_cb, path, 0));
ASSERT(0 == uv_timer_init(loop, &timer)); ASSERT_OK(uv_timer_init(loop, &timer));
ASSERT(0 == uv_timer_start(&timer, timer_cb_watch_twice, 10, 0)); ASSERT_OK(uv_timer_start(&timer, timer_cb_watch_twice, 10, 0));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;
@ -690,31 +699,31 @@ TEST_IMPL(fs_event_watch_file_current_dir) {
#endif #endif
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, r = uv_fs_event_start(&fs_event,
fs_event_cb_file_current_dir, fs_event_cb_file_current_dir,
"watch_file", "watch_file",
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
timer.data = "watch_file"; timer.data = "watch_file";
r = uv_timer_start(&timer, timer_cb_touch, 1100, 0); r = uv_timer_start(&timer, timer_cb_touch, 1100, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(timer_cb_touch_called == 0); ASSERT_OK(timer_cb_touch_called);
ASSERT(fs_event_cb_called == 0); ASSERT_OK(fs_event_cb_called);
ASSERT(close_cb_called == 0); ASSERT_OK(close_cb_called);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(timer_cb_touch_called == 1); ASSERT_EQ(1, timer_cb_touch_called);
/* FSEvents on macOS sometimes sends one change event, sometimes two. */ /* FSEvents on macOS sometimes sends one change event, sometimes two. */
ASSERT_NE(0, fs_event_cb_called); ASSERT_NE(0, fs_event_cb_called);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
/* Cleanup */ /* Cleanup */
remove("watch_file"); remove("watch_file");
@ -737,11 +746,11 @@ TEST_IMPL(fs_event_watch_file_root_dir) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fail_cb, path, 0); r = uv_fs_event_start(&fs_event, fail_cb, path, 0);
if (r == UV_ENOENT) if (r == UV_ENOENT)
RETURN_SKIP("bootsect.bak doesn't exist in system root.\n"); RETURN_SKIP("bootsect.bak doesn't exist in system root.\n");
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &fs_event, NULL); uv_close((uv_handle_t*) &fs_event, NULL);
@ -765,20 +774,20 @@ TEST_IMPL(fs_event_no_callback_after_close) {
create_file("watch_dir/file1"); create_file("watch_dir/file1");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, r = uv_fs_event_start(&fs_event,
fs_event_cb_file, fs_event_cb_file,
"watch_dir/file1", "watch_dir/file1",
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*)&fs_event, close_cb); uv_close((uv_handle_t*)&fs_event, close_cb);
touch_file("watch_dir/file1"); touch_file("watch_dir/file1");
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fs_event_cb_called == 0); ASSERT_OK(fs_event_cb_called);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
/* Cleanup */ /* Cleanup */
remove("watch_dir/file1"); remove("watch_dir/file1");
@ -803,19 +812,19 @@ TEST_IMPL(fs_event_no_callback_on_close) {
create_file("watch_dir/file1"); create_file("watch_dir/file1");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, r = uv_fs_event_start(&fs_event,
fs_event_cb_file, fs_event_cb_file,
"watch_dir/file1", "watch_dir/file1",
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*)&fs_event, close_cb); uv_close((uv_handle_t*)&fs_event, close_cb);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fs_event_cb_called == 0); ASSERT_OK(fs_event_cb_called);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
/* Cleanup */ /* Cleanup */
remove("watch_dir/file1"); remove("watch_dir/file1");
@ -830,9 +839,9 @@ static void timer_cb(uv_timer_t* handle) {
int r; int r;
r = uv_fs_event_init(handle->loop, &fs_event); r = uv_fs_event_init(handle->loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_fail, ".", 0); r = uv_fs_event_start(&fs_event, fs_event_fail, ".", 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*)&fs_event, close_cb); uv_close((uv_handle_t*)&fs_event, close_cb);
uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
@ -850,14 +859,14 @@ TEST_IMPL(fs_event_immediate_close) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, timer_cb, 1, 0); r = uv_timer_start(&timer, timer_cb, 1, 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 2); ASSERT_EQ(2, close_cb_called);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;
@ -877,9 +886,9 @@ TEST_IMPL(fs_event_close_with_pending_event) {
create_file("watch_dir/file"); create_file("watch_dir/file");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir", 0); r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir", 0);
ASSERT(r == 0); ASSERT_OK(r);
/* Generate an fs event. */ /* Generate an fs event. */
touch_file("watch_dir/file"); touch_file("watch_dir/file");
@ -888,7 +897,7 @@ TEST_IMPL(fs_event_close_with_pending_event) {
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
/* Clean up */ /* Clean up */
remove("watch_dir/file"); remove("watch_dir/file");
@ -911,9 +920,9 @@ TEST_IMPL(fs_event_close_with_pending_delete_event) {
create_file("watch_dir/file"); create_file("watch_dir/file");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir/file", 0); r = uv_fs_event_start(&fs_event, fs_event_fail, "watch_dir/file", 0);
ASSERT(r == 0); ASSERT_OK(r);
/* Generate an fs event. */ /* Generate an fs event. */
remove("watch_dir/file"); remove("watch_dir/file");
@ -927,7 +936,7 @@ TEST_IMPL(fs_event_close_with_pending_delete_event) {
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
/* Clean up */ /* Clean up */
remove("watch_dir/"); remove("watch_dir/");
@ -941,6 +950,8 @@ TEST_IMPL(fs_event_close_in_callback) {
RETURN_SKIP(NO_FS_EVENTS); RETURN_SKIP(NO_FS_EVENTS);
#elif defined(__MVS__) #elif defined(__MVS__)
RETURN_SKIP("Directory watching not supported on this platform."); RETURN_SKIP("Directory watching not supported on this platform.");
#elif defined(__APPLE__) && defined(__TSAN__)
RETURN_SKIP("Times out under TSAN.");
#endif #endif
uv_loop_t* loop; uv_loop_t* loop;
int r; int r;
@ -951,14 +962,14 @@ TEST_IMPL(fs_event_close_in_callback) {
create_dir("watch_dir"); create_dir("watch_dir");
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_cb_close, "watch_dir", 0); r = uv_fs_event_start(&fs_event, fs_event_cb_close, "watch_dir", 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer, fs_event_create_files, 100, 0); r = uv_timer_start(&timer, fs_event_create_files, 100, 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
@ -966,8 +977,8 @@ TEST_IMPL(fs_event_close_in_callback) {
uv_run(loop, UV_RUN_ONCE); uv_run(loop, UV_RUN_ONCE);
ASSERT(close_cb_called == 2); ASSERT_EQ(2, close_cb_called);
ASSERT(fs_event_cb_called == 3); ASSERT_EQ(3, fs_event_cb_called);
/* Clean up */ /* Clean up */
fs_event_unlink_files(NULL); fs_event_unlink_files(NULL);
@ -991,21 +1002,21 @@ TEST_IMPL(fs_event_start_and_close) {
create_dir("watch_dir"); create_dir("watch_dir");
r = uv_fs_event_init(loop, &fs_event1); r = uv_fs_event_init(loop, &fs_event1);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event1, fs_event_cb_dir, "watch_dir", 0); r = uv_fs_event_start(&fs_event1, fs_event_cb_dir, "watch_dir", 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_init(loop, &fs_event2); r = uv_fs_event_init(loop, &fs_event2);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event2, fs_event_cb_dir, "watch_dir", 0); r = uv_fs_event_start(&fs_event2, fs_event_cb_dir, "watch_dir", 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &fs_event2, close_cb); uv_close((uv_handle_t*) &fs_event2, close_cb);
uv_close((uv_handle_t*) &fs_event1, close_cb); uv_close((uv_handle_t*) &fs_event1, close_cb);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 2); ASSERT_EQ(2, close_cb_called);
remove("watch_dir/"); remove("watch_dir/");
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
@ -1035,28 +1046,28 @@ TEST_IMPL(fs_event_getpath) {
for (i = 0; i < ARRAY_SIZE(watch_dir); i++) { for (i = 0; i < ARRAY_SIZE(watch_dir); i++) {
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
len = sizeof buf; len = sizeof buf;
r = uv_fs_event_getpath(&fs_event, buf, &len); r = uv_fs_event_getpath(&fs_event, buf, &len);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_fs_event_start(&fs_event, fail_cb, watch_dir[i], 0); r = uv_fs_event_start(&fs_event, fail_cb, watch_dir[i], 0);
ASSERT(r == 0); ASSERT_OK(r);
len = 0; len = 0;
r = uv_fs_event_getpath(&fs_event, buf, &len); r = uv_fs_event_getpath(&fs_event, buf, &len);
ASSERT(r == UV_ENOBUFS); ASSERT_EQ(r, UV_ENOBUFS);
ASSERT(len < sizeof buf); /* sanity check */ ASSERT_LT(len, sizeof buf); /* sanity check */
ASSERT(len == strlen(watch_dir[i]) + 1); ASSERT_EQ(len, strlen(watch_dir[i]) + 1);
r = uv_fs_event_getpath(&fs_event, buf, &len); r = uv_fs_event_getpath(&fs_event, buf, &len);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(len == strlen(watch_dir[i])); ASSERT_EQ(len, strlen(watch_dir[i]));
ASSERT(strcmp(buf, watch_dir[i]) == 0); ASSERT(strcmp(buf, watch_dir[i]) == 0);
r = uv_fs_event_stop(&fs_event); r = uv_fs_event_stop(&fs_event);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &fs_event, close_cb); uv_close((uv_handle_t*) &fs_event, close_cb);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
close_cb_called = 0; close_cb_called = 0;
} }
@ -1108,43 +1119,43 @@ TEST_IMPL(fs_event_error_reporting) {
*/ */
for (i = 0; i < ARRAY_SIZE(loops); i++) { for (i = 0; i < ARRAY_SIZE(loops); i++) {
loop = &loops[i]; loop = &loops[i];
ASSERT(0 == uv_loop_init(loop)); ASSERT_OK(uv_loop_init(loop));
event = &events[i]; event = &events[i];
timer_cb_called = 0; timer_cb_called = 0;
close_cb_called = 0; close_cb_called = 0;
ASSERT(0 == uv_fs_event_init(loop, event)); ASSERT_OK(uv_fs_event_init(loop, event));
ASSERT(0 == uv_fs_event_start(event, ASSERT_OK(uv_fs_event_start(event,
fs_event_error_report_cb, fs_event_error_report_cb,
"watch_dir", "watch_dir",
0)); 0));
uv_unref((uv_handle_t*) event); uv_unref((uv_handle_t*) event);
/* Let loop run for some time */ /* Let loop run for some time */
ASSERT(0 == uv_timer_init(loop, &timer)); ASSERT_OK(uv_timer_init(loop, &timer));
ASSERT(0 == uv_timer_start(&timer, timer_cb_nop, 2, 0)); ASSERT_OK(uv_timer_start(&timer, timer_cb_nop, 2, 0));
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(1 == timer_cb_called); ASSERT_EQ(1, timer_cb_called);
ASSERT(1 == close_cb_called); ASSERT_EQ(1, close_cb_called);
if (fs_event_error_reported != 0) if (fs_event_error_reported != 0)
break; break;
} }
/* At least one loop should fail */ /* At least one loop should fail */
ASSERT(fs_event_error_reported == UV_EMFILE); ASSERT_EQ(fs_event_error_reported, UV_EMFILE);
/* Stop and close all events, and destroy loops */ /* Stop and close all events, and destroy loops */
do { do {
loop = &loops[i]; loop = &loops[i];
event = &events[i]; event = &events[i];
ASSERT(0 == uv_fs_event_stop(event)); ASSERT_OK(uv_fs_event_stop(event));
uv_ref((uv_handle_t*) event); uv_ref((uv_handle_t*) event);
uv_close((uv_handle_t*) event, fs_event_error_report_close_cb); uv_close((uv_handle_t*) event, fs_event_error_report_close_cb);
close_cb_called = 0; close_cb_called = 0;
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
uv_loop_close(loop); uv_loop_close(loop);
} while (i-- != 0); } while (i-- != 0);
@ -1175,13 +1186,13 @@ TEST_IMPL(fs_event_watch_invalid_path) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_fs_event_init(loop, &fs_event); r = uv_fs_event_init(loop, &fs_event);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fs_event_start(&fs_event, fs_event_cb_file, "<:;", 0); r = uv_fs_event_start(&fs_event, fs_event_cb_file, "<:;", 0);
ASSERT(r != 0); ASSERT(r);
ASSERT(uv_is_active((uv_handle_t*) &fs_event) == 0); ASSERT_OK(uv_is_active((uv_handle_t*) &fs_event));
r = uv_fs_event_start(&fs_event, fs_event_cb_file, "", 0); r = uv_fs_event_start(&fs_event, fs_event_cb_file, "", 0);
ASSERT(r != 0); ASSERT(r);
ASSERT(uv_is_active((uv_handle_t*) &fs_event) == 0); ASSERT_OK(uv_is_active((uv_handle_t*) &fs_event));
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;
} }
@ -1206,24 +1217,24 @@ TEST_IMPL(fs_event_stop_in_cb) {
remove(path); remove(path);
create_file(path); create_file(path);
ASSERT_EQ(0, uv_fs_event_init(uv_default_loop(), &fs)); ASSERT_OK(uv_fs_event_init(uv_default_loop(), &fs));
ASSERT_EQ(0, uv_fs_event_start(&fs, fs_event_cb_stop, path, 0)); ASSERT_OK(uv_fs_event_start(&fs, fs_event_cb_stop, path, 0));
/* Note: timer_cb_touch() closes the handle. */ /* Note: timer_cb_touch() closes the handle. */
timer.data = path; timer.data = path;
ASSERT_EQ(0, uv_timer_init(uv_default_loop(), &timer)); ASSERT_OK(uv_timer_init(uv_default_loop(), &timer));
ASSERT_EQ(0, uv_timer_start(&timer, timer_cb_touch, 100, 0)); ASSERT_OK(uv_timer_start(&timer, timer_cb_touch, 100, 0));
ASSERT_EQ(0, fs_event_cb_stop_calls); ASSERT_OK(fs_event_cb_stop_calls);
ASSERT_EQ(0, timer_cb_touch_called); ASSERT_OK(timer_cb_touch_called);
ASSERT_EQ(0, uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT_EQ(1, fs_event_cb_stop_calls); ASSERT_EQ(1, fs_event_cb_stop_calls);
ASSERT_EQ(1, timer_cb_touch_called); ASSERT_EQ(1, timer_cb_touch_called);
uv_close((uv_handle_t*) &fs, NULL); uv_close((uv_handle_t*) &fs, NULL);
ASSERT_EQ(0, uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT_EQ(1, fs_event_cb_stop_calls); ASSERT_EQ(1, fs_event_cb_stop_calls);
remove(path); remove(path);

View File

@ -43,7 +43,7 @@ void assert_nonexistent(int fd) {
void assert_existent(int fd) { void assert_existent(int fd) {
struct uv__fd_info_s info = { 0 }; struct uv__fd_info_s info = { 0 };
ASSERT(uv__fd_hash_get(fd, &info)); ASSERT(uv__fd_hash_get(fd, &info));
ASSERT(info.flags == fd + FD_DIFF); ASSERT_EQ(info.flags, fd + FD_DIFF);
} }
void assert_insertion(int fd) { void assert_insertion(int fd) {
@ -58,7 +58,7 @@ void assert_removal(int fd) {
struct uv__fd_info_s info = { 0 }; struct uv__fd_info_s info = { 0 };
assert_existent(fd); assert_existent(fd);
uv__fd_hash_remove(fd, &info); uv__fd_hash_remove(fd, &info);
ASSERT(info.flags == fd + FD_DIFF); ASSERT_EQ(info.flags, fd + FD_DIFF);
assert_nonexistent(fd); assert_nonexistent(fd);
} }
@ -106,7 +106,7 @@ TEST_IMPL(fs_fd_hash) {
{ {
struct uv__fd_info_s info = { 0 }; struct uv__fd_info_s info = { 0 };
ASSERT(uv__fd_hash_get(0, &info)); ASSERT(uv__fd_hash_get(0, &info));
ASSERT(info.flags == FD_DIFF + FD_DIFF); ASSERT_EQ(info.flags, FD_DIFF + FD_DIFF);
} }
{ {
/* Leave as it was, will be again tested below */ /* Leave as it was, will be again tested below */

View File

@ -68,8 +68,8 @@ static void setup(void) {
uv_fs_req_cleanup(&rmdir_req); uv_fs_req_cleanup(&rmdir_req);
r = uv_fs_mkdir(NULL, &mkdir_req, empty_dir, 0755, NULL); r = uv_fs_mkdir(NULL, &mkdir_req, empty_dir, 0755, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(mkdir_req.result == 0); ASSERT_OK(mkdir_req.result);
uv_fs_req_cleanup(&mkdir_req); uv_fs_req_cleanup(&mkdir_req);
} }
@ -89,13 +89,13 @@ static void refresh(void) {
r = uv_fs_open(NULL, &open_req, empty_file, r = uv_fs_open(NULL, &open_req, empty_file,
UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL); UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
ASSERT(open_req.result >= 0); ASSERT_GE(open_req.result, 0);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
/* dummy_file */ /* dummy_file */
@ -103,19 +103,19 @@ static void refresh(void) {
r = uv_fs_open(NULL, &open_req, dummy_file, r = uv_fs_open(NULL, &open_req, dummy_file,
UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL); UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
ASSERT(open_req.result >= 0); ASSERT_GE(open_req.result, 0);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);
iov = uv_buf_init("a", 1); iov = uv_buf_init("a", 1);
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == 1); ASSERT_EQ(1, r);
ASSERT(write_req.result == 1); ASSERT_EQ(1, write_req.result);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
} }
@ -131,14 +131,14 @@ static void openFail(char *file, int error) {
refresh(); refresh();
r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL); r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
ASSERT(r == error); ASSERT_EQ(r, error);
ASSERT(open_req.result == error); ASSERT_EQ(open_req.result, error);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);
/* Ensure the first call does not create the file */ /* Ensure the first call does not create the file */
r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL); r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
ASSERT(r == error); ASSERT_EQ(r, error);
ASSERT(open_req.result == error); ASSERT_EQ(open_req.result, error);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);
cleanup(); cleanup();
@ -150,8 +150,8 @@ static void refreshOpen(char *file) {
refresh(); refresh();
r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL); r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
ASSERT(open_req.result >= 0); ASSERT_GE(open_req.result, 0);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);
} }
@ -162,37 +162,37 @@ static void writeExpect(char *file, char *expected, int size) {
iov = uv_buf_init("b", 1); iov = uv_buf_init("b", 1);
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == 1); ASSERT_EQ(1, r);
ASSERT(write_req.result == 1); ASSERT_EQ(1, write_req.result);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
iov = uv_buf_init("c", 1); iov = uv_buf_init("c", 1);
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == 1); ASSERT_EQ(1, r);
ASSERT(write_req.result == 1); ASSERT_EQ(1, write_req.result);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
/* Check contents */ /* Check contents */
r = uv_fs_open(NULL, &open_req, file, UV_FS_O_RDONLY, S_IWUSR | S_IRUSR, NULL); r = uv_fs_open(NULL, &open_req, file, UV_FS_O_RDONLY, S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
ASSERT(open_req.result >= 0); ASSERT_GE(open_req.result, 0);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);
iov = uv_buf_init(buf, sizeof(buf)); iov = uv_buf_init(buf, sizeof(buf));
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == size); ASSERT_EQ(r, size);
ASSERT(read_req.result == size); ASSERT_EQ(read_req.result, size);
ASSERT(strncmp(buf, expected, size) == 0); ASSERT_OK(strncmp(buf, expected, size));
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
cleanup(); cleanup();
@ -205,19 +205,19 @@ static void writeFail(char *file, int error) {
iov = uv_buf_init("z", 1); iov = uv_buf_init("z", 1);
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == error); ASSERT_EQ(r, error);
ASSERT(write_req.result == error); ASSERT_EQ(write_req.result, error);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
iov = uv_buf_init("z", 1); iov = uv_buf_init("z", 1);
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == error); ASSERT_EQ(r, error);
ASSERT(write_req.result == error); ASSERT_EQ(write_req.result, error);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
cleanup(); cleanup();
@ -230,14 +230,14 @@ static void readExpect(char *file, char *expected, int size) {
iov = uv_buf_init(buf, sizeof(buf)); iov = uv_buf_init(buf, sizeof(buf));
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == size); ASSERT_EQ(r, size);
ASSERT(read_req.result == size); ASSERT_EQ(read_req.result, size);
ASSERT(strncmp(buf, expected, size) == 0); ASSERT_OK(strncmp(buf, expected, size));
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
cleanup(); cleanup();
@ -250,19 +250,19 @@ static void readFail(char *file, int error) {
iov = uv_buf_init(buf, sizeof(buf)); iov = uv_buf_init(buf, sizeof(buf));
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == error); ASSERT_EQ(r, error);
ASSERT(read_req.result == error); ASSERT_EQ(read_req.result, error);
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
iov = uv_buf_init(buf, sizeof(buf)); iov = uv_buf_init(buf, sizeof(buf));
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL); r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
ASSERT(r == error); ASSERT_EQ(r, error);
ASSERT(read_req.result == error); ASSERT_EQ(read_req.result, error);
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(NULL, &close_req, open_req.result, NULL); r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(close_req.result == 0); ASSERT_OK(close_req.result);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
cleanup(); cleanup();

View File

@ -103,44 +103,44 @@ static void poll_cb(uv_fs_poll_t* handle,
memset(&zero_statbuf, 0, sizeof(zero_statbuf)); memset(&zero_statbuf, 0, sizeof(zero_statbuf));
ASSERT(handle == &poll_handle); ASSERT_PTR_EQ(handle, &poll_handle);
ASSERT(1 == uv_is_active((uv_handle_t*) handle)); ASSERT_EQ(1, uv_is_active((uv_handle_t*) handle));
ASSERT_NOT_NULL(prev); ASSERT_NOT_NULL(prev);
ASSERT_NOT_NULL(curr); ASSERT_NOT_NULL(curr);
switch (poll_cb_called++) { switch (poll_cb_called++) {
case 0: case 0:
ASSERT(status == UV_ENOENT); ASSERT_EQ(status, UV_ENOENT);
ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_OK(memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_OK(memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
touch_file(FIXTURE); touch_file(FIXTURE);
break; break;
case 1: case 1:
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_OK(memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_NE(0, memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 20, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, 20, 0));
break; break;
case 2: case 2:
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_NE(0, memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_NE(0, memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 200, 0)); ASSERT_OK(uv_timer_start(&timer_handle, timer_cb, 200, 0));
break; break;
case 3: case 3:
ASSERT(status == 0); ASSERT_OK(status);
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_NE(0, memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_NE(0, memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
remove(FIXTURE); remove(FIXTURE);
break; break;
case 4: case 4:
ASSERT(status == UV_ENOENT); ASSERT_EQ(status, UV_ENOENT);
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_NE(0, memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT_OK(memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
break; break;
@ -155,14 +155,14 @@ TEST_IMPL(fs_poll) {
remove(FIXTURE); remove(FIXTURE);
ASSERT(0 == uv_timer_init(loop, &timer_handle)); ASSERT_OK(uv_timer_init(loop, &timer_handle));
ASSERT(0 == uv_fs_poll_init(loop, &poll_handle)); ASSERT_OK(uv_fs_poll_init(loop, &poll_handle));
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb, FIXTURE, 100)); ASSERT_OK(uv_fs_poll_start(&poll_handle, poll_cb, FIXTURE, 100));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
ASSERT(poll_cb_called == 5); ASSERT_EQ(5, poll_cb_called);
ASSERT(timer_cb_called == 2); ASSERT_EQ(2, timer_cb_called);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;
@ -176,21 +176,21 @@ TEST_IMPL(fs_poll_getpath) {
remove(FIXTURE); remove(FIXTURE);
ASSERT(0 == uv_fs_poll_init(loop, &poll_handle)); ASSERT_OK(uv_fs_poll_init(loop, &poll_handle));
len = sizeof buf; len = sizeof buf;
ASSERT(UV_EINVAL == uv_fs_poll_getpath(&poll_handle, buf, &len)); ASSERT_EQ(UV_EINVAL, uv_fs_poll_getpath(&poll_handle, buf, &len));
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100)); ASSERT_OK(uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100));
len = sizeof buf; len = sizeof buf;
ASSERT(0 == uv_fs_poll_getpath(&poll_handle, buf, &len)); ASSERT_OK(uv_fs_poll_getpath(&poll_handle, buf, &len));
ASSERT(buf[len - 1] != 0); ASSERT_NE(0, buf[len - 1]);
ASSERT(buf[len] == '\0'); ASSERT_EQ(buf[len], '\0');
ASSERT(0 == memcmp(buf, FIXTURE, len)); ASSERT_OK(memcmp(buf, FIXTURE, len));
uv_close((uv_handle_t*) &poll_handle, close_cb); uv_close((uv_handle_t*) &poll_handle, close_cb);
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;
@ -203,14 +203,14 @@ TEST_IMPL(fs_poll_close_request) {
remove(FIXTURE); remove(FIXTURE);
ASSERT(0 == uv_loop_init(&loop)); ASSERT_OK(uv_loop_init(&loop));
ASSERT(0 == uv_fs_poll_init(&loop, &poll_handle)); ASSERT_OK(uv_fs_poll_init(&loop, &poll_handle));
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100)); ASSERT_OK(uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100));
uv_close((uv_handle_t*) &poll_handle, close_cb); uv_close((uv_handle_t*) &poll_handle, close_cb);
while (close_cb_called == 0) while (close_cb_called == 0)
uv_run(&loop, UV_RUN_ONCE); uv_run(&loop, UV_RUN_ONCE);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(&loop); MAKE_VALGRIND_HAPPY(&loop);
return 0; return 0;
@ -223,18 +223,18 @@ TEST_IMPL(fs_poll_close_request_multi_start_stop) {
remove(FIXTURE); remove(FIXTURE);
ASSERT(0 == uv_loop_init(&loop)); ASSERT_OK(uv_loop_init(&loop));
ASSERT(0 == uv_fs_poll_init(&loop, &poll_handle)); ASSERT_OK(uv_fs_poll_init(&loop, &poll_handle));
for (i = 0; i < 10; ++i) { for (i = 0; i < 10; ++i) {
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100)); ASSERT_OK(uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100));
ASSERT(0 == uv_fs_poll_stop(&poll_handle)); ASSERT_OK(uv_fs_poll_stop(&poll_handle));
} }
uv_close((uv_handle_t*) &poll_handle, close_cb); uv_close((uv_handle_t*) &poll_handle, close_cb);
while (close_cb_called == 0) while (close_cb_called == 0)
uv_run(&loop, UV_RUN_ONCE); uv_run(&loop, UV_RUN_ONCE);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(&loop); MAKE_VALGRIND_HAPPY(&loop);
return 0; return 0;
@ -247,18 +247,18 @@ TEST_IMPL(fs_poll_close_request_multi_stop_start) {
remove(FIXTURE); remove(FIXTURE);
ASSERT(0 == uv_loop_init(&loop)); ASSERT_OK(uv_loop_init(&loop));
ASSERT(0 == uv_fs_poll_init(&loop, &poll_handle)); ASSERT_OK(uv_fs_poll_init(&loop, &poll_handle));
for (i = 0; i < 10; ++i) { for (i = 0; i < 10; ++i) {
ASSERT(0 == uv_fs_poll_stop(&poll_handle)); ASSERT_OK(uv_fs_poll_stop(&poll_handle));
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100)); ASSERT_OK(uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100));
} }
uv_close((uv_handle_t*) &poll_handle, close_cb); uv_close((uv_handle_t*) &poll_handle, close_cb);
while (close_cb_called == 0) while (close_cb_called == 0)
uv_run(&loop, UV_RUN_ONCE); uv_run(&loop, UV_RUN_ONCE);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(&loop); MAKE_VALGRIND_HAPPY(&loop);
return 0; return 0;
@ -271,21 +271,21 @@ TEST_IMPL(fs_poll_close_request_stop_when_active) {
remove(FIXTURE); remove(FIXTURE);
ASSERT(0 == uv_loop_init(&loop)); ASSERT_OK(uv_loop_init(&loop));
/* Set up all handles. */ /* Set up all handles. */
ASSERT(0 == uv_fs_poll_init(&loop, &poll_handle)); ASSERT_OK(uv_fs_poll_init(&loop, &poll_handle));
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_noop, FIXTURE, 100)); ASSERT_OK(uv_fs_poll_start(&poll_handle, poll_cb_noop, FIXTURE, 100));
uv_run(&loop, UV_RUN_ONCE); uv_run(&loop, UV_RUN_ONCE);
/* Close the timer handle, and do not crash. */ /* Close the timer handle, and do not crash. */
ASSERT(0 == uv_fs_poll_stop(&poll_handle)); ASSERT_OK(uv_fs_poll_stop(&poll_handle));
uv_run(&loop, UV_RUN_ONCE); uv_run(&loop, UV_RUN_ONCE);
/* Clean up after the test. */ /* Clean up after the test. */
uv_close((uv_handle_t*) &poll_handle, close_cb); uv_close((uv_handle_t*) &poll_handle, close_cb);
uv_run(&loop, UV_RUN_ONCE); uv_run(&loop, UV_RUN_ONCE);
ASSERT(close_cb_called == 1); ASSERT_EQ(1, close_cb_called);
MAKE_VALGRIND_HAPPY(&loop); MAKE_VALGRIND_HAPPY(&loop);
return 0; return 0;

View File

@ -47,9 +47,9 @@ static void cleanup_test_files(void) {
} }
static void empty_closedir_cb(uv_fs_t* req) { static void empty_closedir_cb(uv_fs_t* req) {
ASSERT(req == &closedir_req); ASSERT_PTR_EQ(req, &closedir_req);
ASSERT(req->fs_type == UV_FS_CLOSEDIR); ASSERT_EQ(req->fs_type, UV_FS_CLOSEDIR);
ASSERT(req->result == 0); ASSERT_OK(req->result);
++empty_closedir_cb_count; ++empty_closedir_cb_count;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
} }
@ -58,25 +58,25 @@ static void empty_readdir_cb(uv_fs_t* req) {
uv_dir_t* dir; uv_dir_t* dir;
int r; int r;
ASSERT(req == &readdir_req); ASSERT_PTR_EQ(req, &readdir_req);
ASSERT(req->fs_type == UV_FS_READDIR); ASSERT_EQ(req->fs_type, UV_FS_READDIR);
ASSERT(req->result == 0); ASSERT_OK(req->result);
dir = req->ptr; dir = req->ptr;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
r = uv_fs_closedir(uv_default_loop(), r = uv_fs_closedir(uv_default_loop(),
&closedir_req, &closedir_req,
dir, dir,
empty_closedir_cb); empty_closedir_cb);
ASSERT(r == 0); ASSERT_OK(r);
} }
static void empty_opendir_cb(uv_fs_t* req) { static void empty_opendir_cb(uv_fs_t* req) {
uv_dir_t* dir; uv_dir_t* dir;
int r; int r;
ASSERT(req == &opendir_req); ASSERT_PTR_EQ(req, &opendir_req);
ASSERT(req->fs_type == UV_FS_OPENDIR); ASSERT_EQ(req->fs_type, UV_FS_OPENDIR);
ASSERT(req->result == 0); ASSERT_OK(req->result);
ASSERT_NOT_NULL(req->ptr); ASSERT_NOT_NULL(req->ptr);
dir = req->ptr; dir = req->ptr;
dir->dirents = dirents; dir->dirents = dirents;
@ -85,7 +85,7 @@ static void empty_opendir_cb(uv_fs_t* req) {
&readdir_req, &readdir_req,
dir, dir,
empty_readdir_cb); empty_readdir_cb);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
++empty_opendir_cb_count; ++empty_opendir_cb_count;
} }
@ -115,9 +115,9 @@ TEST_IMPL(fs_readdir_empty_dir) {
&opendir_req, &opendir_req,
path, path,
NULL); NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(opendir_req.fs_type == UV_FS_OPENDIR); ASSERT_EQ(opendir_req.fs_type, UV_FS_OPENDIR);
ASSERT(opendir_req.result == 0); ASSERT_OK(opendir_req.result);
ASSERT_NOT_NULL(opendir_req.ptr); ASSERT_NOT_NULL(opendir_req.ptr);
dir = opendir_req.ptr; dir = opendir_req.ptr;
uv_fs_req_cleanup(&opendir_req); uv_fs_req_cleanup(&opendir_req);
@ -130,13 +130,13 @@ TEST_IMPL(fs_readdir_empty_dir) {
&readdir_req, &readdir_req,
dir, dir,
NULL); NULL);
ASSERT(nb_entries_read == 0); ASSERT_OK(nb_entries_read);
uv_fs_req_cleanup(&readdir_req); uv_fs_req_cleanup(&readdir_req);
/* Fill the req to ensure that required fields are cleaned up. */ /* Fill the req to ensure that required fields are cleaned up. */
memset(&closedir_req, 0xdb, sizeof(closedir_req)); memset(&closedir_req, 0xdb, sizeof(closedir_req));
uv_fs_closedir(uv_default_loop(), &closedir_req, dir, NULL); uv_fs_closedir(uv_default_loop(), &closedir_req, dir, NULL);
ASSERT(closedir_req.result == 0); ASSERT_OK(closedir_req.result);
uv_fs_req_cleanup(&closedir_req); uv_fs_req_cleanup(&closedir_req);
/* Testing the asynchronous flavor. */ /* Testing the asynchronous flavor. */
@ -147,13 +147,13 @@ TEST_IMPL(fs_readdir_empty_dir) {
memset(&closedir_req, 0xdb, sizeof(closedir_req)); memset(&closedir_req, 0xdb, sizeof(closedir_req));
r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, empty_opendir_cb); r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, empty_opendir_cb);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(empty_opendir_cb_count == 0); ASSERT_OK(empty_opendir_cb_count);
ASSERT(empty_closedir_cb_count == 0); ASSERT_OK(empty_closedir_cb_count);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(empty_opendir_cb_count == 1); ASSERT_EQ(1, empty_opendir_cb_count);
ASSERT(empty_closedir_cb_count == 1); ASSERT_EQ(1, empty_closedir_cb_count);
uv_fs_rmdir(uv_default_loop(), &rmdir_req, path, NULL); uv_fs_rmdir(uv_default_loop(), &rmdir_req, path, NULL);
uv_fs_req_cleanup(&rmdir_req); uv_fs_req_cleanup(&rmdir_req);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
@ -168,9 +168,9 @@ TEST_IMPL(fs_readdir_empty_dir) {
static int non_existing_opendir_cb_count; static int non_existing_opendir_cb_count;
static void non_existing_opendir_cb(uv_fs_t* req) { static void non_existing_opendir_cb(uv_fs_t* req) {
ASSERT(req == &opendir_req); ASSERT_PTR_EQ(req, &opendir_req);
ASSERT(req->fs_type == UV_FS_OPENDIR); ASSERT_EQ(req->fs_type, UV_FS_OPENDIR);
ASSERT(req->result == UV_ENOENT); ASSERT_EQ(req->result, UV_ENOENT);
ASSERT_NULL(req->ptr); ASSERT_NULL(req->ptr);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
@ -188,9 +188,9 @@ TEST_IMPL(fs_readdir_non_existing_dir) {
/* Testing the synchronous flavor. */ /* Testing the synchronous flavor. */
r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, NULL); r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, NULL);
ASSERT(r == UV_ENOENT); ASSERT_EQ(r, UV_ENOENT);
ASSERT(opendir_req.fs_type == UV_FS_OPENDIR); ASSERT_EQ(opendir_req.fs_type, UV_FS_OPENDIR);
ASSERT(opendir_req.result == UV_ENOENT); ASSERT_EQ(opendir_req.result, UV_ENOENT);
ASSERT_NULL(opendir_req.ptr); ASSERT_NULL(opendir_req.ptr);
uv_fs_req_cleanup(&opendir_req); uv_fs_req_cleanup(&opendir_req);
@ -202,11 +202,11 @@ TEST_IMPL(fs_readdir_non_existing_dir) {
&opendir_req, &opendir_req,
path, path,
non_existing_opendir_cb); non_existing_opendir_cb);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(non_existing_opendir_cb_count == 0); ASSERT_OK(non_existing_opendir_cb_count);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(non_existing_opendir_cb_count == 1); ASSERT_EQ(1, non_existing_opendir_cb_count);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
@ -220,9 +220,9 @@ TEST_IMPL(fs_readdir_non_existing_dir) {
static int file_opendir_cb_count; static int file_opendir_cb_count;
static void file_opendir_cb(uv_fs_t* req) { static void file_opendir_cb(uv_fs_t* req) {
ASSERT(req == &opendir_req); ASSERT_PTR_EQ(req, &opendir_req);
ASSERT(req->fs_type == UV_FS_OPENDIR); ASSERT_EQ(req->fs_type, UV_FS_OPENDIR);
ASSERT(req->result == UV_ENOTDIR); ASSERT_EQ(req->result, UV_ENOTDIR);
ASSERT_NULL(req->ptr); ASSERT_NULL(req->ptr);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
@ -241,9 +241,9 @@ TEST_IMPL(fs_readdir_file) {
/* Testing the synchronous flavor. */ /* Testing the synchronous flavor. */
r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, NULL); r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, NULL);
ASSERT(r == UV_ENOTDIR); ASSERT_EQ(r, UV_ENOTDIR);
ASSERT(opendir_req.fs_type == UV_FS_OPENDIR); ASSERT_EQ(opendir_req.fs_type, UV_FS_OPENDIR);
ASSERT(opendir_req.result == UV_ENOTDIR); ASSERT_EQ(opendir_req.result, UV_ENOTDIR);
ASSERT_NULL(opendir_req.ptr); ASSERT_NULL(opendir_req.ptr);
uv_fs_req_cleanup(&opendir_req); uv_fs_req_cleanup(&opendir_req);
@ -253,11 +253,11 @@ TEST_IMPL(fs_readdir_file) {
/* Testing the async flavor. */ /* Testing the async flavor. */
r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, file_opendir_cb); r = uv_fs_opendir(uv_default_loop(), &opendir_req, path, file_opendir_cb);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(file_opendir_cb_count == 0); ASSERT_OK(file_opendir_cb_count);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(file_opendir_cb_count == 1); ASSERT_EQ(1, file_opendir_cb_count);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
} }
@ -273,8 +273,8 @@ static int non_empty_readdir_cb_count;
static int non_empty_closedir_cb_count; static int non_empty_closedir_cb_count;
static void non_empty_closedir_cb(uv_fs_t* req) { static void non_empty_closedir_cb(uv_fs_t* req) {
ASSERT(req == &closedir_req); ASSERT_PTR_EQ(req, &closedir_req);
ASSERT(req->result == 0); ASSERT_OK(req->result);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
++non_empty_closedir_cb_count; ++non_empty_closedir_cb_count;
} }
@ -282,30 +282,30 @@ static void non_empty_closedir_cb(uv_fs_t* req) {
static void non_empty_readdir_cb(uv_fs_t* req) { static void non_empty_readdir_cb(uv_fs_t* req) {
uv_dir_t* dir; uv_dir_t* dir;
ASSERT(req == &readdir_req); ASSERT_PTR_EQ(req, &readdir_req);
ASSERT(req->fs_type == UV_FS_READDIR); ASSERT_EQ(req->fs_type, UV_FS_READDIR);
dir = req->ptr; dir = req->ptr;
if (req->result == 0) { if (req->result == 0) {
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
ASSERT(non_empty_readdir_cb_count == 3); ASSERT_EQ(3, non_empty_readdir_cb_count);
uv_fs_closedir(uv_default_loop(), uv_fs_closedir(uv_default_loop(),
&closedir_req, &closedir_req,
dir, dir,
non_empty_closedir_cb); non_empty_closedir_cb);
} else { } else {
ASSERT(req->result == 1); ASSERT_EQ(1, req->result);
ASSERT(dir->dirents == dirents); ASSERT_PTR_EQ(dir->dirents, dirents);
ASSERT(strcmp(dirents[0].name, "file1") == 0 || ASSERT(strcmp(dirents[0].name, "file1") == 0 ||
strcmp(dirents[0].name, "file2") == 0 || strcmp(dirents[0].name, "file2") == 0 ||
strcmp(dirents[0].name, "test_subdir") == 0); strcmp(dirents[0].name, "test_subdir") == 0);
#ifdef HAVE_DIRENT_TYPES #ifdef HAVE_DIRENT_TYPES
if (!strcmp(dirents[0].name, "test_subdir")) if (!strcmp(dirents[0].name, "test_subdir"))
ASSERT(dirents[0].type == UV_DIRENT_DIR); ASSERT_EQ(dirents[0].type, UV_DIRENT_DIR);
else else
ASSERT(dirents[0].type == UV_DIRENT_FILE); ASSERT_EQ(dirents[0].type, UV_DIRENT_FILE);
#else #else
ASSERT(dirents[0].type == UV_DIRENT_UNKNOWN); ASSERT_EQ(dirents[0].type, UV_DIRENT_UNKNOWN);
#endif /* HAVE_DIRENT_TYPES */ #endif /* HAVE_DIRENT_TYPES */
++non_empty_readdir_cb_count; ++non_empty_readdir_cb_count;
@ -323,9 +323,9 @@ static void non_empty_opendir_cb(uv_fs_t* req) {
uv_dir_t* dir; uv_dir_t* dir;
int r; int r;
ASSERT(req == &opendir_req); ASSERT_PTR_EQ(req, &opendir_req);
ASSERT(req->fs_type == UV_FS_OPENDIR); ASSERT_EQ(req->fs_type, UV_FS_OPENDIR);
ASSERT(req->result == 0); ASSERT_OK(req->result);
ASSERT_NOT_NULL(req->ptr); ASSERT_NOT_NULL(req->ptr);
dir = req->ptr; dir = req->ptr;
@ -336,7 +336,7 @@ static void non_empty_opendir_cb(uv_fs_t* req) {
&readdir_req, &readdir_req,
dir, dir,
non_empty_readdir_cb); non_empty_readdir_cb);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
++non_empty_opendir_cb_count; ++non_empty_opendir_cb_count;
} }
@ -353,7 +353,7 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
cleanup_test_files(); cleanup_test_files();
r = uv_fs_mkdir(uv_default_loop(), &mkdir_req, "test_dir", 0755, NULL); r = uv_fs_mkdir(uv_default_loop(), &mkdir_req, "test_dir", 0755, NULL);
ASSERT(r == 0); ASSERT_OK(r);
/* Create two files synchronously. */ /* Create two files synchronously. */
r = uv_fs_open(uv_default_loop(), r = uv_fs_open(uv_default_loop(),
@ -361,13 +361,13 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
"test_dir/file1", "test_dir/file1",
O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR,
NULL); NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
uv_fs_req_cleanup(&create_req); uv_fs_req_cleanup(&create_req);
r = uv_fs_close(uv_default_loop(), r = uv_fs_close(uv_default_loop(),
&close_req, &close_req,
create_req.result, create_req.result,
NULL); NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_open(uv_default_loop(), r = uv_fs_open(uv_default_loop(),
@ -375,13 +375,13 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
"test_dir/file2", "test_dir/file2",
O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR,
NULL); NULL);
ASSERT(r >= 0); ASSERT_GE(r, 0);
uv_fs_req_cleanup(&create_req); uv_fs_req_cleanup(&create_req);
r = uv_fs_close(uv_default_loop(), r = uv_fs_close(uv_default_loop(),
&close_req, &close_req,
create_req.result, create_req.result,
NULL); NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_mkdir(uv_default_loop(), r = uv_fs_mkdir(uv_default_loop(),
@ -389,7 +389,7 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
"test_dir/test_subdir", "test_dir/test_subdir",
0755, 0755,
NULL); NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_fs_req_cleanup(&mkdir_req); uv_fs_req_cleanup(&mkdir_req);
/* Fill the req to ensure that required fields are cleaned up. */ /* Fill the req to ensure that required fields are cleaned up. */
@ -397,9 +397,9 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
/* Testing the synchronous flavor. */ /* Testing the synchronous flavor. */
r = uv_fs_opendir(uv_default_loop(), &opendir_req, "test_dir", NULL); r = uv_fs_opendir(uv_default_loop(), &opendir_req, "test_dir", NULL);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(opendir_req.fs_type == UV_FS_OPENDIR); ASSERT_EQ(opendir_req.fs_type, UV_FS_OPENDIR);
ASSERT(opendir_req.result == 0); ASSERT_OK(opendir_req.result);
ASSERT_NOT_NULL(opendir_req.ptr); ASSERT_NOT_NULL(opendir_req.ptr);
entries_count = 0; entries_count = 0;
@ -417,23 +417,23 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
strcmp(dirents[0].name, "test_subdir") == 0); strcmp(dirents[0].name, "test_subdir") == 0);
#ifdef HAVE_DIRENT_TYPES #ifdef HAVE_DIRENT_TYPES
if (!strcmp(dirents[0].name, "test_subdir")) if (!strcmp(dirents[0].name, "test_subdir"))
ASSERT(dirents[0].type == UV_DIRENT_DIR); ASSERT_EQ(dirents[0].type, UV_DIRENT_DIR);
else else
ASSERT(dirents[0].type == UV_DIRENT_FILE); ASSERT_EQ(dirents[0].type, UV_DIRENT_FILE);
#else #else
ASSERT(dirents[0].type == UV_DIRENT_UNKNOWN); ASSERT_EQ(dirents[0].type, UV_DIRENT_UNKNOWN);
#endif /* HAVE_DIRENT_TYPES */ #endif /* HAVE_DIRENT_TYPES */
uv_fs_req_cleanup(&readdir_req); uv_fs_req_cleanup(&readdir_req);
++entries_count; ++entries_count;
} }
ASSERT(entries_count == 3); ASSERT_EQ(3, entries_count);
uv_fs_req_cleanup(&readdir_req); uv_fs_req_cleanup(&readdir_req);
/* Fill the req to ensure that required fields are cleaned up. */ /* Fill the req to ensure that required fields are cleaned up. */
memset(&closedir_req, 0xdb, sizeof(closedir_req)); memset(&closedir_req, 0xdb, sizeof(closedir_req));
uv_fs_closedir(uv_default_loop(), &closedir_req, dir, NULL); uv_fs_closedir(uv_default_loop(), &closedir_req, dir, NULL);
ASSERT(closedir_req.result == 0); ASSERT_OK(closedir_req.result);
uv_fs_req_cleanup(&closedir_req); uv_fs_req_cleanup(&closedir_req);
/* Testing the asynchronous flavor. */ /* Testing the asynchronous flavor. */
@ -445,13 +445,13 @@ TEST_IMPL(fs_readdir_non_empty_dir) {
&opendir_req, &opendir_req,
"test_dir", "test_dir",
non_empty_opendir_cb); non_empty_opendir_cb);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(non_empty_opendir_cb_count == 0); ASSERT_OK(non_empty_opendir_cb_count);
ASSERT(non_empty_closedir_cb_count == 0); ASSERT_OK(non_empty_closedir_cb_count);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(non_empty_opendir_cb_count == 1); ASSERT_EQ(1, non_empty_opendir_cb_count);
ASSERT(non_empty_closedir_cb_count == 1); ASSERT_EQ(1, non_empty_closedir_cb_count);
uv_fs_rmdir(uv_default_loop(), &rmdir_req, "test_subdir", NULL); uv_fs_rmdir(uv_default_loop(), &rmdir_req, "test_subdir", NULL);
uv_fs_req_cleanup(&rmdir_req); uv_fs_req_cleanup(&rmdir_req);

File diff suppressed because it is too large Load Diff

View File

@ -60,43 +60,43 @@ TEST_IMPL(get_currentexe) {
* executable_path. * executable_path.
*/ */
ASSERT(match && !strcmp(match, path)); ASSERT(match && !strcmp(match, path));
ASSERT(size == strlen(buffer)); ASSERT_EQ(size, strlen(buffer));
/* Negative tests */ /* Negative tests */
size = sizeof(buffer) / sizeof(buffer[0]); size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_exepath(NULL, &size); r = uv_exepath(NULL, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_exepath(buffer, NULL); r = uv_exepath(buffer, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
size = 0; size = 0;
r = uv_exepath(buffer, &size); r = uv_exepath(buffer, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
memset(buffer, -1, sizeof(buffer)); memset(buffer, -1, sizeof(buffer));
size = 1; size = 1;
r = uv_exepath(buffer, &size); r = uv_exepath(buffer, &size);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(size == 0); ASSERT_OK(size);
ASSERT(buffer[0] == '\0'); ASSERT_EQ(buffer[0], '\0');
memset(buffer, -1, sizeof(buffer)); memset(buffer, -1, sizeof(buffer));
size = 2; size = 2;
r = uv_exepath(buffer, &size); r = uv_exepath(buffer, &size);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(size == 1); ASSERT_EQ(1, size);
ASSERT(buffer[0] != '\0'); ASSERT_NE(buffer[0], '\0');
ASSERT(buffer[1] == '\0'); ASSERT_EQ(buffer[1], '\0');
/* Verify uv_exepath is not affected by uv_set_process_title(). */ /* Verify uv_exepath is not affected by uv_set_process_title(). */
r = uv_set_process_title("foobar"); r = uv_set_process_title("foobar");
ASSERT_EQ(r, 0); ASSERT_OK(r);
size = sizeof(buffer); size = sizeof(buffer);
r = uv_exepath(buffer, &size); r = uv_exepath(buffer, &size);
ASSERT_EQ(r, 0); ASSERT_OK(r);
match = strstr(buffer, path); match = strstr(buffer, path);
/* Verify that the path returned from uv_exepath is a subdirectory of /* Verify that the path returned from uv_exepath is a subdirectory of

View File

@ -27,9 +27,9 @@ TEST_IMPL(get_loadavg) {
double avg[3] = {-1, -1, -1}; double avg[3] = {-1, -1, -1};
uv_loadavg(avg); uv_loadavg(avg);
ASSERT(avg[0] >= 0); ASSERT_GE(avg[0], 0);
ASSERT(avg[1] >= 0); ASSERT_GE(avg[1], 0);
ASSERT(avg[2] >= 0); ASSERT_GE(avg[2], 0);
return 0; return 0;
} }

View File

@ -35,13 +35,13 @@ TEST_IMPL(get_memory) {
(unsigned long long) constrained_mem, (unsigned long long) constrained_mem,
(unsigned long long) available_mem); (unsigned long long) available_mem);
ASSERT(free_mem > 0); ASSERT_GT(free_mem, 0);
ASSERT(total_mem > 0); ASSERT_GT(total_mem, 0);
/* On IBMi PASE, the amount of memory in use is always zero. */ /* On IBMi PASE, the amount of memory in use is always zero. */
#ifdef __PASE__ #ifdef __PASE__
ASSERT(total_mem == free_mem); ASSERT_EQ(total_mem, free_mem);
#else #else
ASSERT(total_mem > free_mem); ASSERT_GT(total_mem, free_mem);
#endif #endif
ASSERT_LE(available_mem, total_mem); ASSERT_LE(available_mem, total_mem);
/* we'd really want to test if available <= free, but that is fragile: /* we'd really want to test if available <= free, but that is fragile:

View File

@ -39,7 +39,7 @@ TEST_IMPL(get_passwd) {
/* Test the normal case */ /* Test the normal case */
r = uv_os_get_passwd(&pwd); r = uv_os_get_passwd(&pwd);
ASSERT_EQ(r, 0); ASSERT_OK(r);
len = strlen(pwd.username); len = strlen(pwd.username);
ASSERT_GT(len, 0); ASSERT_GT(len, 0);
@ -114,7 +114,7 @@ TEST_IMPL(get_passwd2) {
/* Test the normal case */ /* Test the normal case */
r = uv_os_get_passwd(&pwd); r = uv_os_get_passwd(&pwd);
ASSERT_EQ(r, 0); ASSERT_OK(r);
r = uv_os_get_passwd2(&pwd2, pwd.uid); r = uv_os_get_passwd2(&pwd2, pwd.uid);
@ -123,7 +123,7 @@ TEST_IMPL(get_passwd2) {
(void) &len; (void) &len;
#else #else
ASSERT_EQ(r, 0); ASSERT_OK(r);
ASSERT_EQ(pwd.uid, pwd2.uid); ASSERT_EQ(pwd.uid, pwd2.uid);
ASSERT_STR_EQ(pwd.username, pwd2.username); ASSERT_STR_EQ(pwd.username, pwd2.username);
ASSERT_STR_EQ(pwd.shell, pwd2.shell); ASSERT_STR_EQ(pwd.shell, pwd2.shell);
@ -131,15 +131,20 @@ TEST_IMPL(get_passwd2) {
uv_os_free_passwd(&pwd2); uv_os_free_passwd(&pwd2);
r = uv_os_get_passwd2(&pwd2, 0); r = uv_os_get_passwd2(&pwd2, 0);
ASSERT_EQ(r, 0); ASSERT_OK(r);
len = strlen(pwd2.username); len = strlen(pwd2.username);
ASSERT_GT(len, 0); ASSERT_GT(len, 0);
#if defined(__PASE__)
// uid 0 is qsecofr on IBM i
ASSERT_STR_EQ(pwd2.username, "qsecofr");
#else
ASSERT_STR_EQ(pwd2.username, "root"); ASSERT_STR_EQ(pwd2.username, "root");
#endif
len = strlen(pwd2.homedir); len = strlen(pwd2.homedir);
# ifndef __PASE__
ASSERT_GT(len, 0); ASSERT_GT(len, 0);
#endif
len = strlen(pwd2.shell); len = strlen(pwd2.shell);
# ifndef __PASE__ # ifndef __PASE__
ASSERT_GT(len, 0); ASSERT_GT(len, 0);
@ -174,7 +179,7 @@ TEST_IMPL(get_group) {
int r; int r;
r = uv_os_get_passwd(&pwd); r = uv_os_get_passwd(&pwd);
ASSERT_EQ(r, 0); ASSERT_OK(r);
r = uv_os_get_group(&grp, pwd.gid); r = uv_os_get_group(&grp, pwd.gid);
@ -183,7 +188,7 @@ TEST_IMPL(get_group) {
(void) &len; (void) &len;
#else #else
ASSERT_EQ(r, 0); ASSERT_OK(r);
ASSERT_EQ(pwd.gid, grp.gid); ASSERT_EQ(pwd.gid, grp.gid);
len = strlen(grp.groupname); len = strlen(grp.groupname);

View File

@ -40,8 +40,8 @@ static void getaddrinfo_fail_cb(uv_getaddrinfo_t* req,
int status, int status,
struct addrinfo* res) { struct addrinfo* res) {
ASSERT(fail_cb_called == 0); ASSERT_OK(fail_cb_called);
ASSERT(status < 0); ASSERT_LT(status, 0);
ASSERT_NULL(res); ASSERT_NULL(res);
uv_freeaddrinfo(res); /* Should not crash. */ uv_freeaddrinfo(res); /* Should not crash. */
fail_cb_called++; fail_cb_called++;
@ -51,7 +51,7 @@ static void getaddrinfo_fail_cb(uv_getaddrinfo_t* req,
static void getaddrinfo_basic_cb(uv_getaddrinfo_t* handle, static void getaddrinfo_basic_cb(uv_getaddrinfo_t* handle,
int status, int status,
struct addrinfo* res) { struct addrinfo* res) {
ASSERT(handle == getaddrinfo_handle); ASSERT_PTR_EQ(handle, getaddrinfo_handle);
getaddrinfo_cbs++; getaddrinfo_cbs++;
free(handle); free(handle);
uv_freeaddrinfo(res); uv_freeaddrinfo(res);
@ -66,7 +66,7 @@ static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle,
for (i = 0; i < CONCURRENT_COUNT; i++) { for (i = 0; i < CONCURRENT_COUNT; i++) {
if (&getaddrinfo_handles[i] == handle) { if (&getaddrinfo_handles[i] == handle) {
ASSERT(i == *data); ASSERT_EQ(i, *data);
callback_counts[i]++; callback_counts[i]++;
break; break;
@ -89,22 +89,22 @@ TEST_IMPL(getaddrinfo_fail) {
uv_getaddrinfo_t req; uv_getaddrinfo_t req;
ASSERT(UV_EINVAL == uv_getaddrinfo(uv_default_loop(), ASSERT_EQ(UV_EINVAL, uv_getaddrinfo(uv_default_loop(),
&req, &req,
(uv_getaddrinfo_cb) abort, (uv_getaddrinfo_cb) abort,
NULL, NULL,
NULL, NULL,
NULL)); NULL));
/* Use a FQDN by ending in a period */ /* Use a FQDN by ending in a period */
ASSERT(0 == uv_getaddrinfo(uv_default_loop(), ASSERT_OK(uv_getaddrinfo(uv_default_loop(),
&req, &req,
getaddrinfo_fail_cb, getaddrinfo_fail_cb,
"example.invalid.", "example.invalid.",
NULL, NULL,
NULL)); NULL));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(fail_cb_called == 1); ASSERT_EQ(1, fail_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
@ -119,12 +119,12 @@ TEST_IMPL(getaddrinfo_fail_sync) {
uv_getaddrinfo_t req; uv_getaddrinfo_t req;
/* Use a FQDN by ending in a period */ /* Use a FQDN by ending in a period */
ASSERT(0 > uv_getaddrinfo(uv_default_loop(), ASSERT_GT(0, uv_getaddrinfo(uv_default_loop(),
&req, &req,
NULL, NULL,
"example.invalid.", "example.invalid.",
NULL, NULL,
NULL)); NULL));
uv_freeaddrinfo(req.addrinfo); uv_freeaddrinfo(req.addrinfo);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
@ -147,11 +147,11 @@ TEST_IMPL(getaddrinfo_basic) {
name, name,
NULL, NULL,
NULL); NULL);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(getaddrinfo_cbs == 1); ASSERT_EQ(1, getaddrinfo_cbs);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
@ -165,12 +165,12 @@ TEST_IMPL(getaddrinfo_basic_sync) {
#endif #endif
uv_getaddrinfo_t req; uv_getaddrinfo_t req;
ASSERT(0 == uv_getaddrinfo(uv_default_loop(), ASSERT_OK(uv_getaddrinfo(uv_default_loop(),
&req, &req,
NULL, NULL,
name, name,
NULL, NULL,
NULL)); NULL));
uv_freeaddrinfo(req.addrinfo); uv_freeaddrinfo(req.addrinfo);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
@ -201,13 +201,13 @@ TEST_IMPL(getaddrinfo_concurrent) {
name, name,
NULL, NULL,
NULL); NULL);
ASSERT(r == 0); ASSERT_OK(r);
} }
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
for (i = 0; i < CONCURRENT_COUNT; i++) { for (i = 0; i < CONCURRENT_COUNT; i++) {
ASSERT(callback_counts[i] == 1); ASSERT_EQ(1, callback_counts[i]);
} }
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());

View File

@ -32,27 +32,27 @@ TEST_IMPL(gethostname) {
/* Reject invalid inputs */ /* Reject invalid inputs */
size = 1; size = 1;
r = uv_os_gethostname(NULL, &size); r = uv_os_gethostname(NULL, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_os_gethostname(buf, NULL); r = uv_os_gethostname(buf, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
size = 0; size = 0;
r = uv_os_gethostname(buf, &size); r = uv_os_gethostname(buf, &size);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
/* Return UV_ENOBUFS if the buffer cannot hold the hostname */ /* Return UV_ENOBUFS if the buffer cannot hold the hostname */
enobufs_size = 1; enobufs_size = 1;
buf[0] = '\0'; buf[0] = '\0';
r = uv_os_gethostname(buf, &enobufs_size); r = uv_os_gethostname(buf, &enobufs_size);
ASSERT_EQ(r, UV_ENOBUFS); ASSERT_EQ(r, UV_ENOBUFS);
ASSERT(buf[0] == '\0'); ASSERT_EQ(buf[0], '\0');
ASSERT(enobufs_size > 1); ASSERT_GT(enobufs_size, 1);
/* Successfully get the hostname */ /* Successfully get the hostname */
size = UV_MAXHOSTNAMESIZE; size = UV_MAXHOSTNAMESIZE;
r = uv_os_gethostname(buf, &size); r = uv_os_gethostname(buf, &size);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(size > 0 && size == strlen(buf)); ASSERT(size > 0 && size == strlen(buf));
ASSERT(size + 1 == enobufs_size); ASSERT_EQ(size + 1, enobufs_size);
return 0; return 0;
} }

View File

@ -39,7 +39,7 @@ static void getnameinfo_req(uv_getnameinfo_t* handle,
const char* hostname, const char* hostname,
const char* service) { const char* service) {
ASSERT_NOT_NULL(handle); ASSERT_NOT_NULL(handle);
ASSERT(status == 0); ASSERT_OK(status);
ASSERT_NOT_NULL(hostname); ASSERT_NOT_NULL(hostname);
ASSERT_NOT_NULL(service); ASSERT_NOT_NULL(service);
} }
@ -54,14 +54,14 @@ TEST_IMPL(getnameinfo_basic_ip4) {
int r; int r;
r = uv_ip4_addr(address_ip4, port, &addr4); r = uv_ip4_addr(address_ip4, port, &addr4);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_getnameinfo(uv_default_loop(), r = uv_getnameinfo(uv_default_loop(),
&req, &req,
&getnameinfo_req, &getnameinfo_req,
(const struct sockaddr*)&addr4, (const struct sockaddr*)&addr4,
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
@ -76,15 +76,15 @@ TEST_IMPL(getnameinfo_basic_ip4_sync) {
RETURN_SKIP("Test does not currently work in QEMU"); RETURN_SKIP("Test does not currently work in QEMU");
#endif #endif
ASSERT(0 == uv_ip4_addr(address_ip4, port, &addr4)); ASSERT_OK(uv_ip4_addr(address_ip4, port, &addr4));
ASSERT(0 == uv_getnameinfo(uv_default_loop(), ASSERT_OK(uv_getnameinfo(uv_default_loop(),
&req, &req,
NULL, NULL,
(const struct sockaddr*)&addr4, (const struct sockaddr*)&addr4,
0)); 0));
ASSERT(req.host[0] != '\0'); ASSERT_NE(req.host[0], '\0');
ASSERT(req.service[0] != '\0'); ASSERT_NE(req.service[0], '\0');
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
@ -100,14 +100,14 @@ TEST_IMPL(getnameinfo_basic_ip6) {
int r; int r;
r = uv_ip6_addr(address_ip6, port, &addr6); r = uv_ip6_addr(address_ip6, port, &addr6);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_getnameinfo(uv_default_loop(), r = uv_getnameinfo(uv_default_loop(),
&req, &req,
&getnameinfo_req, &getnameinfo_req,
(const struct sockaddr*)&addr6, (const struct sockaddr*)&addr6,
0); 0);
ASSERT(r == 0); ASSERT_OK(r);
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);

View File

@ -73,7 +73,7 @@ static void after_read(uv_stream_t* handle,
req = (uv_shutdown_t*) malloc(sizeof *req); req = (uv_shutdown_t*) malloc(sizeof *req);
r = uv_shutdown(req, handle, after_shutdown); r = uv_shutdown(req, handle, after_shutdown);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -84,22 +84,22 @@ static void check_sockname(struct sockaddr* addr, const char* compare_ip,
char check_ip[17]; char check_ip[17];
int r; int r;
ASSERT(0 == uv_ip4_addr(compare_ip, compare_port, &compare_addr)); ASSERT_OK(uv_ip4_addr(compare_ip, compare_port, &compare_addr));
/* Both addresses should be ipv4 */ /* Both addresses should be ipv4 */
ASSERT(check_addr.sin_family == AF_INET); ASSERT_EQ(check_addr.sin_family, AF_INET);
ASSERT(compare_addr.sin_family == AF_INET); ASSERT_EQ(compare_addr.sin_family, AF_INET);
/* Check if the ip matches */ /* Check if the ip matches */
ASSERT(memcmp(&check_addr.sin_addr, ASSERT_OK(memcmp(&check_addr.sin_addr,
&compare_addr.sin_addr, &compare_addr.sin_addr,
sizeof compare_addr.sin_addr) == 0); sizeof compare_addr.sin_addr));
/* Check if the port matches. If port == 0 anything goes. */ /* Check if the port matches. If port == 0 anything goes. */
ASSERT(compare_port == 0 || check_addr.sin_port == compare_addr.sin_port); ASSERT(compare_port == 0 || check_addr.sin_port == compare_addr.sin_port);
r = uv_ip4_name(&check_addr, (char*) check_ip, sizeof check_ip); r = uv_ip4_name(&check_addr, (char*) check_ip, sizeof check_ip);
ASSERT(r == 0); ASSERT_OK(r);
printf("%s: %s:%d\n", context, check_ip, ntohs(check_addr.sin_port)); printf("%s: %s:%d\n", context, check_ip, ntohs(check_addr.sin_port));
} }
@ -114,34 +114,34 @@ static void on_connection(uv_stream_t* server, int status) {
if (status != 0) { if (status != 0) {
fprintf(stderr, "Connect error %s\n", uv_err_name(status)); fprintf(stderr, "Connect error %s\n", uv_err_name(status));
} }
ASSERT(status == 0); ASSERT_OK(status);
handle = malloc(sizeof(*handle)); handle = malloc(sizeof(*handle));
ASSERT_NOT_NULL(handle); ASSERT_NOT_NULL(handle);
r = uv_tcp_init(loop, handle); r = uv_tcp_init(loop, handle);
ASSERT(r == 0); ASSERT_OK(r);
/* associate server with stream */ /* associate server with stream */
handle->data = server; handle->data = server;
r = uv_accept(server, (uv_stream_t*)handle); r = uv_accept(server, (uv_stream_t*)handle);
ASSERT(r == 0); ASSERT_OK(r);
namelen = sizeof sockname; namelen = sizeof sockname;
r = uv_tcp_getsockname(handle, &sockname, &namelen); r = uv_tcp_getsockname(handle, &sockname, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&sockname, "127.0.0.1", server_port, "accepted socket"); check_sockname(&sockname, "127.0.0.1", server_port, "accepted socket");
getsocknamecount_tcp++; getsocknamecount_tcp++;
namelen = sizeof peername; namelen = sizeof peername;
r = uv_tcp_getpeername(handle, &peername, &namelen); r = uv_tcp_getpeername(handle, &peername, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&peername, "127.0.0.1", connect_port, "accepted socket peer"); check_sockname(&peername, "127.0.0.1", connect_port, "accepted socket peer");
getpeernamecount++; getpeernamecount++;
r = uv_read_start((uv_stream_t*)handle, alloc, after_read); r = uv_read_start((uv_stream_t*)handle, alloc, after_read);
ASSERT(r == 0); ASSERT_OK(r);
} }
@ -149,17 +149,17 @@ static void on_connect(uv_connect_t* req, int status) {
struct sockaddr sockname, peername; struct sockaddr sockname, peername;
int r, namelen; int r, namelen;
ASSERT(status == 0); ASSERT_OK(status);
namelen = sizeof sockname; namelen = sizeof sockname;
r = uv_tcp_getsockname((uv_tcp_t*) req->handle, &sockname, &namelen); r = uv_tcp_getsockname((uv_tcp_t*) req->handle, &sockname, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&sockname, "127.0.0.1", 0, "connected socket"); check_sockname(&sockname, "127.0.0.1", 0, "connected socket");
getsocknamecount_tcp++; getsocknamecount_tcp++;
namelen = sizeof peername; namelen = sizeof peername;
r = uv_tcp_getpeername((uv_tcp_t*) req->handle, &peername, &namelen); r = uv_tcp_getpeername((uv_tcp_t*) req->handle, &peername, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&peername, "127.0.0.1", server_port, "connected socket peer"); check_sockname(&peername, "127.0.0.1", server_port, "connected socket peer");
getpeernamecount++; getpeernamecount++;
@ -173,7 +173,7 @@ static int tcp_listener(void) {
int namelen; int namelen;
int r; int r;
ASSERT(0 == uv_ip4_addr("0.0.0.0", server_port, &addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", server_port, &addr));
r = uv_tcp_init(loop, &tcpServer); r = uv_tcp_init(loop, &tcpServer);
if (r) { if (r) {
@ -196,13 +196,13 @@ static int tcp_listener(void) {
memset(&sockname, -1, sizeof sockname); memset(&sockname, -1, sizeof sockname);
namelen = sizeof sockname; namelen = sizeof sockname;
r = uv_tcp_getsockname(&tcpServer, &sockname, &namelen); r = uv_tcp_getsockname(&tcpServer, &sockname, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&sockname, "0.0.0.0", server_port, "server socket"); check_sockname(&sockname, "0.0.0.0", server_port, "server socket");
getsocknamecount_tcp++; getsocknamecount_tcp++;
namelen = sizeof sockname; namelen = sizeof sockname;
r = uv_tcp_getpeername(&tcpServer, &peername, &namelen); r = uv_tcp_getpeername(&tcpServer, &peername, &namelen);
ASSERT(r == UV_ENOTCONN); ASSERT_EQ(r, UV_ENOTCONN);
getpeernamecount++; getpeernamecount++;
return 0; return 0;
@ -214,7 +214,7 @@ static void tcp_connector(void) {
struct sockaddr sockname; struct sockaddr sockname;
int r, namelen; int r, namelen;
ASSERT(0 == uv_ip4_addr("127.0.0.1", server_port, &server_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", server_port, &server_addr));
r = uv_tcp_init(loop, &tcp); r = uv_tcp_init(loop, &tcp);
tcp.data = &connect_req; tcp.data = &connect_req;
@ -230,9 +230,9 @@ static void tcp_connector(void) {
namelen = sizeof sockname; namelen = sizeof sockname;
r = uv_tcp_getsockname(&tcp, &sockname, &namelen); r = uv_tcp_getsockname(&tcp, &sockname, &namelen);
ASSERT(!r); ASSERT(!r);
ASSERT(sockname.sa_family == AF_INET); ASSERT_EQ(sockname.sa_family, AF_INET);
connect_port = ntohs(((struct sockaddr_in*) &sockname)->sin_port); connect_port = ntohs(((struct sockaddr_in*) &sockname)->sin_port);
ASSERT(connect_port > 0); ASSERT_GT(connect_port, 0);
} }
@ -245,7 +245,7 @@ static void udp_recv(uv_udp_t* handle,
int namelen; int namelen;
int r; int r;
ASSERT(nread >= 0); ASSERT_GE(nread, 0);
free(buf->base); free(buf->base);
if (nread == 0) { if (nread == 0) {
@ -255,7 +255,7 @@ static void udp_recv(uv_udp_t* handle,
memset(&sockname, -1, sizeof sockname); memset(&sockname, -1, sizeof sockname);
namelen = sizeof(sockname); namelen = sizeof(sockname);
r = uv_udp_getsockname(&udp, &sockname, &namelen); r = uv_udp_getsockname(&udp, &sockname, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&sockname, "0.0.0.0", 0, "udp receiving socket"); check_sockname(&sockname, "0.0.0.0", 0, "udp receiving socket");
getsocknamecount_udp++; getsocknamecount_udp++;
@ -275,7 +275,7 @@ static int udp_listener(void) {
int namelen; int namelen;
int r; int r;
ASSERT(0 == uv_ip4_addr("0.0.0.0", server_port, &addr)); ASSERT_OK(uv_ip4_addr("0.0.0.0", server_port, &addr));
r = uv_udp_init(loop, &udpServer); r = uv_udp_init(loop, &udpServer);
if (r) { if (r) {
@ -292,12 +292,12 @@ static int udp_listener(void) {
memset(&sockname, -1, sizeof sockname); memset(&sockname, -1, sizeof sockname);
namelen = sizeof sockname; namelen = sizeof sockname;
r = uv_udp_getsockname(&udpServer, &sockname, &namelen); r = uv_udp_getsockname(&udpServer, &sockname, &namelen);
ASSERT(r == 0); ASSERT_OK(r);
check_sockname(&sockname, "0.0.0.0", server_port, "udp listener socket"); check_sockname(&sockname, "0.0.0.0", server_port, "udp listener socket");
getsocknamecount_udp++; getsocknamecount_udp++;
r = uv_udp_recv_start(&udpServer, alloc, udp_recv); r = uv_udp_recv_start(&udpServer, alloc, udp_recv);
ASSERT(r == 0); ASSERT_OK(r);
return 0; return 0;
} }
@ -312,7 +312,7 @@ static void udp_sender(void) {
ASSERT(!r); ASSERT(!r);
buf = uv_buf_init("PING", 4); buf = uv_buf_init("PING", 4);
ASSERT(0 == uv_ip4_addr("127.0.0.1", server_port, &server_addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", server_port, &server_addr));
r = uv_udp_send(&send_req, r = uv_udp_send(&send_req,
&udp, &udp,
@ -334,8 +334,8 @@ TEST_IMPL(getsockname_tcp) {
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(getsocknamecount_tcp == 3); ASSERT_EQ(3, getsocknamecount_tcp);
ASSERT(getpeernamecount == 3); ASSERT_EQ(3, getpeernamecount);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;
@ -352,10 +352,10 @@ TEST_IMPL(getsockname_udp) {
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(getsocknamecount_udp == 2); ASSERT_EQ(2, getsocknamecount_udp);
ASSERT(udp.send_queue_size == 0); ASSERT_OK(udp.send_queue_size);
ASSERT(udpServer.send_queue_size == 0); ASSERT_OK(udpServer.send_queue_size);
MAKE_VALGRIND_HAPPY(loop); MAKE_VALGRIND_HAPPY(loop);
return 0; return 0;

View File

@ -30,9 +30,9 @@ int cookie3;
TEST_IMPL(handle_type_name) { TEST_IMPL(handle_type_name) {
ASSERT(strcmp(uv_handle_type_name(UV_NAMED_PIPE), "pipe") == 0); ASSERT_OK(strcmp(uv_handle_type_name(UV_NAMED_PIPE), "pipe"));
ASSERT(strcmp(uv_handle_type_name(UV_UDP), "udp") == 0); ASSERT_OK(strcmp(uv_handle_type_name(UV_UDP), "udp"));
ASSERT(strcmp(uv_handle_type_name(UV_FILE), "file") == 0); ASSERT_OK(strcmp(uv_handle_type_name(UV_FILE), "file"));
ASSERT_NULL(uv_handle_type_name(UV_HANDLE_TYPE_MAX)); ASSERT_NULL(uv_handle_type_name(UV_HANDLE_TYPE_MAX));
ASSERT_NULL(uv_handle_type_name(UV_HANDLE_TYPE_MAX + 1)); ASSERT_NULL(uv_handle_type_name(UV_HANDLE_TYPE_MAX + 1));
ASSERT_NULL(uv_handle_type_name(UV_UNKNOWN_HANDLE)); ASSERT_NULL(uv_handle_type_name(UV_UNKNOWN_HANDLE));
@ -41,9 +41,9 @@ TEST_IMPL(handle_type_name) {
TEST_IMPL(req_type_name) { TEST_IMPL(req_type_name) {
ASSERT(strcmp(uv_req_type_name(UV_REQ), "req") == 0); ASSERT_OK(strcmp(uv_req_type_name(UV_REQ), "req"));
ASSERT(strcmp(uv_req_type_name(UV_UDP_SEND), "udp_send") == 0); ASSERT_OK(strcmp(uv_req_type_name(UV_UDP_SEND), "udp_send"));
ASSERT(strcmp(uv_req_type_name(UV_WORK), "work") == 0); ASSERT_OK(strcmp(uv_req_type_name(UV_WORK), "work"));
ASSERT_NULL(uv_req_type_name(UV_REQ_TYPE_MAX)); ASSERT_NULL(uv_req_type_name(UV_REQ_TYPE_MAX));
ASSERT_NULL(uv_req_type_name(UV_REQ_TYPE_MAX + 1)); ASSERT_NULL(uv_req_type_name(UV_REQ_TYPE_MAX + 1));
ASSERT_NULL(uv_req_type_name(UV_UNKNOWN_REQ)); ASSERT_NULL(uv_req_type_name(UV_UNKNOWN_REQ));
@ -60,48 +60,48 @@ TEST_IMPL(getters_setters) {
loop = malloc(uv_loop_size()); loop = malloc(uv_loop_size());
ASSERT_NOT_NULL(loop); ASSERT_NOT_NULL(loop);
r = uv_loop_init(loop); r = uv_loop_init(loop);
ASSERT(r == 0); ASSERT_OK(r);
uv_loop_set_data(loop, &cookie1); uv_loop_set_data(loop, &cookie1);
ASSERT(loop->data == &cookie1); ASSERT_PTR_EQ(loop->data, &cookie1);
ASSERT(uv_loop_get_data(loop) == &cookie1); ASSERT_PTR_EQ(uv_loop_get_data(loop), &cookie1);
pipe = malloc(uv_handle_size(UV_NAMED_PIPE)); pipe = malloc(uv_handle_size(UV_NAMED_PIPE));
r = uv_pipe_init(loop, pipe, 0); r = uv_pipe_init(loop, pipe, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(uv_handle_get_type((uv_handle_t*)pipe) == UV_NAMED_PIPE); ASSERT_EQ(uv_handle_get_type((uv_handle_t*)pipe), UV_NAMED_PIPE);
ASSERT(uv_handle_get_loop((uv_handle_t*)pipe) == loop); ASSERT_PTR_EQ(uv_handle_get_loop((uv_handle_t*)pipe), loop);
pipe->data = &cookie2; pipe->data = &cookie2;
ASSERT(uv_handle_get_data((uv_handle_t*)pipe) == &cookie2); ASSERT_PTR_EQ(uv_handle_get_data((uv_handle_t*)pipe), &cookie2);
uv_handle_set_data((uv_handle_t*)pipe, &cookie1); uv_handle_set_data((uv_handle_t*)pipe, &cookie1);
ASSERT(uv_handle_get_data((uv_handle_t*)pipe) == &cookie1); ASSERT_PTR_EQ(uv_handle_get_data((uv_handle_t*)pipe), &cookie1);
ASSERT(pipe->data == &cookie1); ASSERT_PTR_EQ(pipe->data, &cookie1);
ASSERT(uv_stream_get_write_queue_size((uv_stream_t*)pipe) == 0); ASSERT_OK(uv_stream_get_write_queue_size((uv_stream_t*)pipe));
pipe->write_queue_size++; pipe->write_queue_size++;
ASSERT(uv_stream_get_write_queue_size((uv_stream_t*)pipe) == 1); ASSERT_EQ(1, uv_stream_get_write_queue_size((uv_stream_t*)pipe));
pipe->write_queue_size--; pipe->write_queue_size--;
uv_close((uv_handle_t*)pipe, NULL); uv_close((uv_handle_t*)pipe, NULL);
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
fs = malloc(uv_req_size(UV_FS)); fs = malloc(uv_req_size(UV_FS));
uv_fs_stat(loop, fs, ".", NULL); uv_fs_stat(loop, fs, ".", NULL);
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(uv_fs_get_type(fs) == UV_FS_STAT); ASSERT_EQ(uv_fs_get_type(fs), UV_FS_STAT);
ASSERT(uv_fs_get_result(fs) == 0); ASSERT_OK(uv_fs_get_result(fs));
ASSERT(uv_fs_get_ptr(fs) == uv_fs_get_statbuf(fs)); ASSERT_PTR_EQ(uv_fs_get_ptr(fs), uv_fs_get_statbuf(fs));
ASSERT(uv_fs_get_statbuf(fs)->st_mode & S_IFDIR); ASSERT(uv_fs_get_statbuf(fs)->st_mode & S_IFDIR);
ASSERT(strcmp(uv_fs_get_path(fs), ".") == 0); ASSERT_OK(strcmp(uv_fs_get_path(fs), "."));
uv_fs_req_cleanup(fs); uv_fs_req_cleanup(fs);
r = uv_loop_close(loop); r = uv_loop_close(loop);
ASSERT(r == 0); ASSERT_OK(r);
free(pipe); free(pipe);
free(fs); free(fs);

View File

@ -28,12 +28,12 @@ TEST_IMPL(gettimeofday) {
tv.tv_sec = 0; tv.tv_sec = 0;
r = uv_gettimeofday(&tv); r = uv_gettimeofday(&tv);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(tv.tv_sec != 0); ASSERT_NE(0, tv.tv_sec);
/* Test invalid input. */ /* Test invalid input. */
r = uv_gettimeofday(NULL); r = uv_gettimeofday(NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
return 0; return 0;
} }

View File

@ -56,49 +56,49 @@ TEST_IMPL(handle_fileno) {
uv_loop_t* loop; uv_loop_t* loop;
loop = uv_default_loop(); loop = uv_default_loop();
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
r = uv_idle_init(loop, &idle); r = uv_idle_init(loop, &idle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &idle, &fd); r = uv_fileno((uv_handle_t*) &idle, &fd);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
uv_close((uv_handle_t*) &idle, NULL); uv_close((uv_handle_t*) &idle, NULL);
r = uv_tcp_init(loop, &tcp); r = uv_tcp_init(loop, &tcp);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &tcp, &fd); r = uv_fileno((uv_handle_t*) &tcp, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
r = uv_tcp_bind(&tcp, (const struct sockaddr*) &addr, 0); r = uv_tcp_bind(&tcp, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &tcp, &fd); r = uv_fileno((uv_handle_t*) &tcp, &fd);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &tcp, NULL); uv_close((uv_handle_t*) &tcp, NULL);
r = uv_fileno((uv_handle_t*) &tcp, &fd); r = uv_fileno((uv_handle_t*) &tcp, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
r = uv_udp_init(loop, &udp); r = uv_udp_init(loop, &udp);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &udp, &fd); r = uv_fileno((uv_handle_t*) &udp, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
r = uv_udp_bind(&udp, (const struct sockaddr*) &addr, 0); r = uv_udp_bind(&udp, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &udp, &fd); r = uv_fileno((uv_handle_t*) &udp, &fd);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &udp, NULL); uv_close((uv_handle_t*) &udp, NULL);
r = uv_fileno((uv_handle_t*) &udp, &fd); r = uv_fileno((uv_handle_t*) &udp, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
r = uv_pipe_init(loop, &pipe, 0); r = uv_pipe_init(loop, &pipe, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &pipe, &fd); r = uv_fileno((uv_handle_t*) &pipe, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
r = uv_pipe_bind(&pipe, TEST_PIPENAME); r = uv_pipe_bind(&pipe, TEST_PIPENAME);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_fileno((uv_handle_t*) &pipe, &fd); r = uv_fileno((uv_handle_t*) &pipe, &fd);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &pipe, NULL); uv_close((uv_handle_t*) &pipe, NULL);
r = uv_fileno((uv_handle_t*) &pipe, &fd); r = uv_fileno((uv_handle_t*) &pipe, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
tty_fd = get_tty_fd(); tty_fd = get_tty_fd();
if (tty_fd < 0) { if (tty_fd < 0) {
@ -106,14 +106,14 @@ TEST_IMPL(handle_fileno) {
fflush(stderr); fflush(stderr);
} else { } else {
r = uv_tty_init(loop, &tty, tty_fd, 0); r = uv_tty_init(loop, &tty, tty_fd, 0);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(uv_is_readable((uv_stream_t*) &tty)); ASSERT(uv_is_readable((uv_stream_t*) &tty));
ASSERT(!uv_is_writable((uv_stream_t*) &tty)); ASSERT(!uv_is_writable((uv_stream_t*) &tty));
r = uv_fileno((uv_handle_t*) &tty, &fd); r = uv_fileno((uv_handle_t*) &tty, &fd);
ASSERT(r == 0); ASSERT_OK(r);
uv_close((uv_handle_t*) &tty, NULL); uv_close((uv_handle_t*) &tty, NULL);
r = uv_fileno((uv_handle_t*) &tty, &fd); r = uv_fileno((uv_handle_t*) &tty, &fd);
ASSERT(r == UV_EBADF); ASSERT_EQ(r, UV_EBADF);
ASSERT(!uv_is_readable((uv_stream_t*) &tty)); ASSERT(!uv_is_readable((uv_stream_t*) &tty));
ASSERT(!uv_is_writable((uv_stream_t*) &tty)); ASSERT(!uv_is_writable((uv_stream_t*) &tty));
} }

View File

@ -34,39 +34,39 @@ TEST_IMPL(homedir) {
/* Test the normal case */ /* Test the normal case */
len = sizeof homedir; len = sizeof homedir;
homedir[0] = '\0'; homedir[0] = '\0';
ASSERT(strlen(homedir) == 0); ASSERT_OK(strlen(homedir));
r = uv_os_homedir(homedir, &len); r = uv_os_homedir(homedir, &len);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(strlen(homedir) == len); ASSERT_EQ(strlen(homedir), len);
ASSERT(len > 0); ASSERT_GT(len, 0);
ASSERT(homedir[len] == '\0'); ASSERT_EQ(homedir[len], '\0');
#ifdef _WIN32 #ifdef _WIN32
if (len == 3 && homedir[1] == ':') if (len == 3 && homedir[1] == ':')
ASSERT(homedir[2] == '\\'); ASSERT_EQ(homedir[2], '\\');
else else
ASSERT(homedir[len - 1] != '\\'); ASSERT_NE(homedir[len - 1], '\\');
#else #else
if (len == 1) if (len == 1)
ASSERT(homedir[0] == '/'); ASSERT_EQ(homedir[0], '/');
else else
ASSERT(homedir[len - 1] != '/'); ASSERT_NE(homedir[len - 1], '/');
#endif #endif
/* Test the case where the buffer is too small */ /* Test the case where the buffer is too small */
len = SMALLPATH; len = SMALLPATH;
r = uv_os_homedir(homedir, &len); r = uv_os_homedir(homedir, &len);
ASSERT(r == UV_ENOBUFS); ASSERT_EQ(r, UV_ENOBUFS);
ASSERT(len > SMALLPATH); ASSERT_GT(len, SMALLPATH);
/* Test invalid inputs */ /* Test invalid inputs */
r = uv_os_homedir(NULL, &len); r = uv_os_homedir(NULL, &len);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
r = uv_os_homedir(homedir, NULL); r = uv_os_homedir(homedir, NULL);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
len = 0; len = 0;
r = uv_os_homedir(homedir, &len); r = uv_os_homedir(homedir, &len);
ASSERT(r == UV_EINVAL); ASSERT_EQ(r, UV_EINVAL);
return 0; return 0;
} }

View File

@ -45,7 +45,7 @@ TEST_IMPL(hrtime) {
* that the difference between the two hrtime values has a reasonable * that the difference between the two hrtime values has a reasonable
* lower bound. * lower bound.
*/ */
ASSERT(diff > (uint64_t) 25 * NANOSEC / MILLISEC); ASSERT_UINT64_GT(diff, (uint64_t) 25 * NANOSEC / MILLISEC);
--i; --i;
} }
return 0; return 0;
@ -57,8 +57,8 @@ TEST_IMPL(clock_gettime) {
ASSERT_EQ(UV_EINVAL, uv_clock_gettime(1337, &t)); ASSERT_EQ(UV_EINVAL, uv_clock_gettime(1337, &t));
ASSERT_EQ(UV_EFAULT, uv_clock_gettime(1337, NULL)); ASSERT_EQ(UV_EFAULT, uv_clock_gettime(1337, NULL));
ASSERT_EQ(0, uv_clock_gettime(UV_CLOCK_MONOTONIC, &t)); ASSERT_OK(uv_clock_gettime(UV_CLOCK_MONOTONIC, &t));
ASSERT_EQ(0, uv_clock_gettime(UV_CLOCK_REALTIME, &t)); ASSERT_OK(uv_clock_gettime(UV_CLOCK_REALTIME, &t));
ASSERT_GT(1682500000000ll, t.tv_sec); /* 2023-04-26T09:06:40.000Z */ ASSERT_GT(1682500000000ll, t.tv_sec); /* 2023-04-26T09:06:40.000Z */
return 0; return 0;

View File

@ -39,7 +39,7 @@ static void close_cb(uv_handle_t* handle) {
static void timer_cb(uv_timer_t* handle) { static void timer_cb(uv_timer_t* handle) {
ASSERT(handle == &timer_handle); ASSERT_PTR_EQ(handle, &timer_handle);
uv_close((uv_handle_t*) &idle_handle, close_cb); uv_close((uv_handle_t*) &idle_handle, close_cb);
uv_close((uv_handle_t*) &check_handle, close_cb); uv_close((uv_handle_t*) &check_handle, close_cb);
@ -52,7 +52,7 @@ static void timer_cb(uv_timer_t* handle) {
static void idle_cb(uv_idle_t* handle) { static void idle_cb(uv_idle_t* handle) {
ASSERT(handle == &idle_handle); ASSERT_PTR_EQ(handle, &idle_handle);
idle_cb_called++; idle_cb_called++;
fprintf(stderr, "idle_cb %d\n", idle_cb_called); fprintf(stderr, "idle_cb %d\n", idle_cb_called);
@ -61,7 +61,7 @@ static void idle_cb(uv_idle_t* handle) {
static void check_cb(uv_check_t* handle) { static void check_cb(uv_check_t* handle) {
ASSERT(handle == &check_handle); ASSERT_PTR_EQ(handle, &check_handle);
check_cb_called++; check_cb_called++;
fprintf(stderr, "check_cb %d\n", check_cb_called); fprintf(stderr, "check_cb %d\n", check_cb_called);
@ -73,26 +73,26 @@ TEST_IMPL(idle_starvation) {
int r; int r;
r = uv_idle_init(uv_default_loop(), &idle_handle); r = uv_idle_init(uv_default_loop(), &idle_handle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_idle_start(&idle_handle, idle_cb); r = uv_idle_start(&idle_handle, idle_cb);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_check_init(uv_default_loop(), &check_handle); r = uv_check_init(uv_default_loop(), &check_handle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_check_start(&check_handle, check_cb); r = uv_check_start(&check_handle, check_cb);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_init(uv_default_loop(), &timer_handle); r = uv_timer_init(uv_default_loop(), &timer_handle);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_timer_start(&timer_handle, timer_cb, 50, 0); r = uv_timer_start(&timer_handle, timer_cb, 50, 0);
ASSERT(r == 0); ASSERT_OK(r);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT_OK(r);
ASSERT(idle_cb_called > 0); ASSERT_GT(idle_cb_called, 0);
ASSERT(timer_cb_called == 1); ASSERT_EQ(1, timer_cb_called);
ASSERT(close_cb_called == 3); ASSERT_EQ(3, close_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0; return 0;
@ -105,19 +105,19 @@ static void idle_stop(uv_idle_t* handle) {
TEST_IMPL(idle_check) { TEST_IMPL(idle_check) {
ASSERT_EQ(0, uv_idle_init(uv_default_loop(), &idle_handle)); ASSERT_OK(uv_idle_init(uv_default_loop(), &idle_handle));
ASSERT_EQ(0, uv_idle_start(&idle_handle, idle_stop)); ASSERT_OK(uv_idle_start(&idle_handle, idle_stop));
ASSERT_EQ(0, uv_check_init(uv_default_loop(), &check_handle)); ASSERT_OK(uv_check_init(uv_default_loop(), &check_handle));
ASSERT_EQ(0, uv_check_start(&check_handle, check_cb)); ASSERT_OK(uv_check_start(&check_handle, check_cb));
ASSERT_EQ(1, uv_run(uv_default_loop(), UV_RUN_ONCE)); ASSERT_EQ(1, uv_run(uv_default_loop(), UV_RUN_ONCE));
ASSERT_EQ(1, check_cb_called); ASSERT_EQ(1, check_cb_called);
ASSERT_EQ(0, close_cb_called); ASSERT_OK(close_cb_called);
uv_close((uv_handle_t*) &idle_handle, close_cb); uv_close((uv_handle_t*) &idle_handle, close_cb);
uv_close((uv_handle_t*) &check_handle, close_cb); uv_close((uv_handle_t*) &check_handle, close_cb);
ASSERT_EQ(0, uv_run(uv_default_loop(), UV_RUN_ONCE)); ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_ONCE));
ASSERT_EQ(2, close_cb_called); ASSERT_EQ(2, close_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop()); MAKE_VALGRIND_HAPPY(uv_default_loop());

View File

@ -20,6 +20,7 @@
*/ */
#include "task.h" #include "task.h"
#define uv__malloc malloc
#include "../src/idna.c" #include "../src/idna.c"
#include <string.h> #include <string.h>
@ -31,66 +32,66 @@ TEST_IMPL(utf8_decode1) {
/* ASCII. */ /* ASCII. */
p = b; p = b;
snprintf(b, sizeof(b), "%c\x7F", 0x00); snprintf(b, sizeof(b), "%c\x7F", 0x00);
ASSERT(0 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_OK(uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 1); ASSERT_PTR_EQ(p, b + 1);
ASSERT(127 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(127, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2); ASSERT_PTR_EQ(p, b + 2);
/* Two-byte sequences. */ /* Two-byte sequences. */
p = b; p = b;
snprintf(b, sizeof(b), "\xC2\x80\xDF\xBF"); snprintf(b, sizeof(b), "\xC2\x80\xDF\xBF");
ASSERT(128 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(128, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2); ASSERT_PTR_EQ(p, b + 2);
ASSERT(0x7FF == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(0x7FF, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4); ASSERT_PTR_EQ(p, b + 4);
/* Three-byte sequences. */ /* Three-byte sequences. */
p = b; p = b;
snprintf(b, sizeof(b), "\xE0\xA0\x80\xEF\xBF\xBF"); snprintf(b, sizeof(b), "\xE0\xA0\x80\xEF\xBF\xBF");
ASSERT(0x800 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(0x800, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 3); ASSERT_PTR_EQ(p, b + 3);
ASSERT(0xFFFF == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(0xFFFF, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 6); ASSERT_PTR_EQ(p, b + 6);
/* Four-byte sequences. */ /* Four-byte sequences. */
p = b; p = b;
snprintf(b, sizeof(b), "\xF0\x90\x80\x80\xF4\x8F\xBF\xBF"); snprintf(b, sizeof(b), "\xF0\x90\x80\x80\xF4\x8F\xBF\xBF");
ASSERT(0x10000 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(0x10000, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4); ASSERT_PTR_EQ(p, b + 4);
ASSERT(0x10FFFF == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ(0x10FFFF, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 8); ASSERT_PTR_EQ(p, b + 8);
/* Four-byte sequences > U+10FFFF; disallowed. */ /* Four-byte sequences > U+10FFFF; disallowed. */
p = b; p = b;
snprintf(b, sizeof(b), "\xF4\x90\xC0\xC0\xF7\xBF\xBF\xBF"); snprintf(b, sizeof(b), "\xF4\x90\xC0\xC0\xF7\xBF\xBF\xBF");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4); ASSERT_PTR_EQ(p, b + 4);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 8); ASSERT_PTR_EQ(p, b + 8);
/* Overlong; disallowed. */ /* Overlong; disallowed. */
p = b; p = b;
snprintf(b, sizeof(b), "\xC0\x80\xC1\x80"); snprintf(b, sizeof(b), "\xC0\x80\xC1\x80");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2); ASSERT_PTR_EQ(p, b + 2);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4); ASSERT_PTR_EQ(p, b + 4);
/* Surrogate pairs; disallowed. */ /* Surrogate pairs; disallowed. */
p = b; p = b;
snprintf(b, sizeof(b), "\xED\xA0\x80\xED\xA3\xBF"); snprintf(b, sizeof(b), "\xED\xA0\x80\xED\xA3\xBF");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 3); ASSERT_PTR_EQ(p, b + 3);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 6); ASSERT_PTR_EQ(p, b + 6);
/* Simply illegal. */ /* Simply illegal. */
p = b; p = b;
snprintf(b, sizeof(b), "\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"); snprintf(b, sizeof(b), "\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
for (i = 1; i <= 8; i++) { for (i = 1; i <= 8; i++) {
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b))); ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + i); ASSERT_PTR_EQ(p, b + i);
} }
return 0; return 0;
@ -122,7 +123,7 @@ TEST_IMPL(utf8_decode1_overrun) {
do { \ do { \
char d[256] = {0}; \ char d[256] = {0}; \
static const char s[] = "" input ""; \ static const char s[] = "" input ""; \
ASSERT(err == uv__idna_toascii(s, s + sizeof(s) - 1, d, d + sizeof(d))); \ ASSERT_EQ(err, uv__idna_toascii(s, s + sizeof(s) - 1, d, d + sizeof(d))); \
} while (0) } while (0)
#define T(input, expected) \ #define T(input, expected) \
@ -132,13 +133,13 @@ TEST_IMPL(utf8_decode1_overrun) {
char d2[256] = {0}; \ char d2[256] = {0}; \
static const char s[] = "" input ""; \ static const char s[] = "" input ""; \
n = uv__idna_toascii(s, s + sizeof(s) - 1, d1, d1 + sizeof(d1)); \ n = uv__idna_toascii(s, s + sizeof(s) - 1, d1, d1 + sizeof(d1)); \
ASSERT(n == sizeof(expected)); \ ASSERT_EQ(n, sizeof(expected)); \
ASSERT(0 == memcmp(d1, expected, n)); \ ASSERT_OK(memcmp(d1, expected, n)); \
/* Sanity check: encoding twice should not change the output. */ \ /* Sanity check: encoding twice should not change the output. */ \
n = uv__idna_toascii(d1, d1 + strlen(d1), d2, d2 + sizeof(d2)); \ n = uv__idna_toascii(d1, d1 + strlen(d1), d2, d2 + sizeof(d2)); \
ASSERT(n == sizeof(expected)); \ ASSERT_EQ(n, sizeof(expected)); \
ASSERT(0 == memcmp(d2, expected, n)); \ ASSERT_OK(memcmp(d2, expected, n)); \
ASSERT(0 == memcmp(d1, d2, sizeof(d2))); \ ASSERT_OK(memcmp(d1, d2, sizeof(d2))); \
} while (0) } while (0)
TEST_IMPL(idna_toascii) { TEST_IMPL(idna_toascii) {

Some files were not shown because too many files have changed in this diff Show More