diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2015-06-26 13:55:01 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2015-06-27 16:04:07 +0100 |
commit | 203c3841fc6bf9bd2b71ff9ce8e86874375eec1e (patch) | |
tree | 08a123d2208601104847b1ffa9facafdb799ae31 /lib/tests | |
parent | 76ea7b913373d1291a95706dfede7e48a812777e (diff) |
stats: Zero the whole structure at init() time
Because the structure started small, I initialized every member
directly, but that means that the new fields added weren't properly
initialized (sigh!). Zero the whole thing first then.
Also, the punishment for introducing a bug should be to write the
corresponding unit test. It's not a perfect one, but I'll take it.
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/igt_stats.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c index f9081c76..f76d3344 100644 --- a/lib/tests/igt_stats.c +++ b/lib/tests/igt_stats.c @@ -25,6 +25,16 @@ #include "igt_core.h" #include "igt_stats.h" +/* Make sure we zero igt_stats_t fields at init() time */ +static void test_init_zero(void) +{ + igt_stats_t stats; + + stats.mean = 1.; + igt_stats_init(&stats, 2); + igt_assert(stats.mean == 0.); +} + static void test_mean(void) { igt_stats_t stats; @@ -103,6 +113,7 @@ static void test_std_deviation(void) igt_simple_main { + test_init_zero(); test_mean(); test_invalidate_mean(); test_std_deviation(); |