aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/evlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/evlist.c')
-rw-r--r--tools/perf/tests/evlist.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/tools/perf/tests/evlist.c b/tools/perf/tests/evlist.c
index 77579158f4d9..99d7dfd4e20a 100644
--- a/tools/perf/tests/evlist.c
+++ b/tools/perf/tests/evlist.c
@@ -1,5 +1,7 @@
#include "util/evlist.h"
#include "util/debug.h"
+#include "util/thread_map.h"
+#include "util/cpumap.h"
#include "tests/tests.h"
static void perf_evlist__init_pollfd(struct perf_evlist *evlist,
@@ -101,3 +103,112 @@ int test__perf_evlist__filter_pollfd(void)
return 0;
}
+
+int test__perf_evlist__add_pollfd(void)
+{
+ struct perf_evsel evsel = {
+ .system_wide = false,
+ };
+ struct thread_map threads = {
+ .nr = 2,
+ };
+ struct perf_evlist evlist_alloc = {
+ .pollfd = NULL,
+ .threads = &threads,
+ }, *evlist = &evlist_alloc;
+
+ INIT_LIST_HEAD(&evlist->entries);
+ list_add(&evsel.node, &evlist->entries);
+
+ if (perf_evlist__alloc_pollfd(evlist) < 0) {
+ pr_debug("\nperf_evlist__alloc_pollfd(evlist) failed!");
+ return TEST_FAIL;
+ }
+
+ if (evlist->nr_fds_alloc != threads.nr) {
+ pr_debug("\n_evlist__alloc_pollfd: nr_fds_alloc=%d != (threads->nr(%d) * cpu_map->nr(%d))=%d",
+ evlist->nr_fds_alloc, thread_map__nr(evlist->threads), cpu_map__nr(evlist->cpus),
+ thread_map__nr(evlist->threads) * cpu_map__nr(evlist->cpus));
+ return TEST_FAIL;
+ }
+
+ if (perf_evlist__add_pollfd(evlist, 1) < 0) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 1) failed!");
+ return TEST_FAIL;
+ }
+
+ if (evlist->nr_fds != 1) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 1)=%d != 1", evlist->nr_fds);
+ return TEST_FAIL;
+ }
+
+ if (perf_evlist__add_pollfd(evlist, 2) < 0) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 2) failed!");
+ return TEST_FAIL;
+ }
+
+ if (evlist->nr_fds != 2) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 2)=%d != 2", evlist->nr_fds);
+ return TEST_FAIL;
+ }
+
+ perf_evlist__fprintf_pollfd(evlist, "before growing array", stderr);
+
+ if (perf_evlist__add_pollfd(evlist, 35) < 0) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 35) failed!");
+ return TEST_FAIL;
+ }
+
+ if (evlist->nr_fds != 3) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 35)=%d != 3", evlist->nr_fds);
+ return TEST_FAIL;
+ }
+
+ if (evlist->pollfd == NULL) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 35) should have allocated evlist->pollfd!");
+ return TEST_FAIL;
+ }
+
+ perf_evlist__fprintf_pollfd(evlist, "after 3rd add_pollfd", stderr);
+
+ if (evlist->pollfd[2].fd != 35) {
+ pr_debug("\nevlist->pollfd[2](%d) != 35!", evlist->pollfd[2].fd);
+ return TEST_FAIL;
+ }
+
+ if (perf_evlist__add_pollfd(evlist, 88) < 0) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 88) failed!");
+ return TEST_FAIL;
+ }
+
+ if (evlist->nr_fds != 4) {
+ pr_debug("\nperf_evlist__add_pollfd(evlist, 88)=%d != 2", evlist->nr_fds);
+ return TEST_FAIL;
+ }
+
+ perf_evlist__fprintf_pollfd(evlist, "after 4th add_pollfd", stderr);
+
+ if (evlist->pollfd[0].fd != 1) {
+ pr_debug("\nevlist->pollfd[0](%d) != 1!", evlist->pollfd[0].fd);
+ return TEST_FAIL;
+ }
+
+ if (evlist->pollfd[1].fd != 2) {
+ pr_debug("\nevlist->pollfd[1](%d) != 2!", evlist->pollfd[1].fd);
+ return TEST_FAIL;
+ }
+
+ if (evlist->pollfd[2].fd != 35) {
+ pr_debug("\nevlist->pollfd[2](%d) != 35!", evlist->pollfd[2].fd);
+ return TEST_FAIL;
+ }
+
+ if (evlist->pollfd[3].fd != 88) {
+ pr_debug("\nevlist->pollfd[3](%d) != 88!", evlist->pollfd[3].fd);
+ return TEST_FAIL;
+ }
+
+ pr_debug("\n");
+
+ return 0;
+}