From 219c8fb1eebfaf3ab40e5c7e5ba0242cf6e27643 Mon Sep 17 00:00:00 2001 From: chantra Date: Thu, 11 Aug 2022 22:11:06 +0000 Subject: [PATCH] [test][sockhash/map] Fix the test to work with kernels >= 5.15 Those tests have started to fail since kernel 5.15. The restriction was lifted in https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=0c48eefae712c2fd91480346a07a1a9cd0f9470b This diff makes the expected returned value to the call to `update_value` conditional on the kernel version. Tested on 5.15 (using a Ubuntu 22.04 host), which is representative of the kernel running in GH CI. Also tested on Ubuntu 20.04 stock kernel: ``` $ docker run -ti \ --privileged \ --network=host \ --pid=host \ -v $(pwd):/bcc \ -v /sys/kernel/debug:/sys/kernel/debug:rw \ -v /lib/modules:/lib/modules:ro \ -v /usr/src:/usr/src:ro \ -e CTEST_OUTPUT_ON_FAILURE=1 \ bcc-docker-focal \ /bin/bash -c \ '/bcc/build/tests/wrapper.sh \ c_test_all sudo /bcc/build/tests/cc/test_libbcc "test sock*"' =============================================================================== All tests passed (8 assertions in 2 test cases) [22:40:55] chantra@focal:bcc git:(fix_sock_map_tests*) $ uname -a Linux focal 5.4.0-122-generic #138-Ubuntu SMP Wed Jun 22 15:00:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux ``` --- tests/cc/test_sock_table.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/cc/test_sock_table.cc b/tests/cc/test_sock_table.cc index e389b9fb6737..e0aa41a47257 100644 --- a/tests/cc/test_sock_table.cc +++ b/tests/cc/test_sock_table.cc @@ -25,6 +25,14 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) +// Prior to 5.15, the socket must be TCP established socket to be updatable. +// https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=0c48eefae712c2fd91480346a07a1a9cd0f9470b +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) + bool expected_update_result = false; +#else + bool expected_update_result = true; +#endif + TEST_CASE("test sock map", "[sockmap]") { { const std::string BPF_PROGRAM = R"( @@ -58,9 +66,8 @@ int test(struct bpf_sock_ops *skops) res = sk_map.remove_value(key); REQUIRE(!res.ok()); - // the socket must be TCP established socket. res = sk_map.update_value(key, val); - REQUIRE(!res.ok()); + REQUIRE(res.ok() == expected_update_result); } } @@ -101,9 +108,8 @@ int test(struct bpf_sock_ops *skops) res = sk_hash.remove_value(key); REQUIRE(!res.ok()); - // the socket must be TCP established socket. res = sk_hash.update_value(key, val); - REQUIRE(!res.ok()); + REQUIRE(res.ok() == expected_update_result); } }