summaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-08-14 17:12:05 -0400
committerNick Mathewson <nickm@torproject.org>2009-08-14 17:12:05 -0400
commitb9e45cc508b6fbf596e1ba40761e11d0629a3291 (patch)
tree7d099a8223b0527cb500bd634f36af33e85fa5dd /src/or/test.c
parente0dc2e907eb029bd4e3d7933ef72f3ff942a9b81 (diff)
parent9e1fe29bebf57fc38975c552eefaa9cb97dd5c68 (diff)
downloadtor-b9e45cc508b6fbf596e1ba40761e11d0629a3291.tar.gz
tor-b9e45cc508b6fbf596e1ba40761e11d0629a3291.zip
Merge commit 'mikeperry/bandwidth-voting-final'
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index dffb0a5ade..b86ced723a 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -3232,6 +3232,72 @@ test_dirutil(void)
smartlist_free(sl);
}
+static void
+test_dirutil_measured_bw(void)
+{
+ measured_bw_line_t mbwl;
+ int i;
+ const char *lines_pass[] = {
+ "node_id=$557365204145532d32353620696e73746561642e bw=1024\n",
+ "node_id=$557365204145532d32353620696e73746561642e\t bw=1024 \n",
+ " node_id=$557365204145532d32353620696e73746561642e bw=1024\n",
+ "\tnoise\tnode_id=$557365204145532d32353620696e73746561642e "
+ "bw=1024 junk=007\n",
+ "misc=junk node_id=$557365204145532d32353620696e73746561642e "
+ "bw=1024 junk=007\n",
+ "end"
+ };
+ const char *lines_fail[] = {
+ /* Test possible python stupidity on input */
+ "node_id=None bw=1024\n",
+ "node_id=$None bw=1024\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=None\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=1024.0\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=.1024\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=1.024\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=1024 bw=0\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=1024 bw=None\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=-1024\n",
+ /* Test incomplete writes due to race conditions, partial copies, etc */
+ "node_i",
+ "node_i\n",
+ "node_id=",
+ "node_id=\n",
+ "node_id=$557365204145532d32353620696e73746561642e bw=",
+ "node_id=$557365204145532d32353620696e73746561642e bw=1024",
+ "node_id=$557365204145532d32353620696e73746561642e bw=\n",
+ "node_id=$557365204145532d32353620696e7374",
+ "node_id=$557365204145532d32353620696e7374\n",
+ "",
+ "\n",
+ " \n ",
+ " \n\n",
+ /* Test assorted noise */
+ " node_id= ",
+ "node_id==$557365204145532d32353620696e73746561642e bw==1024\n",
+ "node_id=$55736520414552d32353620696e73746561642e bw=1024\n",
+ "node_id=557365204145532d32353620696e73746561642e bw=1024\n",
+ "node_id= $557365204145532d32353620696e73746561642e bw=0.23\n",
+ "end"
+ };
+
+ for (i = 0; strcmp(lines_fail[i], "end"); i++) {
+ //fprintf(stderr, "Testing: %s\n", lines_fail[i]);
+ test_assert(measured_bw_line_parse(&mbwl, lines_fail[i]) == -1);
+ }
+
+ for (i = 0; strcmp(lines_pass[i], "end"); i++) {
+ //fprintf(stderr, "Testing: %s %d\n", lines_pass[i], TOR_ISSPACE('\n'));
+ test_assert(measured_bw_line_parse(&mbwl, lines_pass[i]) == 0);
+ test_assert(mbwl.bw == 1024);
+ test_assert(strcmp(mbwl.node_hex,
+ "557365204145532d32353620696e73746561642e") == 0);
+ }
+
+done:
+ return;
+}
+
extern const char AUTHORITY_CERT_1[];
extern const char AUTHORITY_SIGNKEY_1[];
extern const char AUTHORITY_CERT_2[];
@@ -3512,6 +3578,17 @@ test_v3_networkstatus(void)
test_eq(rs->dir_port, 0);
test_eq(vrs->flags, U64_LITERAL(254)); // all flags except "authority."
+ {
+ measured_bw_line_t mbw;
+ memset(mbw.node_id, 33, sizeof(mbw.node_id));
+ mbw.bw = 1024;
+ test_assert(measured_bw_line_apply(&mbw,
+ v1->routerstatus_list) == 1);
+ vrs = smartlist_get(v1->routerstatus_list, 2);
+ test_assert(vrs->status.has_measured_bw &&
+ vrs->status.measured_bw == 1024);
+ }
+
/* Generate second vote. It disagrees on some of the times,
* and doesn't list versions, and knows some crazy flags */
vote->published = now+1;
@@ -4284,6 +4361,39 @@ test_util_datadir(void)
tor_free(f);
}
+static void
+test_util_strtok(void)
+{
+ char buf[128];
+ char buf2[128];
+ char *cp1, *cp2;
+ strlcpy(buf, "Graved on the dark in gestures of descent", sizeof(buf));
+ strlcpy(buf2, "they.seemed;their!own;most.perfect;monument", sizeof(buf2));
+ /* -- "Year's End", Richard Wilbur */
+
+ test_streq("Graved", tor_strtok_r_impl(buf, " ", &cp1));
+ test_streq("they", tor_strtok_r_impl(buf2, ".!..;!", &cp2));
+#define S1() tor_strtok_r_impl(NULL, " ", &cp1)
+#define S2() tor_strtok_r_impl(NULL, ".!..;!", &cp2)
+ test_streq("on", S1());
+ test_streq("the", S1());
+ test_streq("dark", S1());
+ test_streq("seemed", S2());
+ test_streq("their", S2());
+ test_streq("own", S2());
+ test_streq("in", S1());
+ test_streq("gestures", S1());
+ test_streq("of", S1());
+ test_streq("most", S2());
+ test_streq("perfect", S2());
+ test_streq("descent", S1());
+ test_streq("monument", S2());
+ test_assert(NULL == S1());
+ test_assert(NULL == S2());
+ done:
+ ;
+}
+
/** Test AES-CTR encryption and decryption with IV. */
static void
test_crypto_aes_iv(void)
@@ -4692,9 +4802,11 @@ static struct {
SUBENT(util, threads),
SUBENT(util, order_functions),
SUBENT(util, sscanf),
+ SUBENT(util, strtok),
ENT(onion_handshake),
ENT(dir_format),
ENT(dirutil),
+ SUBENT(dirutil, measured_bw),
ENT(v3_networkstatus),
ENT(policies),
ENT(rend_fns),