Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 29, 2011
1 parent e53d125 commit 72d8d76
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 1 deletion.
33 changes: 33 additions & 0 deletions test/run-tests.c
Expand Up @@ -24,6 +24,7 @@

#include "runner.h"
#include "task.h"
#include "uv.h"

/* Actual tests and helpers are defined in test-list.h */
#include "test-list.h"
Expand All @@ -48,12 +49,44 @@ int main(int argc, char **argv) {
}


static int ipc_helper() {
/*
* This is launched from test-ipc.c. stdin is a duplex channel that we
* over which a handle will be transmitted. In this initial version only
* data is transfered over the channel. XXX edit this comment after handle
* transfer is added.
*/
uv_pipe_t channel;
uv_write_t write_req;
int r;
uv_buf_t buf;

r = uv_pipe_init(uv_default_loop(), &channel);
ASSERT(r == 0);

uv_pipe_open(&channel, 0);

buf = uv_buf_init("hello\n", 6);
r = uv_write(&write_req, (uv_stream_t*)&channel, &buf, 1, NULL);
ASSERT(r == 0);

r = uv_run(uv_default_loop());
ASSERT(r == 0);

return 0;
}


static int maybe_run_test(int argc, char **argv) {
if (strcmp(argv[1], "--list") == 0) {
print_tests(stdout);
return 0;
}

if (strcmp(argv[1], "ipc_helper") == 0) {
return ipc_helper();
}

if (strcmp(argv[1], "spawn_helper1") == 0) {
return 1;
}
Expand Down
93 changes: 93 additions & 0 deletions test/test-ipc.c
@@ -0,0 +1,93 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "uv.h"
#include "task.h"

#include <string.h>

static char exepath[1024];
static size_t exepath_size = 1024;
static char* args[3];
static uv_pipe_t channel;

static int exit_cb_called;


static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
printf("exit_cb\n");
exit_cb_called++;
ASSERT(exit_status == 1);
ASSERT(term_signal == 0);
uv_close((uv_handle_t*)process, NULL);
}


static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
return uv_buf_init(malloc(suggested_size), suggested_size);
}


static void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) {
/* listen on the handle provided.... */

printf("got %d bytes\n", (int)nread);

if (buf.base) {
free(buf.base);
}
}


TEST_IMPL(ipc) {
int r;
uv_process_options_t options;
uv_process_t process;

r = uv_pipe_init(uv_default_loop(), &channel);
ASSERT(r == 0);

memset(&options, 0, sizeof(uv_process_options_t));

r = uv_exepath(exepath, &exepath_size);
ASSERT(r == 0);
exepath[exepath_size] = '\0';
args[0] = exepath;
args[1] = "ipc_helper";
args[2] = NULL;
options.file = exepath;
options.args = args;
options.exit_cb = exit_cb;
options.stdin_stream = &channel;
options.stdout_stream = NULL;
options.stderr_stream = NULL;

r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);

uv_read_start((uv_stream_t*)&channel, on_alloc, on_read);

r = uv_run(uv_default_loop());
ASSERT(r == 0);

ASSERT(exit_cb_called == 1);
return 0;
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -20,6 +20,7 @@
*/

TEST_DECLARE (tty)
TEST_DECLARE (ipc)
TEST_DECLARE (tcp_ping_pong)
TEST_DECLARE (tcp_ping_pong_v6)
TEST_DECLARE (tcp_ref)
Expand Down Expand Up @@ -108,6 +109,7 @@ HELPER_DECLARE (pipe_echo_server)

TASK_LIST_START
TEST_ENTRY (tty)
TEST_ENTRY (ipc)


TEST_ENTRY (tcp_ref)
Expand Down
2 changes: 1 addition & 1 deletion test/test-spawn.c
Expand Up @@ -67,7 +67,7 @@ static void kill_cb(uv_process_t* process, int exit_status, int term_signal) {
}


uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
uv_buf_t buf;
buf.base = output + output_used;
buf.len = OUTPUT_SIZE - output_used;
Expand Down

0 comments on commit 72d8d76

Please sign in to comment.