From a63cfa9612899e44bcef6b204dee83032de79de5 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 20 Oct 2017 00:15:04 +0200 Subject: [PATCH] Parse the XML file Test.xml from `ctest -D` ... eventually, that will help move from our testsuite scripts to CTest testsuite, plus CDash. --- .../cmake/modules/CGAL_add_test.cmake | 24 +++++----- Installation/test/Installation/CMakeLists.txt | 2 +- Testsuite/test/parse-ctest-dashboard-xml.py | 48 +++++++++++++++++++ 3 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 Testsuite/test/parse-ctest-dashboard-xml.py diff --git a/Installation/cmake/modules/CGAL_add_test.cmake b/Installation/cmake/modules/CGAL_add_test.cmake index 52d549228f5..f337edf68a5 100644 --- a/Installation/cmake/modules/CGAL_add_test.cmake +++ b/Installation/cmake/modules/CGAL_add_test.cmake @@ -46,9 +46,11 @@ function(expand_list_with_globbing list_name) endfunction() function(cgal_add_test exe_name) + add_test(NAME "compilation_of__${exe_name}" + COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}") set(cin_file "${CGAL_CURRENT_SOURCE_DIR}/${exe_name}.cin") if(EXISTS ${cin_file}) - add_test(NAME ${exe_name} + add_test(NAME execution___of__${exe_name} COMMAND ${CMAKE_COMMAND} -DCMD:STRING=$ -DCIN:STRING=${cin_file} @@ -77,19 +79,17 @@ function(cgal_add_test exe_name) expand_list_with_globbing(ARGS) endif() # message(STATUS "add test: ${exe_name} ${ARGS}") - add_test(NAME ${exe_name} COMMAND ${exe_name} ${ARGS}) + add_test(NAME execution___of__${exe_name} COMMAND $ ${ARGS}) endif() - set_property(TEST "${exe_name}" + set_property(TEST "execution___of__${exe_name}" APPEND PROPERTY LABELS "${PROJECT_NAME}") # message(STATUS " working dir: ${CGAL_CURRENT_SOURCE_DIR}") - set_property(TEST "${exe_name}" + set_property(TEST "execution___of__${exe_name}" PROPERTY WORKING_DIRECTORY ${CGAL_CURRENT_SOURCE_DIR}) - add_test(NAME "build_target_${exe_name}" - COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}") - set_property(TEST "build_target_${exe_name}" + set_property(TEST "compilation_of__${exe_name}" APPEND PROPERTY LABELS "${PROJECT_NAME}") - set_property(TEST "${exe_name}" - APPEND PROPERTY DEPENDS "build_target_${exe_name}") + set_property(TEST "execution___of__${exe_name}" + APPEND PROPERTY DEPENDS "compilation_of__${exe_name}") return() @@ -108,9 +108,9 @@ function(cgal_add_test exe_name) # see https://github.com/CGAL/cgal/pull/1295/files/c65d3abe17bb3e677b8077996cdaf8672f9c4c6f#r71705451 endif() string(REPLACE ";" " " args_str "${ARGS}") - add_test(NAME ${exe_name} - COMMAND ${exe_name} ${ARGS} + add_test(NAME execution___of__${exe_name} + COMMAND $ ${ARGS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - set_property(TEST "${exe_name}" + set_property(TEST "execution___of__${exe_name}" APPEND PROPERTY LABELS "${PROJECT_NAME}") endfunction() diff --git a/Installation/test/Installation/CMakeLists.txt b/Installation/test/Installation/CMakeLists.txt index 71751fc3e05..ca9a06d013b 100644 --- a/Installation/test/Installation/CMakeLists.txt +++ b/Installation/test/Installation/CMakeLists.txt @@ -42,7 +42,7 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( will_fail.cpp will_fail_aux.cpp ) if(BUILD_TESTING) - set_property(TEST will_fail PROPERTY WILL_FAIL TRUE) + set_property(TEST execution___of__will_fail PROPERTY WILL_FAIL TRUE) endif() find_package( TBB QUIET ) diff --git a/Testsuite/test/parse-ctest-dashboard-xml.py b/Testsuite/test/parse-ctest-dashboard-xml.py new file mode 100644 index 00000000000..ee4e97cf163 --- /dev/null +++ b/Testsuite/test/parse-ctest-dashboard-xml.py @@ -0,0 +1,48 @@ +from __future__ import print_function +from collections import defaultdict +import xml.etree.ElementTree as ET +import os +import errno + +xml = open("Test.xml", 'rb').read(); + +def open_file_create_dir(filename, mode): + if not os.path.exists(os.path.dirname(filename)): + try: + os.makedirs(os.path.dirname(filename)) + except OSError as exc: # Guard against race condition + if exc.errno != errno.EEXIST: + raise + return open(filename, mode) + +root=ET.fromstring(xml) +testing = root.find('Testing') +testlist = testing.find('TestList') +nb = 0 +tests_ids = {} +for t in testlist: + tests_ids[t.text] = nb + nb += 1 + +tests = {} +for t in testing.findall('Test'): + tests[tests_ids[t.find('FullName').text]] = \ + { \ + "Name": t.find('Name').text, \ + "Status": t.attrib['Status'], \ + "Output": t.find('Results').find('Measurement').find('Value').text, \ + "Labels": [l.text for l in t.find('Labels').findall('Label')], \ + } + +tests_per_label = defaultdict(list) +for t_id in range(0, len(tests)): + t = tests[t_id] + for label in t['Labels']: + tests_per_label[label].append(t) + +for label, tests in tests_per_label.items(): + with open_file_create_dir("{}/error.txt".format(label), 'w') as error: + for t in tests: + print(" {} of {}".format("successful " if (t['Status'] == 'passed') else "ERROR: ", t['Name']), file=error) + with open("{}/ProgramOutput.{}".format(label, t['Name']), 'w') as f: + f.write(t['Output'] if t['Output'] != None else "")