Resurrect dead code in test_channelpadding.c

A for-loop in test_channelpadding_timers() would never run because it
was trying to increment a counter up to CHANNELS_TO_TEST/3 after an
earlier block already incremented it to CHANNELS_TO_TEST/2.

Fixes #22221, CID 1405983.
This commit is contained in:
Taylor Yu 2017-05-10 13:57:18 -04:00
parent ee3ccd2fac
commit 2bf4263800

View File

@ -287,22 +287,22 @@ test_channelpadding_timers(void *arg)
tt_int_op(tried_to_write_cell, OP_EQ, 0); tt_int_op(tried_to_write_cell, OP_EQ, 0);
} }
/* This loop should add timers to our existing lists in a weak /* This loop should add timers to the first position in the timerslot
* pseudorandom pattern. It ensures that the lists can grow with multiple * array, since its timeout is before all other timers. */
* timers in them. */ for (; i < CHANNELS_TO_TEST/3; i++) {
for (; i < CHANNELS_TO_TEST/2; i++) { chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 1;
chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 10 +
i*3 % CHANNELPADDING_MAX_TIMERS;
decision = channelpadding_decide_to_pad_channel(chans[i]); decision = channelpadding_decide_to_pad_channel(chans[i]);
tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED); tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
tt_assert(chans[i]->pending_padding_callback); tt_assert(chans[i]->pending_padding_callback);
tt_int_op(tried_to_write_cell, OP_EQ, 0); tt_int_op(tried_to_write_cell, OP_EQ, 0);
} }
/* This loop should add timers to the first position in the timerslot /* This loop should add timers to our existing lists in a weak
* array, since its timeout is before all other timers. */ * pseudorandom pattern. It ensures that the lists can grow with multiple
for (; i < CHANNELS_TO_TEST/3; i++) { * timers in them. */
chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 1; for (; i < CHANNELS_TO_TEST/2; i++) {
chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 10 +
i*3 % CHANNELPADDING_MAX_TIMERS;
decision = channelpadding_decide_to_pad_channel(chans[i]); decision = channelpadding_decide_to_pad_channel(chans[i]);
tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED); tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
tt_assert(chans[i]->pending_padding_callback); tt_assert(chans[i]->pending_padding_callback);