aboutsummaryrefslogtreecommitdiff
path: root/third-party/libuv/test/test-callback-stack.c
diff options
context:
space:
mode:
authorJohn Szakmeister <john@szakmeister.net>2014-03-03 10:09:06 -0500
committerJohn Szakmeister <john@szakmeister.net>2014-03-21 15:22:00 -0400
commit0b2f6a0cf4c50d86744b1d3d774103db39773b4c (patch)
tree7bbc6275200f2c42ba20bf0a910c2b92fbdc4a50 /third-party/libuv/test/test-callback-stack.c
parent5dd0ce4263721b636f5b006a47ceb7e769e10dca (diff)
downloadrneovim-0b2f6a0cf4c50d86744b1d3d774103db39773b4c.tar.gz
rneovim-0b2f6a0cf4c50d86744b1d3d774103db39773b4c.tar.bz2
rneovim-0b2f6a0cf4c50d86744b1d3d774103db39773b4c.zip
Revamp the build system.
This achieves several goals: * Less reliance on scripts so we have better portability to Windows (though we still have a ways to go for proper Windows support). Luajit, luarocks, moonscript, and busted are all installed via CMake now. * Trying to make use of pkg-config to get the correct libraries. The latest libuv is still broken in this regard, but we'll at least be in a position to use it. * Allow the use of Ninja or make. The former runs faster in many environments, and automatically makes use of parallel builds. This also allows for system installed dependencies--though not through the Makefile just yet--and adds support for FreeBSD. This also make us build libuv and luajit as static libraries only, since we're only concerned about having static libraries for our bundled dependencies.
Diffstat (limited to 'third-party/libuv/test/test-callback-stack.c')
-rw-r--r--third-party/libuv/test/test-callback-stack.c206
1 files changed, 0 insertions, 206 deletions
diff --git a/third-party/libuv/test/test-callback-stack.c b/third-party/libuv/test/test-callback-stack.c
deleted file mode 100644
index accd549697..0000000000
--- a/third-party/libuv/test/test-callback-stack.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-/*
- * TODO: Add explanation of why we want on_close to be called from fresh
- * stack.
- */
-
-#include "uv.h"
-#include "task.h"
-
-
-static const char MESSAGE[] = "Failure is for the weak. Everyone dies alone.";
-
-static uv_tcp_t client;
-static uv_timer_t timer;
-static uv_connect_t connect_req;
-static uv_write_t write_req;
-static uv_shutdown_t shutdown_req;
-
-static int nested = 0;
-static int close_cb_called = 0;
-static int connect_cb_called = 0;
-static int write_cb_called = 0;
-static int timer_cb_called = 0;
-static int bytes_received = 0;
-static int shutdown_cb_called = 0;
-
-
-static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
- buf->len = size;
- buf->base = malloc(size);
- ASSERT(buf->base != NULL);
-}
-
-
-static void close_cb(uv_handle_t* handle) {
- ASSERT(nested == 0 && "close_cb must be called from a fresh stack");
-
- close_cb_called++;
-}
-
-
-static void shutdown_cb(uv_shutdown_t* req, int status) {
- ASSERT(status == 0);
- ASSERT(nested == 0 && "shutdown_cb must be called from a fresh stack");
-
- shutdown_cb_called++;
-}
-
-
-static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
- ASSERT(nested == 0 && "read_cb must be called from a fresh stack");
-
- printf("Read. nread == %d\n", (int)nread);
- free(buf->base);
-
- if (nread == 0) {
- return;
-
- } else if (nread < 0) {
- ASSERT(nread == UV_EOF);
-
- nested++;
- uv_close((uv_handle_t*)tcp, close_cb);
- nested--;
-
- return;
- }
-
- bytes_received += nread;
-
- /* We call shutdown here because when bytes_received == sizeof MESSAGE */
- /* there will be no more data sent nor received, so here it would be */
- /* possible for a backend to to call shutdown_cb immediately and *not* */
- /* from a fresh stack. */
- if (bytes_received == sizeof MESSAGE) {
- nested++;
-
- puts("Shutdown");
-
- if (uv_shutdown(&shutdown_req, (uv_stream_t*)tcp, shutdown_cb)) {
- FATAL("uv_shutdown failed");
- }
- nested--;
- }
-}
-
-
-static void timer_cb(uv_timer_t* handle, int status) {
- ASSERT(handle == &timer);
- ASSERT(status == 0);
- ASSERT(nested == 0 && "timer_cb must be called from a fresh stack");
-
- puts("Timeout complete. Now read data...");
-
- nested++;
- if (uv_read_start((uv_stream_t*)&client, alloc_cb, read_cb)) {
- FATAL("uv_read_start failed");
- }
- nested--;
-
- timer_cb_called++;
-
- uv_close((uv_handle_t*)handle, close_cb);
-}
-
-
-static void write_cb(uv_write_t* req, int status) {
- int r;
-
- ASSERT(status == 0);
- ASSERT(nested == 0 && "write_cb must be called from a fresh stack");
-
- puts("Data written. 500ms timeout...");
-
- /* After the data has been sent, we're going to wait for a while, then */
- /* start reading. This makes us certain that the message has been echoed */
- /* back to our receive buffer when we start reading. This maximizes the */
- /* temptation for the backend to use dirty stack for calling read_cb. */
- nested++;
- r = uv_timer_init(uv_default_loop(), &timer);
- ASSERT(r == 0);
- r = uv_timer_start(&timer, timer_cb, 500, 0);
- ASSERT(r == 0);
- nested--;
-
- write_cb_called++;
-}
-
-
-static void connect_cb(uv_connect_t* req, int status) {
- uv_buf_t buf;
-
- puts("Connected. Write some data to echo server...");
-
- ASSERT(status == 0);
- ASSERT(nested == 0 && "connect_cb must be called from a fresh stack");
-
- nested++;
-
- buf.base = (char*) &MESSAGE;
- buf.len = sizeof MESSAGE;
-
- if (uv_write(&write_req, (uv_stream_t*)req->handle, &buf, 1, write_cb)) {
- FATAL("uv_write failed");
- }
-
- nested--;
-
- connect_cb_called++;
-}
-
-
-TEST_IMPL(callback_stack) {
- struct sockaddr_in addr;
-
- ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
-
- if (uv_tcp_init(uv_default_loop(), &client)) {
- FATAL("uv_tcp_init failed");
- }
-
- puts("Connecting...");
-
- nested++;
-
- if (uv_tcp_connect(&connect_req,
- &client,
- (const struct sockaddr*) &addr,
- connect_cb)) {
- FATAL("uv_tcp_connect failed");
- }
- nested--;
-
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
-
- ASSERT(nested == 0);
- ASSERT(connect_cb_called == 1 && "connect_cb must be called exactly once");
- ASSERT(write_cb_called == 1 && "write_cb must be called exactly once");
- ASSERT(timer_cb_called == 1 && "timer_cb must be called exactly once");
- ASSERT(bytes_received == sizeof MESSAGE);
- ASSERT(shutdown_cb_called == 1 && "shutdown_cb must be called exactly once");
- ASSERT(close_cb_called == 2 && "close_cb must be called exactly twice");
-
- MAKE_VALGRIND_HAPPY();
- return 0;
-}