aboutsummaryrefslogtreecommitdiff
path: root/tools/perf/tests/expr.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2017-03-24 19:37:40 +0100
committerIngo Molnar <mingo@kernel.org>2017-03-24 19:37:40 +0100
commite3a6a62400520452fe39740dca90a1d0b94b8f92 (patch)
tree0339ad6ca5de37105e47d4fa0d3b082e091ccbb0 /tools/perf/tests/expr.c
parent267dd0a07eefbb37264fcfad984fffc8856898ad (diff)
parentbf874fcf9f2fed58510dc83abcee388cee2b427e (diff)
Merge tag 'perf-core-for-mingo-4.12-20170324' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: User visible changes: - Allow suppressing 'uncore_' when specifying PMU events (Andi Kleen) - Collapse identically named PMU events in 'perf stat', allow not merging it via --no-merge (Andi Kleen) Fixes: - Use more precise 'grep -v' to suppress unwanted 'objdump -dS' disassembly output to not ditch line:number lines needed by 'perf annotate --print-lines' logic (Taeung Song) Infrastructure changes: - SDT (Statically Defined Tracing)/uprobes_events arguments improvements (Alexis Berlemont, Ravi Bangoria) - Improvements for the handling of JSON described vendor events, including having an expression parser to calculate metrics from multiple vendor events (Andi Kleen) - Update Intel JSON vendor event files (Andi Kleen) - Restore error reporting in 'perf probe -d' when none of the events requested to be deleted exist. (Kefeng Wang) - Bump MAX_CMDLEN in 'perf probe' to match what the kernel accepts (Ravi Bangoria) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/tests/expr.c')
-rw-r--r--tools/perf/tests/expr.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
new file mode 100644
index 000000000000..6c6a3749aaf6
--- /dev/null
+++ b/tools/perf/tests/expr.c
@@ -0,0 +1,56 @@
+#include "util/debug.h"
+#include "util/expr.h"
+#include "tests.h"
+#include <stdlib.h>
+
+static int test(struct parse_ctx *ctx, const char *e, double val2)
+{
+ double val;
+
+ if (expr__parse(&val, ctx, &e))
+ TEST_ASSERT_VAL("parse test failed", 0);
+ TEST_ASSERT_VAL("unexpected value", val == val2);
+ return 0;
+}
+
+int test__expr(int subtest __maybe_unused)
+{
+ const char *p;
+ const char **other;
+ double val;
+ int ret;
+ struct parse_ctx ctx;
+ int num_other;
+
+ expr__ctx_init(&ctx);
+ expr__add_id(&ctx, "FOO", 1);
+ expr__add_id(&ctx, "BAR", 2);
+
+ ret = test(&ctx, "1+1", 2);
+ ret |= test(&ctx, "FOO+BAR", 3);
+ ret |= test(&ctx, "(BAR/2)%2", 1);
+ ret |= test(&ctx, "1 - -4", 5);
+ ret |= test(&ctx, "(FOO-1)*2 + (BAR/2)%2 - -4", 5);
+
+ if (ret)
+ return ret;
+
+ p = "FOO/0";
+ ret = expr__parse(&val, &ctx, &p);
+ TEST_ASSERT_VAL("division by zero", ret == 1);
+
+ p = "BAR/";
+ ret = expr__parse(&val, &ctx, &p);
+ TEST_ASSERT_VAL("missing operand", ret == 1);
+
+ TEST_ASSERT_VAL("find other",
+ expr__find_other("FOO + BAR + BAZ + BOZO", "FOO", &other, &num_other) == 0);
+ TEST_ASSERT_VAL("find other", num_other == 3);
+ TEST_ASSERT_VAL("find other", !strcmp(other[0], "BAR"));
+ TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
+ TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
+ TEST_ASSERT_VAL("find other", other[3] == NULL);
+ free((void *)other);
+
+ return 0;
+}