Skip to content

Commit 7eab3a5

Browse files
chentao-kernelanakryiko
authored andcommitted
bpf/selftests: Check errno when percpu map value size exceeds
This test case checks the errno message when percpu map value size exceeds PCPU_MIN_UNIT_SIZE. root@debian:~# ./test_maps ... test_map_percpu_stats_hash_of_maps:PASS test_map_percpu_stats_map_value_size:PASS test_sk_storage_map:PASS Signed-off-by: Jinke Han <[email protected]> Signed-off-by: Tao Chen <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 1d24478 commit 7eab3a5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tools/testing/selftests/bpf/map_tests/map_percpu_stats.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define MAX_ENTRIES_HASH_OF_MAPS 64
1818
#define N_THREADS 8
1919
#define MAX_MAP_KEY_SIZE 4
20+
#define PCPU_MIN_UNIT_SIZE 32768
2021

2122
static void map_info(int map_fd, struct bpf_map_info *info)
2223
{
@@ -456,6 +457,22 @@ static void map_percpu_stats_hash_of_maps(void)
456457
printf("test_%s:PASS\n", __func__);
457458
}
458459

460+
static void map_percpu_stats_map_value_size(void)
461+
{
462+
int fd;
463+
int value_sz = PCPU_MIN_UNIT_SIZE + 1;
464+
struct bpf_map_create_opts opts = { .sz = sizeof(opts) };
465+
enum bpf_map_type map_types[] = { BPF_MAP_TYPE_PERCPU_ARRAY,
466+
BPF_MAP_TYPE_PERCPU_HASH,
467+
BPF_MAP_TYPE_LRU_PERCPU_HASH };
468+
for (int i = 0; i < ARRAY_SIZE(map_types); i++) {
469+
fd = bpf_map_create(map_types[i], NULL, sizeof(__u32), value_sz, 1, &opts);
470+
CHECK(fd < 0 && errno != E2BIG, "percpu map value size",
471+
"error: %s\n", strerror(errno));
472+
}
473+
printf("test_%s:PASS\n", __func__);
474+
}
475+
459476
void test_map_percpu_stats(void)
460477
{
461478
map_percpu_stats_hash();
@@ -467,4 +484,5 @@ void test_map_percpu_stats(void)
467484
map_percpu_stats_percpu_lru_hash();
468485
map_percpu_stats_percpu_lru_hash_no_common();
469486
map_percpu_stats_hash_of_maps();
487+
map_percpu_stats_map_value_size();
470488
}

0 commit comments

Comments
 (0)