From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Borkmann Subject: Re: [PATCH bpf-next 2/3] selftests/bpf: add test cases for BPF_MAP_TYPE_QUEUE Date: Tue, 7 Aug 2018 15:42:20 +0200 Message-ID: References: <153356387977.6981.12236150594041620482.stgit@kernel> <153356391611.6981.14864460244240605372.stgit@kernel> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org To: Mauricio Vasquez B , Alexei Starovoitov Return-path: Received: from www62.your-server.de ([213.133.104.62]:34333 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389242AbeHGP4s (ORCPT ); Tue, 7 Aug 2018 11:56:48 -0400 In-Reply-To: <153356391611.6981.14864460244240605372.stgit@kernel> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 08/06/2018 03:58 PM, Mauricio Vasquez B wrote: > Signed-off-by: Mauricio Vasquez B > --- > tools/include/uapi/linux/bpf.h | 5 ++ > tools/testing/selftests/bpf/test_maps.c | 72 +++++++++++++++++++++++++++++++ > 2 files changed, 77 insertions(+) > > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h > index 0ebaaf7f3568..2c171c40eb45 100644 > --- a/tools/include/uapi/linux/bpf.h > +++ b/tools/include/uapi/linux/bpf.h > @@ -120,6 +120,7 @@ enum bpf_map_type { > BPF_MAP_TYPE_CPUMAP, > BPF_MAP_TYPE_XSKMAP, > BPF_MAP_TYPE_SOCKHASH, > + BPF_MAP_TYPE_QUEUE, > }; > > enum bpf_prog_type { > @@ -255,6 +256,10 @@ enum bpf_attach_type { > /* Flag for stack_map, store build_id+offset instead of pointer */ > #define BPF_F_STACK_BUILD_ID (1U << 5) > > +/* Flags for queue_map, type of queue */ > +#define BPF_F_QUEUE_FIFO (1U << 16) > +#define BPF_F_QUEUE_LIFO (2U << 16) > + > enum bpf_stack_build_id_status { > /* user space need an empty entry to identify end of a trace */ > BPF_STACK_BUILD_ID_EMPTY = 0, > diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c > index 6c253343a6f9..34567b017dbb 100644 > --- a/tools/testing/selftests/bpf/test_maps.c > +++ b/tools/testing/selftests/bpf/test_maps.c > @@ -457,6 +457,77 @@ static void test_devmap(int task, void *data) > close(fd); > } > > +static void test_queuemap(int task, void *data) > +{ > + __u32 value; > + int fd, i; > + > + /* test FIFO */ > + fd = bpf_create_map(BPF_MAP_TYPE_QUEUE, 0, sizeof(value), 32, > + BPF_F_QUEUE_FIFO); We should also feed in 'map_flags' so that both prealloc and non-prealloc will be tested. > + if (fd < 0) { > + printf("Failed to create queuemap '%s'!\n", strerror(errno)); > + exit(1); > + } > + > + /* Push 32 elements */ > + for (i = 0; i < 32; i++) { > + value = 1000 - i * 3; > + assert(bpf_map_update_elem(fd, NULL, &value, 0) == 0); > + } > + > + /* Check that element cannot be pushed due to max_entries limit */ > + value = 1000; > + assert(bpf_map_update_elem(fd, NULL, &value, 0) == -1 && > + errno == E2BIG); > + > + /* Pop all elements */ > + for (i = 0; i < 32; i++) > + assert(bpf_map_lookup_elem(fd, NULL, &value) == 0 && > + value == (1000 - i * 3)); > + > + /* Check that there are not elements left */ > + assert(bpf_map_lookup_elem(fd, NULL, &value) == -1 && errno == ENOENT); > + > + assert(bpf_map_delete_elem(fd, NULL) == -1 && errno == EINVAL); > + assert(bpf_map_get_next_key(fd, NULL, NULL) == -1 && errno == EINVAL); > + > + close(fd); > + > + /* test LIFO */ > + fd = bpf_create_map(BPF_MAP_TYPE_QUEUE, 0, sizeof(value), 32, > + BPF_F_QUEUE_LIFO); Ditto. > + if (fd < 0) { > + printf("Failed to create queuemap '%s'!\n", strerror(errno)); > + exit(1); > + } > + > + /* Push 32 elements */ > + for (i = 0; i < 32; i++) { > + value = 1000 - i * 3; > + assert(bpf_map_update_elem(fd, NULL, &value, 0) == 0); > + } > + > + /* Check that element cannot be pushed due to max_entries limit */ > + value = 1000; > + assert(bpf_map_update_elem(fd, NULL, &value, 0) == -1 && > + errno == E2BIG); > + > + /* Pop all elements */ > + for (i = 31; i >= 0; i--) > + assert(bpf_map_lookup_elem(fd, NULL, &value) == 0 && > + value == (1000 - i * 3)); > + > + /* Check that there are not elements left */ > + assert(bpf_map_lookup_elem(fd, NULL, &value) == -1 && > + errno == ENOENT); > + > + assert(bpf_map_delete_elem(fd, NULL) == -1 && errno == EINVAL); > + assert(bpf_map_get_next_key(fd, NULL, NULL) == -1 && errno == EINVAL); > + > + close(fd); > +} > + > #include > #include > #include > @@ -1162,6 +1233,7 @@ static void run_all_tests(void) > test_arraymap_percpu_many_keys(); > > test_devmap(0, NULL); > + test_queuemap(0, NULL); > test_sockmap(0, NULL); > > test_map_large(); >