Skip to content

Commit 292be22

Browse files
authored
Add script that generates list of test targets (#4464)
Add script that calculates test targets based on gn deps is added to the build step. The output from this script is then passed through the build pipeline to each of the steps that use the list. b/382508397
1 parent 0a51082 commit 292be22

42 files changed

Lines changed: 758 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/build/action.yaml‎

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
targets:
55
description: "List of ninja targets for Cobalt build."
66
required: true
7+
test_root_target:
8+
description: "The root target from which to deduce what tests to run."
9+
required: true
710
upload_on_host_test_artifacts:
811
description: "Indicates if on-host test artifacts should be uploaded."
912
required: true
@@ -16,27 +19,6 @@ inputs:
1619
runs:
1720
using: "composite"
1821
steps:
19-
- name: Get depot tools
20-
run: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
21-
shell: bash
22-
- name: Add depot tools to PATH
23-
run: echo "$GITHUB_WORKSPACE/depot_tools" >> $GITHUB_PATH
24-
shell: bash
25-
- name: Generate gclient file
26-
run: gclient config --name=src --custom-var=download_remoteexec_cfg=True --custom-var='rbe_instance="projects/cobalt-actions-prod/instances/default_instance"' https://github.com/${{ github.repository }}
27-
shell: bash
28-
- name: Set target OS for Android
29-
if: ${{ contains(matrix.platform, 'android') }}
30-
run: |
31-
echo "target_os=['android']" >> .gclient
32-
gclient validate
33-
shell: bash
34-
- name: gclient sync
35-
run: gclient sync -v --shallow --no-history -r ${{ github.sha }}
36-
shell: bash
37-
- name: Disable Chromium client side build telemetry
38-
run: build_telemetry opt-out
39-
shell: bash
4022
- name: GN gen
4123
run: |
4224
cd src
@@ -47,23 +29,57 @@ runs:
4729
cd src
4830
gn args --list --short --overrides-only out/${{ matrix.platform }}_${{ matrix.config }}
4931
shell: bash
50-
- name: Calculate Test Targets
51-
# TODO(b/382508397): Replace hardcoded list with dynamically generated one.
52-
id: test-targets
53-
if: inputs.upload_on_host_test_artifacts == 'true' || inputs.upload_on_device_test_artifacts == 'true'
32+
- name: Get list of changed files
33+
if: github.event_name == 'pull_request'
34+
id: changed-files
35+
run: |
36+
set -x
37+
cd src
38+
changed_files=($(git diff --name-only -r ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}))
39+
# Convert the bash array to a JSON array.
40+
changed_files_json=$(jq -nc '$ARGS.positional' --args ${changed_files[@]})
41+
echo "changed_files_json=${changed_files_json}" >> $GITHUB_OUTPUT
42+
shell: bash
43+
- name: Calculate test targets
44+
if: matrix.config == 'devel' && inputs.test_root_target != 'null'
45+
id: calculate-test-targets
5446
env:
55-
TEST_TARGETS_JSON_FILE: cobalt/build/testing/targets/${{ matrix.platform }}/test_targets.json
47+
CHANGED_FILES_JSON: ${{ steps.changed-files.outputs.changed_files_json }}
48+
ROOT_TARGET: ${{ inputs.test_root_target }}
49+
TEST_TARGETS_JSON_FILE: out/${{ matrix.platform }}_${{ matrix.config }}/test_targets.json
5650
run: |
57-
set -ex
51+
set -x
5852
cd src
59-
echo "test_targets=$(cat ${TEST_TARGETS_JSON_FILE} | jq -c '.test_targets')" >> $GITHUB_OUTPUT
53+
gn desc out/${{ matrix.platform }}_${{ matrix.config }}/ "*" --format=json > gn_desc.json
54+
# Trim any warning gn printed before the json (all lines above the first curly brace).
55+
sed -n '/^{/,$p' -i gn_desc.json
56+
57+
changed_files_arg=""
58+
if [[ -n "${CHANGED_FILES_JSON}" ]]; then
59+
changed_files_arg="--sources $(echo ${CHANGED_FILES_JSON} | jq -cr '. | join(",")')"
60+
fi
61+
62+
vpython3 cobalt/build/test_targets.py \
63+
--root-target "${ROOT_TARGET}" \
64+
${changed_files_arg} \
65+
--gn-json gn_desc.json \
66+
--json-output > "${TEST_TARGETS_JSON_FILE}"
67+
68+
echo "test_targets_json_file=${TEST_TARGETS_JSON_FILE}" >> $GITHUB_OUTPUT
69+
70+
test_targets_json=$(cat ${TEST_TARGETS_JSON_FILE} | jq -cr '.test_targets')
71+
echo "test_targets_json=${test_targets_json}" >> $GITHUB_OUTPUT
72+
73+
test_targets_count=$(echo ${test_targets_json} | jq -cr 'length')
74+
echo "test_targets_count=${test_targets_count}" >> $GITHUB_OUTPUT
6075
shell: bash
6176
- name: Ninja build test targets
62-
if: inputs.upload_on_host_test_artifacts == 'true' || inputs.upload_on_device_test_artifacts == 'true'
77+
if: ${{ matrix.config == 'devel' && fromJSON(steps.calculate-test-targets.outputs.test_targets_count || 0) > 0 }}
78+
id: build-test-targets
6379
run: |
6480
set -ex
6581
cd src
66-
TEST_TARGETS=$(jq -cr '. | join(" ")' <<< '${{ steps.test-targets.outputs.test_targets }}')
82+
TEST_TARGETS=$(cat ${{ steps.calculate-test-targets.outputs.test_targets_json_file }} | jq -cr '.test_targets | join(" ")')
6783
time autoninja -C out/${{ matrix.platform }}_${{ matrix.config }} ${TEST_TARGETS}
6884
shell: bash
6985
- name: Ninja build
@@ -84,15 +100,20 @@ runs:
84100
src/out/${{ matrix.platform }}_qa/*_apk/*.apk
85101
src/out/${{ matrix.platform }}_qa/gen/build_info.json
86102
- name: Upload Test Artifacts
87-
if: inputs.upload_on_host_test_artifacts == 'true' || inputs.upload_on_device_test_artifacts == 'true'
103+
if: steps.build-test-targets.outcome == 'success'
88104
uses: ./src/.github/actions/upload_test_artifacts
89105
with:
90106
test_artifacts_key: ${{ inputs.test_artifacts_key }}
91107
upload_on_host_test_artifacts: ${{ inputs.upload_on_host_test_artifacts }}
92108
upload_on_device_test_artifacts: ${{ inputs.upload_on_device_test_artifacts }}
93-
# TODO(b/382508397): Replace hardcoded list with dynamically generated one.
94-
test_targets_json_file: cobalt/build/testing/targets/${{ matrix.platform }}/test_targets.json
109+
test_targets_json_file: '${{ steps.calculate-test-targets.outputs.test_targets_json_file }}'
95110
outputs:
96-
test_targets:
97-
description: The test targets that were built
98-
value: ${{ steps.test-targets.outputs.test_targets }}
111+
test_targets_count:
112+
description: The number of test targets build.
113+
value: ${{ steps.calculate-test-targets.outputs.test_targets_count || 0 }}
114+
test_targets_json:
115+
description: The test targets in a JSON array.
116+
value: ${{ steps.calculate-test-targets.outputs.test_targets_json }}
117+
test_targets_json_file:
118+
description: The generated test targets json file path.
119+
value: ${{ steps.calculate-test-targets.outputs.test_targets_json_file }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Set Up Depot Tools
2+
description: Sets up Depot Tools and initializes gclient.
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Get depot tools
7+
run: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
8+
shell: bash
9+
- name: Add depot tools to PATH
10+
run: echo "$GITHUB_WORKSPACE/depot_tools" >> $GITHUB_PATH
11+
shell: bash
12+
- name: Generate gclient file
13+
run: gclient config --name=src --custom-var=download_remoteexec_cfg=True --custom-var='rbe_instance="projects/cobalt-actions-prod/instances/default_instance"' https://github.com/${{ github.repository }}
14+
shell: bash
15+
- name: Set target OS for Android
16+
if: ${{ contains(matrix.platform, 'android') }}
17+
run: |
18+
echo "target_os=['android']" >> .gclient
19+
gclient validate
20+
shell: bash
21+
- name: gclient sync
22+
run: gclient sync -v --shallow --no-history -r ${{ github.sha }}
23+
shell: bash
24+
- name: Disable Chromium client side build telemetry
25+
run: build_telemetry opt-out
26+
shell: bash

‎.github/actions/on_device_tests/action.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: On Device Test
22
description: Runs on-device tests.
33
inputs:
4-
test_targets:
4+
test_targets_json:
55
description: "The test targets in a JSON array."
66
required: true
77
gcs_results_path:
@@ -36,7 +36,7 @@ runs:
3636
shell: bash
3737
- name: Run Tests on ${{ matrix.platform }} Platform
3838
env:
39-
TEST_TARGETS_JSON: ${{ inputs.test_targets }}
39+
TEST_TARGETS_JSON: ${{ inputs.test_targets_json }}
4040
GCS_ARTIFACTS_PATH: /bigstore/${{ env.PROJECT_NAME }}-test-artifacts/${{ github.workflow }}/${{ github.run_number }}/${{ matrix.platform }}
4141
GCS_RESULTS_PATH: gs://cobalt-unittest-storage/results/${{ matrix.name }}/${{ github.run_id }}
4242
GITHUB_SHA: ${{ github.sha }}

‎.github/actions/on_host_tests/action.yaml‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,19 @@ runs:
7272
xml_path="${test_output}/${test_binary}_result.xml"
7373
log_path="${test_output}/${test_binary}_log.txt"
7474
# TODO: Investigate test_runner.py
75-
/usr/bin/xvfb-run -a --server-args="${XVFB_SERVER_ARGS}" \
76-
./"${test_binary_path}" \
77-
--test-launcher-shard-index=${{ matrix.shard }} \
78-
--test-launcher-total-shards=${{ inputs.num_gtest_shards }} \
79-
--gtest_output="xml:${xml_path}" \
80-
--gtest_filter="${test_filter}" | tee ${log_path} || {
81-
failed_suites="${failed_suites} ${test_binary}"
82-
}
75+
76+
if [ "${test_filter}" == "-*" ]; then
77+
echo "Skipped due to test filter." > ${log_path}
78+
else
79+
/usr/bin/xvfb-run -a --server-args="${XVFB_SERVER_ARGS}" \
80+
./"${test_binary_path}" \
81+
--test-launcher-shard-index=${{ matrix.shard }} \
82+
--test-launcher-total-shards=${{ inputs.num_gtest_shards }} \
83+
--gtest_output="xml:${xml_path}" \
84+
--gtest_filter="${test_filter}" | tee ${log_path} || {
85+
failed_suites="${failed_suites} ${test_binary}"
86+
}
87+
fi
8388
done
8489
echo "Finished running tests..."
8590
if [ -n "${failed_suites}" ]; then
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Print Logs
2+
description: Processes test results to produce a test summary and upload results to DataDog.
3+
inputs:
4+
logfile_glob:
5+
description: "Path (or glob) to test log files."
6+
required: true
7+
test_status:
8+
description: "Test status. If the value is not success this step will fail."
9+
required: false
10+
default: 'success'
11+
symbolize:
12+
description: "If logs should be ran through crash symbolization tools."
13+
required: false
14+
default: 'false'
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Set Up Cloud SDK
19+
if: inputs.symbolize == 'true'
20+
uses: isarkis/setup-gcloud@40dce7857b354839efac498d3632050f568090b6 # v1.1.1
21+
- name: Set GCS Project Name
22+
if: inputs.symbolize == 'true'
23+
id: gcs-project
24+
run: |
25+
echo "name=$(gcloud config get-value project)" >> $GITHUB_OUTPUT
26+
shell: bash
27+
- name: Download Test Symbols
28+
if: inputs.symbolize == 'true'
29+
env:
30+
WORKFLOW: ${{ github.workflow }}
31+
run: |
32+
gsutil -m cp "gs://${{ steps.gcs-project.outputs.name }}-test-artifacts/${WORKFLOW}/${GITHUB_RUN_NUMBER}/${{matrix.platform}}/symbols/*" \
33+
"${GITHUB_WORKSPACE}/src/out/${{ matrix.platform }}_${{ matrix.config }}/lib.unstripped/
34+
shell: bash
35+
- run: |
36+
set -x
37+
# Enable globstar shell option for globstar paths e.g. /**/*.xml and
38+
# nullopt to returns empty string if the glob matches no files.
39+
shopt -s globstar nullglob
40+
41+
log_files=(${{ inputs.logfile_glob }})
42+
43+
if [ ${#log_files[@]} -eq 0 ]; then
44+
echo "::error::No log files were collected."
45+
exit 1
46+
else
47+
for log_file in ${log_files[@]}; do
48+
if [ "${{ inputs.symbolize }}" == "true" ]; then
49+
cd src/
50+
# TODO: stack.py fails import packages. Perhaps needs depot tools setup?
51+
cat ../${log_file} | python3 third_party/android_platform/development/scripts/stack.py --pass-through --output-directory out/${{ matrix.platform }}_${{ matrix.config }}/
52+
else
53+
cat ${log_file}
54+
fi
55+
done
56+
fi
57+
58+
# By failing this step if tests failed the logs will be expanded by default.
59+
# Note that if any steps after this one fails the logs will no longer be expanded.
60+
if [ "${{ inputs.test_status }}" != "success" ]; then
61+
echo "Tests failed"
62+
grep -h "\[ FAILED \]" ${{ inputs.logfile_glob }}
63+
exit 1
64+
fi
65+
shell: bash

‎.github/actions/upload_test_artifacts/action.yaml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ runs:
2222
mkdir ${GITHUB_WORKSPACE}/artifacts
2323
cd src/
2424
25-
# Put test targets json file in the out folder for the archiving script to pick up.
26-
cp "${{ inputs.test_targets_json_file }}" out/${{ matrix.platform }}_${{ matrix.config }}/
27-
2825
time vpython3 -u ./cobalt/build/archive_test_artifacts.py \
2926
--source-dir ${GITHUB_WORKSPACE}/src \
3027
--out-dir out/${{ matrix.platform }}_${{ matrix.config }}/ \
31-
--destination ${GITHUB_WORKSPACE}/artifacts \
28+
--destination-dir ${GITHUB_WORKSPACE}/artifacts \
3229
--platform ${{ matrix.platform }} \
3330
--targets $(cat "${{ inputs.test_targets_json_file }}" | jq -cr '.test_targets | join(",")')
3431
shell: bash
@@ -50,6 +47,6 @@ runs:
5047
set -eux
5148
project_name=$(gcloud config get-value project)
5249
53-
gsutil cp "${GITHUB_WORKSPACE}/artifacts/*" \
50+
gsutil -m cp "${GITHUB_WORKSPACE}/artifacts/*" \
5451
"gs://${project_name}-test-artifacts/${WORKFLOW}/${GITHUB_RUN_NUMBER}/${{matrix.platform}}/"
5552
shell: bash

‎.github/config/android-arm.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"android-arm"
55
],
66
"test_on_device": true,
7+
"test_root_target": "//cobalt/android:cobalt_apk",
78
"test_dimensions": {
89
"device_type": "sabrina",
910
"device_pool": "maneki"

‎.github/config/android-arm64.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"android-arm64"
55
],
66
"test_on_device": true,
7+
"test_root_target": "//cobalt/android:cobalt_apk",
78
"test_dimensions": {
89
"device_type": "nvidia_shield",
910
"device_pool": "maneki"

‎.github/config/linux.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"linux-x64x11"
55
],
66
"test_on_host": true,
7+
"test_root_target": "//cobalt:gn_all",
78
"num_gtest_shards": 10,
89
"targets": [
910
"cobalt:gn_all",

0 commit comments

Comments
 (0)