diff options
author | Andrea Shepard <andrea@torproject.org> | 2013-12-18 17:07:54 -0800 |
---|---|---|
committer | Andrea Shepard <andrea@torproject.org> | 2014-09-30 23:09:00 -0700 |
commit | ba294ff2dcdbf75c49a478cd9f0ad20fc0ad4b50 (patch) | |
tree | ee167c532f06fed14cef33a4ba6cf3e8584f6c88 /src | |
parent | 37baef0687e4bef0cfadf927bfbc832a59de32f4 (diff) | |
download | tor-ba294ff2dcdbf75c49a478cd9f0ad20fc0ad4b50.tar.gz tor-ba294ff2dcdbf75c49a478cd9f0ad20fc0ad4b50.zip |
Implement channel flush unit test
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test_channel.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/test_channel.c b/src/test/test_channel.c index c47d2925b4..9e6ef17502 100644 --- a/src/test/test_channel.c +++ b/src/test/test_channel.c @@ -37,6 +37,7 @@ static channel_t * new_fake_channel(void); static void scheduler_channel_doesnt_want_writes_mock(channel_t *ch); static void scheduler_release_channel_mock(channel_t *ch); +static void test_channel_flush(void *arg); static void test_channel_lifecycle(void *arg); static void test_channel_multi(void *arg); static void test_channel_queue_size(void *arg); @@ -217,6 +218,65 @@ scheduler_release_channel_mock(channel_t *ch) } static void +test_channel_flush(void *arg) +{ + channel_t *ch = NULL; + cell_t *cell = NULL; + packed_cell_t *p_cell = NULL; + var_cell_t *v_cell = NULL; + int init_count; + + (void)arg; + + init_cell_pool(); + + ch = new_fake_channel(); + test_assert(ch); + + /* Cache the original count */ + init_count = test_cells_written; + + /* Stop accepting so we can queue some */ + test_chan_accept_cells = 0; + + /* Queue a regular cell */ + cell = tor_malloc_zero(sizeof(cell_t)); + make_fake_cell(cell); + channel_write_cell(ch, cell); + /* It should be queued, so assert that we didn't write it */ + test_eq(test_cells_written, init_count); + + /* Queue a var cell */ + v_cell = tor_malloc_zero(sizeof(var_cell_t) + CELL_PAYLOAD_SIZE); + make_fake_var_cell(v_cell); + channel_write_var_cell(ch, v_cell); + /* It should be queued, so assert that we didn't write it */ + test_eq(test_cells_written, init_count); + + /* Try a packed cell now */ + p_cell = packed_cell_new(); + test_assert(p_cell); + channel_write_packed_cell(ch, p_cell); + /* It should be queued, so assert that we didn't write it */ + test_eq(test_cells_written, init_count); + + /* Now allow writes through again */ + test_chan_accept_cells = 1; + + /* ...and flush */ + channel_flush_cells(ch); + + /* All three should have gone through */ + test_eq(test_cells_written, init_count + 3); + + done: + tor_free(ch); + free_cell_pool(); + + return; +} + +static void test_channel_lifecycle(void *arg) { channel_t *ch1 = NULL, *ch2 = NULL; @@ -676,6 +736,7 @@ test_channel_write(void *arg) } struct testcase_t channel_tests[] = { + { "flush", test_channel_flush, TT_FORK, NULL, NULL }, { "lifecycle", test_channel_lifecycle, TT_FORK, NULL, NULL }, { "multi", test_channel_multi, TT_FORK, NULL, NULL }, { "queue_size", test_channel_queue_size, TT_FORK, NULL, NULL }, |