Skip to content
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

multiple cmake macros #127

Merged
merged 16 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
162 changes: 92 additions & 70 deletions atf_core/cmake/atf_core-extras.cmake.em
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
set(generate_tests_script @(CMAKE_SOURCE_DIR)/scripts/generate_tests.py)

function(atf_test TEST_GENERATION_CONFIG_FILE)
set(ExtraMacroArgs ${ARGN})
# Get the length of the list
list(LENGTH ExtraMacroArgs NumExtraMacroArgs)

# set default
set(EXECUTE_TESTS True)

# Execute the following block only if the length is > 0
if(NumExtraMacroArgs GREATER 0)
#foreach(ExtraArg ${ExtraMacroArgs})
# message( ">>> Element of list of opt args = ${ExtraArg}")
#endforeach()
set(EXECUTE_TESTS ${ARGV1})
endif()

#message("TEST_GENERATION_CONFIG_FILE = ${TEST_GENERATION_CONFIG_FILE}")
#message( "EXECUTE_TESTS = ${EXECUTE_TESTS}")

if(CATKIN_ENABLE_TESTING)
message(STATUS "ATF: executing test generation macro")
message("ATF: executing test generation macro with '${TEST_GENERATION_CONFIG_FILE}' and EXECUTE_TESTS=${EXECUTE_TESTS}")

find_package(roslaunch REQUIRED)
find_package(rostest REQUIRED)

# prints the cmake targets and its dependencies in the terminal (uncomment for debugging)
#set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)

############
message(STATUS "ATF: generating test files")
message(STATUS "ATF: generating test files")
execute_process(
COMMAND python ${generate_tests_script} ${PROJECT_NAME} ${TEST_GENERATION_CONFIG_FILE} ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}
RESULT_VARIABLE generation_result
Expand All @@ -17,79 +38,80 @@ function(atf_test TEST_GENERATION_CONFIG_FILE)
message(FATAL_ERROR "-- ATF: generating test files failed: exit_code='${generation_result}'")
endif()

set(TEST_GENERATED_PATH ${PROJECT_BINARY_DIR}/test_generated)
string(REPLACE "/" "_" TEST_GENERATION_CONFIG_FILE_REPLACED ${TEST_GENERATION_CONFIG_FILE})
set(TARGET_NAME ${PROJECT_NAME}_${TEST_GENERATION_CONFIG_FILE_REPLACED})
set(TEST_GENERATED_PATH ${PROJECT_BINARY_DIR}/test_generated/${TEST_GENERATION_CONFIG_FILE_REPLACED})

############
message(STATUS "ATF: roslaunch checking test files")
file(GLOB_RECURSE test_list
LIST_DIRECTORIES false
"${TEST_GENERATED_PATH}/*.test"
)
foreach(test ${test_list})
message("roslaunch check for test file: ${test}")
roslaunch_add_file_check(${test})
endforeach()
if(EXECUTE_TESTS)
############ roslaunch checks
message(STATUS "ATF: roslaunch checking test files")
file(GLOB_RECURSE test_list
LIST_DIRECTORIES false
"${TEST_GENERATED_PATH}/*.test"
)
foreach(test ${test_list})
message("roslaunch check for test file: ${test}")
roslaunch_add_file_check(${test})
endforeach()

############
message(STATUS "ATF: cleaning")
add_rostest(${TEST_GENERATED_PATH}/cleaning.test)
add_custom_target(atf_${PROJECT_NAME}_cleaning
COMMAND echo "cccccccccccccccccccccccccccccccleaning"
DEPENDS
_run_tests_${PROJECT_NAME}_rostest_test_generated_cleaning.test
)
############ cleaning
message(STATUS "ATF: cleaning")
add_rostest(${TEST_GENERATED_PATH}/cleaning.test)
add_custom_target(atf_${TARGET_NAME}_cleaning
COMMAND echo "cccccccccccccccccccccccccccccccleaning"
DEPENDS
_run_tests_${PROJECT_NAME}_rostest_test_generated_${TEST_GENERATION_CONFIG_FILE_REPLACED}_cleaning.test
)

############
message(STATUS "ATF: recording")
file(GLOB TEST_NAMES_RECORDING RELATIVE ${TEST_GENERATED_PATH} ${TEST_GENERATED_PATH}/recording_*.test)
foreach(TEST_NAME_RECORDING ${TEST_NAMES_RECORDING})
# recording
set(TARGET_NAME_RECORDING run_tests_${PROJECT_NAME}_rostest_test_generated_${TEST_NAME_RECORDING})
set(_TARGET_NAME_RECORDING _run_tests_${PROJECT_NAME}_rostest_test_generated_${TEST_NAME_RECORDING})
string(REPLACE "/" "_" TARGET_NAME_RECORDING ${TARGET_NAME_RECORDING})
string(REPLACE "/" "_" _TARGET_NAME_RECORDING ${_TARGET_NAME_RECORDING})
list(APPEND TARGET_NAMES_RECORDING ${TARGET_NAME_RECORDING})
list(APPEND _TARGET_NAMES_RECORDING ${_TARGET_NAME_RECORDING})
add_rostest(${TEST_GENERATED_PATH}/${TEST_NAME_RECORDING} DEPENDENCIES _run_tests_${PROJECT_NAME}_rostest_test_generated_cleaning.test)
endforeach()
add_custom_target(atf_${PROJECT_NAME}_recording
COMMAND echo "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrecording"
DEPENDS
atf_${PROJECT_NAME}_cleaning
${_TARGET_NAMES_RECORDING}
)
############ recording
message(STATUS "ATF: recording")
file(GLOB TEST_NAMES_RECORDING RELATIVE ${TEST_GENERATED_PATH} ${TEST_GENERATED_PATH}/recording_*.test)
foreach(TEST_NAME_RECORDING ${TEST_NAMES_RECORDING})
set(TARGET_NAME_RECORDING _run_tests_${PROJECT_NAME}_rostest_test_generated_${TEST_GENERATION_CONFIG_FILE_REPLACED}_${TEST_NAME_RECORDING})
list(APPEND TARGET_NAMES_RECORDING ${TARGET_NAME_RECORDING})
add_rostest(${TEST_GENERATED_PATH}/${TEST_NAME_RECORDING} DEPENDENCIES atf_${TARGET_NAME}_cleaning)
endforeach()
add_custom_target(atf_${TARGET_NAME}_recording
COMMAND echo "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrecording"
DEPENDS
atf_${TARGET_NAME}_cleaning
${TARGET_NAMES_RECORDING}
)

############
message(STATUS "ATF: analysing")
add_rostest(${TEST_GENERATED_PATH}/analysing.test DEPENDENCIES ${_TARGET_NAMES_RECORDING})
add_custom_target(atf_${PROJECT_NAME}_analysing
COMMAND echo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaanalysing"
DEPENDS
atf_${PROJECT_NAME}_recording
_run_tests_${PROJECT_NAME}_rostest_test_generated_analysing.test
)
add_rostest(${TEST_GENERATED_PATH}/uploading.test DEPENDENCIES atf_${PROJECT_NAME}_analysing)
############ analysing
message(STATUS "ATF: analysing")
add_rostest(${TEST_GENERATED_PATH}/analysing.test DEPENDENCIES atf_${TARGET_NAME}_recording)
add_custom_target(atf_${TARGET_NAME}_analysing
COMMAND echo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaanalysing"
DEPENDS
atf_${TARGET_NAME}_recording
_run_tests_${PROJECT_NAME}_rostest_test_generated_${TEST_GENERATION_CONFIG_FILE_REPLACED}_analysing.test
)
add_rostest(${TEST_GENERATED_PATH}/uploading.test DEPENDENCIES atf_${TARGET_NAME}_analysing)

############
message(STATUS "ATF: uploading")
add_custom_target(atf_${PROJECT_NAME}_uploading
COMMAND echo "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuploading"
DEPENDS
atf_${PROJECT_NAME}_analysing
_run_tests_${PROJECT_NAME}_rostest_test_generated_uploading.test
)
############
message(STATUS "ATF: gathering all atf test steps")
add_custom_target(atf_${PROJECT_NAME}
COMMAND echo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaatf"
DEPENDS
atf_${PROJECT_NAME}_cleaning
atf_${PROJECT_NAME}_recording
atf_${PROJECT_NAME}_analysing
atf_${PROJECT_NAME}_uploading
)
add_dependencies(run_tests atf_${PROJECT_NAME})
add_dependencies(run_tests_${PROJECT_NAME} atf_${PROJECT_NAME})
############ uploading
message(STATUS "ATF: uploading")
add_custom_target(atf_${TARGET_NAME}_uploading
COMMAND echo "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuploading"
DEPENDS
atf_${TARGET_NAME}_analysing
_run_tests_${PROJECT_NAME}_rostest_test_generated_${TEST_GENERATION_CONFIG_FILE_REPLACED}_uploading.test
)
############ all
message(STATUS "ATF: gathering all atf test steps")
add_custom_target(atf_${TARGET_NAME}
COMMAND echo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaatf"
DEPENDS
atf_${TARGET_NAME}_cleaning
atf_${TARGET_NAME}_recording
atf_${TARGET_NAME}_analysing
atf_${TARGET_NAME}_uploading
)

add_dependencies(run_tests atf_${TARGET_NAME})
add_dependencies(run_tests_${PROJECT_NAME} atf_${TARGET_NAME})

endif()

message(STATUS "ATF: executing test generation macro done!")
endif()
Expand Down
1 change: 1 addition & 0 deletions atf_core/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<exec_depend>atf_msgs</exec_depend>
<exec_depend>atf_recorder_plugins</exec_depend>
<exec_depend>atf_status_server</exec_depend>
<exec_depend>diagnostic_msgs</exec_depend>
<exec_depend>python-lxml</exec_depend>
<exec_depend>python-progressbar</exec_depend>
<exec_depend>roslaunch</exec_depend>
Expand Down
27 changes: 17 additions & 10 deletions atf_core/scripts/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@


class Analyser:
def __init__(self, package_name):
def __init__(self, package_name, test_generation_config_file = "atf/test_generation_config.yaml"):
print "ATF analyser: started!"
start_time = time.time()
self.ns = "/atf/"
self.error = False

# parse configuration
self.configuration_parser = ATFConfigurationParser(package_name)
self.configuration_parser = ATFConfigurationParser(package_name, test_generation_config_file)
self.tests = self.configuration_parser.get_tests()

# generate results
Expand Down Expand Up @@ -182,23 +182,30 @@ def print_result_summary(self, atf_result):

class TestAnalysing(unittest.TestCase):
def test_analysing(self):
analyser = Analyser(sys.argv[1])
analyser = Analyser(package_name, test_generation_config_file)
atf_result = analyser.get_result()
analyser.print_result(atf_result)
if atf_result.groundtruth_result != None:
self.assertTrue(atf_result.groundtruth_result, atf_result.groundtruth_error_message)

if __name__ == '__main__':
if len(sys.argv) < 2:
if len(sys.argv) == 2:
package_name = sys.argv[1]
test_generation_config_file = "atf/test_generation_config.yaml"
elif len(sys.argv) > 2:
package_name = sys.argv[1]
test_generation_config_file = sys.argv[2]
else:
print "ERROR: please specify a test package"
print "usage: rosrun atf_core analyser.py <<ATF TEST PACKAGE>>"
print "usage: rosrun atf_core analyser.py <<ATF TEST PACKAGE>> [<<TEST_GENERATION_CONFIG_FILE>>]"
sys.exit(1)
print "analysing for package", sys.argv[1]
if "standalone" in sys.argv:
analyser = Analyser(sys.argv[1])
print "analysing for package '%s' and test generation config file '%s'" %(package_name, test_generation_config_file)

if "execute_as_test" in sys.argv:
rostest.rosrun("atf_core", 'analysing', TestAnalysing)
else:
analyser = Analyser(package_name, test_generation_config_file)
atf_result = analyser.get_result()
if "verbose" in sys.argv:
analyser.print_result_details(atf_result)
analyser.print_result(atf_result)
else:
rostest.rosrun("atf_core", 'analysing', TestAnalysing, sysargs=sys.argv)
36 changes: 23 additions & 13 deletions atf_core/scripts/cleaner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
import rospy
import unittest
import rostest
import shutil
Expand All @@ -10,10 +9,9 @@


class Cleaner():
def __init__(self, package_name):
self.result = False

self.atf_configuration_parser = ATFConfigurationParser(package_name)
def __init__(self, package_name, test_generation_config_file):
# parse configuration
self.atf_configuration_parser = ATFConfigurationParser(package_name, test_generation_config_file)

def clean(self):
if os.path.exists(self.atf_configuration_parser.generation_config["bagfile_output"]):
Expand All @@ -24,17 +22,29 @@ def clean(self):
shutil.rmtree(self.atf_configuration_parser.generation_config["json_output"])
if os.path.exists(self.atf_configuration_parser.generation_config["yaml_output"]):
shutil.rmtree(self.atf_configuration_parser.generation_config["yaml_output"])
self.result = True
return True

class TestCleaning(unittest.TestCase):

def test_cleaning_results(self):
cleaner = Cleaner(sys.argv[1])
cleaner.clean()
self.assertTrue(cleaner.result, "Could not clean results.")
cleaner = Cleaner(package_name, test_generation_config_file)
self.assertTrue(cleaner.clean(), "Could not clean results.")

if __name__ == '__main__':
print "cleaning for package", sys.argv[1]
if "standalone" in sys.argv:
cleaner = Cleaner(sys.argv[1])
if len(sys.argv) == 2:
package_name = sys.argv[1]
test_generation_config_file = "atf/test_generation_config.yaml"
elif len(sys.argv) > 2:
package_name = sys.argv[1]
test_generation_config_file = sys.argv[2]
else:
rostest.rosrun("atf_core", 'cleaning', TestCleaning, sysargs=sys.argv)
print "ERROR: please specify a test package"
print "usage: rosrun atf_core cleaner.py <<ATF TEST PACKAGE>> [<<TEST_GENERATION_CONFIG_FILE>>]"
sys.exit(1)
print "cleaning for package '%s' and test generation config file '%s'" %(package_name, test_generation_config_file)

if "execute_as_test" in sys.argv:
rostest.rosrun("atf_core", 'cleaning', TestCleaning)
else:
cleaner = Cleaner(package_name, test_generation_config_file)
cleaner.clean()