Blame SOURCES/0088-utils-boot-analysis-Add-magic-asserts-to-some-struct.patch

e76f14
From 3b2ac7b9ac4d8a40c17ae28e255f50704180782b Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Sat, 14 May 2016 18:45:25 +0100
e76f14
Subject: [PATCH] utils: boot-analysis: Add magic & asserts to some structs.
e76f14
e76f14
I suspected data corruption (but didn't prove it).  This commit just
e76f14
adds some magic numbers to the structs so we will see data corruption
e76f14
quickly if it happens again.
e76f14
e76f14
(cherry picked from commit bf80587367d5f01e493426bbb2cda6099a15e7ab)
e76f14
---
e76f14
 utils/boot-analysis/boot-analysis.c | 9 +++++++++
e76f14
 utils/boot-analysis/boot-analysis.h | 6 ++++++
e76f14
 2 files changed, 15 insertions(+)
e76f14
e76f14
diff --git a/utils/boot-analysis/boot-analysis.c b/utils/boot-analysis/boot-analysis.c
e76f14
index 3d38fe2..3690ed4 100644
e76f14
--- a/utils/boot-analysis/boot-analysis.c
e76f14
+++ b/utils/boot-analysis/boot-analysis.c
e76f14
@@ -571,6 +571,7 @@ set_up_event_handlers (guestfs_h *g, size_t pass)
e76f14
   assert (/* 0 <= pass && */ pass < NR_TEST_PASSES);
e76f14
 
e76f14
   data = &pass_data[pass];
e76f14
+  data->magic = PASS_MAGIC;
e76f14
   data->pass = pass;
e76f14
   data->nr_events = 0;
e76f14
   data->events = NULL;
e76f14
@@ -779,6 +780,7 @@ check_pass_data (void)
e76f14
   const char *message;
e76f14
 
e76f14
   for (i = 0; i < NR_TEST_PASSES; ++i) {
e76f14
+    assert (pass_data[i].magic == PASS_MAGIC);
e76f14
     assert (pass_data[i].pass == i);
e76f14
     assert (pass_data[i].elapsed_ns > 1000);
e76f14
     assert (pass_data[i].nr_events > 0);
e76f14
@@ -890,6 +892,7 @@ add_activity (const char *name, int flags)
e76f14
   if (activities == NULL)
e76f14
     error (EXIT_FAILURE, errno, "realloc");
e76f14
   ret = &activities[nr_activities-1];
e76f14
+  ret->magic = ACTIVITY_MAGIC;
e76f14
   ret->name = strdup (name);
e76f14
   if (ret->name == NULL)
e76f14
     error (EXIT_FAILURE, errno, "strdup");
e76f14
@@ -934,6 +937,9 @@ compare_activities_by_t (const void *av, const void *bv)
e76f14
   const struct activity *a = av;
e76f14
   const struct activity *b = bv;
e76f14
 
e76f14
+  assert (a->magic == ACTIVITY_MAGIC);
e76f14
+  assert (b->magic == ACTIVITY_MAGIC);
e76f14
+
e76f14
   return a->t - b->t;
e76f14
 }
e76f14
 
e76f14
@@ -1028,6 +1034,7 @@ static void
e76f14
 print_activity (struct activity *activity)
e76f14
 {
e76f14
   if (activity->warning) ansi_red (); else ansi_green ();
e76f14
+  assert (activity->magic == ACTIVITY_MAGIC);
e76f14
   print_escaped_string (activity->name);
e76f14
   ansi_restore ();
e76f14
   printf (" %.1fms ±%.1fms ",
e76f14
@@ -1148,6 +1155,8 @@ compare_activities_pointers_by_mean (const void *av, const void *bv)
e76f14
   const struct activity * const *a = av;
e76f14
   const struct activity * const *b = bv;
e76f14
 
e76f14
+  assert ((*a)->magic == ACTIVITY_MAGIC);
e76f14
+  assert ((*b)->magic == ACTIVITY_MAGIC);
e76f14
   return (*b)->mean - (*a)->mean;
e76f14
 }
e76f14
 
e76f14
diff --git a/utils/boot-analysis/boot-analysis.h b/utils/boot-analysis/boot-analysis.h
e76f14
index a07f12e..38cd339 100644
e76f14
--- a/utils/boot-analysis/boot-analysis.h
e76f14
+++ b/utils/boot-analysis/boot-analysis.h
e76f14
@@ -24,6 +24,9 @@
e76f14
 
e76f14
 /* Per-pass data collected. */
e76f14
 struct pass_data {
e76f14
+#define PASS_MAGIC 0x45545545
e76f14
+  uint32_t magic;		/* Struct magic. */
e76f14
+
e76f14
   size_t pass;
e76f14
   struct timespec start_t;
e76f14
   struct timespec end_t;
e76f14
@@ -67,6 +70,9 @@ extern struct pass_data pass_data[NR_TEST_PASSES];
e76f14
  * long they take (mean, variance, standard deviation of length).
e76f14
  */
e76f14
 struct activity {
e76f14
+#define ACTIVITY_MAGIC 0xAC1AC1AC
e76f14
+  uint32_t magic;		/* Struct magic. */
e76f14
+
e76f14
   char *name;                   /* Name of this activity. */
e76f14
   int flags;
e76f14
 #define LONG_ACTIVITY 1         /* Expected to take a long time. */
e76f14
-- 
e76f14
1.8.3.1
e76f14