All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Lespiau <damien.lespiau@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t 01/18] stats: Zero the whole structure at init() time
Date: Sat, 27 Jun 2015 16:07:59 +0100	[thread overview]
Message-ID: <1435417696-28115-2-git-send-email-damien.lespiau@intel.com> (raw)
In-Reply-To: <1435417696-28115-1-git-send-email-damien.lespiau@intel.com>

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>
---
 lib/igt_stats.c       |  4 +++-
 lib/tests/igt_stats.c | 11 +++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/igt_stats.c b/lib/igt_stats.c
index 65c0ac6..67ee947 100644
--- a/lib/igt_stats.c
+++ b/lib/igt_stats.c
@@ -23,16 +23,18 @@
  */
 
 #include <math.h>
+#include <string.h>
 
 #include "igt_core.h"
 #include "igt_stats.h"
 
 void igt_stats_init(igt_stats_t *stats, unsigned int capacity)
 {
+	memset(stats, 0, sizeof(*stats));
+
 	stats->values = calloc(capacity, sizeof(*stats->values));
 	igt_assert(stats->values);
 	stats->capacity = capacity;
-	stats->n_values = 0;
 }
 
 void igt_stats_fini(igt_stats_t *stats)
diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c
index f9081c7..f76d334 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();
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-06-27 15:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-27 15:07 More stats thingies Damien Lespiau
2015-06-27 15:07 ` Damien Lespiau [this message]
2015-06-27 15:08 ` [PATCH i-g-t 02/18] doc: Remove i-g-t/intel prefixes and capitalize section titles Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 03/18] stats: Add header gards Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 04/18] stats: Add gtkdoc section for igt_stats Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 05/18] stats: Add a way to specify if the data set is a population or a sample Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 06/18] stats: Add a getter for the population property Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 07/18] stats: Add a note about the standard deviation derived from unbiased variance Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 08/18] stats: Factor out a fixture to initialize stats Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 09/18] stats: Add functions to retrieve min/max values of the dataset Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 10/18] stats: Add igt_stats_get_range() Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 11/18] docs: Fix a "libraray" typo Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 12/18] docs: Add documentation for igt_assert_u32() Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 13/18] docs: Add documentation for igt_assert_cmpuint() Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 14/18] lib: Add double versions of igt_assert_cmp() and igt_assert_eq() Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 15/18] stats: Use igt_assert_eq_double() when asserting on doubles Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 16/18] stats: Add a bulk version of _push() Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 17/18] stats: Add support for quartiles (and thus median) Damien Lespiau
2015-06-27 15:15   ` Chris Wilson
2015-06-27 15:52     ` Damien Lespiau
2015-06-27 15:56       ` Chris Wilson
2015-06-27 16:04         ` Damien Lespiau
2015-06-27 15:08 ` [PATCH i-g-t 18/18] stats: Add support for the interquartile range (IQR) Damien Lespiau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435417696-28115-2-git-send-email-damien.lespiau@intel.com \
    --to=damien.lespiau@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.