From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 4/7] perf tests: Add test for bitmap_snprintf function
Date: Mon, 1 Aug 2016 20:02:32 +0200 [thread overview]
Message-ID: <1470074555-24889-5-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1470074555-24889-1-git-send-email-jolsa@kernel.org>
Automatically test the bitmap_snprintf function.
Link: http://lkml.kernel.org/n/tip-h64apsddvna438czg4ug5txu@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/tests/Build | 1 +
tools/perf/tests/bitmap.c | 53 +++++++++++++++++++++++++++++++++++++++++
tools/perf/tests/builtin-test.c | 4 ++++
tools/perf/tests/tests.h | 1 +
4 files changed, 59 insertions(+)
create mode 100644 tools/perf/tests/bitmap.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index cb20ae1c0d35..dc51bc570e51 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -41,6 +41,7 @@ perf-y += event-times.o
perf-y += backward-ring-buffer.o
perf-y += sdt.o
perf-y += is_printable_array.o
+perf-y += bitmap.o
$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
$(call rule_mkdir)
diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c
new file mode 100644
index 000000000000..9270ba3c3c2a
--- /dev/null
+++ b/tools/perf/tests/bitmap.c
@@ -0,0 +1,53 @@
+#include <linux/compiler.h>
+#include <linux/bitmap.h>
+#include "tests.h"
+#include "cpumap.h"
+#include "debug.h"
+
+#define NBITS 100
+
+static unsigned long *get_bitmap(const char *str, int nbits)
+{
+ struct cpu_map *map = cpu_map__new(str);
+ unsigned long *bm = NULL;
+ int i;
+
+ bm = bitmap_alloc(nbits);
+
+ if (map && bm) {
+ bitmap_zero(bm, nbits);
+
+ for (i = 0; i < map->nr; i++)
+ set_bit(map->map[i], bm);
+ }
+
+ if (map)
+ cpu_map__put(map);
+ return bm;
+}
+
+static int test_bitmap(const char *str)
+{
+ unsigned long *bm = get_bitmap(str, NBITS);
+ char buf[100];
+ int ret;
+
+ bitmap_snprintf(bm, NBITS, buf, sizeof(buf));
+ pr_debug("bitmap: %s\n", buf);
+
+ ret = !strcmp(buf, str);
+ free(bm);
+ return ret;
+}
+
+int test__bitmap_print(int subtest __maybe_unused)
+{
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
+ TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
+ return 0;
+}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 10eb30686c9c..778668a2a966 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -226,6 +226,10 @@ static struct test generic_tests[] = {
.func = test__is_printable_array,
},
{
+ .desc = "Test bitmap print",
+ .func = test__bitmap_print,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 9bfc0e06c61a..7c196c585472 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -90,6 +90,7 @@ int test__backward_ring_buffer(int subtest);
int test__cpu_map_print(int subtest);
int test__sdt_event(int subtest);
int test__is_printable_array(int subtest);
+int test__bitmap_print(int subtest);
#if defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
--
2.4.11
next prev parent reply other threads:[~2016-08-01 18:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-01 18:02 [PATCH 0/7] perf tools: Several fixes Jiri Olsa
2016-08-01 18:02 ` [PATCH 1/7] tools lib: Add bitmap_alloc function Jiri Olsa
2016-08-01 18:45 ` David Ahern
2016-08-02 9:33 ` Jiri Olsa
2016-08-02 11:33 ` [PATCHv2 " Jiri Olsa
2016-08-02 12:56 ` Arnaldo Carvalho de Melo
2016-08-02 13:03 ` Jiri Olsa
2016-08-04 9:11 ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2016-08-01 18:02 ` [PATCH 2/7] tools lib: Add bitmap_snprintf function Jiri Olsa
2016-08-02 15:25 ` Arnaldo Carvalho de Melo
2016-08-04 9:11 ` [tip:perf/urgent] tools lib: Add bitmap_scnprintf function tip-bot for Jiri Olsa
2016-08-01 18:02 ` [PATCH 3/7] tools lib: Add bitmap_and function Jiri Olsa
2016-08-04 9:11 ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2016-08-01 18:02 ` Jiri Olsa [this message]
2016-08-04 9:12 ` [tip:perf/urgent] perf tests: Add test for bitmap_scnprintf function tip-bot for Jiri Olsa
2016-08-01 18:02 ` [PATCH 5/7] perf tools: Move config/Makefile into Makefile.config Jiri Olsa
2016-08-04 9:13 ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2016-08-01 18:02 ` [PATCH 6/7] perf tools: Introduce hists__output_resort_cb function Jiri Olsa
2016-08-04 9:13 ` [tip:perf/urgent] perf hists: Introduce output_resort_cb method tip-bot for Jiri Olsa
2016-08-01 18:02 ` [PATCH 7/7] perf tools: Add --sample-cpu option to record command Jiri Olsa
2016-08-04 9:14 ` [tip:perf/urgent] perf record: Add --sample-cpu option tip-bot for Jiri Olsa
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=1470074555-24889-5-git-send-email-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=dsahern@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox