aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_dir.c
diff options
context:
space:
mode:
authorjuga0 <juga@riseup.net>2018-05-28 14:41:55 +0000
committerjuga0 <juga@riseup.net>2018-07-16 14:43:48 +0000
commite5dd46beabb7f456fcf4456271676bc507886fe5 (patch)
tree7344784e22c181373caf368b588b6ac10f88db31 /src/test/test_dir.c
parent8505522e508c8d2379afbd86154a910948cf8c70 (diff)
downloadtor-e5dd46beabb7f456fcf4456271676bc507886fe5.tar.gz
tor-e5dd46beabb7f456fcf4456271676bc507886fe5.zip
Add the Bandwidth List file headers to votes
* add bwlist_headers argument to dirserv_read_measured_bandwidth in order to store all the headers found when parsing the file * add bwlist_headers to networkstatus_t in order to store the the headers found by the previous function * include the bandwidth headers as string in vote documents * add test to check that dirserv_read_measured_bandwidth generates the bwlist_headers
Diffstat (limited to 'src/test/test_dir.c')
-rw-r--r--src/test/test_dir.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index bda56b3a8e..e44f161547 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -1595,18 +1595,55 @@ test_dir_measured_bw_kb(void *arg)
static void
test_dir_dirserv_read_measured_bandwidths_empty(void *arg)
{
- char *fname=NULL;
(void)arg;
+ char *content = NULL;
+ time_t timestamp = time(NULL);
+ char *fname = tor_strdup(get_fname("V3BandwidthsFile"));
+ smartlist_t *bwlist_headers = smartlist_new();
+ char *bwlist_headers_str = NULL;
+ char *out_bwlist_headers_str = NULL;
- fname = tor_strdup(get_fname("V3BandwidthsFile"));
/* Test an empty file */
write_str_to_file(fname, "", 0);
setup_capture_of_logs(LOG_WARN);
- tt_int_op(-1, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
+ tt_int_op(-1, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL, NULL));
expect_log_msg("Empty bandwidth file\n");
+ /* Test v1.1.0 headers */
+ const char *v110_header_lines=
+ "version=1.1.0\n"
+ "software=sbws\n"
+ "software_version=0.1.0\n"
+ "generator_started=2018-05-08T16:13:25\n"
+ "earliest_bandwidth=2018-05-08T16:13:26\n"
+ "====\n";
+
+ /* And test bwlist_headers generation for dirvote.c */
+ tor_asprintf(&content, "%ld\n%s", timestamp, v110_header_lines);
+ write_str_to_file(fname, content, 0);
+ tor_free(content);
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
+ bwlist_headers));
+
+ /* The bwlist_headers str that should get generated by the previous
+ * v110v110_header_lines */
+ const char *headers_str = "version=1.1.0 software=sbws "
+ "software_version=0.1.0 "
+ "generator_started=2018-05-08T16:13:25 "
+ "earliest_bandwidth=2018-05-08T16:13:26";
+ tor_asprintf(&bwlist_headers_str, "timestamp=%ld %s", timestamp,
+ headers_str);
+ /* Compare the strings */
+ out_bwlist_headers_str = smartlist_join_strings(bwlist_headers, " ",
+ 0, NULL);
+ tt_str_op(bwlist_headers_str, OP_EQ, out_bwlist_headers_str);
+
done:
tor_free(fname);
+ tor_free(bwlist_headers_str);
+ tor_free(out_bwlist_headers_str);
+ SMARTLIST_FOREACH(bwlist_headers, char *, cp, tor_free(cp));
+ smartlist_free(bwlist_headers);
teardown_capture_of_logs();
}