Skip to content

Commit 82daea9

Browse files
nashifgalak
authored andcommitted
ci: limit CI to only changed architecture
If files are changed for architecture code, then only run CI on those architectures. Combine all scripts into one and make it simpler. Signed-off-by: Anas Nashif <[email protected]>
1 parent 28bc79b commit 82daea9

File tree

5 files changed

+137
-170
lines changed

5 files changed

+137
-170
lines changed

scripts/ci/get_modified_boards.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

scripts/ci/get_modified_tests.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

scripts/ci/get_twister_opt.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Copyright (c) 2021 Intel Corporation
4+
5+
# A script to generate twister options based on modified files.
6+
7+
import re, os
8+
import sh
9+
import argparse
10+
import glob
11+
12+
if "ZEPHYR_BASE" not in os.environ:
13+
exit("$ZEPHYR_BASE environment variable undefined.")
14+
15+
repository_path = os.environ['ZEPHYR_BASE']
16+
sh_special_args = {
17+
'_tty_out': False,
18+
'_cwd': repository_path
19+
}
20+
21+
def parse_args():
22+
parser = argparse.ArgumentParser(
23+
description="Generate twister argument files based on modified file")
24+
parser.add_argument('-c', '--commits', default=None,
25+
help="Commit range in the form: a..b")
26+
return parser.parse_args()
27+
28+
def find_archs(files):
29+
# we match both arch/<arch>/* and include/arch/<arch> and skip common.
30+
# Some architectures like riscv require special handling, i.e. riscv
31+
# directory covers 2 architectures known to twister: riscv32 and riscv64.
32+
archs = set()
33+
34+
for f in files:
35+
p = re.match(r"^arch\/([^/]+)\/", f)
36+
if not p:
37+
p = re.match(r"^include\/arch\/([^/]+)\/", f)
38+
if p:
39+
if p.group(1) != 'common':
40+
if p.group(1) == 'riscv':
41+
archs.add('riscv32')
42+
archs.add('riscv64')
43+
else:
44+
archs.add(p.group(1))
45+
46+
if archs:
47+
with open("modified_archs.args", "w") as fp:
48+
fp.write("-a\n%s" %("\n-a\n".join(archs)))
49+
50+
def find_boards(files):
51+
boards = set()
52+
all_boards = set()
53+
54+
for f in files:
55+
if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"):
56+
continue
57+
p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f)
58+
if p and p.groups():
59+
boards.add(p.group(1))
60+
61+
for b in boards:
62+
suboards = glob.glob("boards/*/%s/*.yaml" %(b))
63+
for subboard in suboards:
64+
name = os.path.splitext(os.path.basename(subboard))[0]
65+
if name:
66+
all_boards.add(name)
67+
68+
if all_boards:
69+
with open("modified_boards.args", "w") as fp:
70+
fp.write("-p\n%s" %("\n-p\n".join(all_boards)))
71+
72+
def find_tests(files):
73+
tests = set()
74+
for f in files:
75+
if f.endswith(".rst"):
76+
continue
77+
d = os.path.dirname(f)
78+
while d:
79+
if os.path.exists(os.path.join(d, "testcase.yaml")) or \
80+
os.path.exists(os.path.join(d, "sample.yaml")):
81+
tests.add(d)
82+
break
83+
else:
84+
d = os.path.dirname(d)
85+
86+
if tests:
87+
with open("modified_tests.args", "w") as fp:
88+
fp.write("-T\n%s\n--all" %("\n-T\n".join(tests)))
89+
90+
if __name__ == "__main__":
91+
92+
args = parse_args()
93+
if not args.commits:
94+
exit(1)
95+
96+
# pylint does not like the 'sh' library
97+
# pylint: disable=too-many-function-args,unexpected-keyword-arg
98+
commit = sh.git("diff", "--name-only", args.commits, **sh_special_args)
99+
files = commit.split("\n")
100+
101+
find_boards(files)
102+
find_archs(files)
103+
find_tests(files)

scripts/ci/run_ci.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ set -xe
2222

2323
twister_options=" --inline-logs -N -v --integration"
2424
export BSIM_OUT_PATH="${BSIM_OUT_PATH:-/opt/bsim/}"
25-
if [ ! -d "${BSIM_OUT_PATH}" ]; then
25+
if [ ! -d "${BSIM_OUT_PATH}x" ]; then
2626
unset BSIM_OUT_PATH
2727
fi
2828
export BSIM_COMPONENTS_PATH="${BSIM_OUT_PATH}/components/"
@@ -104,16 +104,21 @@ function run_bsim_bt_tests() {
104104

105105
function get_tests_to_run() {
106106
./scripts/zephyr_module.py --twister-out module_tests.args
107-
./scripts/ci/get_modified_tests.py --commits ${commit_range} > modified_tests.args
108-
./scripts/ci/get_modified_boards.py --commits ${commit_range} > modified_boards.args
107+
./scripts/ci/get_twister_opt.py --commits ${commit_range}
109108

110109
if [ -s modified_boards.args ]; then
111-
${twister} ${twister_options} +modified_boards.args --save-tests test_file_1.txt || exit 1
110+
${twister} ${twister_options} +modified_boards.args \
111+
--save-tests test_file_1.txt || exit 1
112112
fi
113113
if [ -s modified_tests.args ]; then
114-
${twister} ${twister_options} +modified_tests.args --save-tests test_file_2.txt || exit 1
114+
${twister} ${twister_options} +modified_tests.args \
115+
--save-tests test_file_2.txt || exit 1
115116
fi
116-
rm -f modified_tests.args modified_boards.args
117+
if [ -s modified_archs.args ]; then
118+
${twister} ${twister_options} +modified_archs.args \
119+
--save-tests test_file_3.txt || exit 1
120+
fi
121+
rm -f modified_tests.args modified_boards.args modified_archs.args
117122
}
118123

119124

@@ -209,6 +214,7 @@ if [ -n "$main_ci" ]; then
209214
# https://stackoverflow.com/questions/3398258/edit-shell-script-while-its-running
210215
git rebase $remote/${branch}
211216
else
217+
echo "Full Run"
212218
SC="full"
213219
fi
214220
$short_git_log
@@ -226,7 +232,7 @@ if [ -n "$main_ci" ]; then
226232

227233
# cleanup
228234
rm -f test_file.txt
229-
touch test_file_1.txt test_file_2.txt
235+
touch test_file_1.txt test_file_2.txt test_file_3.txt
230236

231237
# In a pull-request see if we have changed any tests or board definitions
232238
if [ -n "${pull_request_nr}" -o -n "${local_run}" ]; then
@@ -235,16 +241,18 @@ if [ -n "$main_ci" ]; then
235241

236242
if [ "$SC" == "full" ]; then
237243
# Save list of tests to be run
238-
${twister} ${twister_options} --save-tests test_file_3.txt || exit 1
244+
${twister} ${twister_options} --save-tests test_file_4.txt || exit 1
239245
else
240-
echo "test,arch,platform,status,extra_args,handler,handler_time,ram_size,rom_size" > test_file_3.txt
246+
echo "test,arch,platform,status,extra_args,handler,handler_time,ram_size,rom_size" \
247+
> test_file_4.txt
241248
fi
242249

243250
# Remove headers from all files but the first one to generate one
244251
# single file with only one header row
252+
tail -n +2 test_file_3.txt > test_file_3_in.txt
245253
tail -n +2 test_file_2.txt > test_file_2_in.txt
246254
tail -n +2 test_file_1.txt > test_file_1_in.txt
247-
cat test_file_3.txt test_file_2_in.txt test_file_1_in.txt > test_file.txt
255+
cat test_file_4.txt test_file_3_in.txt test_file_2_in.txt test_file_1_in.txt > test_file.txt
248256

249257
echo "+++ run twister"
250258

scripts/ci/twister_ignore.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ Makefile
2323
tests/*
2424
samples/*
2525
boards/*/*/*
26+
arch/xtensa/*
27+
arch/x86/*
28+
arch/posix/*
29+
arch/arc/*
30+
arch/sparc/*
31+
arch/arm/*
32+
arch/nios2/*
33+
arch/riscv/*
34+
include/arch/xtensa/*
35+
include/arch/x86/*
36+
include/arch/posix/*
37+
include/arch/arc/*
38+
include/arch/sparc/*
39+
include/arch/arm/*
40+
include/arch/nios2/*
41+
include/arch/riscv/*
2642
doc/*
2743
# GH action have no impact on code
2844
.github/*

0 commit comments

Comments
 (0)