From ddfedaa921bb22452147aa1b25cc3e764a66802e Mon Sep 17 00:00:00 2001 From: Dave Marchevsky Date: Tue, 28 Dec 2021 22:45:22 -0500 Subject: [PATCH] add fedora docker tests + move dockerfiles to a new dir Dockerfiles are cluttering up the main repo dir, so move them to a newly-created 'docker' dir. Add a fedora dockerfile and use it in bcc-test workflow. --- .dockerignore | 1 + .github/workflows/bcc-test.yml | 82 ++++++++++++++++++- CMakeLists.txt | 1 + Dockerfile.debian => docker/Dockerfile.debian | 0 docker/Dockerfile.fedora | 43 ++++++++++ Dockerfile.tests => docker/Dockerfile.tests | 0 Dockerfile.ubuntu => docker/Dockerfile.ubuntu | 0 scripts/docker/build.sh | 2 +- tests/lua/CMakeLists.txt | 26 +++--- tests/lua/test_uprobes.lua | 8 +- tests/python/test_uprobes.py | 9 +- 11 files changed, 151 insertions(+), 21 deletions(-) rename Dockerfile.debian => docker/Dockerfile.debian (100%) create mode 100644 docker/Dockerfile.fedora rename Dockerfile.tests => docker/Dockerfile.tests (100%) rename Dockerfile.ubuntu => docker/Dockerfile.ubuntu (100%) diff --git a/.dockerignore b/.dockerignore index d963b7ea70ad..1a8eb5e6fc1c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ Dockerfile* build .*.swp +docker/Dockerfile* diff --git a/.github/workflows/bcc-test.yml b/.github/workflows/bcc-test.yml index e59d8a461dd6..6085062d54f8 100644 --- a/.github/workflows/bcc-test.yml +++ b/.github/workflows/bcc-test.yml @@ -28,7 +28,7 @@ jobs: docker build \ --build-arg UBUNTU_VERSION=${{ matrix.os.version }} \ --build-arg UBUNTU_SHORTNAME=${{ matrix.os.nick }} \ - -t bcc-docker -f Dockerfile.tests . + -t bcc-docker -f docker/Dockerfile.tests . - name: Run bcc build env: ${{ matrix.env }} run: | @@ -94,6 +94,86 @@ jobs: name: critical-tests-${{ matrix.env['TYPE'] }}-${{ matrix.os.version }} path: tests/python/critical.log + test_bcc_fedora: + runs-on: ubuntu-20.04 + strategy: + matrix: + env: + - TYPE: Debug + PYTHON_TEST_LOGFILE: critical.log + - TYPE: Release + PYTHON_TEST_LOGFILE: critical.log + steps: + - uses: actions/checkout@v2 + - name: System info + run: | + uname -a + ip addr + - name: Build docker container with all deps + run: | + docker build \ + -t bcc-docker -f docker/Dockerfile.fedora . + - name: Run bcc build + env: ${{ matrix.env }} + run: | + /bin/bash -c \ + "docker run --privileged \ + --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 \ + -v /usr/include/linux:/usr/include/linux:ro \ + bcc-docker \ + /bin/bash -c \ + 'mkdir -p /bcc/build && cd /bcc/build && \ + cmake -DCMAKE_BUILD_TYPE=${TYPE} -DENABLE_LLVM_SHARED=ON -DRUN_LUA_TESTS=OFF .. && make -j9'" + - name: Run bcc's cc tests + env: ${{ matrix.env }} + # tests are wrapped with `script` as a hack to get a TTY as github actions doesn't provide this + # see https://github.com/actions/runner/issues/241 + run: | + script -e -c /bin/bash -c \ + "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 \ + /bin/bash -c \ + '/bcc/build/tests/wrapper.sh \ + c_test_all sudo /bcc/build/tests/cc/test_libbcc'" + + - name: Run all tests + env: ${{ matrix.env }} + run: | + script -e -c /bin/bash -c \ + "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 \ + /bin/bash -c \ + 'cd /bcc/build && \ + make test PYTHON_TEST_LOGFILE=$PYTHON_TEST_LOGFILE ARGS=-V'" + + - name: Check critical tests + env: ${{ matrix.env }} + run: | + critical_count=$(grep @mayFail tests/python/critical.log | wc -l) + echo "There were $critical_count critical tests skipped with @mayFail:" + grep -A2 @mayFail tests/python/critical.log + + # To debug weird issues, you can add this step to be able to SSH to the test environment # https://github.com/marketplace/actions/debugging-with-tmate # - name: Setup tmate session diff --git a/CMakeLists.txt b/CMakeLists.txt index 13abaec62a30..1d7dabe58aca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON) option(ENABLE_EXAMPLES "Build examples" ON) option(ENABLE_MAN "Build man pages" ON) option(ENABLE_TESTS "Build tests" ON) +option(RUN_LUA_TESTS "Run lua tests" ON) CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/Dockerfile.debian b/docker/Dockerfile.debian similarity index 100% rename from Dockerfile.debian rename to docker/Dockerfile.debian diff --git a/docker/Dockerfile.fedora b/docker/Dockerfile.fedora new file mode 100644 index 000000000000..4089049c2843 --- /dev/null +++ b/docker/Dockerfile.fedora @@ -0,0 +1,43 @@ +# Copyright (c) PLUMgrid, Inc. +# Licensed under the Apache License, Version 2.0 (the "License") + +FROM fedora:34 + +MAINTAINER Dave Marchevsky + +RUN dnf -y install \ + bison \ + cmake \ + flex \ + gcc \ + gcc-c++ \ + git \ + libxml2-devel \ + make \ + rpm-build \ + wget \ + zlib-devel \ + llvm \ + llvm-devel \ + clang-devel \ + elfutils-debuginfod-client-devel \ +# elfutils-libelf-devel-static \ + elfutils-libelf-devel \ + luajit \ + luajit-devel \ + python3-devel \ + libstdc++ \ + libstdc++-devel + +RUN dnf -y install \ + python3 \ + python3-pip + +RUN dnf -y install \ + procps \ + iputils \ + net-tools \ + hostname \ + iproute + +RUN pip3 install pyroute2==0.5.18 netaddr==0.8.0 dnslib==0.9.14 cachetools==3.1.1 diff --git a/Dockerfile.tests b/docker/Dockerfile.tests similarity index 100% rename from Dockerfile.tests rename to docker/Dockerfile.tests diff --git a/Dockerfile.ubuntu b/docker/Dockerfile.ubuntu similarity index 100% rename from Dockerfile.ubuntu rename to docker/Dockerfile.ubuntu diff --git a/scripts/docker/build.sh b/scripts/docker/build.sh index e2952c337483..9c906389a435 100755 --- a/scripts/docker/build.sh +++ b/scripts/docker/build.sh @@ -20,7 +20,7 @@ distro=${4:-ubuntu} # The main docker image build, echo "Building ${distro} ${os_tag} release docker image for ${docker_repo}:${docker_tag}" -docker build -t ${docker_repo}:${docker_tag} --build-arg OS_TAG=${os_tag} -f Dockerfile.${distro} . +docker build -t ${docker_repo}:${docker_tag} --build-arg OS_TAG=${os_tag} -f docker/Dockerfile.${distro} . echo "Copying build artifacts to $(pwd)/output" mkdir -p output diff --git a/tests/lua/CMakeLists.txt b/tests/lua/CMakeLists.txt index d3d7298a93bb..7db41e910605 100644 --- a/tests/lua/CMakeLists.txt +++ b/tests/lua/CMakeLists.txt @@ -1,21 +1,23 @@ find_program(LUAJIT luajit) find_program(BUSTED busted) -if(LUAJIT) - add_test(NAME lua_test_clang WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ${TEST_WRAPPER} lua_test_clang sudo ${LUAJIT} test_clang.lua) +if(RUN_LUA_TESTS) + if(LUAJIT) + add_test(NAME lua_test_clang WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${TEST_WRAPPER} lua_test_clang sudo ${LUAJIT} test_clang.lua) - add_test(NAME lua_test_uprobes WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ${TEST_WRAPPER} lua_test_uprobes sudo ${LUAJIT} test_uprobes.lua) + add_test(NAME lua_test_uprobes WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${TEST_WRAPPER} lua_test_uprobes sudo ${LUAJIT} test_uprobes.lua) - add_test(NAME lua_test_dump WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ${TEST_WRAPPER} lua_test_dump sudo ${LUAJIT} test_dump.lua) + add_test(NAME lua_test_dump WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${TEST_WRAPPER} lua_test_dump sudo ${LUAJIT} test_dump.lua) - add_test(NAME lua_test_standalone WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_standalone.sh) + add_test(NAME lua_test_standalone WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_standalone.sh) - if(BUSTED) - add_test(NAME lua_test_busted WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND busted --lua=${LUAJIT} -m "${CMAKE_CURRENT_SOURCE_DIR}/../../src/lua/?.lua" -m "${CMAKE_CURRENT_SOURCE_DIR}/../../src/lua/?/init.lua;") + if(BUSTED) + add_test(NAME lua_test_busted WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND busted --lua=${LUAJIT} -m "${CMAKE_CURRENT_SOURCE_DIR}/../../src/lua/?.lua" -m "${CMAKE_CURRENT_SOURCE_DIR}/../../src/lua/?/init.lua;") + endif() endif() endif() diff --git a/tests/lua/test_uprobes.lua b/tests/lua/test_uprobes.lua index 059486e28110..9323d61a5a2e 100644 --- a/tests/lua/test_uprobes.lua +++ b/tests/lua/test_uprobes.lua @@ -54,10 +54,12 @@ int count(struct pt_regs *ctx) { }]] local b = BPF:new{text=text} - b:attach_uprobe{name="/usr/bin/python", sym="main", fn_name="count"} - b:attach_uprobe{name="/usr/bin/python", sym="main", fn_name="count", retprobe=true} + local pythonpath = "/usr/bin/python3" + local symname = "_start" + b:attach_uprobe{name=pythonpath, sym=symname, fn_name="count"} + b:attach_uprobe{name=pythonpath, sym=symname, fn_name="count", retprobe=true} - os.spawn("/usr/bin/python -V") + os.spawn(pythonpath .. " -V") local stats = b:get_table("stats") assert_true(tonumber(stats:get(0)) >= 2) diff --git a/tests/python/test_uprobes.py b/tests/python/test_uprobes.py index afbf0e11308d..3682f460403c 100755 --- a/tests/python/test_uprobes.py +++ b/tests/python/test_uprobes.py @@ -57,13 +57,14 @@ def test_simple_binary(self): }""" b = bcc.BPF(text=text) pythonpath = "/usr/bin/python3" - b.attach_uprobe(name=pythonpath, sym="main", fn_name="count") - b.attach_uretprobe(name=pythonpath, sym="main", fn_name="count") + symname = "_start" + b.attach_uprobe(name=pythonpath, sym=symname, fn_name="count") + b.attach_uretprobe(name=pythonpath, sym=symname, fn_name="count") with os.popen(pythonpath + " -V") as f: pass self.assertGreater(b["stats"][ctypes.c_int(0)].value, 0) - b.detach_uretprobe(name=pythonpath, sym="main") - b.detach_uprobe(name=pythonpath, sym="main") + b.detach_uretprobe(name=pythonpath, sym=symname) + b.detach_uprobe(name=pythonpath, sym=symname) def test_mount_namespace(self): text = """