Skip to content

Commit

Permalink
Pass test target json to test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
oxve committed Dec 27, 2024
1 parent ebcbdbe commit bd323d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/actions/build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ runs:
test_artifacts_key: ${{ inputs.test_artifacts_key }}
on_host: ${{ inputs.test_on_host }}
on_device: ${{ inputs.test_on_device }}
test_targets_json: ${{ env.TEST_TARGETS }}
5 changes: 3 additions & 2 deletions .github/actions/on_host_tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ runs:
failed_suites=""
cd ${test_dir}
for test_binary in $(ls {*tests,nplb}); do
for test_binary_path in $(cat test_targets.json | jq -c '.executables | join(" ")'); do
test_binary=$(basename "${test_binary_path}")
echo "Running tests for suite: ${test_binary}"
test_filter="*"
Expand All @@ -57,7 +58,7 @@ runs:
echo "Test filter evaluated to: ${test_filter}"
xml_path="${results_dir}/${test_binary}_testoutput.xml"
/usr/bin/xvfb-run -a --server-args="${XVFB_SERVER_ARGS}" "./${test_binary}" --gtest_filter="${test_filter}" --gtest_output="xml:${xml_path}" || {
./"$(dirname test_binary_path)/bin/run_${test_binary}" --gtest_output="xml:${xml_path}" || {
# Set exit code on failure.
failed_suites="${failed_suites} ${test_binary}"
}
Expand Down
16 changes: 11 additions & 5 deletions .github/actions/upload_test_artifacts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
test_artifacts_key:
description: "Artifact key used to store on-host test artifacts."
required: true
test_targets_json:
description: "Test target json."
required: true
runs:
using: "composite"
steps:
Expand All @@ -31,12 +34,15 @@ runs:
if: inputs.on_host == 'true'
run: |
set -x
cd src/out/${{ matrix.platform }}_${{ matrix.config }}
cd src/
test_deps_file="test.deps"
for test_binary in $(ls {nplb,*tests}); do
echo $test_binary
if [ -f "${test_binary}.runtime_deps" ]; then
cat "${test_binary}.runtime_deps" >> "${test_deps_file}"
# Add the test target json to the archive.
echo "${{ inputs.test_targets_json }}" > test_targets.json
echo "test_targets.json" > "${test_deps_file}"
for test_binary_path in $(cat test_targets.json | jq -c '.executables | join(" ")'); do
echo $test_binary_path
if [ -f "${test_binary_path}.runtime_deps" ]; then
cat "${test_binary_path}.runtime_deps" >> "${test_deps_file}"
fi
done
tar cvf - -T "${test_deps_file}" | xz -T0 -1 -z - > "${GITHUB_WORKSPACE}/test_artifacts.tar.xz"
Expand Down
20 changes: 14 additions & 6 deletions cobalt/build/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def _create_graph(data) -> nx.DiGraph:
# Only save the attributes we need to deduce which are the test targets.
node_attributes = {
'is_testonly': attributes.get('testonly', False),
'is_executable': attributes.get('type') == 'executable'
'is_executable': attributes.get('type') == 'executable',
'output': attributes.get('outputs')
}
g.add_node(target_name, **node_attributes)
g.add_edges_from((target_name, dep) for dep in attributes['deps'])
Expand All @@ -82,16 +83,19 @@ def get_relevant_test_targets(root_target, gn_json_path) -> typing.List[str]:
filter(lambda n: _is_test_target(g, n),
nx.ancestors(g, '//testing/gtest:gtest')))
tests_to_run = []
executables = []
for target in all_test_targets:
for descendant in descendants:
if _is_in_same_root_package(descendant, target) \
and nx.has_path(g, target, descendant):
# The ninja target name is the fully qualified gn target with the
# leading // removed.
tests_to_run.append(target[2:])
ninja_target = target[2:]
tests_to_run.append(ninja_target)
executables += g.nodes[target]['outputs']
# Break the inner loop, no need to add the test target more than once.
break
return tests_to_run
return sorted(tests_to_run), sorted(executables)


def main():
Expand All @@ -114,10 +118,14 @@ def main():
'If omitted the targets are printed to stdout in text format.')
args = parser.parse_args()

tests_to_run = sorted(
get_relevant_test_targets(args.root_target, args.gn_json))
tests_to_run, executables = get_relevant_test_targets(args.root_target,
args.gn_json)
if args.json_output:
print(json.dumps({'test_targets': tests_to_run}))
print(
json.dumps({
'test_targets': tests_to_run,
'executables': executables
}))
else:
print('\n'.join(tests_to_run))

Expand Down

0 comments on commit bd323d4

Please sign in to comment.