Merge ~canonical-kernel-team/+git/autotest-client-tests:phlin/add-ubuntu_kselftests_net into ~canonical-kernel-team/+git/autotest-client-tests:master

Proposed by Po-Hsu Lin
Status: Merged
Merge reported by: Po-Hsu Lin
Merged at revision: e3f2032d7b2afc6978a879a3fa9d868d6f322676
Proposed branch: ~canonical-kernel-team/+git/autotest-client-tests:phlin/add-ubuntu_kselftests_net
Merge into: ~canonical-kernel-team/+git/autotest-client-tests:master
Diff against target: 290 lines (+260/-0)
5 files modified
ubuntu_kselftests_net/blacklist.trusty (+1/-0)
ubuntu_kselftests_net/control (+47/-0)
ubuntu_kselftests_net/control.ubuntu.xenial (+33/-0)
ubuntu_kselftests_net/helper.mk (+5/-0)
ubuntu_kselftests_net/ubuntu_kselftests_net.py (+174/-0)
Reviewer Review Type Date Requested Status
Sean Feole Approve
Magali Lemes do Sacramento Approve
Review via email: mp+456765@code.launchpad.net

Commit message

After moving ftrace out into ubuntu_kselftests_ftrace, net test is now
the biggest test in ubuntu_kernel_selftests. It can take up to 7h25m
on a Mantic Starfive VM (the whole test will take 8h9m)

By moving this test out it will:
  * Shorten the time we need if we need to rerun the test.
  * More flexibility for test suite selection (for CVE respins).
  * Give us more room to cover more tests in ubuntu_kernel_selftests,
    without the need to bump the timeout again.
  * If there is anything goes wrong in net category, we can still
    finish other tests in ubuntu_kernel_selftests.

The trade off is it will take extra provision time.

To post a comment you must log in.
Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

After merging this and it's running OK, we can proceed to remove the net test in https://code.launchpad.net/~canonical-kernel-team/+git/autotest-client-tests/+merge/456774

Revision history for this message
Magali Lemes do Sacramento (magalilemes) :
Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Inline comment replied, thanks for reviewing this. I will update the commit.

Revision history for this message
Po-Hsu Lin (cypressyew) wrote (last edit ):

New changes include:
  * Adding missing helper.mk
  * Fixing erroneous if statement for fcnal-test.sh test check
  * Adding missing kernel-wedge package
  * Fix a mis-indented else statement in control file.

Patch tested with B/F/J/L/M.

Revision history for this message
Magali Lemes do Sacramento (magalilemes) wrote :

LGTM!

review: Approve
Revision history for this message
Sean Feole (sfeole) wrote :
review: Approve
Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Applied and pushed, thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/ubuntu_kselftests_net/blacklist.trusty b/ubuntu_kselftests_net/blacklist.trusty
2new file mode 100644
3index 0000000..4682f80
4--- /dev/null
5+++ b/ubuntu_kselftests_net/blacklist.trusty
6@@ -0,0 +1 @@
7+We don't run net test on Trusty, just ['setup','breakpoints','cpu-hotplug','efivarfs','ipc','mount','powerpc','ptrace'].
8diff --git a/ubuntu_kselftests_net/control b/ubuntu_kselftests_net/control
9new file mode 100644
10index 0000000..23031df
11--- /dev/null
12+++ b/ubuntu_kselftests_net/control
13@@ -0,0 +1,47 @@
14+AUTHOR = "Ubuntu"
15+NAME = 'ubuntu_kselftests_net'
16+CRITERIA = """
17+Uses built-in kernel repository self tests for net.
18+"""
19+SUITE = "None"
20+TIME = "SHORT"
21+TEST_CLASS = 'kernel'
22+TEST_CATEGORY = 'Functional'
23+TEST_TYPE = "client"
24+DOC = ""
25+
26+
27+categories = ['net']
28+arch = platform.machine()
29+arch_scale = 1
30+# Scale timeouts by 2 for riscv64, some tests timeout due to lack of
31+# timeout, despite progressing fine
32+if arch in ['riscv64']:
33+ arch_scale = 2
34+
35+result = job.run_test_detail(NAME, test_name='setup', tag='setup', timeout=arch_scale*60*45)
36+if result == 'GOOD':
37+ for category in categories:
38+ build = '{}-build'.format(category)
39+ result = job.run_test_detail(NAME, test_name=build, tag=build, timeout=arch_scale*60*60)
40+ if result == 'ERROR':
41+ print("ERROR: test suite '{}' failed to build, skipping all the sub tests".format(category))
42+ continue
43+ mk_helper = os.path.join(job.testdir, NAME, 'helper.mk')
44+ dir_root = os.path.join(job.bindir, 'tmp', NAME, 'src', 'linux/tools/testing/selftests/')
45+ dir_src = os.path.join(dir_root, category)
46+ mk_src = os.path.join(dir_src, 'Makefile')
47+ os.chdir(dir_src)
48+ if os.path.isfile(mk_src):
49+ cmd = 'make -f {} -f {} gettests'.format(mk_src, mk_helper)
50+ tests = utils.system_output(cmd).split()
51+ for item in tests:
52+ timeout_threshold = arch_scale*60*45
53+ if item == 'fcnal-test.sh':
54+ timeout_threshold = arch_scale*60*75 # lp:2006499, lp:2012016
55+ test = "{}:{}".format(category, item)
56+ job.run_test_detail(NAME, test_name=test, tag=test, timeout=timeout_threshold)
57+else:
58+ print("ERROR: test failed to build, skipping all the sub tests")
59+
60+# vi:set ts=4 sw=4 expandtab syntax=python:
61diff --git a/ubuntu_kselftests_net/control.ubuntu.xenial b/ubuntu_kselftests_net/control.ubuntu.xenial
62new file mode 100644
63index 0000000..37dec82
64--- /dev/null
65+++ b/ubuntu_kselftests_net/control.ubuntu.xenial
66@@ -0,0 +1,33 @@
67+AUTHOR = "Ubuntu"
68+NAME = 'ubuntu_kselftests_net'
69+CRITERIA = """
70+Uses built-in kernel repository self tests for net.
71+"""
72+SUITE = "None"
73+TIME = "SHORT"
74+TEST_CLASS = 'kernel'
75+TEST_CATEGORY = 'Functional'
76+TEST_TYPE = "client"
77+DOC = ""
78+
79+
80+categories = ['net']
81+
82+result = job.run_test_detail(NAME, test_name='setup', tag='setup', timeout=60*30)
83+if result == 'ERROR':
84+ print("ERROR: test failed to build, skipping all the sub tests")
85+else:
86+ for category in categories:
87+ build = '{}-build'.format(category)
88+ job.run_test_detail(NAME, test_name=build, tag=build, timeout=60*10)
89+ mk_helper = os.path.join(job.testdir, NAME, 'helper.mk')
90+ dir_src = os.path.join(job.bindir, 'tmp', NAME, 'src', 'linux/tools/testing/selftests/', category)
91+ mk_src = os.path.join(dir_src, 'Makefile')
92+ os.chdir(dir_src)
93+ cmd = 'make -f {} -f {} gettests'.format(mk_helper, mk_src)
94+ tests = utils.system_output(cmd).split()
95+ for item in tests:
96+ test = "{}:{}".format(category, os.path.basename(item))
97+ job.run_test_detail(NAME, test_name=test, tag=test, timeout=60*30)
98+
99+# vi:set ts=4 sw=4 expandtab syntax=python:
100diff --git a/ubuntu_kselftests_net/helper.mk b/ubuntu_kselftests_net/helper.mk
101new file mode 100755
102index 0000000..ab3bb36
103--- /dev/null
104+++ b/ubuntu_kselftests_net/helper.mk
105@@ -0,0 +1,5 @@
106+gettests:
107+ @echo '$(notdir $(TEST_GEN_PROGS)) $(notdir $(TEST_CUSTOM_PROGS)) $(notdir $(TEST_PROGS))'
108+
109+getsubdirs:
110+ @echo '$(SUB_DIRS)'
111diff --git a/ubuntu_kselftests_net/ubuntu_kselftests_net.py b/ubuntu_kselftests_net/ubuntu_kselftests_net.py
112new file mode 100644
113index 0000000..766c904
114--- /dev/null
115+++ b/ubuntu_kselftests_net/ubuntu_kselftests_net.py
116@@ -0,0 +1,174 @@
117+#
118+#
119+import os
120+import platform
121+import re
122+from autotest.client import test, utils
123+from autotest.client.shared import error
124+
125+class ubuntu_kselftests_net(test.test):
126+ version = 1
127+
128+ def install_required_pkgs(self):
129+ '''Function to install necessary packages.'''
130+ pkgs = [
131+ 'build-essential',
132+ 'docutils-common', # For bpf test build
133+ 'ethtool', # For net:udpgro_fwd.sh
134+ 'iptables', # For net:ip_defrag.sh
135+ 'jq', # For net:altnames.sh
136+ 'kernel-wedge', # For "fakeroot debian/rules clean"
137+ 'libfuse-dev', # For net:reuseport_bpf_numa
138+ 'libnuma-dev', # For net:reuseport_bpf_numa
139+ 'libssl-dev', # For net:tcp_mmap
140+ 'netsniff-ng', # For net:altnames.sh
141+ 'net-tools', # For net:rtnetlink.sh
142+ 'pkg-config',
143+ 'uuid-runtime', # For net:rtnetlink.sh
144+ ]
145+ # For net:fib_tests.sh
146+ if not self.series in ['trusty', 'xenial', 'bionic']:
147+ pkgs.append('socat')
148+ if not self.arch == 's390x':
149+ if not self.series in ['trusty', 'xenial', 'bionic', 'focal', 'jammy']:
150+ # With recent kernels BPF requires lld (LLVM-based linker) to
151+ # build the corresponding kernel selftests, so make sure this
152+ # package is installed (in the releases where it is available)
153+ # lld is not available for s390x
154+ pkgs.append('lld')
155+ gcc = 'gcc' if self.arch in ['ppc64le', 'aarch64', 's390x', 'riscv64'] else 'gcc-multilib'
156+ pkgs.append(gcc)
157+
158+ # The modules-extra is required for net:rtnetlink.sh test
159+ if any(x in self.flavour for x in ['aws', 'azure', 'gcp', 'gke', 'ibm', 'oracle']):
160+ if not (self.flavour == 'aws' and self.series == 'trusty'):
161+ pkgs.append('linux-modules-extra-' + platform.uname()[2])
162+
163+ if self.kv >= 415:
164+ # extra packages for building bpf tests, which is required for some tests in net
165+ pkgs.extend(['libcap-dev', 'libelf-dev'])
166+ if self.kv == 504:
167+ # special case for B-5.4 (lp:1882559) / B-5.3 (lp:1845860)
168+ # clang on F is clang-10 but we need clang-9 (see commit 95f91d59642)
169+ # clang on E is clang-9, so it's ok to just check kv here
170+ pkgs.extend(['clang-9', 'llvm-9'])
171+ else:
172+ pkgs.extend(['clang', 'llvm'])
173+
174+ cmd = 'yes "" | DEBIAN_FRONTEND=noninteractive apt-get install --yes --force-yes ' + ' '.join(pkgs)
175+ utils.system_output(cmd, retain_output=True)
176+
177+ def initialize(self):
178+ self.arch = platform.processor()
179+ self.flavour = re.split('-\d*-', platform.uname()[2])[-1]
180+ try:
181+ self.series = platform.dist()[2]
182+ except AttributeError:
183+ import distro
184+ self.series = distro.codename()
185+ self.kv = platform.release().split(".")[:2]
186+ self.kv = int(self.kv[0]) * 100 + int(self.kv[1])
187+
188+ def download(self):
189+ '''Function to download kernel source.'''
190+ cmd = "dpkg -S /lib/modules/" + platform.release() + "/kernel | cut -d: -f 1 | cut -d, -f 1"
191+ pkg = os.popen(cmd).readlines()[0].strip()
192+ utils.system("apt-get source --download-only " + pkg)
193+
194+ def extract(self):
195+ '''Function to extract kernel source.'''
196+ os.system("rm -rf linux/")
197+ utils.system("dpkg-source -x linux*dsc linux")
198+
199+ def setup(self):
200+ '''Function to setup the test environment.'''
201+ self.install_required_pkgs()
202+ self.job.require_gcc()
203+ os.chdir(self.srcdir)
204+
205+ # Use a local repo for manual testing. If it does not exist, then clone from the master
206+ # repository.
207+ #
208+ if not os.path.exists('linux'):
209+ self.download()
210+ self.extract()
211+
212+ # clean source tree so changes from debian.foo/reconstruct
213+ # (e.g. deleting files) are applied
214+ os.chdir('linux')
215+ cmd = 'fakeroot debian/rules clean'
216+ utils.system(cmd)
217+ os.chdir(self.srcdir)
218+
219+ # net/txtimestamp.sh is very fragile, disable it
220+ #
221+ fn = 'linux/tools/testing/selftests/net/Makefile'
222+ if os.path.exists(fn):
223+ cmd = 'sed -i "/^TEST_PROGS += txtimestamp.sh$/d" ' + fn
224+ utils.system(cmd)
225+
226+ # Build header first (LP: #2031400)
227+ if not self.series in ['trusty', 'xenial', 'bionic', 'focal']:
228+ cmd = "make -C linux/ headers"
229+ utils.system_output(cmd, retain_output=True)
230+
231+
232+ def run_once(self, test_name):
233+ if test_name == 'setup':
234+ return
235+ if test_name.endswith('-build'):
236+ os.chdir(self.srcdir)
237+ if "net" in test_name:
238+ cmds = []
239+ cmds.append("sh -c 'echo 1 > /proc/sys/net/ipv4/conf/all/accept_local'")
240+ # The net benchmarching tests (e.g. udpgso) can fail when
241+ # optmem limit is reached.
242+ # https://www.kernel.org/doc/html/latest/networking/msg_zerocopy.html#transmission
243+ # LP #1960907
244+ cmds.append("sh -c 'echo 2048000 > /proc/sys/net/core/optmem_max'")
245+ for cmd in cmds:
246+ utils.system(cmd)
247+
248+ if self.kv >= 415:
249+ # net selftests use a module built by bpf selftests, bpf is available since bionic kernel
250+ if self.kv == 504:
251+ os.environ["CLANG"] = "clang-9"
252+ os.environ["LLC"] = "llc-9"
253+ os.environ["LLVM_OBJCOPY"] = "llvm-objcopy-9"
254+ os.environ["LLVM_READELF"] = "llvm-readelf-9"
255+ cmd = "make -C linux/tools/testing/selftests TARGETS=bpf SKIP_TARGETS= KDIR=/usr/src/linux-headers-{}".format(platform.release())
256+ # keep running selftests/net, even if selftests/bpf build fails
257+ utils.system(cmd, ignore_status=True)
258+ cmd = "make -C linux/tools/testing/selftests TARGETS={}".format(test_name.replace('-build', ''))
259+ utils.system_output(cmd, retain_output=True)
260+ return
261+
262+ category = test_name.split(':')[0]
263+ sub_test = test_name.split(':')[1]
264+ dir_root = os.path.join(self.srcdir, 'linux', 'tools', 'testing', 'selftests')
265+ os.chdir(dir_root)
266+ cmd = "make run_tests -C {} TEST_PROGS={} TEST_GEN_PROGS='' TEST_CUSTOM_PROGS=''".format(category, sub_test)
267+ result = utils.system_output(cmd, retain_output=True)
268+
269+ # The output of test_bpf.sh / test_blackhole_dev.sh test will be in the dmesg
270+ kernel_module_tests = {'test_bpf.sh': 'CONFIG_TEST_BPF',
271+ 'test_blackhole_dev.sh': 'CONFIG_TEST_BLACKHOLE_DEV'}
272+ if sub_test in kernel_module_tests.keys():
273+ output = utils.system_output('dmesg', retain_output=True)
274+ if not output:
275+ print("Looks like there's no dmesg output, checking for {}...".format(kernel_module_tests[sub_test]))
276+ cmd = "grep ^{} /boot/config-$(uname -r)".format(kernel_module_tests[sub_test])
277+ if not utils.system_output(cmd, verbose=False, ignore_status=True):
278+ print("{} not enabled.".format(kernel_module_tests[sub_test]))
279+
280+ # Old pattern for Xenial
281+ pattern = re.compile('selftests: *(?P<case>[\w\-\.]+) \[FAIL\]\n')
282+ if re.search(pattern, result):
283+ raise error.TestError(test_name + ' failed.')
284+ # If the test was not end by previous check, check again with new pattern
285+ pattern = re.compile('not ok [\d\.]* selftests: {}: {} # (?!.*SKIP)'.format(category, sub_test))
286+ if re.search(pattern, result):
287+ raise error.TestError(test_name + ' failed.')
288+
289+
290+# vi:set ts=4 sw=4 expandtab syntax=python:

Subscribers

People subscribed via source and target branches

to all changes: