-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
621 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
libs/scenario_execution_os/scenario_execution_os/actions/check_file_not_exists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
import py_trees | ||
|
||
|
||
class CheckFileNotExists(py_trees.behaviour.Behaviour): | ||
""" | ||
Check that a file does not exist | ||
""" | ||
|
||
def __init__(self, name, file_name): | ||
super().__init__(name) | ||
self.file_name = file_name | ||
|
||
def update(self) -> py_trees.common.Status: | ||
if os.path.isfile(self.file_name): | ||
self.feedback_message = f"File '{self.file_name}' exists" # pylint: disable= attribute-defined-outside-init | ||
return py_trees.common.Status.FAILURE | ||
else: | ||
self.feedback_message = f"File '{self.file_name}' does not exist" # pylint: disable= attribute-defined-outside-init | ||
return py_trees.common.Status.SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
libs/scenario_execution_os/test/test_check_file_not_exists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import unittest | ||
import tempfile | ||
from scenario_execution import ScenarioExecution | ||
from scenario_execution.model.osc2_parser import OpenScenario2Parser | ||
from scenario_execution.model.model_to_py_tree import create_py_tree | ||
from scenario_execution.utils.logging import Logger | ||
|
||
from antlr4.InputStream import InputStream | ||
|
||
|
||
class TestCheckData(unittest.TestCase): | ||
# pylint: disable=missing-function-docstring,missing-class-docstring | ||
|
||
def setUp(self) -> None: | ||
self.parser = OpenScenario2Parser(Logger('test', False)) | ||
self.scenario_execution = ScenarioExecution(debug=False, log_model=False, live_tree=False, | ||
scenario_file="test.osc", output_dir=None) | ||
self.tmp_file = tempfile.NamedTemporaryFile() | ||
print(self.tmp_file.name) | ||
|
||
def test_success(self): | ||
scenario_content = """ | ||
import osc.os | ||
scenario test: | ||
do parallel: | ||
serial: | ||
check_file_not_exists('UNKNOWN_FILE') | ||
emit end | ||
time_out: serial: | ||
wait elapsed(1s) | ||
emit fail | ||
""" | ||
|
||
parsed_tree = self.parser.parse_input_stream(InputStream(scenario_content)) | ||
model = self.parser.create_internal_model(parsed_tree, "test.osc", False) | ||
scenarios = create_py_tree(model, self.parser.logger, False) | ||
self.scenario_execution.scenarios = scenarios | ||
self.scenario_execution.run() | ||
self.assertTrue(self.scenario_execution.process_results()) | ||
|
||
def test_fail(self): | ||
scenario_content = """ | ||
import osc.os | ||
scenario test: | ||
do parallel: | ||
serial: | ||
check_file_not_exists('""" + self.tmp_file.name + """') | ||
emit end | ||
time_out: serial: | ||
wait elapsed(1s) | ||
emit fail | ||
""" | ||
|
||
parsed_tree = self.parser.parse_input_stream(InputStream(scenario_content)) | ||
model = self.parser.create_internal_model(parsed_tree, "test.osc", False) | ||
scenarios = create_py_tree(model, self.parser.logger, False) | ||
self.scenario_execution.scenarios = scenarios | ||
self.scenario_execution.run() | ||
self.assertFalse(self.scenario_execution.process_results()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
scenario_execution_ros/scenario_execution_ros/actions/ros_launch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from enum import Enum | ||
|
||
from scenario_execution.actions.run_process import RunProcess | ||
import signal | ||
|
||
|
||
class RosLaunchActionState(Enum): | ||
""" | ||
States for executing a ros bag recording | ||
""" | ||
WAITING_FOR_TOPICS = 1 | ||
RECORDING = 2 | ||
FAILURE = 5 | ||
|
||
|
||
class RosLaunch(RunProcess): | ||
""" | ||
Class to execute ros bag recording | ||
""" | ||
|
||
def __init__(self, name, package_name: str, launch_file: str, arguments: list, wait_for_shutdown: bool, shutdown_timeout: float): | ||
super().__init__(name, None, wait_for_shutdown, shutdown_timeout, shutdown_signal=("", signal.SIGINT)) | ||
self.package_name = package_name | ||
self.launch_file = launch_file | ||
self.arguments = arguments | ||
self.wait_for_shutdown = wait_for_shutdown | ||
self.command = None | ||
|
||
def setup(self, **kwargs): | ||
self.command = ["ros2", "launch", self.package_name, self.launch_file] | ||
|
||
for arg in self.arguments: | ||
if not arg["key"] or not arg["value"]: | ||
raise ValueError(f'Invalid ros argument key:{arg["key"]}, value:{arg["value"]}') | ||
self.command.append(f'{arg["key"]}:={arg["value"]}') | ||
|
||
self.logger.info(f'Command: {" ".join(self.command)}') |
Oops, something went wrong.