diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-04-13 10:51:59 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-04-13 10:54:26 -0400 |
commit | 03b96882deb60cd21c3c77746f4f9cd4aac0a724 (patch) | |
tree | dc9f65dc453aa4d0eb468e74880fded889f4bd8e /src/test/test_bwmgt.c | |
parent | b152d62cee7480ee7b9b68dd9b619db65b6cd112 (diff) | |
download | tor-03b96882deb60cd21c3c77746f4f9cd4aac0a724.tar.gz tor-03b96882deb60cd21c3c77746f4f9cd4aac0a724.zip |
Rename token_bucket_t to token_bucket_rw_t.
This is a simple search-and-replace to rename the token bucket type
to indicate that it contains both a read and a write bucket, bundled
with their configuration. It's preliminary to refactoring the
bucket type.
Diffstat (limited to 'src/test/test_bwmgt.c')
-rw-r--r-- | src/test/test_bwmgt.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/test/test_bwmgt.c b/src/test/test_bwmgt.c index 1a54f44fc4..9e4748af7f 100644 --- a/src/test/test_bwmgt.c +++ b/src/test/test_bwmgt.c @@ -21,9 +21,9 @@ static void test_bwmgt_token_buf_init(void *arg) { (void)arg; - token_bucket_t b; + token_bucket_rw_t b; - token_bucket_init(&b, 16*KB, 64*KB, START_TS); + token_bucket_rw_init(&b, 16*KB, 64*KB, START_TS); // Burst is correct tt_uint_op(b.burst, OP_EQ, 64*KB); // Rate is correct, within 1 percent. @@ -47,31 +47,31 @@ static void test_bwmgt_token_buf_adjust(void *arg) { (void)arg; - token_bucket_t b; + token_bucket_rw_t b; - token_bucket_init(&b, 16*KB, 64*KB, START_TS); + token_bucket_rw_init(&b, 16*KB, 64*KB, START_TS); uint32_t rate_orig = b.rate; // Increasing burst - token_bucket_adjust(&b, 16*KB, 128*KB); + token_bucket_rw_adjust(&b, 16*KB, 128*KB); tt_uint_op(b.rate, OP_EQ, rate_orig); tt_uint_op(b.read_bucket, OP_EQ, 64*KB); tt_uint_op(b.burst, OP_EQ, 128*KB); // Decreasing burst but staying above bucket - token_bucket_adjust(&b, 16*KB, 96*KB); + token_bucket_rw_adjust(&b, 16*KB, 96*KB); tt_uint_op(b.rate, OP_EQ, rate_orig); tt_uint_op(b.read_bucket, OP_EQ, 64*KB); tt_uint_op(b.burst, OP_EQ, 96*KB); // Decreasing burst below bucket, - token_bucket_adjust(&b, 16*KB, 48*KB); + token_bucket_rw_adjust(&b, 16*KB, 48*KB); tt_uint_op(b.rate, OP_EQ, rate_orig); tt_uint_op(b.read_bucket, OP_EQ, 48*KB); tt_uint_op(b.burst, OP_EQ, 48*KB); // Changing rate. - token_bucket_adjust(&b, 32*KB, 48*KB); + token_bucket_rw_adjust(&b, 32*KB, 48*KB); tt_uint_op(b.rate, OP_GE, rate_orig*2 - 10); tt_uint_op(b.rate, OP_LE, rate_orig*2 + 10); tt_uint_op(b.read_bucket, OP_EQ, 48*KB); @@ -85,33 +85,33 @@ static void test_bwmgt_token_buf_dec(void *arg) { (void)arg; - token_bucket_t b; - token_bucket_init(&b, 16*KB, 64*KB, START_TS); + token_bucket_rw_t b; + token_bucket_rw_init(&b, 16*KB, 64*KB, START_TS); // full-to-not-full. - tt_int_op(0, OP_EQ, token_bucket_dec_read(&b, KB)); + tt_int_op(0, OP_EQ, token_bucket_rw_dec_read(&b, KB)); tt_int_op(b.read_bucket, OP_EQ, 63*KB); // Full to almost-not-full - tt_int_op(0, OP_EQ, token_bucket_dec_read(&b, 63*KB - 1)); + tt_int_op(0, OP_EQ, token_bucket_rw_dec_read(&b, 63*KB - 1)); tt_int_op(b.read_bucket, OP_EQ, 1); // almost-not-full to empty. - tt_int_op(1, OP_EQ, token_bucket_dec_read(&b, 1)); + tt_int_op(1, OP_EQ, token_bucket_rw_dec_read(&b, 1)); tt_int_op(b.read_bucket, OP_EQ, 0); // reset bucket, try full-to-empty - token_bucket_init(&b, 16*KB, 64*KB, START_TS); - tt_int_op(1, OP_EQ, token_bucket_dec_read(&b, 64*KB)); + token_bucket_rw_init(&b, 16*KB, 64*KB, START_TS); + tt_int_op(1, OP_EQ, token_bucket_rw_dec_read(&b, 64*KB)); tt_int_op(b.read_bucket, OP_EQ, 0); // reset bucket, try underflow. - token_bucket_init(&b, 16*KB, 64*KB, START_TS); - tt_int_op(1, OP_EQ, token_bucket_dec_read(&b, 64*KB + 1)); + token_bucket_rw_init(&b, 16*KB, 64*KB, START_TS); + tt_int_op(1, OP_EQ, token_bucket_rw_dec_read(&b, 64*KB + 1)); tt_int_op(b.read_bucket, OP_EQ, -1); // A second underflow does not make the bucket empty. - tt_int_op(0, OP_EQ, token_bucket_dec_read(&b, 1000)); + tt_int_op(0, OP_EQ, token_bucket_rw_dec_read(&b, 1000)); tt_int_op(b.read_bucket, OP_EQ, -1001); done: @@ -122,21 +122,21 @@ static void test_bwmgt_token_buf_refill(void *arg) { (void)arg; - token_bucket_t b; + token_bucket_rw_t b; const uint32_t SEC = (uint32_t)monotime_msec_to_approx_coarse_stamp_units(1000); printf("%d\n", (int)SEC); - token_bucket_init(&b, 16*KB, 64*KB, START_TS); + token_bucket_rw_init(&b, 16*KB, 64*KB, START_TS); /* Make the buffer much emptier, then let one second elapse. */ - token_bucket_dec_read(&b, 48*KB); + token_bucket_rw_dec_read(&b, 48*KB); tt_int_op(b.read_bucket, OP_EQ, 16*KB); - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC)); tt_int_op(b.read_bucket, OP_GT, 32*KB - 300); tt_int_op(b.read_bucket, OP_LT, 32*KB + 300); /* Another half second. */ - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*3/2)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*3/2)); tt_int_op(b.read_bucket, OP_GT, 40*KB - 400); tt_int_op(b.read_bucket, OP_LT, 40*KB + 400); tt_uint_op(b.last_refilled_at_ts, OP_EQ, START_TS + SEC*3/2); @@ -144,48 +144,48 @@ test_bwmgt_token_buf_refill(void *arg) /* No time: nothing happens. */ { const uint32_t bucket_orig = b.read_bucket; - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*3/2)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*3/2)); tt_int_op(b.read_bucket, OP_EQ, bucket_orig); } /* Another 30 seconds: fill the bucket. */ - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*3/2 + SEC*30)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*3/2 + SEC*30)); tt_int_op(b.read_bucket, OP_EQ, b.burst); tt_uint_op(b.last_refilled_at_ts, OP_EQ, START_TS + SEC*3/2 + SEC*30); /* Another 30 seconds: nothing happens. */ - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*3/2 + SEC*60)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*3/2 + SEC*60)); tt_int_op(b.read_bucket, OP_EQ, b.burst); tt_uint_op(b.last_refilled_at_ts, OP_EQ, START_TS + SEC*3/2 + SEC*60); /* Empty the bucket, let two seconds pass, and make sure that a refill is * noticed. */ - tt_int_op(1, OP_EQ, token_bucket_dec_read(&b, b.burst)); + tt_int_op(1, OP_EQ, token_bucket_rw_dec_read(&b, b.burst)); tt_int_op(0, OP_EQ, b.read_bucket); - tt_int_op(1, OP_EQ, token_bucket_refill(&b, START_TS + SEC*3/2 + SEC*61)); - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*3/2 + SEC*62)); + tt_int_op(1, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*3/2 + SEC*61)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*3/2 + SEC*62)); tt_int_op(b.read_bucket, OP_GT, 32*KB-400); tt_int_op(b.read_bucket, OP_LT, 32*KB+400); /* Underflow the bucket, make sure we detect when it has tokens again. */ - tt_int_op(1, OP_EQ, token_bucket_dec_read(&b, b.read_bucket+16*KB)); + tt_int_op(1, OP_EQ, token_bucket_rw_dec_read(&b, b.read_bucket+16*KB)); tt_int_op(-16*KB, OP_EQ, b.read_bucket); // half a second passes... - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*64)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*64)); tt_int_op(b.read_bucket, OP_GT, -8*KB-300); tt_int_op(b.read_bucket, OP_LT, -8*KB+300); // a second passes - tt_int_op(1, OP_EQ, token_bucket_refill(&b, START_TS + SEC*65)); + tt_int_op(1, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*65)); tt_int_op(b.read_bucket, OP_GT, 8*KB-400); tt_int_op(b.read_bucket, OP_LT, 8*KB+400); // We step a second backwards, and nothing happens. - tt_int_op(0, OP_EQ, token_bucket_refill(&b, START_TS + SEC*64)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, START_TS + SEC*64)); tt_int_op(b.read_bucket, OP_GT, 8*KB-400); tt_int_op(b.read_bucket, OP_LT, 8*KB+400); // A ridiculous amount of time passes. - tt_int_op(0, OP_EQ, token_bucket_refill(&b, INT32_MAX)); + tt_int_op(0, OP_EQ, token_bucket_rw_refill(&b, INT32_MAX)); tt_int_op(b.read_bucket, OP_EQ, b.burst); done: |