Skip to content

Commit 8d40928

Browse files
committed
actions: twister: determine nodes in python script
Improve calculation of matrix and move calculations from workflow to the testplan script. We now generate a file that can be parsed by the action with the data needed to start twister with the right number of nodes. Signed-off-by: Anas Nashif <[email protected]>
1 parent d52212b commit 8d40928

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

.github/workflows/twister.yaml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,26 @@ jobs:
7676
echo "Your branch is not up to date, you need to rebase on top of latest HEAD of main branch"
7777
exit 1
7878
)
79-
python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --pull-request
80-
81-
# get number of tests
82-
if [ -s testplan.csv ]; then
83-
lines=$(wc -l < testplan.csv)
84-
else
85-
lines=1
86-
fi
87-
if [ "$lines" = 1 ]; then
88-
# no tests, so we need 0 nodes
89-
nodes=0
79+
python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --pull-request -t $TESTS_PER_BUILDER
80+
if [ -s .testplan ]; then
81+
cat .testplan >> $GITHUB_ENV
9082
else
91-
nodes=$(( ${lines} / ${TESTS_PER_BUILDER}))
92-
if [ ${nodes} -gt 4 -a ${nodes} -lt 10 ]; then
93-
nodes=${MATRIX_SIZE}
94-
elif [ "${nodes}" = 0 ]; then
95-
# for less than TESTS_PER_BUILDER, we take at least 1 node
96-
nodes=1
97-
fi
83+
echo "TWISTER_NODES=${MATRIX_SIZE}" >> $GITHUB_ENV
9884
fi
99-
echo "::set-output name=calculated_matrix_size::${nodes}";
100-
rm -f testplan.csv
85+
86+
87+
rm -f testplan.csv .testplan
10188
10289
- name: Determine matrix size
10390
id: output-services
10491
run: |
10592
if [ "${{github.event_name}}" = "pull_request_target" ]; then
106-
if [ -n "${{steps.test-plan.outputs.calculated_matrix_size}}" ]; then
107-
subset="[$(seq -s',' 1 ${{steps.test-plan.outputs.calculated_matrix_size}})]"
93+
if [ -n "${TWISTER_NODES}" ]; then
94+
subset="[$(seq -s',' 1 ${TWISTER_NODES})]"
10895
else
10996
subset="[$(seq -s',' 1 ${MATRIX_SIZE})]"
11097
fi
111-
size=${{ steps.test-plan.outputs.calculated_matrix_size }}
98+
size=${TWISTER_NODES}
11299
elif [ "${{github.event_name}}" = "push" ]; then
113100
subset="[$(seq -s',' 1 ${PUSH_MATRIX_SIZE})]"
114101
size=${MATRIX_SIZE}

scripts/ci/test_plan.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ def parse_args():
284284
help="This is a pull request")
285285
parser.add_argument('-p', '--platform', action="append",
286286
help="Limit this for a platform or a list of platforms.")
287+
parser.add_argument('-t', '--tests_per_builder', default=700, type=int,
288+
help="Number of tests per builder")
289+
parser.add_argument('-n', '--default-matrix', default=10, type=int,
290+
help="Number of tests per builder")
287291

288292
return parser.parse_args()
289293

@@ -317,6 +321,18 @@ def parse_args():
317321
dup_free_set.add(tuple(x))
318322

319323
logging.info(f'Total tests to be run: {len(dup_free)}')
324+
with open(".testplan", "w") as tp:
325+
total_tests = len(dup_free)
326+
nodes = round(total_tests / args.tests_per_builder)
327+
if total_tests % args.tests_per_builder != total_tests:
328+
nodes = nodes + 1
329+
330+
if nodes > 5:
331+
nodes = args.default_matrix
332+
333+
tp.write(f"TWISTER_TESTS={total_tests}\n")
334+
tp.write(f"TWISTER_NODES={nodes}\n")
335+
320336
header = ['test', 'arch', 'platform', 'status', 'extra_args', 'handler',
321337
'handler_time', 'ram_size', 'rom_size']
322338

0 commit comments

Comments
 (0)