[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Expose fake channel utility functions in test suite in fakechans.h, and fix a test_channel.c bug



commit 79b8f14c25ecbb4cda8fe587f18694dedd3ee9c0
Author: Andrea Shepard <andrea@xxxxxxxxxxxxxx>
Date:   Tue Jan 21 00:46:57 2014 -0800

    Expose fake channel utility functions in test suite in fakechans.h, and fix a test_channel.c bug
---
 src/test/fakechans.h    |   16 ++++++++++++++++
 src/test/test_channel.c |   35 +++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/src/test/fakechans.h b/src/test/fakechans.h
new file mode 100644
index 0000000..b474810
--- /dev/null
+++ b/src/test/fakechans.h
@@ -0,0 +1,16 @@
+ /* Copyright (c) 2014, The Tor Project, Inc. */
+ /* See LICENSE for licensing information */
+
+#ifndef TOR_FAKECHANS_H
+#define TOR_FAKECHANS_H
+
+/**
+ * \file fakechans.h
+ * \brief Declarations for fake channels for test suite use
+ */
+
+void make_fake_cell(cell_t *c);
+void make_fake_var_cell(var_cell_t *c);
+channel_t * new_fake_channel(void);
+
+#endif /* !defined(TOR_FAKECHANS_H) */
diff --git a/src/test/test_channel.c b/src/test/test_channel.c
index 9e6ef17..1ab7f32 100644
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@ -13,7 +13,10 @@
 #include "relay.h"
 /* For init/free stuff */
 #include "scheduler.h"
+
+/* Test suite stuff */
 #include "test.h"
+#include "fakechans.h"
 
 static int test_chan_accept_cells = 0;
 static int test_cells_written = 0;
@@ -31,9 +34,6 @@ static int chan_test_write_cell(channel_t *ch, cell_t *cell);
 static int chan_test_write_packed_cell(channel_t *ch,
                                        packed_cell_t *packed_cell);
 static int chan_test_write_var_cell(channel_t *ch, var_cell_t *var_cell);
-static void make_fake_cell(cell_t *c);
-static void make_fake_var_cell(var_cell_t *c);
-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);
 
@@ -150,7 +150,11 @@ chan_test_write_var_cell(channel_t *ch, var_cell_t *var_cell)
   return rv;
 }
 
-static void
+/**
+ * Fill out c with a new fake cell for test suite use
+ */
+
+void
 make_fake_cell(cell_t *c)
 {
   test_assert(c != NULL);
@@ -163,7 +167,11 @@ make_fake_cell(cell_t *c)
   return;
 }
 
-static void
+/**
+ * Fill out c with a new fake var_cell for test suite use
+ */
+
+void
 make_fake_var_cell(var_cell_t *c)
 {
   test_assert(c != NULL);
@@ -177,7 +185,11 @@ make_fake_var_cell(var_cell_t *c)
   return;
 }
 
-static channel_t *
+/**
+ * Set up a new fake channel for the test suite
+ */
+
+channel_t *
 new_fake_channel(void)
 {
   channel_t *chan = tor_malloc_zero(sizeof(channel_t));
@@ -492,6 +504,17 @@ test_channel_multi(void *arg)
   global_queue_estimate = channel_get_global_queue_estimate();
   test_eq(global_queue_estimate, 512);
 
+  /*
+   * Since the fake channels aren't registered, channel_free_all() can't
+   * see them properly.
+   */
+  MOCK(scheduler_release_channel, scheduler_release_channel_mock);
+  channel_mark_for_close(ch1);
+  UNMOCK(scheduler_release_channel);
+
+  global_queue_estimate = channel_get_global_queue_estimate();
+  test_eq(global_queue_estimate, 0);
+
   /* Now free everything */
   MOCK(scheduler_release_channel, scheduler_release_channel_mock);
   channel_free_all();



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits