diff mbox

[05/13] throttle: Set always an average value when setting a maximum value

Message ID d61850f1ba9bebe39d0d50ec9710fbeb3f5466e8.1454669823.git.berto@igalia.com
State New
Headers show

Commit Message

Alberto Garcia Feb. 5, 2016, 10:59 a.m. UTC
When testing the ranges of valid values, set_cfg_value() creates
sometimes invalid throttling configurations by setting bucket.max
while leaving bucket.avg uninitialized.

While this doesn't break the current tests, it will as soon as
we unify all functions that check the validity of the throttling
configuration.

This patch ensures that the value of bucket.avg is valid when setting
bucket.max.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 tests/test-throttle.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox

Patch

diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index 5f0b7d4..5031eb7 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -221,6 +221,8 @@  static void set_cfg_value(bool is_max, int index, int value)
 {
     if (is_max) {
         cfg.buckets[index].max = value;
+        /* If max is set, avg should never be 0 */
+        cfg.buckets[index].avg = MAX(cfg.buckets[index].avg, 1);
     } else {
         cfg.buckets[index].avg = value;
     }