Skip to content

Commit 9028bbc

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftest/bpf: Fix compilation warnings in 32-bit mode
Fix compilation warnings emitted when compiling selftests for 32-bit platform (x86 in my case). Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 09f44b7 commit 9028bbc

File tree

9 files changed

+24
-19
lines changed

9 files changed

+24
-19
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ void test_bpf_obj_id(void)
159159
/* Check getting link info */
160160
info_len = sizeof(struct bpf_link_info) * 2;
161161
bzero(&link_infos[i], info_len);
162-
link_infos[i].raw_tracepoint.tp_name = (__u64)&tp_name;
162+
link_infos[i].raw_tracepoint.tp_name = ptr_to_u64(&tp_name);
163163
link_infos[i].raw_tracepoint.tp_name_len = sizeof(tp_name);
164164
err = bpf_obj_get_info_by_fd(bpf_link__fd(links[i]),
165165
&link_infos[i], &info_len);
166166
if (CHECK(err ||
167167
link_infos[i].type != BPF_LINK_TYPE_RAW_TRACEPOINT ||
168168
link_infos[i].prog_id != prog_infos[i].id ||
169-
link_infos[i].raw_tracepoint.tp_name != (__u64)&tp_name ||
170-
strcmp((char *)link_infos[i].raw_tracepoint.tp_name,
169+
link_infos[i].raw_tracepoint.tp_name != ptr_to_u64(&tp_name) ||
170+
strcmp(u64_to_ptr(link_infos[i].raw_tracepoint.tp_name),
171171
"sys_enter") ||
172172
info_len != sizeof(struct bpf_link_info),
173173
"get-link-info(fd)",
@@ -178,7 +178,7 @@ void test_bpf_obj_id(void)
178178
link_infos[i].type, BPF_LINK_TYPE_RAW_TRACEPOINT,
179179
link_infos[i].id,
180180
link_infos[i].prog_id, prog_infos[i].id,
181-
(char *)link_infos[i].raw_tracepoint.tp_name,
181+
(const char *)u64_to_ptr(link_infos[i].raw_tracepoint.tp_name),
182182
"sys_enter"))
183183
goto done;
184184

tools/testing/selftests/bpf/prog_tests/core_extern.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ void test_core_extern(void)
159159
exp = (uint64_t *)&t->data;
160160
for (j = 0; j < n; j++) {
161161
CHECK(got[j] != exp[j], "check_res",
162-
"result #%d: expected %lx, but got %lx\n",
163-
j, exp[j], got[j]);
162+
"result #%d: expected %llx, but got %llx\n",
163+
j, (__u64)exp[j], (__u64)got[j]);
164164
}
165165
cleanup:
166166
test_core_extern__destroy(skel);

tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
1616
__u32 duration = 0, retval;
1717
struct bpf_map *data_map;
1818
const int zero = 0;
19-
u64 *result = NULL;
19+
__u64 *result = NULL;
2020

2121
err = bpf_prog_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
2222
&pkt_obj, &pkt_fd);
@@ -29,7 +29,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
2929

3030
link = calloc(sizeof(struct bpf_link *), prog_cnt);
3131
prog = calloc(sizeof(struct bpf_program *), prog_cnt);
32-
result = malloc((prog_cnt + 32 /* spare */) * sizeof(u64));
32+
result = malloc((prog_cnt + 32 /* spare */) * sizeof(__u64));
3333
if (CHECK(!link || !prog || !result, "alloc_memory",
3434
"failed to alloc memory"))
3535
goto close_prog;
@@ -72,7 +72,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
7272
goto close_prog;
7373

7474
for (i = 0; i < prog_cnt; i++)
75-
if (CHECK(result[i] != 1, "result", "fexit_bpf2bpf failed err %ld\n",
75+
if (CHECK(result[i] != 1, "result", "fexit_bpf2bpf failed err %llu\n",
7676
result[i]))
7777
goto close_prog;
7878

tools/testing/selftests/bpf/prog_tests/flow_dissector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ void test_flow_dissector(void)
591591
CHECK_ATTR(tattr.data_size_out != sizeof(flow_keys) ||
592592
err || tattr.retval != 1,
593593
tests[i].name,
594-
"err %d errno %d retval %d duration %d size %u/%lu\n",
594+
"err %d errno %d retval %d duration %d size %u/%zu\n",
595595
err, errno, tattr.retval, tattr.duration,
596596
tattr.data_size_out, sizeof(flow_keys));
597597
CHECK_FLOW_KEYS(tests[i].name, flow_keys, tests[i].keys);

tools/testing/selftests/bpf/prog_tests/global_data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
static void test_global_data_number(struct bpf_object *obj, __u32 duration)
66
{
77
int i, err, map_fd;
8-
uint64_t num;
8+
__u64 num;
99

1010
map_fd = bpf_find_map(__func__, obj, "result_number");
1111
if (CHECK_FAIL(map_fd < 0))
@@ -14,7 +14,7 @@ static void test_global_data_number(struct bpf_object *obj, __u32 duration)
1414
struct {
1515
char *name;
1616
uint32_t key;
17-
uint64_t num;
17+
__u64 num;
1818
} tests[] = {
1919
{ "relocate .bss reference", 0, 0 },
2020
{ "relocate .data reference", 1, 42 },
@@ -32,7 +32,7 @@ static void test_global_data_number(struct bpf_object *obj, __u32 duration)
3232
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
3333
err = bpf_map_lookup_elem(map_fd, &tests[i].key, &num);
3434
CHECK(err || num != tests[i].num, tests[i].name,
35-
"err %d result %lx expected %lx\n",
35+
"err %d result %llx expected %llx\n",
3636
err, num, tests[i].num);
3737
}
3838
}

tools/testing/selftests/bpf/prog_tests/prog_run_xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void test_prog_run_xattr(void)
2828
"err %d errno %d retval %d\n", err, errno, tattr.retval);
2929

3030
CHECK_ATTR(tattr.data_size_out != sizeof(pkt_v4), "data_size_out",
31-
"incorrect output size, want %lu have %u\n",
31+
"incorrect output size, want %zu have %u\n",
3232
sizeof(pkt_v4), tattr.data_size_out);
3333

3434
CHECK_ATTR(buf[5] != 0, "overflow",

tools/testing/selftests/bpf/prog_tests/skb_ctx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void test_skb_ctx(void)
8181

8282
CHECK_ATTR(tattr.ctx_size_out != sizeof(skb),
8383
"ctx_size_out",
84-
"incorrect output size, want %lu have %u\n",
84+
"incorrect output size, want %zu have %u\n",
8585
sizeof(skb), tattr.ctx_size_out);
8686

8787
for (i = 0; i < 5; i++)

tools/testing/selftests/bpf/test_btf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,7 +3883,7 @@ static int test_big_btf_info(unsigned int test_num)
38833883
info_garbage.garbage = 0;
38843884
err = bpf_obj_get_info_by_fd(btf_fd, info, &info_len);
38853885
if (CHECK(err || info_len != sizeof(*info),
3886-
"err:%d errno:%d info_len:%u sizeof(*info):%lu",
3886+
"err:%d errno:%d info_len:%u sizeof(*info):%zu",
38873887
err, errno, info_len, sizeof(*info))) {
38883888
err = -1;
38893889
goto done;
@@ -4094,7 +4094,7 @@ static int do_test_get_info(unsigned int test_num)
40944094
if (CHECK(err || !info.id || info_len != sizeof(info) ||
40954095
info.btf_size != raw_btf_size ||
40964096
(ret = memcmp(raw_btf, user_btf, expected_nbytes)),
4097-
"err:%d errno:%d info.id:%u info_len:%u sizeof(info):%lu raw_btf_size:%u info.btf_size:%u expected_nbytes:%u memcmp:%d",
4097+
"err:%d errno:%d info.id:%u info_len:%u sizeof(info):%zu raw_btf_size:%u info.btf_size:%u expected_nbytes:%u memcmp:%d",
40984098
err, errno, info.id, info_len, sizeof(info),
40994099
raw_btf_size, info.btf_size, expected_nbytes, ret)) {
41004100
err = -1;
@@ -4730,15 +4730,15 @@ ssize_t get_pprint_expected_line(enum pprint_mapv_kind_t mapv_kind,
47304730

47314731
nexpected_line = snprintf(expected_line, line_size,
47324732
"%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
4733-
"{%lu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
4733+
"{%llu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
47344734
"%u,0x%x,[[%d,%d],[%d,%d]]}\n",
47354735
percpu_map ? "\tcpu" : "",
47364736
percpu_map ? cpu : next_key,
47374737
v->ui32, v->si32,
47384738
v->unused_bits2a,
47394739
v->bits28,
47404740
v->unused_bits2b,
4741-
v->ui64,
4741+
(__u64)v->ui64,
47424742
v->ui8a[0], v->ui8a[1],
47434743
v->ui8a[2], v->ui8a[3],
47444744
v->ui8a[4], v->ui8a[5],

tools/testing/selftests/bpf/test_progs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ static inline __u64 ptr_to_u64(const void *ptr)
135135
return (__u64) (unsigned long) ptr;
136136
}
137137

138+
static inline void *u64_to_ptr(__u64 ptr)
139+
{
140+
return (void *) (unsigned long) ptr;
141+
}
142+
138143
int bpf_find_map(const char *test, struct bpf_object *obj, const char *name);
139144
int compare_map_keys(int map1_fd, int map2_fd);
140145
int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len);

0 commit comments

Comments
 (0)