Re: [PATCH bpf-next v3 12/13] selftests/bpf: Add C tests for kptr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 20, 2022 at 09:25:09PM +0530, Kumar Kartikeya Dwivedi wrote:

SNIP

> +static __always_inline
> +void test_kptr(struct map_value *v)
> +{
> +	test_kptr_unref(v);
> +	test_kptr_ref(v);
> +	test_kptr_get(v);
> +}
> +
> +SEC("tc")
> +int test_map_kptr(struct __sk_buff *ctx)
> +{
> +	void *maps[] = {
> +		&array_map,
> +		&hash_map,
> +		&hash_malloc_map,
> +		&lru_hash_map,
> +	};
> +	struct map_value *v;
> +	int i, key = 0;
> +
> +	for (i = 0; i < sizeof(maps) / sizeof(*maps); i++) {
> +		v = bpf_map_lookup_elem(&array_map, &key);

hi,
I was just quickly checking on the usage, so I might be missing something,
but should this be lookup to maps[i] instead of array_map ?

similar below in test_map_in_map_kptr

jirka

> +		if (!v)
> +			return 0;
> +		test_kptr(v);
> +	}
> +	return 0;
> +}
> +
> +SEC("tc")
> +int test_map_in_map_kptr(struct __sk_buff *ctx)
> +{
> +	void *map_of_maps[] = {
> +		&array_of_array_maps,
> +		&array_of_hash_maps,
> +		&array_of_hash_malloc_maps,
> +		&array_of_lru_hash_maps,
> +		&hash_of_array_maps,
> +		&hash_of_hash_maps,
> +		&hash_of_hash_malloc_maps,
> +		&hash_of_lru_hash_maps,
> +	};
> +	struct map_value *v;
> +	int i, key = 0;
> +	void *map;
> +
> +	for (i = 0; i < sizeof(map_of_maps) / sizeof(*map_of_maps); i++) {
> +		map = bpf_map_lookup_elem(&array_of_array_maps, &key);
> +		if (!map)
> +			return 0;
> +		v = bpf_map_lookup_elem(map, &key);
> +		if (!v)
> +			return 0;
> +		test_kptr(v);
> +	}
> +	return 0;
> +}
> +
> +char _license[] SEC("license") = "GPL";
> -- 
> 2.35.1
> 



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux