docker + tests: Run tests using python3, refactor Dockerfile
authorDave Marchevsky <davemarchevsky@fb.com>
Mon, 20 Dec 2021 20:23:37 +0000 (15:23 -0500)
committeryonghong-song <ys114321@gmail.com>
Mon, 20 Dec 2021 22:49:45 +0000 (14:49 -0800)
In #3707, I added ubuntu-20.04 to the list of OS's bcc-test uses to run
tests. I expected that this would result in the tests running on both
18.04 and 20.04. Unfortunately this change was effectively a no-op as
the tests are run in a Docker container and the os field in bcc-test.yml
dictates the type/version of the _host_ OS, not the container's OS.

So it's not necessary to run on both, just run on 20.04. It will be
necessary to modify Dockerfile.test to use both 18.04 and 20.04. To
prepare for this, move all python tests to use python3 interpreter, as
20.04 doesn't have python2 pip readily available.

Also, refactor Dockerfile.tests a bit so that it's possible to provide
ubuntu version and shortname as build input.

This commit does not result in the docker test container working/running
both 18.04 and 20.04, rather lays groundwork for future commits to do
so.

Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
45 files changed:
.github/workflows/bcc-test.yml
Dockerfile.tests
src/python/CMakeLists.txt
tests/python/test_array.py
tests/python/test_attach_perf_event.py
tests/python/test_bpf_log.py
tests/python/test_brb.py
tests/python/test_brb2.py
tests/python/test_call1.py
tests/python/test_clang.py
tests/python/test_debuginfo.py
tests/python/test_disassembler.py
tests/python/test_dump_func.py
tests/python/test_flags.py
tests/python/test_free_bcc_memory.py
tests/python/test_histogram.py
tests/python/test_license.py
tests/python/test_lpm_trie.py
tests/python/test_lru.py
tests/python/test_map_batch_ops.py
tests/python/test_map_in_map.py
tests/python/test_percpu.py
tests/python/test_perf_event.py
tests/python/test_probe_count.py
tests/python/test_queuestack.py
tests/python/test_ringbuf.py
tests/python/test_rlimit.py
tests/python/test_shared_table.py
tests/python/test_stackid.py
tests/python/test_stat1.py
tests/python/test_tools_memleak.py
tests/python/test_tools_smoke.py
tests/python/test_trace2.py
tests/python/test_trace3.py
tests/python/test_trace4.py
tests/python/test_trace_maxactive.py
tests/python/test_tracepoint.py
tests/python/test_uprobes.py
tests/python/test_uprobes2.py
tests/python/test_usdt.py
tests/python/test_usdt2.py
tests/python/test_usdt3.py
tests/python/test_utils.py
tests/python/test_xlate1.py
tests/wrapper.sh.in

index 324495f7709e727a2ee1bc3ab2653b12e7fb720c..4f52d7adfc14fd8d04d17c53132c56eea3927b37 100644 (file)
@@ -11,7 +11,7 @@ jobs:
     runs-on: ${{ matrix.os }}
     strategy:
       matrix:
-        os: [ubuntu-18.04, ubuntu-20.04] # 18.04.3 release has 5.0.0 kernel                                        
+        os: [ubuntu-20.04]
         env:
         - TYPE: Debug
           PYTHON_TEST_LOGFILE: critical.log
index 99b6a445bdd47854d991db4b8a4c005c02cbb3b6..3b082364b65edfdc2d24578c6670b16780b689cf 100644 (file)
@@ -1,17 +1,23 @@
-FROM ubuntu:18.04
+ARG UBUNTU_VERSION="18.04"
+FROM ubuntu:${UBUNTU_VERSION}
 
 ARG LLVM_VERSION="8"
 ENV LLVM_VERSION=$LLVM_VERSION
 
+ARG UBUNTU_SHORTNAME="bionic"
+
 RUN apt-get update && apt-get install -y curl gnupg &&\
     llvmRepository="\n\
-deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main\n\
-deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main\n\
-deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${LLVM_VERSION} main\n\
-deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${LLVM_VERSION} main\n" &&\
+deb http://apt.llvm.org/${UBUNTU_SHORTNAME}/ llvm-toolchain-${UBUNTU_SHORTNAME} main\n\
+deb-src http://apt.llvm.org/${UBUNTU_SHORTNAME}/ llvm-toolchain-${UBUNTU_SHORTNAME} main\n\
+deb http://apt.llvm.org/${UBUNTU_SHORTNAME}/ llvm-toolchain-${UBUNTU_SHORTNAME}-${LLVM_VERSION} main\n\
+deb-src http://apt.llvm.org/${UBUNTU_SHORTNAME}/ llvm-toolchain-${UBUNTU_SHORTNAME}-${LLVM_VERSION} main\n" &&\
     echo $llvmRepository >> /etc/apt/sources.list && \
     curl -L https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
 
+ARG DEBIAN_FRONTEND="noninteractive"
+ENV TZ="Etc/UTC"
+
 RUN apt-get update && apt-get install -y \
       util-linux \
       bison \
@@ -40,7 +46,6 @@ RUN apt-get update && apt-get install -y \
       iproute2 \
       python3 \
       python3-pip \
-      python-pip \
       ethtool \
       arping \
       netperf \
@@ -50,8 +55,7 @@ RUN apt-get update && apt-get install -y \
       libtinfo5 \
       libtinfo-dev
 
-RUN pip3 install pyroute2 netaddr dnslib cachetools
-RUN pip install pyroute2==0.5.18 netaddr==0.8.0 dnslib==0.9.14 cachetools==3.1.1
+RUN pip3 install pyroute2==0.5.18 netaddr==0.8.0 dnslib==0.9.14 cachetools==3.1.1
 
 # FIXME this is faster than building from source, but it seems there is a bug
 # in probing libruby.so rather than ruby binary
index fa602397c1a85ef30ebd7304e84ab3af362a26c6..f5c40b953a7d0397e126256eb92fd5a455047594 100644 (file)
@@ -2,7 +2,7 @@
 # Licensed under the Apache License, Version 2.0 (the "License")
 
 if(NOT PYTHON_CMD)
-  set(PYTHON_CMD "python")
+  set(PYTHON_CMD "python3")
 endif()
 
 if(EXISTS "/etc/debian_version")
index 1461226d11538d82a517af6d5c07b1680e16102c..0ca995d437059388797daf0a82ce0f6b2fd2b935 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index a843b575c2ed6dc015bd3814110564bf08b649ce..f4bae4ff122c3840b9cc0656f4b638861609b257 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright 2021, Athira Rajeev, IBM Corp.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index cb3d00385db3e6eb40a812307fedada541dc81e3..e38c5eae4895b827f0584390926970215d09c993 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 74617566fab41f99c4a6d2ccbbe8febf4d22466e..ed4cb7f7d4beb4a578eadc9e73292251b4b1b3f4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index f983de1626d44484b00891e57e1bc3711f3fcfa9..c7ef90ee4804350f8617bf92fdc359ccf033ab0f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 6766cab3026f00af1b961b648d592b8616223ab6..db40e1a791d7bc2c4555c0c7e1d634b8a7f68b8f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index f6c05baeae670a7ee74252ecd787fb4b6ac706da..7bf12cc36116bbfda3666a0124daa33a77d87c2f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 28f29e6fe25815eb2a5f82789910dfd57ad74b42..3bf5a2b9574e6fd3265635531dd60ca5a08d8974 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) Sasha Goldshtein
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 89c4ec5606a1efdd553ccda9e658f0a697b67ab2..bf324d2b362462ca55eb20e91cf72bff356b9d22 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) Clevernet
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 6fd3b49c1bd75cb12088f3072d16c383263bee44..56872f5d0129a52bf3accf9b98bdf8887e6905fd 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index a5d2b42d39a84dca8b00ee1dd07cc29d986c8a36..1e0cb5a4868ea6e86d60f0219e47b260f030131b 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 7d6f6f4340d5d4bd258a2884e553bcd0c2a79024..232baa6ec8b8d029106f279aa29be092d4d346f8 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_usdt.py
 #
index cb878c6de883b44a1a61b3c3c7409dba285223c0..92eee91e2bd96d740cdd5e7149b38ef2aa4a1995 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 1358579cb471080d21b2dee9cbe771641d5f79ce..f9b070da4ff6efb41d9a0184b3e1c00b12392a65 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) 2018 Clevernet, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 638362a64ea894acdd10bc4a0c72f376b3fff2f8..e77ae3f42309daae59413cff0261e8f68dcf33a9 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) 2017 Facebook, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 2946edccf47bcac82bbec7ed372159bf0416ff16..5d4a049e4f351b3c04bec48444ddecea97d6c080 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index ffc9bde633b3b67718673a54abf781d8a6a83bb8..8efa6855cb01ca2c0cdf11f67917e87fbe70dc1d 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_map_batch_ops.py
 #
index 751eb79ea79fdd09638fd96647f440f7c1839ed4..46e62927051efbd23c5502cbe6633a5e0b530ff1 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_map_in_map.py
 #
index b493752eeac23b1567ffefb3380f112a990f4bf9..e1c646c033d791247c9cb40ac1f654b7909a61ea 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 882e71a1e437f0b00e20038ab306e26ab2d4c858..6119ec722e9850d7c7863792924d948c132d0c30 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) 2016 PLUMgrid
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 1e40305f0af76cdfd7d3f75b930add39d0333787..3fbfc1802528beb89065c778f81612274c8dfdd0 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) Suchakra Sharma <suchakrapani.sharma@polymtl.ca>
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index c00283db164da0cef542e967fbe398027661aa38..47ee792508f161c543e7c2ec2c325ecd00fe62e4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 93245be5d708a2647fdae572c9b153da1c48df99..87adbff440df5629dc6ad08a92547675755e0c97 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index deda8a7806380753e959a4f405f813f952c183ce..8e93baba00eb02b71159d59c8b376fd8105e6274 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_usdt.py
 #
index 10dd63f8749e884d557320139336823221f1d9c4..7b8f9d5bea279bcd82df0a3725d3ad143600045b 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) 2016 Facebook, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 34a756b47ba48beb85a1f3d3330681ac0404ba73..707604e9d8fb7e347e4ea6814560bb5d55a6a47f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 1043309952009c1a5888e1e934d88b646f46e07b..313e2a9e210f9280542e4a33171316cdbb27beff 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 45528b83c1b6c5d27eb3d991cf15cfeade6b4c88..df023667f62519b2ed9abc5f6615b59fa74f6a1c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from unittest import main, skipUnless, TestCase
 from utils import kernel_version_ge
index 64bf500adf0a22dcdf3190d90600c3636038b7d6..182e3e911d6eb3b54aa57066e34dcd20f44eb88b 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) Sasha Goldshtein, 2017
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 8614bca79ccc35c899b835143b783304f3e7dbc1..d7094c3bc816844961d324731297855c6031f1c3 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 7843d74284486cd0e0cf447af2bc6056546c5d1b..a0493011d44b32765ef069d72cad7b390c0e5466 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 8fb680e68e152834688374d502f71870683c901c..a4b8ab02078891e8671cd3f860ba8ce417c65cdb 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 677ca8bb5c91c9d90464c233fc3600c24c914bd5..e75d7e87b3f6d974562a159abb90630adb58c7bc 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index ddc2c9797682bbd471cfde7a5384e720e7285a67..a2dd40f4ce17794b6e228efcbefce7831d79ad55 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) Sasha Goldshtein
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index f7c78e7547f72e946a1a105797a67e4795569edc..621b45cff8700dde62e94c2c9ac79098a15d0bf9 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 6118754a6068c570fce217a688aa71c8c710243b..0c0b0101f23c372b8bc3c161c977fbde6535674a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_uprobe2.py
 #
index d84ccc99afe15e71fd3ae5ca279ba0851d1f07e6..d026a503e891b80db3e2d47ea72b0b819f2d7929 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_usdt.py
 #
index c2b2daeb8f24629c71f5f1e2df063a24b9c864bc..f8da339d798e2ae00ea407428fe85c35897d6ec3 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_usdt2.py
 #
index 5fe2ef4f18c3088ddc2bfd2f07313bdd948fa8af..a378fd48509e9c24cb28bf18480c48f3a41ddf43 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # USAGE: test_usdt3.py
 #
index 54b97cfb4b75186cd73c687c3fa031cdb102c35c..9a3b7b7a5e4116caee273a80aa2f15cd1da2ffd4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) Catalysts GmbH
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 5183e2a2097b0379fd8691d0fa3dff3568dc17b5..3057c45d12b5970d3f060f164c0ca372c1332465 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (c) PLUMgrid, Inc.
 # Licensed under the Apache License, Version 2.0 (the "License")
 
index 88229dcd3cf0b98dd3f78c2ee8dd959d8980cde7..a096ac87551a49e959c26599ccb6a162e2f07d84 100755 (executable)
@@ -8,7 +8,7 @@ name=$1; shift
 kind=$1; shift
 cmd=$1; shift
 
-PYTHONPATH=@CMAKE_BINARY_DIR@/src/python/bcc-python
+PYTHONPATH=@CMAKE_BINARY_DIR@/src/python/bcc-python3
 LD_LIBRARY_PATH=@CMAKE_BINARY_DIR@:@CMAKE_BINARY_DIR@/src/cc
 
 ns=$name