Skip to content

Commit

Permalink
test: move loop cleanup code to the individual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Oct 16, 2012
1 parent 28eb619 commit 47eb034
Show file tree
Hide file tree
Showing 70 changed files with 187 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/benchmark-async-pummel.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static int test_async_pummel(int nthreads) {
fmt(callbacks / (time / 1e9)));

free(tids);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions test/benchmark-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static int test_async(int nthreads) {

free(threads);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions test/benchmark-fs-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@ BENCHMARK_IMPL(fs_stat) {
warmup(path);
sync_bench(path);
async_bench(path);
MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/benchmark-getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ BENCHMARK_IMPL(getaddrinfo) {
LOGF("getaddrinfo: %.0f req/s\n",
(double) calls_completed / (double) (end_time - start_time) * 1000.0);

MAKE_VALGRIND_HAPPY();
return 0;
}
2 changes: 2 additions & 0 deletions test/benchmark-loop-count.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ BENCHMARK_IMPL(loop_count) {
ns / 1e9,
NUM_TICKS / (ns / 1e9));

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand All @@ -84,5 +85,6 @@ BENCHMARK_IMPL(loop_count_timed) {

LOGF("loop_count: %lu ticks (%.0f ticks/s)\n", ticks, ticks / 5.0);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/benchmark-million-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ BENCHMARK_IMPL(million_timers) {

LOGF("%.2f seconds\n", (after - before) / 1e9);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/benchmark-multi-accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ static int test_tcp(unsigned int num_servers, unsigned int num_clients) {
free(clients);
free(servers);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions test/benchmark-ping-pongs.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,6 @@ BENCHMARK_IMPL(ping_pongs) {

ASSERT(completed_pingers == 1);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/benchmark-pound.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ static int pound_it(int concurrency,
closed_streams / secs,
conns_failed);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions test/benchmark-pump.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ HELPER_IMPL(pipe_pump_server) {

uv_run(loop);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand All @@ -421,6 +422,8 @@ void tcp_pump(int n) {
maybe_connect_some();

uv_run(loop);

MAKE_VALGRIND_HAPPY();
}


Expand All @@ -435,6 +438,8 @@ void pipe_pump(int n) {
maybe_connect_some();

uv_run(loop);

MAKE_VALGRIND_HAPPY();
}


Expand Down
1 change: 1 addition & 0 deletions test/benchmark-spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,6 @@ BENCHMARK_IMPL(spawn) {
LOGF("spawn: %.0f spawns/s\n",
(double) N / (double) (end_time - start_time) * 1000.0);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/benchmark-tcp-write-batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@ BENCHMARK_IMPL(tcp_write_batch) {
(long)NUM_WRITE_REQS,
(stop - start) / 1e9);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/benchmark-udp-pummel.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ static int do_packet_storm(int n_senders,
send_cb_called,
duration / 1000.0);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down
1 change: 0 additions & 1 deletion test/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ int run_test_part(const char* test, const char* part) {
if (strcmp(test, task->task_name) == 0 &&
strcmp(part, task->process_name) == 0) {
r = task->main();
uv_loop_delete(uv_default_loop());
return r;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ typedef enum {
} \
} while (0)

/* This macro cleans up the main loop. This is used to avoid valgrind
* warnings about memory being "leaked" by the main event loop.
*/
#define MAKE_VALGRIND_HAPPY() \
uv_loop_delete(uv_default_loop())

/* Just sugar for wrapping the main() for a task or helper. */
#define TEST_IMPL(name) \
Expand Down
1 change: 1 addition & 0 deletions test/test-active.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ TEST_IMPL(active) {

ASSERT(close_cb_called == 1);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/test-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ TEST_IMPL(async) {

ASSERT(0 == uv_thread_join(&thread));

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/test-callback-order.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ TEST_IMPL(callback_order) {
ASSERT(idle_cb_called == 1);
ASSERT(timer_cb_called == 1);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/test-callback-stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ TEST_IMPL(callback_stack) {
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;
}
2 changes: 2 additions & 0 deletions test/test-connection-fail.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ TEST_IMPL(connection_fail) {
ASSERT(timer_close_cb_calls == 0);
ASSERT(timer_cb_calls == 0);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand All @@ -144,5 +145,6 @@ TEST_IMPL(connection_fail_doesnt_auto_close) {
ASSERT(timer_close_cb_calls == 1);
ASSERT(timer_cb_calls == 1);

MAKE_VALGRIND_HAPPY();
return 0;
}
1 change: 1 addition & 0 deletions test/test-delayed-accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,6 @@ TEST_IMPL(delayed_accept) {
ASSERT(connect_cb_called == 2);
ASSERT(close_cb_called == 7);

MAKE_VALGRIND_HAPPY();
return 0;
}
8 changes: 8 additions & 0 deletions test/test-fs-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ TEST_IMPL(fs_event_watch_dir) {
remove("watch_dir/file1");
remove("watch_dir/");

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down Expand Up @@ -234,6 +235,7 @@ TEST_IMPL(fs_event_watch_file) {
remove("watch_dir/file1");
remove("watch_dir/");

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand All @@ -252,6 +254,7 @@ TEST_IMPL(fs_event_watch_file_twice) {
ASSERT(0 == uv_timer_start(&timer, timer_cb_watch_twice, 10, 0));
ASSERT(0 == uv_run(loop));

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down Expand Up @@ -289,6 +292,7 @@ TEST_IMPL(fs_event_watch_file_current_dir) {
/* Cleanup */
remove("watch_file");

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down Expand Up @@ -321,6 +325,7 @@ TEST_IMPL(fs_event_no_callback_on_close) {
remove("watch_dir/file1");
remove("watch_dir/");

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down Expand Up @@ -361,6 +366,7 @@ TEST_IMPL(fs_event_immediate_close) {

ASSERT(close_cb_called == 2);

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down Expand Up @@ -390,6 +396,7 @@ TEST_IMPL(fs_event_close_with_pending_event) {
remove("watch_dir/file");
remove("watch_dir/");

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down Expand Up @@ -455,6 +462,7 @@ TEST_IMPL(fs_event_close_in_callback) {
remove("watch_dir/file5");
remove("watch_dir/");

MAKE_VALGRIND_HAPPY();
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions test/test-fs-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ TEST_IMPL(fs_poll) {
ASSERT(timer_cb_called == 2);
ASSERT(close_cb_called == 1);

MAKE_VALGRIND_HAPPY();
return 0;
}
Loading

0 comments on commit 47eb034

Please sign in to comment.