Skip to content

Commit 9d29a75

Browse files
committed
Fail the test on unbounded buffer growth in resampler_typical_uses
The monotonic_state checks were printf-only, so unbounded internal buffer growth would go unnoticed in CI. Use gtest EXPECT/ADD_FAILURE so buffer buildup actually fails the test.
1 parent a43b217 commit 9d29a75

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

test/test_resampler.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,26 +1269,19 @@ struct monotonic_state {
12691269
}
12701270
~monotonic_state()
12711271
{
1272-
float ratio =
1273-
static_cast<float>(source_rate) / static_cast<float>(target_rate);
1274-
// Only report if there has been a meaningful increase in buffering. Do
1272+
// Only flag if there has been a meaningful increase in buffering. Do
12751273
// not warn if the buffering was constant and small.
12761274
if (monotonic && max_value && max_value != max_step) {
1277-
printf("%s is monotonically increasing, max: %zu, max_step: %zu, "
1278-
"in: %dHz, out: "
1279-
"%dHz, block_size: %d, ratio: %lf\n",
1280-
what, max_value, max_step, source_rate, target_rate, block_size,
1281-
ratio);
1282-
}
1283-
// Arbitrary limit: if more than this number of frames has been buffered,
1284-
// print a message.
1285-
constexpr int BUFFER_SIZE_THRESHOLD = 20;
1286-
if (max_value > BUFFER_SIZE_THRESHOLD) {
1287-
printf("%s, unexpected large max buffering value, max: %zu, max_step: "
1288-
"%zu, in: %dHz, out: %dHz, block_size: %d, ratio: %lf\n",
1289-
what, max_value, max_step, source_rate, target_rate, block_size,
1290-
ratio);
1275+
ADD_FAILURE() << what << " is monotonically increasing, max: " << max_value
1276+
<< ", max_step: " << max_step << ", in: " << source_rate
1277+
<< "Hz, out: " << target_rate
1278+
<< "Hz, block_size: " << block_size;
12911279
}
1280+
constexpr size_t BUFFER_SIZE_THRESHOLD = 20;
1281+
EXPECT_LE(max_value, BUFFER_SIZE_THRESHOLD)
1282+
<< what << ", in: " << source_rate << "Hz, out: " << target_rate
1283+
<< "Hz, block_size: " << block_size
1284+
<< ", max_step: " << max_step;
12921285
}
12931286
void set_new_value(size_t new_value)
12941287
{

0 commit comments

Comments
 (0)