Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Improve inner_map test coverage.

Check that hash and array inner maps are properly initialized.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211201181040.23337-14-alexei.starovoitov@gmail.com

authored by

Alexei Starovoitov and committed by
Andrii Nakryiko
d82fa9b7 bc5f75da

+14 -2
+14 -2
tools/testing/selftests/bpf/progs/map_ptr_kern.c
··· 334 334 return 1; 335 335 } 336 336 337 + #define INNER_MAX_ENTRIES 1234 338 + 337 339 struct inner_map { 338 340 __uint(type, BPF_MAP_TYPE_ARRAY); 339 - __uint(max_entries, 1); 341 + __uint(max_entries, INNER_MAX_ENTRIES); 340 342 __type(key, __u32); 341 343 __type(value, __u32); 342 344 } inner_map SEC(".maps"); ··· 350 348 __type(value, __u32); 351 349 __array(values, struct { 352 350 __uint(type, BPF_MAP_TYPE_ARRAY); 353 - __uint(max_entries, 1); 351 + __uint(max_entries, INNER_MAX_ENTRIES); 354 352 __type(key, __u32); 355 353 __type(value, __u32); 356 354 }); ··· 362 360 { 363 361 struct bpf_array *array_of_maps = (struct bpf_array *)&m_array_of_maps; 364 362 struct bpf_map *map = (struct bpf_map *)&m_array_of_maps; 363 + struct bpf_array *inner_map; 364 + int key = 0; 365 365 366 366 VERIFY(check_default(&array_of_maps->map, map)); 367 + inner_map = bpf_map_lookup_elem(array_of_maps, &key); 368 + VERIFY(inner_map != 0); 369 + VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES); 367 370 368 371 return 1; 369 372 } ··· 389 382 { 390 383 struct bpf_htab *hash_of_maps = (struct bpf_htab *)&m_hash_of_maps; 391 384 struct bpf_map *map = (struct bpf_map *)&m_hash_of_maps; 385 + struct bpf_htab *inner_map; 386 + int key = 2; 392 387 393 388 VERIFY(check_default(&hash_of_maps->map, map)); 389 + inner_map = bpf_map_lookup_elem(hash_of_maps, &key); 390 + VERIFY(inner_map != 0); 391 + VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES); 394 392 395 393 return 1; 396 394 }