aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_stats.c
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-10-31 16:20:33 +1000
committerteor <teor@torproject.org>2019-11-05 10:50:39 +1000
commit5d85c247e8d28726402eaa51eb0e48ea7a1b6d7b (patch)
tree0518ec75635b466b87a591df275447c4b527d990 /src/test/test_stats.c
parent5d0848ebde298d42c104ae20c78f2eefd0a6d73a (diff)
downloadtor-5d85c247e8d28726402eaa51eb0e48ea7a1b6d7b.tar.gz
tor-5d85c247e8d28726402eaa51eb0e48ea7a1b6d7b.zip
test/stats: Add minimal tests for rephist mtbf
Part of 32213.
Diffstat (limited to 'src/test/test_stats.c')
-rw-r--r--src/test/test_stats.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/test/test_stats.c b/src/test/test_stats.c
index 0697cb27bb..64e723c706 100644
--- a/src/test/test_stats.c
+++ b/src/test/test_stats.c
@@ -42,7 +42,7 @@
#include "feature/stats/rephist.h"
#include "app/config/statefile.h"
-/** Run unit tests for stats code. */
+/** Run unit tests for some stats code. */
static void
test_stats(void *arg)
{
@@ -202,6 +202,49 @@ test_stats(void *arg)
tor_free(s);
}
+/** Run unit tests the mtbf stats code. */
+static void
+test_rephist_mtbf(void *arg)
+{
+ (void)arg;
+
+ time_t now = 1572500000; /* 2010-10-31 05:33:20 UTC */
+ time_t far_future = MAX(now, time(NULL)) + 365*24*60*60;
+ int r;
+
+ /* Make a temporary datadir for these tests */
+ char *ddir_fname = tor_strdup(get_fname_rnd("datadir_mtbf"));
+ tor_free(get_options_mutable()->DataDirectory);
+ get_options_mutable()->DataDirectory = tor_strdup(ddir_fname);
+ check_private_dir(ddir_fname, CPD_CREATE, NULL);
+
+ rep_history_clean(far_future);
+
+ /* No data */
+
+ r = rep_hist_load_mtbf_data(now);
+ tt_int_op(r, OP_EQ, -1);
+ rep_history_clean(far_future);
+
+ /* Blank data */
+
+ r = rep_hist_record_mtbf_data(now, 0);
+ tt_int_op(r, OP_EQ, 0);
+ r = rep_hist_load_mtbf_data(now);
+ tt_int_op(r, OP_EQ, 0);
+ rep_history_clean(far_future);
+
+ r = rep_hist_record_mtbf_data(now, 1);
+ tt_int_op(r, OP_EQ, 0);
+ r = rep_hist_load_mtbf_data(now);
+ tt_int_op(r, OP_EQ, 0);
+ rep_history_clean(far_future);
+
+ done:
+ rep_history_clean(far_future);
+ tor_free(ddir_fname);
+}
+
#define ENT(name) \
{ #name, test_ ## name , 0, NULL, NULL }
#define FORK(name) \
@@ -209,6 +252,7 @@ test_stats(void *arg)
struct testcase_t stats_tests[] = {
FORK(stats),
+ ENT(rephist_mtbf),
END_OF_TESTCASES
};