Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kenlig committed Oct 19, 2024
1 parent 05fd2aa commit a16889a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions runtime/unit-test/maps/kernel_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,36 @@ TEST_CASE("test_arraymap_percpu (kernel)")
key = 1;
REQUIRE((map.elem_delete_userspace(&key) < 0 && errno == EINVAL));
}
TEST_CASE("test_arraymap_percpu_many_keys (kernel)")
{
shm_remove remover(SHM_NAME);
managed_shared_memory mem(boost::interprocess::create_only, SHM_NAME,
20 << 20);

unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
BPF_DECLARE_PERCPU(long, values);
/* nr_keys is not too large otherwise the test stresses percpu
* allocator more than anything else
*/
unsigned int nr_keys = 2000;
int key, i;

per_cpu_array_map_impl map(mem, sizeof(bpf_percpu(values, 0)), nr_keys);

for (i = 0; i < (int)nr_cpus; i++)
bpf_percpu(values, i) = i + 10;

for (key = 0; key < (int)nr_keys; key++)
REQUIRE(map.elem_update_userspace(&key, values, BPF_ANY) == 0);

for (key = 0; key < (int)nr_keys; key++) {
for (i = 0; i < (int)nr_cpus; i++)
bpf_percpu(values, i) = 0;
void *value_ptr;
REQUIRE((value_ptr = map.elem_lookup_userspace(&key)) !=
nullptr);
memcpy(values, value_ptr, sizeof(values));
for (i = 0; i < (int)nr_cpus; i++)
REQUIRE(bpf_percpu(values, i) == i + 10);
}
}

0 comments on commit a16889a

Please sign in to comment.