Skip to content

Commit

Permalink
[test][sockhash/map] Fix the test to work with kernels >= 5.15
Browse files Browse the repository at this point in the history
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 iovisor#138-Ubuntu SMP Wed Jun 22 15:00:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
```
  • Loading branch information
chantra committed Aug 11, 2022
1 parent 69f652e commit 219c8fb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tests/cc/test_sock_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 219c8fb

Please sign in to comment.