| # SPDX-FileCopyrightText: The Eigen Authors | |
| # SPDX-License-Identifier: MPL-2.0 | |
| cmake_minimum_required(VERSION 3.18) | |
| if(NOT DEFINED OUTPUT_MANIFEST OR NOT EXISTS "${OUTPUT_MANIFEST}") | |
| message(FATAL_ERROR "Missing LAPACK output manifest") | |
| endif() | |
| file(STRINGS "${OUTPUT_MANIFEST}" OUTPUT_FILES) | |
| if(NOT OUTPUT_FILES) | |
| message(FATAL_ERROR "No LAPACK test output files were specified") | |
| endif() | |
| if(NOT DEFINED REPORT_FILE) | |
| set(REPORT_FILE "${CMAKE_CURRENT_BINARY_DIR}/testing_results.txt") | |
| endif() | |
| file(WRITE "${REPORT_FILE}" "") | |
| # ALLOWED_FAILURES names a file of "<output> <numerical errors> <other errors>" | |
| # lines; '#' starts a comment. An output without a line may report no failures. | |
| set(allowed_outputs "") | |
| if(DEFINED ALLOWED_FAILURES AND NOT ALLOWED_FAILURES STREQUAL "") | |
| if(NOT EXISTS "${ALLOWED_FAILURES}") | |
| message(FATAL_ERROR "Missing LAPACK allowed-failure file: ${ALLOWED_FAILURES}") | |
| endif() | |
| file(STRINGS "${ALLOWED_FAILURES}" entries) | |
| foreach(entry IN LISTS entries) | |
| string(REGEX REPLACE "#.*$" "" entry "${entry}") | |
| string(STRIP "${entry}" entry) | |
| if(entry STREQUAL "") | |
| continue() | |
| endif() | |
| if(NOT entry MATCHES "^([^ \t]+)[ \t]+([0-9]+)[ \t]+([0-9]+)$") | |
| message(FATAL_ERROR "Malformed LAPACK allowed-failure entry: ${entry}") | |
| endif() | |
| if(CMAKE_MATCH_1 IN_LIST allowed_outputs) | |
| message(FATAL_ERROR "Duplicate LAPACK allowed-failure entry: ${CMAKE_MATCH_1}") | |
| endif() | |
| list(APPEND allowed_outputs "${CMAKE_MATCH_1}") | |
| set("allowed_failed_${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") | |
| set("allowed_other_${CMAKE_MATCH_1}" "${CMAKE_MATCH_3}") | |
| endforeach() | |
| endif() | |
| set(unmatched_allowed "${allowed_outputs}") | |
| set(exceeded "") | |
| set(observed "") | |
| set(total_run 0) | |
| set(total_failed 0) | |
| set(total_other 0) | |
| message(STATUS "LAPACK TESTING SUMMARY") | |
| foreach(output IN LISTS OUTPUT_FILES) | |
| if(NOT EXISTS "${output}") | |
| message(FATAL_ERROR "Missing LAPACK test output: ${output}") | |
| endif() | |
| file(READ "${output}" contents) | |
| file(APPEND "${REPORT_FILE}" "${contents}") | |
| file(STRINGS "${output}" lines) | |
| set(run 0) | |
| set(failed 0) | |
| set(other 0) | |
| set(routine_errors 0) | |
| set(balance_errors 0) | |
| set(dmd_cases 0) | |
| set(dmd_summarized 0) | |
| foreach(line IN LISTS lines) | |
| string(TOLOWER "${line}" lower) | |
| # Failed groups give their total after "out of"; successful groups give "tests run". | |
| if(line MATCHES "([0-9]+)[ \t]+out of[ \t]+([0-9]+)") | |
| math(EXPR failed "${failed} + ${CMAKE_MATCH_1}") | |
| math(EXPR run "${run} + ${CMAKE_MATCH_2}") | |
| elseif(line MATCHES "([0-9]+)[ \t]+tests[ \t]+run\\)") | |
| math(EXPR run "${run} + ${CMAKE_MATCH_1}") | |
| elseif(lower MATCHES "total number of examples tested[ \t]*=[ \t]*([0-9]+)") | |
| math(EXPR run "${run} + ${CMAKE_MATCH_1}") | |
| math(EXPR other "${other} + ${balance_errors}") | |
| set(balance_errors 0) | |
| endif() | |
| # xCHKEQ reports failing routines without an "out of" summary. | |
| if(lower MATCHES "^[ \t]*[sdcz](ge|gb|po|pp|pb)equ[ \t]+failed test with value[ \t]+") | |
| math(EXPR failed "${failed} + 1") | |
| endif() | |
| # xCHKDMD reports each of its checks as "test PASSED" or with a failure count. | |
| if(line MATCHES "test PASSED") | |
| math(EXPR run "${run} + 1") | |
| elseif(line MATCHES "test FAILED[ \t]+([0-9]+)") | |
| set(count "${CMAKE_MATCH_1}") | |
| math(EXPR run "${run} + 1") | |
| math(EXPR failed "${failed} + ${count}") | |
| if(line MATCHES "F - Q\\*R test") | |
| math(EXPR dmd_summarized "${dmd_summarized} + ${count}") | |
| endif() | |
| elseif(line MATCHES "([0-9]+)[ \t]+times\\.[ \t]+Test FAILED") | |
| math(EXPR run "${run} + 1") | |
| math(EXPR failed "${failed} + ${CMAKE_MATCH_1}") | |
| math(EXPR dmd_summarized "${dmd_summarized} + ${CMAKE_MATCH_1}") | |
| endif() | |
| # xCHKDMD also prints this line for each case that fails its singular-value or F - Q*R | |
| # check, which its summary counts again. Only lines beyond the summary's count are other | |
| # errors, as when the driver stops before printing its summary. | |
| if(line MATCHES "FAILED! Something was wrong with the run") | |
| math(EXPR dmd_cases "${dmd_cases} + 1") | |
| endif() | |
| # xCHKDMD stops at the first case that fails a check outside its summary. | |
| if(line MATCHES "[SDCZ]GEDMDQ? FAILED!") | |
| math(EXPR other "${other} + 1") | |
| endif() | |
| # Balance tests report example indices as well as a total error count. | |
| # An index is only evidence of an error, not the number of errors. | |
| if(lower MATCHES "number of examples where info is not 0[ \t]*=[ \t]*([0-9]+)") | |
| if(CMAKE_MATCH_1 GREATER balance_errors) | |
| set(balance_errors "${CMAKE_MATCH_1}") | |
| endif() | |
| elseif(lower MATCHES "example number where (.*info is not (zero|0)|ilo or ihi( is)? wrong)[ \t]*=[ \t]*([0-9]+)") | |
| if(CMAKE_MATCH_4 GREATER 0 AND balance_errors EQUAL 0) | |
| set(balance_errors 1) | |
| endif() | |
| endif() | |
| if(lower MATCHES "(value|ratio) of largest test error[ \t]*=[ \t]*([^ \t]+)") | |
| if(CMAKE_MATCH_2 MATCHES "inf|nan|\\*") | |
| math(EXPR failed "${failed} + 1") | |
| endif() | |
| endif() | |
| if(lower MATCHES "error code from" OR line MATCHES "(^|[ \t])INFO([ \t=]|$)") | |
| math(EXPR routine_errors "${routine_errors} + 1") | |
| elseif(lower MATCHES "([0-9]+)[ \t]+error messages recorded") | |
| # ALASUM summarizes the preceding ALAERH diagnostics; count each error once. | |
| if(CMAKE_MATCH_1 GREATER routine_errors) | |
| set(routine_errors "${CMAKE_MATCH_1}") | |
| endif() | |
| math(EXPR other "${other} + ${routine_errors}") | |
| set(routine_errors 0) | |
| endif() | |
| if(lower MATCHES "illegal|xerbla was called|failed the tests of the error exits" | |
| OR lower MATCHES "^[ \t]*error in[ \t]+") | |
| math(EXPR other "${other} + 1") | |
| endif() | |
| endforeach() | |
| math(EXPR other "${other} + ${routine_errors} + ${balance_errors}") | |
| if(dmd_cases GREATER dmd_summarized) | |
| math(EXPR other "${other} + ${dmd_cases} - ${dmd_summarized}") | |
| endif() | |
| get_filename_component(name "${output}" NAME) | |
| set(allowed_failed 0) | |
| set(allowed_other 0) | |
| if(name IN_LIST allowed_outputs) | |
| set(allowed_failed "${allowed_failed_${name}}") | |
| set(allowed_other "${allowed_other_${name}}") | |
| list(REMOVE_ITEM unmatched_allowed "${name}") | |
| endif() | |
| set(verdict "") | |
| if(failed GREATER allowed_failed OR other GREATER allowed_other) | |
| set(verdict "; more than the ${allowed_failed} numerical and ${allowed_other} other allowed") | |
| list(APPEND exceeded "${name}") | |
| elseif(failed LESS allowed_failed OR other LESS allowed_other) | |
| set(verdict "; fewer than the ${allowed_failed} numerical and ${allowed_other} other allowed, lower its entry") | |
| elseif(failed GREATER 0 OR other GREATER 0) | |
| set(verdict "; allowed") | |
| endif() | |
| message(STATUS "${name}: ${run} tests, ${failed} numerical errors, ${other} other errors${verdict}") | |
| if(failed GREATER 0 OR other GREATER 0) | |
| string(APPEND observed "${name} ${failed} ${other}\n") | |
| endif() | |
| # xCHKEC failure output contains diagnostics without a test-count summary. | |
| if(run EQUAL 0 AND failed EQUAL 0 AND other EQUAL 0) | |
| message(FATAL_ERROR "No LAPACK numerical tests were analyzed in: ${output}") | |
| endif() | |
| math(EXPR total_run "${total_run} + ${run}") | |
| math(EXPR total_failed "${total_failed} + ${failed}") | |
| math(EXPR total_other "${total_other} + ${other}") | |
| endforeach() | |
| message(STATUS "TOTAL: ${total_run} tests, ${total_failed} numerical errors, ${total_other} other errors") | |
| # The observed counts, in the allowed-failure file's format. | |
| if(DEFINED FAILURES_FILE) | |
| file(WRITE "${FAILURES_FILE}" "${observed}") | |
| endif() | |
| if(unmatched_allowed) | |
| message(FATAL_ERROR "Allowed-failure entries name no LAPACK test output: ${unmatched_allowed}") | |
| endif() | |
| if(exceeded) | |
| message(FATAL_ERROR "LAPACK test output reports failures: ${exceeded}") | |
| endif() | |
| if(total_run EQUAL 0) | |
| message(FATAL_ERROR "No LAPACK numerical tests were analyzed") | |
| endif() |