perf test sample-parsing: Add endian test for struct branch_flags
authorMadhavan Srinivasan <maddy@linux.ibm.com>
Thu, 28 Oct 2021 11:37:14 +0000 (17:07 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 28 Oct 2021 12:34:01 +0000 (09:34 -0300)
Extend the sample-parsing test to include a branch_flag bitfield-endian
swap test.

This patch adds a include for "util/trace-event.h" in the sample-parsing
test for importing tep_is_bigendian() and extends samples_same() to
include "needs_swap" to detect/enable check for bitfield-endian swap.

Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211028113714.600549-2-maddy@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/sample-parsing.c

index 8fd8a4ef97da1521f3441ead3f367b328bc815c1..c83a11514129147b14e569dec433f9f8e33aca16 100644 (file)
@@ -13,6 +13,7 @@
 #include "evsel.h"
 #include "debug.h"
 #include "util/synthetic-events.h"
+#include "util/trace-event.h"
 
 #include "tests.h"
 
        }                                               \
 } while (0)
 
+/*
+ * Hardcode the expected values for branch_entry flags.
+ * These are based on the input value (213) specified
+ * in branch_stack variable.
+ */
+#define BS_EXPECTED_BE 0xa00d000000000000
+#define BS_EXPECTED_LE 0xd5000000
+#define FLAG(s)        s->branch_stack->entries[i].flags
+
 static bool samples_same(const struct perf_sample *s1,
                         const struct perf_sample *s2,
-                        u64 type, u64 read_format)
+                        u64 type, u64 read_format, bool needs_swap)
 {
        size_t i;
 
@@ -100,8 +110,14 @@ static bool samples_same(const struct perf_sample *s1,
        if (type & PERF_SAMPLE_BRANCH_STACK) {
                COMP(branch_stack->nr);
                COMP(branch_stack->hw_idx);
-               for (i = 0; i < s1->branch_stack->nr; i++)
-                       MCOMP(branch_stack->entries[i]);
+               for (i = 0; i < s1->branch_stack->nr; i++) {
+                       if (needs_swap)
+                               return ((tep_is_bigendian()) ?
+                                       (FLAG(s2).value == BS_EXPECTED_BE) :
+                                       (FLAG(s2).value == BS_EXPECTED_LE));
+                       else
+                               MCOMP(branch_stack->entries[i]);
+               }
        }
 
        if (type & PERF_SAMPLE_REGS_USER) {
@@ -248,7 +264,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
                },
        };
        struct sample_read_value values[] = {{1, 5}, {9, 3}, {2, 7}, {6, 4},};
-       struct perf_sample sample_out;
+       struct perf_sample sample_out, sample_out_endian;
        size_t i, sz, bufsz;
        int err, ret = -1;
 
@@ -313,12 +329,29 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
                goto out_free;
        }
 
-       if (!samples_same(&sample, &sample_out, sample_type, read_format)) {
+       if (!samples_same(&sample, &sample_out, sample_type, read_format, evsel.needs_swap)) {
                pr_debug("parsing failed for sample_type %#"PRIx64"\n",
                         sample_type);
                goto out_free;
        }
 
+       if (sample_type == PERF_SAMPLE_BRANCH_STACK) {
+               evsel.needs_swap = true;
+               evsel.sample_size = __evsel__sample_size(sample_type);
+               err = evsel__parse_sample(&evsel, event, &sample_out_endian);
+               if (err) {
+                       pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
+                                "evsel__parse_sample", sample_type, err);
+                       goto out_free;
+               }
+
+               if (!samples_same(&sample, &sample_out_endian, sample_type, read_format, evsel.needs_swap)) {
+                       pr_debug("parsing failed for sample_type %#"PRIx64"\n",
+                                sample_type);
+                       goto out_free;
+               }
+       }
+
        ret = 0;
 out_free:
        free(event);