Pass CTest test description in custom property or environment
Prior to this change, each test would have, as label, it's description. This leads to many labels, which are normally reserved for grouping tests. Move the description into a custom property instead. Since we rely on the JSON output for the generation of HTML reports, we need to also extract the description from the generated JSON. However, custom properties are only logged starting from cmake 3.30. For back-wards compatibility, write an additional, separate environment variable TEST_DESCRIPTION from which the description can be read as a fallback. For the add_timed_physim_test(), this has been already done in a parent commit.
This commit is contained in:
@@ -28,6 +28,23 @@ import json
|
||||
|
||||
class Analysis():
|
||||
|
||||
def _get_test_description(properties):
|
||||
env_vars = None
|
||||
for p in properties:
|
||||
if p["name"] == "ENVIRONMENT":
|
||||
env_vars = p["value"] # save for later if no custom property
|
||||
if p["name"] == "TEST_DESCRIPTION":
|
||||
return p["value"]
|
||||
# if we came till here, it means there is no custom test property
|
||||
# saved in JSON. See if we have a description in environment variables
|
||||
if not env_vars:
|
||||
return "<none>"
|
||||
for ev in env_vars:
|
||||
name, value = ev.split("=", 1)
|
||||
if name == "TEST_DESCRIPTION":
|
||||
return value
|
||||
return "<none>"
|
||||
|
||||
def analyze_physim(result_junit, details_json, logPath):
|
||||
try:
|
||||
tree = ET.parse(result_junit)
|
||||
@@ -60,7 +77,7 @@ class Analysis():
|
||||
for test in root: # for each test
|
||||
test_name = test.attrib["name"]
|
||||
test_exec = json_test_desc[test_name]["properties"][1]["value"][0]
|
||||
desc = json_test_desc[test_name]["properties"][1]["value"][1]
|
||||
desc = Analysis._get_test_description(json_test_desc[test_name]["properties"])
|
||||
# get runtime and checks
|
||||
test_check = test.attrib["status"] == "run"
|
||||
time = round(float(test.attrib["time"]), 1)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
define_property(TEST PROPERTY TEST_DESCRIPTION BRIEF_DOCS "A human-readable description of this test")
|
||||
|
||||
# Define a macro to add tests for different physical simulators
|
||||
macro(add_physim_test test_name test_description test_exec)
|
||||
# catch all the arguments past the last expected arqument and store them in the options_list
|
||||
@@ -11,8 +13,12 @@ macro(add_physim_test test_name test_description test_exec)
|
||||
COMMAND_EXPAND_LISTS
|
||||
)
|
||||
set_tests_properties(${test_name} PROPERTIES
|
||||
LABELS "${test_exec}: ${test_description};${test_exec}"
|
||||
ENVIRONMENT "LD_LIBRARY_PATH=."
|
||||
LABELS "${test_exec}"
|
||||
TEST_DESCRIPTION "${test_description}"
|
||||
# pass test description also through environment variable: for cmake < 3.30,
|
||||
# in JSON export, we cannot recover the description otherwise
|
||||
# see also https://gitlab.kitware.com/cmake/cmake/-/issues/21490
|
||||
ENVIRONMENT "LD_LIBRARY_PATH=.;TEST_DESCRIPTION=${test_description}"
|
||||
)
|
||||
add_dependencies(tests ${test_exec})
|
||||
endmacro()
|
||||
|
||||
Reference in New Issue
Block a user