Skip to content

Commit 7bf4518

Browse files
authored
Merge pull request #2942 from vrbagalkot/bpf_v2
[v2] Enhancing kselftest to support BPF selftests
2 parents 98bea5c + dd860e3 commit 7bf4518

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

kernel/kselftest.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def setUp(self):
5959
if self.comp == "cpufreq":
6060
self.test_mode = self.params.get('test_mode', default='')
6161
self.testdir = 'tools/testing/selftests/cpufreq'
62+
if self.comp == "bpf":
63+
self.test_mode = self.params.get('test_mode', default='')
64+
self.testdir = 'tools/testing/selftests/bpf'
6265

6366
self.build_option = self.params.get('build_option', default='-bp')
6467
self.run_type = self.params.get('type', default='upstream')
@@ -104,30 +107,33 @@ def setUp(self):
104107
if self.run_type == 'upstream':
105108
location = self.params.get('location', default='https://github.c'
106109
'om/torvalds/linux/archive/master.zip')
107-
git_branch = self.params.get('branch', default='master')
108-
path = ''
109-
match = next(
110-
(ext for ext in [".zip", ".tar", ".gz"] if ext in location), None)
111-
if match:
112-
tarball = self.fetch_asset("kselftest%s" % match,
113-
locations=[location], expire='1d')
114-
extracted_dir = archive.uncompress(tarball, self.workdir)
115-
path = glob.glob(os.path.join(self.workdir, extracted_dir))
116-
else:
117-
git.get_repo(location, branch=git_branch,
118-
destination_dir=self.workdir)
119-
path = glob.glob(self.workdir)
120-
for l_dir in path:
121-
if os.path.isdir(l_dir) and 'Makefile' in os.listdir(l_dir):
122-
self.buldir = os.path.join(self.workdir, l_dir)
123-
break
110+
if re.match(r'^https|^git', location):
111+
git_branch = self.params.get('branch', default='master')
112+
path = ''
113+
match = next(
114+
(ext for ext in [".zip", ".tar", ".gz"] if ext in location), None)
115+
if match:
116+
tarball = self.fetch_asset("kselftest%s" % match,
117+
locations=[location], expire='1d')
118+
extracted_dir = archive.uncompress(tarball, self.workdir)
119+
path = glob.glob(os.path.join(self.workdir, extracted_dir))
120+
else:
121+
git.get_repo(location, branch=git_branch,
122+
destination_dir=self.workdir)
123+
path = glob.glob(self.workdir)
124+
for l_dir in path:
125+
if os.path.isdir(l_dir) and 'Makefile' in os.listdir(l_dir):
126+
self.buldir = os.path.join(self.workdir, l_dir)
127+
break
124128

125-
self.sourcedir = os.path.join(self.buldir, self.testdir)
126-
if self.comp != "cpufreq":
127-
process.system("make headers -C %s" % self.buldir, shell=True,
128-
sudo=True)
129-
process.system("make install -C %s" % self.sourcedir,
130-
shell=True, sudo=True)
129+
self.sourcedir = os.path.join(self.buldir, self.testdir)
130+
if (self.comp != "cpufreq" and self.comp != "bpf"):
131+
process.system("make headers -C %s" % self.buldir, shell=True,
132+
sudo=True)
133+
process.system("make install -C %s" % self.sourcedir,
134+
shell=True, sudo=True)
135+
else:
136+
self.buldir = self.params.get('location', default='')
131137
else:
132138
if self.subtest == 'pmu/event_code_tests':
133139
self.cancel("selftest not supported on distro")
@@ -163,7 +169,7 @@ def setUp(self):
163169
shell=True, sudo=True)
164170
process.system("sed -i 's/^.*cmsg_time.sh/#&/g' %s" % make_path,
165171
shell=True, sudo=True)
166-
if self.comp != "cpufreq":
172+
if (self.comp != "cpufreq" and self.comp != "bpf"):
167173
if self.comp:
168174
build_str = '-C %s' % self.comp
169175
if build.make(self.sourcedir, extra_args='%s' % build_str):
@@ -243,11 +249,13 @@ def ksmtest(self):
243249
.format(ksm_test_dir))
244250

245251
def bpf(self):
246-
bpf_test_dir = self.sourcedir + "/bpf/"
247-
os.chdir(bpf_test_dir)
248-
build.make(bpf_test_dir)
249-
self.run_cmd("./test_verifier")
250-
build.make(bpf_test_dir, extra_args='run_tests')
252+
"""
253+
Execute the kernel bpf selftests
254+
"""
255+
self.sourcedir = os.path.join(self.buldir, self.testdir)
256+
os.chdir(self.sourcedir)
257+
build.make(self.sourcedir)
258+
build.make(self.sourcedir, extra_args='run_tests')
251259

252260
def cpufreq(self):
253261
"""

kernel/kselftest.py.data/bpf.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
component: !mux
2+
bpf:
3+
comp: 'bpf'
4+
run_type: !mux
5+
upstream:
6+
type: 'upstream'
7+
location: ''

0 commit comments

Comments
 (0)