Skip to content

Add GitHub Action step to verify random_test_runner execution #1627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ do
fi
done < "$file_path"

random_output_dir="/tmp/random_test_runner"
mkdir -p "$random_output_dir"

# Note: In this case, we consider the test as PASSED if at least one scenario passes.
ros2 launch random_test_runner random_test.launch.py output_directory:="$random_output_dir"
ros2 run random_test_runner result_checker.py "$random_output_dir/random_test_runner/result.junit.xml"
random_passed=$?

if [ $random_passed -ne 0 ]; then
echo "Error: caught non-zero exit status(code: $random_passed)"
exit_status=1
fi

exit $exit_status
6 changes: 6 additions & 0 deletions test_runner/random_test_runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ endif()

# find dependencies
find_package(ament_cmake_auto REQUIRED)
find_package(ament_cmake_python REQUIRED)
include(FindProtobuf REQUIRED)

# TODO(HansRobo): Remove this workaround once https://github.com/autowarefoundation/autoware_universe/issues/10410 is fixed
Expand Down Expand Up @@ -78,6 +79,11 @@ install(
DESTINATION share/${PROJECT_NAME}
)

install(
PROGRAMS scripts/result_checker.py
DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
Expand Down
1 change: 1 addition & 0 deletions test_runner/random_test_runner/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<exec_depend>openscenario_visualization</exec_depend>
<exec_depend>behavior_tree_plugin</exec_depend>
<exec_depend>ament_cmake_python</exec_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
57 changes: 57 additions & 0 deletions test_runner/random_test_runner/scripts/result_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2020 TIER IV, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import xml.etree.ElementTree as ET
import sys

class ResultChecker:
def __init__(self):
pass

def check(self, xml_path):
try:
tree = ET.parse(xml_path)
root = tree.getroot()
except Exception as e:
print(f"Failed to parse XML: {e}")
return False

passed, failed = 0, 0

for suite in root:
for case in suite:
if case.find("failure") is None and case.find("error") is None:
passed += 1
else:
failed += 1

return passed > 0


def main():
parser = argparse.ArgumentParser(description="Check result.junit.xml: passes if at least one test passed.")
parser.add_argument("xml", help="JUnit XML result file")
args = parser.parse_args()

checker = ResultChecker()
result = checker.check(args.xml)
sys.exit(0 if result else 1)


if __name__ == "__main__":
main()
Loading