aboutsummaryrefslogtreecommitdiff
path: root/src/test/test.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2013-09-04 23:44:39 -0400
committerRoger Dingledine <arma@torproject.org>2013-09-04 23:44:39 -0400
commit6156887adfa724805f90b3b7cf2be6213f08a450 (patch)
tree0aadbdae3ed165be0b8249a07811feb86a4bf267 /src/test/test.c
parentd5e9573ed24df7c0eb795617de9db2a0c3e40b4d (diff)
parentc6f1668db3010de6aed22bd87850aa846911d43b (diff)
downloadtor-6156887adfa724805f90b3b7cf2be6213f08a450.tar
tor-6156887adfa724805f90b3b7cf2be6213f08a450.tar.gz
Merge branch 'maint-0.2.4'
Conflicts: src/test/test.c
Diffstat (limited to 'src/test/test.c')
-rw-r--r--src/test/test.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/test.c b/src/test/test.c
index f89556356..21d035647 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -41,6 +41,8 @@ long int lround(double x);
double fabs(double x);
#include "or.h"
+#include "buffers.h"
+#include "circuitlist.h"
#include "circuitstats.h"
#include "config.h"
#include "connection_edge.h"
@@ -50,6 +52,7 @@ double fabs(double x);
#include "torgzip.h"
#include "mempool.h"
#include "memarea.h"
+#include "onion.h"
#include "onion_tap.h"
#include "policies.h"
#include "rephist.h"
@@ -401,6 +404,49 @@ test_ntor_handshake(void *arg)
}
#endif
+/** Run unit tests for the onion queues. */
+static void
+test_onion_queues(void)
+{
+ uint8_t buf1[TAP_ONIONSKIN_CHALLENGE_LEN] = {0};
+ uint8_t buf2[NTOR_ONIONSKIN_LEN] = {0};
+
+ or_circuit_t *circ1 = or_circuit_new(0, NULL);
+ or_circuit_t *circ2 = or_circuit_new(0, NULL);
+
+ create_cell_t *onionskin = NULL;
+ create_cell_t *create1 = tor_malloc_zero(sizeof(create_cell_t));
+ create_cell_t *create2 = tor_malloc_zero(sizeof(create_cell_t));
+
+ create_cell_init(create1, CELL_CREATE, ONION_HANDSHAKE_TYPE_TAP,
+ TAP_ONIONSKIN_CHALLENGE_LEN, buf1);
+ create_cell_init(create2, CELL_CREATE, ONION_HANDSHAKE_TYPE_NTOR,
+ NTOR_ONIONSKIN_LEN, buf2);
+
+ test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP));
+ test_eq(0, onion_pending_add(circ1, create1));
+ test_eq(1, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP));
+
+ test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR));
+ test_eq(0, onion_pending_add(circ2, create2));
+ test_eq(1, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR));
+
+ test_eq_ptr(circ2, onion_next_task(&onionskin));
+ test_eq(1, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP));
+ test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR));
+
+ clear_pending_onions();
+ test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP));
+ test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR));
+
+ done:
+ ;
+// circuit_free(circ1);
+// circuit_free(circ2);
+ /* and free create1 and create2 */
+ /* XXX leaks everything here */
+}
+
static void
test_circuit_timeout(void)
{
@@ -1541,6 +1587,7 @@ const struct testcase_setup_t legacy_setup = {
static struct testcase_t test_array[] = {
ENT(onion_handshake),
{ "bad_onion_handshake", test_bad_onion_handshake, 0, NULL, NULL },
+ ENT(onion_queues),
#ifdef CURVE25519_ENABLED
{ "ntor_handshake", test_ntor_handshake, 0, NULL, NULL },
#endif