summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoanne Koong <joannekoong@fb.com>2021-10-30 01:49:09 +0300
committerAlexei Starovoitov <ast@kernel.org>2021-11-02 00:16:03 +0300
commit7a67087250f0003acc1b9e20eda01635e1e51f9a (patch)
tree0aa974eb45a14bdf059b733702ac35caee42134d
parent8845b4681bf44b9d2d2badf2c67cf476e42a86bd (diff)
downloadlinux-7a67087250f0003acc1b9e20eda01635e1e51f9a.tar.xz
selftests/bpf: Add bloom map success test for userspace calls
This patch has two changes: 1) Adds a new function "test_success_cases" to test successfully creating + adding + looking up a value in a bloom filter map from the userspace side. 2) Use bpf_create_map instead of bpf_create_map_xattr in the "test_fail_cases" and test_inner_map to make the code look cleaner. Signed-off-by: Joanne Koong <joannekoong@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20211029224909.1721024-4-joannekoong@fb.com
-rw-r--r--tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c b/tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
index 9aa3fbed918b..be73e3de6668 100644
--- a/tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
+++ b/tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
@@ -7,44 +7,31 @@
static void test_fail_cases(void)
{
- struct bpf_create_map_attr xattr = {
- .name = "bloom_filter_map",
- .map_type = BPF_MAP_TYPE_BLOOM_FILTER,
- .max_entries = 100,
- .value_size = 11,
- };
__u32 value;
int fd, err;
/* Invalid key size */
- xattr.key_size = 4;
- fd = bpf_create_map_xattr(&xattr);
+ fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 4, sizeof(value), 100, 0);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid key size"))
close(fd);
- xattr.key_size = 0;
/* Invalid value size */
- xattr.value_size = 0;
- fd = bpf_create_map_xattr(&xattr);
+ fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, 0, 100, 0);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid value size 0"))
close(fd);
- xattr.value_size = 11;
/* Invalid max entries size */
- xattr.max_entries = 0;
- fd = bpf_create_map_xattr(&xattr);
+ fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 0, 0);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid max entries size"))
close(fd);
- xattr.max_entries = 100;
/* Bloom filter maps do not support BPF_F_NO_PREALLOC */
- xattr.map_flags = BPF_F_NO_PREALLOC;
- fd = bpf_create_map_xattr(&xattr);
+ fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 100,
+ BPF_F_NO_PREALLOC);
if (!ASSERT_LT(fd, 0, "bpf_create_map bloom filter invalid flags"))
close(fd);
- xattr.map_flags = 0;
- fd = bpf_create_map_xattr(&xattr);
+ fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 100, 0);
if (!ASSERT_GE(fd, 0, "bpf_create_map bloom filter"))
return;
@@ -67,6 +54,30 @@ static void test_fail_cases(void)
close(fd);
}
+static void test_success_cases(void)
+{
+ char value[11];
+ int fd, err;
+
+ /* Create a map */
+ fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(value), 100,
+ BPF_F_ZERO_SEED | BPF_F_NUMA_NODE);
+ if (!ASSERT_GE(fd, 0, "bpf_create_map bloom filter success case"))
+ return;
+
+ /* Add a value to the bloom filter */
+ err = bpf_map_update_elem(fd, NULL, &value, 0);
+ if (!ASSERT_OK(err, "bpf_map_update_elem bloom filter success case"))
+ goto done;
+
+ /* Lookup a value in the bloom filter */
+ err = bpf_map_lookup_elem(fd, NULL, &value);
+ ASSERT_OK(err, "bpf_map_update_elem bloom filter success case");
+
+done:
+ close(fd);
+}
+
static void check_bloom(struct bloom_filter_map *skel)
{
struct bpf_link *link;
@@ -86,16 +97,11 @@ static void test_inner_map(struct bloom_filter_map *skel, const __u32 *rand_vals
__u32 nr_rand_vals)
{
int outer_map_fd, inner_map_fd, err, i, key = 0;
- struct bpf_create_map_attr xattr = {
- .name = "bloom_filter_inner_map",
- .map_type = BPF_MAP_TYPE_BLOOM_FILTER,
- .value_size = sizeof(__u32),
- .max_entries = nr_rand_vals,
- };
struct bpf_link *link;
/* Create a bloom filter map that will be used as the inner map */
- inner_map_fd = bpf_create_map_xattr(&xattr);
+ inner_map_fd = bpf_create_map(BPF_MAP_TYPE_BLOOM_FILTER, 0, sizeof(*rand_vals),
+ nr_rand_vals, 0);
if (!ASSERT_GE(inner_map_fd, 0, "bpf_create_map bloom filter inner map"))
return;
@@ -190,6 +196,7 @@ void test_bloom_filter_map(void)
int err;
test_fail_cases();
+ test_success_cases();
err = setup_progs(&skel, &rand_vals, &nr_rand_vals);
if (err)