diff mbox

[i-g-t,3/3] stats: Exercise the reallocation paths

Message ID 1435424869-17455-4-git-send-email-damien.lespiau@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lespiau, Damien June 27, 2015, 5:07 p.m. UTC
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 lib/tests/igt_stats.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox

Patch

diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c
index 6e4b233..12778e2 100644
--- a/lib/tests/igt_stats.c
+++ b/lib/tests/igt_stats.c
@@ -204,6 +204,29 @@  static void test_std_deviation(void)
 	igt_stats_fini(&stats);
 }
 
+static void test_reallocation(void)
+{
+	igt_stats_t stats;
+	unsigned int i;
+
+	igt_stats_init_with_size(&stats, 1);
+
+	for (i = 0; i < 101; i++) {
+		igt_stats_push(&stats, i);
+		/* also triggers ->sorted reallocations */
+		if (i > 10)
+			igt_stats_get_median(&stats);
+	}
+
+	igt_assert_eq(stats.n_values, 101);
+	for (i = 0; i < 101; i++)
+		igt_assert_eq(stats.values[i], i);
+	igt_assert_eq_double(igt_stats_get_mean(&stats), 50.0);
+	igt_assert_eq_double(igt_stats_get_median(&stats), 50.0);
+
+	igt_stats_fini(&stats);
+}
+
 igt_simple_main
 {
 	test_init_zero();
@@ -215,4 +238,5 @@  igt_simple_main
 	test_mean();
 	test_invalidate_mean();
 	test_std_deviation();
+	test_reallocation();
 }