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