[PATCH v1 09/48] perf tests: Silence -Wshorten-64-to-32 warnings

Ian Rogers
2025-04-01T18:24:55Z

tools/perf/tests/api-io.c | 2 +-
tools/perf/tests/bp_signal.c | 6 +++---
tools/perf/tests/bp_signal_overflow.c | 6 +++---
tools/perf/tests/builtin-test.c | 9 +++++----
tools/perf/tests/code-reading.c | 4 ++--
tools/perf/tests/dso-data.c | 10 +++++-----
tools/perf/tests/mmap-thread-lookup.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/pmu-events.c | 2 +-
tools/perf/tests/sigtrap.c | 4 ++--
tools/perf/tests/switch-tracking.c | 11 ++++++-----
tools/perf/tests/vmlinux-kallsyms.c | 4 ++--
tools/perf/tests/wp.c | 4 ++--
13 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/tools/perf/tests/api-io.c b/tools/perf/tests/api-io.c
index 0ba3d5ccebcf..4aee1cff062e 100644
--- a/tools/perf/tests/api-io.c
+++ b/tools/perf/tests/api-io.c
@@ -74,7 +74,7 @@ static int setup_test(char path[PATH_MAX], const char *contents,
unlink(path);
return -1;
}
- io__init(io, io->fd, io->buf, buf_size);
+ io__init(io, io->fd, io->buf, (unsigned int)buf_size);
return 0;
}

diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
index 3faeb5b6fe0b..5ecac6c2d8b6 100644
--- a/tools/perf/tests/bp_signal.c
+++ b/tools/perf/tests/bp_signal.c
@@ -64,7 +64,7 @@ static noinline int test_function(void)
{
__test_function(&the_var);
the_var++;
- return time(NULL);
+ return (int)time(NULL);
}

static void sig_handler_2(int signum __maybe_unused,
@@ -151,11 +151,11 @@ static int wp_event(void *addr, int sig)
static long long bp_count(int fd)
{
long long count;
- int ret;
+ ssize_t ret;

ret = read(fd, &count, sizeof(long long));
if (ret != sizeof(long long)) {
- pr_debug("failed to read: %d\n", ret);
+ pr_debug("failed to read: %zd\n", ret);
return TEST_FAIL;
}

diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c
index ee560e156be6..eb9021ad8177 100644
--- a/tools/perf/tests/bp_signal_overflow.c
+++ b/tools/perf/tests/bp_signal_overflow.c
@@ -33,7 +33,7 @@ static int overflows;

static noinline int test_function(void)
{
- return time(NULL);
+ return (int)time(NULL);
}

static void sig_handler(int signum __maybe_unused,
@@ -46,11 +46,11 @@ static void sig_handler(int signum __maybe_unused,
static long long bp_count(int fd)
{
long long count;
- int ret;
+ ssize_t ret;

ret = read(fd, &count, sizeof(long long));
if (ret != sizeof(long long)) {
- pr_debug("failed to read: %d\n", ret);
+ pr_debug("failed to read: %zd\n", ret);
return TEST_FAIL;
}

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 14d30a5053be..4ea840580876 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -301,7 +301,7 @@ static int print_test_result(struct test_suite *t, int curr_suite, int curr_test
return 0;
}

-static void finish_test(struct child_test **child_tests, int running_test, int child_test_num,
+static void finish_test(struct child_test **child_tests, size_t running_test, size_t child_test_num,
int width)
{
struct child_test *child_test = child_tests[running_test];
@@ -349,7 +349,7 @@ static void finish_test(struct child_test **child_tests, int running_test, int c
if (perf_use_color_default) {
int running = 0;

- for (int y = running_test; y < child_test_num; y++) {
+ for (size_t y = running_test; y < child_test_num; y++) {
if (child_tests[y] == NULL)
continue;
if (check_if_command_finished(&child_tests[y]->process) == 0)
@@ -478,13 +478,14 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
int err = 0;

for (struct test_suite **t = suites; *t; t++) {
- int i, len = strlen(test_description(*t, -1));
+ int i;
+ int len = (int)strlen(test_description(*t, -1));

if (width < len)
width = len;

test_suite__for_each_test_case(*t, i) {
- len = strlen(test_description(*t, i));
+ len = (int)strlen(test_description(*t, i));
if (width < len)
width = len;
num_tests += runs_per_test;
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index cf6edbe697b2..0c31d5ff77e2 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -188,7 +188,7 @@ static int objdump_version(void)
char *line = NULL;
const char *fmt;
FILE *f;
- int ret;
+ ssize_t ret;

int version_tmp, version_num = 0;
char *version = 0, *token;
@@ -295,7 +295,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
if (len) {
pr_debug("objdump read too few bytes: %zd\n", len);
if (!ret)
- ret = len;
+ ret = (int)len;
}

pclose(f);
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index a1fff4203b75..2954e06ae5b3 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -233,14 +233,14 @@ static int dsos__create(int cnt, int size, struct dsos *dsos)
return 0;
}

-static int set_fd_limit(int n)
+static int set_fd_limit(long n)
{
struct rlimit rlim;

if (getrlimit(RLIMIT_NOFILE, &rlim))
return -1;

- pr_debug("file limit %ld, new %d\n", (long) rlim.rlim_cur, n);
+ pr_debug("file limit %ld, new %ld\n", (long) rlim.rlim_cur, n);

rlim.rlim_cur = n;
return setrlimit(RLIMIT_NOFILE, &rlim);
@@ -249,8 +249,8 @@ static int set_fd_limit(int n)
static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
struct machine machine;
- long nr_end, nr = open_files_cnt();
- int dso_cnt, limit, i, fd;
+ long dso_cnt, limit, nr_end, nr = open_files_cnt();
+ int i, fd;

/* Rest the internal dso open counter limit. */
reset_fd_limit();
@@ -264,7 +264,7 @@ static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subt
/* and this is now our dso open FDs limit */
dso_cnt = limit / 2;
TEST_ASSERT_VAL("failed to create dsos\n",
- !dsos__create(dso_cnt, TEST_FILE_SIZE, &machine.dsos));
+ !dsos__create((int)dso_cnt, TEST_FILE_SIZE, &machine.dsos));

for (i = 0; i < (dso_cnt - 1); i++) {
struct dso *dso = machine.dsos.dsos[i];
diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c
index 446a3615d720..b328ad6973a3 100644
--- a/tools/perf/tests/mmap-thread-lookup.c
+++ b/tools/perf/tests/mmap-thread-lookup.c
@@ -45,7 +45,7 @@ static int thread_init(struct thread_data *td)
}

td->map = map;
- td->tid = syscall(SYS_gettid);
+ td->tid = (pid_t)syscall(SYS_gettid);

pr_debug("tid = %d, map = %p\n", td->tid, map);
return 0;
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 0ef4ba7c1571..68f1498d0a47 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -119,7 +119,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
goto out_delete_evlist;
}

- tp_flags = evsel__intval(evsel, &sample, "flags");
+ tp_flags = (int)evsel__intval(evsel, &sample, "flags");
perf_sample__exit(&sample);
if (flags != tp_flags) {
pr_debug("%s: Expected flags=%#x, got %#x\n",
diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c
index db004d26fcb0..2762794827ce 100644
--- a/tools/perf/tests/pmu-events.c
+++ b/tools/perf/tests/pmu-events.c
@@ -609,7 +609,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
pmu_add_sys_aliases(pmu);

/* Count how many aliases we generated */
- alias_count = perf_pmu__num_events(pmu);
+ alias_count = (int)perf_pmu__num_events(pmu);

/* Count how many aliases we expect from the known table */
for (table = &test_pmu->aliases[0]; *table; table++)
diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
index a67c756f90b8..b7d7735f8a72 100644
--- a/tools/perf/tests/sigtrap.c
+++ b/tools/perf/tests/sigtrap.c
@@ -154,13 +154,13 @@ sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __may
{
if (!__atomic_fetch_add(&ctx.signal_count, 1, __ATOMIC_RELAXED))
ctx.first_siginfo = *info;
- __atomic_fetch_sub(&ctx.tids_want_signal, syscall(SYS_gettid), __ATOMIC_RELAXED);
+ __atomic_fetch_sub(&ctx.tids_want_signal, (pid_t)syscall(SYS_gettid), __ATOMIC_RELAXED);
}

static void *test_thread(void *arg)
{
pthread_barrier_t *barrier = (pthread_barrier_t *)arg;
- pid_t tid = syscall(SYS_gettid);
+ pid_t tid = (pid_t)syscall(SYS_gettid);
int i;

pthread_barrier_wait(barrier);
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 8df3f9d9ffd2..1f0f8321ae40 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist,

evsel = evlist__id2evsel(evlist, sample.id);
if (evsel == switch_tracking->switch_evsel) {
- next_tid = evsel__intval(evsel, &sample, "next_pid");
- prev_tid = evsel__intval(evsel, &sample, "prev_pid");
+ next_tid = (int)evsel__intval(evsel, &sample, "next_pid");
+ prev_tid = (int)evsel__intval(evsel, &sample, "prev_pid");
cpu = sample.cpu;
pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n",
cpu, prev_tid, next_tid);
@@ -262,9 +262,10 @@ static int compar(const void *a, const void *b)
{
const struct event_node *nodea = a;
const struct event_node *nodeb = b;
- s64 cmp = nodea->event_time - nodeb->event_time;

- return cmp;
+ if (nodea->event_time == nodeb->event_time)
+ return 0;
+ return nodea->event_time < nodeb->event_time ? -1 : 1;
}

static int process_events(struct evlist *evlist,
@@ -398,7 +399,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub

switch_evsel = evlist__add_sched_switch(evlist, true);
if (IS_ERR(switch_evsel)) {
- err = PTR_ERR(switch_evsel);
+ err = (int)PTR_ERR(switch_evsel);
pr_debug("Failed to create event %s\n", sched_switch);
goto out_err;
}
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index 74cdbd2ce9d0..fbdb463e965d 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -82,7 +82,7 @@ static bool is_ignored_symbol(const char *name, char type)
return true;

for (p = ignored_suffixes; *p; p++) {
- int l = strlen(name) - strlen(*p);
+ ssize_t l = strlen(name) - strlen(*p);

if (l >= 0 && !strcmp(name + l, *p))
return true;
@@ -313,7 +313,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
* _really_ have a problem.
*/
s64 skew = mem_end - UM(pair->end);
- if (llabs(skew) >= page_size)
+ if (llabs(skew) >= (s64)page_size)
pr_debug("WARN: %#" PRIx64 ": diff end addr for %s v: %#" PRIx64 " k: %#" PRIx64 "\n",
mem_start, sym->name, mem_end,
UM(pair->end));
diff --git a/tools/perf/tests/wp.c b/tools/perf/tests/wp.c
index 6c178985e37f..d5dd17eb5c05 100644
--- a/tools/perf/tests/wp.c
+++ b/tools/perf/tests/wp.c
@@ -31,10 +31,10 @@ volatile u8 data2[3];
#ifndef __s390x__
static int wp_read(int fd, long long *count, int size)
{
- int ret = read(fd, count, size);
+ ssize_t ret = read(fd, count, size);

if (ret != size) {
- pr_debug("failed to read: %d\n", ret);
+ pr_debug("failed to read: %zd\n", ret);
return -1;
}
return 0;
--
2.49.0.504.g3bcea36a83-goog