Tests/RunCMake/Instrumentation: Factor out common JSON logic

This commit is contained in:
Tyler Yankee
2025-07-28 11:29:36 -04:00
parent 4d21b9e6d8
commit 27bc7d5782
7 changed files with 149 additions and 142 deletions

View File

@@ -1,4 +1,4 @@
include(${CMAKE_CURRENT_LIST_DIR}/verify-snippet.cmake) include(${CMAKE_CURRENT_LIST_DIR}/json.cmake)
if (NOT IS_DIRECTORY "${v1}/data/content") if (NOT IS_DIRECTORY "${v1}/data/content")
add_error("Custom content directory does not exist.") add_error("Custom content directory does not exist.")

View File

@@ -1,4 +1,4 @@
include(${CMAKE_CURRENT_LIST_DIR}/check-data-dir.cmake) include(${CMAKE_CURRENT_LIST_DIR}/json.cmake)
if (NOT IS_DIRECTORY "${v1}/data/content") if (NOT IS_DIRECTORY "${v1}/data/content")
add_error("Custom content directory does not exist.") add_error("Custom content directory does not exist.")
@@ -10,27 +10,17 @@ if (NOT ${num} EQUAL 2)
add_error("Found ${num} custom content files, expected 2.") add_error("Found ${num} custom content files, expected 2.")
endif() endif()
macro(assert_key contents key expected)
string(JSON value ERROR_VARIABLE errors GET "${contents}" ${key})
if (errors)
add_error("Did not find expected key \"${key}\" in custom content.")
endif()
if (NOT ${value} MATCHES ${expected})
add_error("Unexpected data in custom content file:\nGot ${value}, Expected ${expected}.")
endif()
endmacro()
# Check contents of configureContent files # Check contents of configureContent files
set(firstFile "") set(firstFile "")
foreach(content_file IN LISTS content_files) foreach(content_file IN LISTS content_files)
read_json("${content_file}" contents) read_json("${content_file}" contents)
assert_key("${contents}" myString "string") json_assert_key("${content_file}" "${contents}" myString "string")
assert_key("${contents}" myBool "OFF") json_assert_key("${content_file}" "${contents}" myBool "OFF")
assert_key("${contents}" myInt "1") json_assert_key("${content_file}" "${contents}" myInt "1")
assert_key("${contents}" myFloat "2.5") json_assert_key("${content_file}" "${contents}" myFloat "2.5")
assert_key("${contents}" myTrue "ON") json_assert_key("${content_file}" "${contents}" myTrue "ON")
assert_key("${contents}" myList "[ \"a\", \"b\", \"c\" ]") json_assert_key("${content_file}" "${contents}" myList "[ \"a\", \"b\", \"c\" ]")
assert_key("${contents}" myObject "{.*\"key\".*:.*\"value\".*}") json_assert_key("${content_file}" "${contents}" myObject "{.*\"key\".*:.*\"value\".*}")
if (NOT firstFile) if (NOT firstFile)
set(firstFile "${content_file}") set(firstFile "${content_file}")
endif() endif()

View File

@@ -25,14 +25,14 @@ foreach(snippet IN LISTS snippets)
if (NOT target MATCHES NOTFOUND) if (NOT target MATCHES NOTFOUND)
set(targets "main;lib;customTarget;TARGET_NAME") set(targets "main;lib;customTarget;TARGET_NAME")
if (NOT ${target} IN_LIST targets) if (NOT ${target} IN_LIST targets)
snippet_error("${snippet}" "Unexpected target: ${target}") json_error("${snippet}" "Unexpected target: ${target}")
endif() endif()
endif() endif()
# Verify output # Verify output
string(JSON result GET "${contents}" result) string(JSON result GET "${contents}" result)
if (NOT ${result} EQUAL 0) if (NOT ${result} EQUAL 0)
snippet_error("${snippet}" "Compile command had non-0 result") json_error("${snippet}" "Compile command had non-0 result")
endif() endif()
# Verify contents of compile-* Snippets # Verify contents of compile-* Snippets
@@ -41,10 +41,10 @@ foreach(snippet IN LISTS snippets)
string(JSON source GET "${contents}" source) string(JSON source GET "${contents}" source)
string(JSON language GET "${contents}" language) string(JSON language GET "${contents}" language)
if (NOT language MATCHES "C\\+\\+") if (NOT language MATCHES "C\\+\\+")
snippet_error("${snippet}" "Expected C++ compile language") json_error("${snippet}" "Expected C++ compile language")
endif() endif()
if (NOT source MATCHES "${target}.cxx$") if (NOT source MATCHES "${target}.cxx$")
snippet_error("${snippet}" "Unexpected source file") json_error("${snippet}" "Unexpected source file")
endif() endif()
endif() endif()
@@ -55,30 +55,30 @@ foreach(snippet IN LISTS snippets)
string(JSON targetLabels GET "${contents}" targetLabels) string(JSON targetLabels GET "${contents}" targetLabels)
if (target MATCHES "main") if (target MATCHES "main")
if (NOT targetType MATCHES "EXECUTABLE") if (NOT targetType MATCHES "EXECUTABLE")
snippet_error("${snippet}" "Expected EXECUTABLE, target type was ${targetType}") json_error("${snippet}" "Expected EXECUTABLE, target type was ${targetType}")
endif() endif()
string(JSON nlabels LENGTH "${targetLabels}") string(JSON nlabels LENGTH "${targetLabels}")
if (NOT nlabels STREQUAL 2) if (NOT nlabels STREQUAL 2)
snippet_error("${snippet}" "Missing Target Labels for: ${target}") json_error("${snippet}" "Missing Target Labels for: ${target}")
else() else()
string(JSON label1 GET "${contents}" targetLabels 0) string(JSON label1 GET "${contents}" targetLabels 0)
string(JSON label2 GET "${contents}" targetLabels 1) string(JSON label2 GET "${contents}" targetLabels 1)
if (NOT label1 MATCHES "label1" OR NOT label2 MATCHES "label2") if (NOT label1 MATCHES "label1" OR NOT label2 MATCHES "label2")
snippet_error("${snippet}" "Missing Target Labels for: ${target}") json_error("${snippet}" "Missing Target Labels for: ${target}")
endif() endif()
endif() endif()
endif() endif()
if (target MATCHES "lib") if (target MATCHES "lib")
if (NOT targetType MATCHES "STATIC_LIBRARY") if (NOT targetType MATCHES "STATIC_LIBRARY")
snippet_error("${snippet}" "Expected STATIC_LIBRARY, target type was ${targetType}") json_error("${snippet}" "Expected STATIC_LIBRARY, target type was ${targetType}")
endif() endif()
string(JSON nlabels LENGTH "${targetLabels}") string(JSON nlabels LENGTH "${targetLabels}")
if (NOT nlabels STREQUAL 1) if (NOT nlabels STREQUAL 1)
snippet_error("${snippet}" "Missing Target Labels for: ${target}") json_error("${snippet}" "Missing Target Labels for: ${target}")
else() else()
string(JSON label ERROR_VARIABLE noLabels GET "${contents}" targetLabels 0) string(JSON label ERROR_VARIABLE noLabels GET "${contents}" targetLabels 0)
if (NOT label MATCHES "label3") if (NOT label MATCHES "label3")
snippet_error("${snippet}" "Missing Target Labels for: ${target}") json_error("${snippet}" "Missing Target Labels for: ${target}")
endif() endif()
endif() endif()
endif() endif()
@@ -88,7 +88,7 @@ foreach(snippet IN LISTS snippets)
if (filename MATCHES "^custom-") if (filename MATCHES "^custom-")
string(JSON outputs GET "${contents}" outputs) string(JSON outputs GET "${contents}" outputs)
if (NOT output1 MATCHES "output1" OR NOT output2 MATCHES "output2") if (NOT output1 MATCHES "output1" OR NOT output2 MATCHES "output2")
snippet_error("${snippet}" "Custom command missing outputs") json_error("${snippet}" "Custom command missing outputs")
endif() endif()
endif() endif()
@@ -96,7 +96,7 @@ foreach(snippet IN LISTS snippets)
if (filename MATCHES "^test-") if (filename MATCHES "^test-")
string(JSON testName GET "${contents}" testName) string(JSON testName GET "${contents}" testName)
if (NOT testName STREQUAL "test") if (NOT testName STREQUAL "test")
snippet_error("${snippet}" "Unexpected testName: ${testName}") json_error("${snippet}" "Unexpected testName: ${testName}")
endif() endif()
endif() endif()
@@ -104,7 +104,7 @@ foreach(snippet IN LISTS snippets)
if (filename MATCHES "^test|^compile|^link") if (filename MATCHES "^test|^compile|^link")
string(JSON config GET "${contents}" config) string(JSON config GET "${contents}" config)
if (NOT config STREQUAL "Debug") if (NOT config STREQUAL "Debug")
snippet_error(${snippet} "Unexpected config: ${config}") json_error(${snippet} "Unexpected config: ${config}")
endif() endif()
endif() endif()
@@ -112,7 +112,7 @@ foreach(snippet IN LISTS snippets)
if (filename MATCHES "^cmakeBuild|^ctest") if (filename MATCHES "^cmakeBuild|^ctest")
string(JSON command GET "${contents}" command) string(JSON command GET "${contents}" command)
if (NOT command MATCHES "Debug") if (NOT command MATCHES "Debug")
snippet_error(${snippet} "Command value missing passed arguments") json_error(${snippet} "Command value missing passed arguments")
endif() endif()
endif() endif()

View File

@@ -1,18 +1,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/json.cmake) include(${CMAKE_CURRENT_LIST_DIR}/json.cmake)
function(check_generated_json n)
set(expected_file "${RunCMake_TEST_BINARY_DIR}/query/query-${n}.json")
set(generated_file "${v1}/query/generated/query-${n}.json")
read_json("${expected_file}" expected)
read_json("${generated_file}" generated)
string(JSON equal EQUAL ${expected} ${generated})
if (NOT equal)
set(RunCMake_TEST_FAILED
"Generated JSON ${generated}\nNot equal to expected ${expected}"
)
endif()
return(PROPAGATE RunCMake_TEST_FAILED)
endfunction()
foreach(n IN LISTS generated_queries) foreach(n IN LISTS generated_queries)
check_generated_json(${n}) set(expected_file "${RunCMake_TEST_BINARY_DIR}/query/query-${n}.json")
set(generated_file "${v1}/query/generated/query-${n}.json")
json_equals(${expected_file} ${generated_file})
endforeach() endforeach()

View File

@@ -20,22 +20,10 @@ function(add_error error)
return(PROPAGATE ERROR_MESSAGE) return(PROPAGATE ERROR_MESSAGE)
endfunction() endfunction()
function(has_key_index key json) json_has_key("${index}" "${contents}" version)
cmake_parse_arguments(ARG "UNEXPECTED" "" "" ${ARGN}) json_has_key("${index}" "${contents}" buildDir)
unset(missingKey) json_has_key("${index}" "${contents}" dataDir)
string(JSON ${key} ERROR_VARIABLE missingKey GET "${json}" ${key}) json_has_key("${index}" "${contents}" snippets)
if (NOT ARG_UNEXPECTED AND NOT missingKey MATCHES NOTFOUND)
add_error("\nKey \"${key}\" not in index:\n${json}")
elseif(ARG_UNEXPECTED AND missingKey MATCHES NOTFOUND)
add_error("\nUnexpected key \"${key}\" in index:\n${json}")
endif()
return(PROPAGATE ERROR_MESSAGE ${key})
endfunction()
has_key_index(version "${contents}")
has_key_index(buildDir "${contents}")
has_key_index(dataDir "${contents}")
has_key_index(snippets "${contents}")
if (NOT version EQUAL 1) if (NOT version EQUAL 1)
add_error("Version must be 1, got: ${version}") add_error("Version must be 1, got: ${version}")
@@ -52,26 +40,26 @@ foreach(i RANGE ${length})
verify_snippet(${dataDir}/${filename} "${snippet_contents}") verify_snippet(${dataDir}/${filename} "${snippet_contents}")
endforeach() endforeach()
has_key_index(staticSystemInformation "${contents}" ${hasStaticInfo}) json_has_key("${index}" "${contents}" staticSystemInformation ${hasStaticInfo})
if (NOT hasStaticInfo STREQUAL UNEXPECTED) if (NOT hasStaticInfo STREQUAL UNEXPECTED)
has_key_index(OSName "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" OSName ${hasStaticInfo})
has_key_index(OSPlatform "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" OSPlatform ${hasStaticInfo})
has_key_index(OSRelease "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" OSRelease ${hasStaticInfo})
has_key_index(OSVersion "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" OSVersion ${hasStaticInfo})
has_key_index(familyId "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" familyId ${hasStaticInfo})
has_key_index(hostname "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" hostname ${hasStaticInfo})
has_key_index(is64Bits "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" is64Bits ${hasStaticInfo})
has_key_index(modelId "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" modelId ${hasStaticInfo})
has_key_index(numberOfLogicalCPU "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" numberOfLogicalCPU ${hasStaticInfo})
has_key_index(numberOfPhysicalCPU "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" numberOfPhysicalCPU ${hasStaticInfo})
has_key_index(processorAPICID "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" processorAPICID ${hasStaticInfo})
has_key_index(processorCacheSize "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" processorCacheSize ${hasStaticInfo})
has_key_index(processorClockFrequency "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" processorClockFrequency ${hasStaticInfo})
has_key_index(processorName "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" processorName ${hasStaticInfo})
has_key_index(totalPhysicalMemory "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" totalPhysicalMemory ${hasStaticInfo})
has_key_index(totalVirtualMemory "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" totalVirtualMemory ${hasStaticInfo})
has_key_index(vendorID "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" vendorID ${hasStaticInfo})
has_key_index(vendorString "${staticSystemInformation}" ${hasStaticInfo}) json_has_key("${index}" "${staticSystemInformation}" vendorString ${hasStaticInfo})
endif() endif()
get_filename_component(dataDir ${index} DIRECTORY) get_filename_component(dataDir ${index} DIRECTORY)

View File

@@ -1,4 +1,69 @@
# Read the JSON `filename` into `outvar`.
function(read_json filename outvar) function(read_json filename outvar)
file(READ "${filename}" ${outvar}) file(READ "${filename}" ${outvar})
return(PROPAGATE ${outvar}) return(PROPAGATE ${outvar})
endfunction() endfunction()
# Utility for error messages.
function(add_error error)
string(APPEND RunCMake_TEST_FAILED " ${error}\n")
string(APPEND ERROR_MESSAGE " ${error}\n")
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
# Utility for JSON-specific error messages.
function(json_error file error)
add_error("Error in JSON file ${file}:\n${error}")
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
# Check if the JSON string `json` has `key` when it's not
# UNEXPECTED. If so, return it in `key`.
function(json_has_key file json key)
cmake_parse_arguments(ARG "UNEXPECTED" "" "" ${ARGN})
unset(missingKey)
string(JSON ${key} ERROR_VARIABLE missingKey GET "${json}" ${key})
if (NOT ARG_UNEXPECTED AND NOT missingKey MATCHES NOTFOUND)
json_error("${file}" "Missing key \'${key}\':\n${json}")
elseif (ARG_UNEXPECTED AND missingKey MATCHES NOTFOUND)
json_error("${file}" "\nUnexpected key \'${key}\':\n${json}")
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE ${key})
endfunction()
# Check if the JSON string `json` does not have `key`.
function(json_missing_key file json key)
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
if (missingKey MATCHES NOTFOUND)
json_error("${file}" "Has unexpected ${key}.")
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
# Check if the JSON string `json` has `key` and its value matches `expected`.
function(json_assert_key file json key expected)
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
if (NOT missingKey MATCHES NOTFOUND)
json_error("${file}" "Missing ${key}.")
endif()
if (NOT ${data} MATCHES ${expected})
json_error(
"${file}"
"Unexpected data in custom content file:\nGot ${data}, Expected ${expected}."
)
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
# Check if the two given JSON files are equal.
function(json_equals expected_file actual_file)
read_json("${expected_file}" expected_contents)
read_json("${actual_file}" actual_contents)
string(JSON equal EQUAL ${expected_contents} ${actual_contents})
if (NOT equal)
add_error(
"JSON ${expected_file} does not equal ${actual_file}."
)
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()

View File

@@ -1,78 +1,53 @@
# Performs generic (non-project specific) validation of v1 Snippet File Contents # Performs generic (non-project specific) validation of v1 Snippet File Contents
function(add_error error) include(${CMAKE_CURRENT_LIST_DIR}/json.cmake)
string(APPEND RunCMake_TEST_FAILED " ${error}\n")
string(APPEND ERROR_MESSAGE " ${error}\n")
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
function(snippet_error snippet error)
add_error("Error in snippet file ${snippet}:\n${error}")
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
function(has_key snippet json key)
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
if (NOT missingKey MATCHES NOTFOUND)
snippet_error("${snippet}" "Missing ${key}")
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
function(has_not_key snippet json key)
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
if (missingKey MATCHES NOTFOUND)
snippet_error("${snippet}" "Has unexpected ${key}")
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction()
function(snippet_has_fields snippet contents) function(snippet_has_fields snippet contents)
get_filename_component(filename "${snippet}" NAME) get_filename_component(filename "${snippet}" NAME)
has_key("${snippet}" "${contents}" role) json_has_key("${snippet}" "${contents}" role)
has_key("${snippet}" "${contents}" result) json_has_key("${snippet}" "${contents}" result)
has_key("${snippet}" "${contents}" workingDir) json_has_key("${snippet}" "${contents}" workingDir)
if (NOT filename MATCHES "^build-*") if (NOT filename MATCHES "^build-*")
has_key("${snippet}" "${contents}" command) json_has_key("${snippet}" "${contents}" command)
endif() endif()
if (filename MATCHES "^link-*") if (filename MATCHES "^link-*")
has_key("${snippet}" "${contents}" target) json_has_key("${snippet}" "${contents}" target)
has_key("${snippet}" "${contents}" outputs) json_has_key("${snippet}" "${contents}" outputs)
has_key("${snippet}" "${contents}" outputSizes) json_has_key("${snippet}" "${contents}" outputSizes)
has_key("${snippet}" "${contents}" targetType) json_has_key("${snippet}" "${contents}" targetType)
has_key("${snippet}" "${contents}" targetLabels) json_has_key("${snippet}" "${contents}" targetLabels)
has_key("${snippet}" "${contents}" config) json_has_key("${snippet}" "${contents}" config)
elseif (filename MATCHES "^compile-*") elseif (filename MATCHES "^compile-*")
has_key("${snippet}" "${contents}" target) json_has_key("${snippet}" "${contents}" target)
has_key("${snippet}" "${contents}" outputs) json_has_key("${snippet}" "${contents}" outputs)
has_key("${snippet}" "${contents}" outputSizes) json_has_key("${snippet}" "${contents}" outputSizes)
has_key("${snippet}" "${contents}" source) json_has_key("${snippet}" "${contents}" source)
has_key("${snippet}" "${contents}" language) json_has_key("${snippet}" "${contents}" language)
has_key("${snippet}" "${contents}" config) json_has_key("${snippet}" "${contents}" config)
elseif (filename MATCHES "^custom-*") elseif (filename MATCHES "^custom-*")
has_key("${snippet}" "${contents}" outputs) json_has_key("${snippet}" "${contents}" outputs)
has_key("${snippet}" "${contents}" outputSizes) json_has_key("${snippet}" "${contents}" outputSizes)
elseif (filename MATCHES "^test-*") elseif (filename MATCHES "^test-*")
has_key("${snippet}" "${contents}" testName) json_has_key("${snippet}" "${contents}" testName)
has_key("${snippet}" "${contents}" config) json_has_key("${snippet}" "${contents}" config)
endif() endif()
if(ARGS_DYNAMIC_QUERY) if(ARGS_DYNAMIC_QUERY)
has_key("${snippet}" "${contents}" dynamicSystemInformation) json_has_key("${snippet}" "${contents}" dynamicSystemInformation)
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation) string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation)
if (noInfo MATCHES NOTFOUND) if (noInfo MATCHES NOTFOUND)
has_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage) json_has_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
has_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed) json_has_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
has_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage) json_has_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
has_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed) json_has_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
endif() endif()
else() else()
has_not_key("${snippet}" "${contents}" dynamicSystemInformation) json_missing_key("${snippet}" "${contents}" dynamicSystemInformation)
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation) string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation)
if (noInfo MATCHES NOTFOUND) if (noInfo MATCHES NOTFOUND)
has_not_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage) json_missing_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
has_not_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed) json_missing_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
has_not_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage) json_missing_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
has_not_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed) json_missing_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
endif() endif()
endif() endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE) return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
@@ -85,7 +60,7 @@ function(snippet_valid_timing contents)
snippet_error("${snippet}" "Negative time start: ${start}") snippet_error("${snippet}" "Negative time start: ${start}")
endif() endif()
if (duration LESS 0) if (duration LESS 0)
snippet_error("${snippet}" "Negative duration: ${end}") json_error("${snippet}" "Negative duration: ${end}")
endif() endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE) return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
endfunction() endfunction()
@@ -95,12 +70,12 @@ function(verify_snippet snippet contents)
snippet_valid_timing("${contents}") snippet_valid_timing("${contents}")
string(JSON version GET "${contents}" version) string(JSON version GET "${contents}" version)
if (NOT version EQUAL 1) if (NOT version EQUAL 1)
snippet_error("${snippet}" "Version must be 1, got: ${version}") json_error("${snippet}" "Version must be 1, got: ${version}")
endif() endif()
string(JSON role GET "${contents}" role) string(JSON role GET "${contents}" role)
get_filename_component(filename "${snippet}" NAME) get_filename_component(filename "${snippet}" NAME)
if (NOT filename MATCHES "^${role}-") if (NOT filename MATCHES "^${role}-")
snippet_error("${snippet}" "Role \"${role}\" doesn't match snippet filename") json_error("${snippet}" "Role \"${role}\" doesn't match snippet filename")
endif() endif()
string(JSON outputs ERROR_VARIABLE noOutputs GET "${contents}" outputs) string(JSON outputs ERROR_VARIABLE noOutputs GET "${contents}" outputs)
if (NOT outputs MATCHES NOTFOUND) if (NOT outputs MATCHES NOTFOUND)
@@ -108,7 +83,7 @@ function(verify_snippet snippet contents)
list(LENGTH outputs outputsLen) list(LENGTH outputs outputsLen)
list(LENGTH outputSizes outputSizesLen) list(LENGTH outputSizes outputSizesLen)
if (outputSizes MATCHES NOTFOUND OR NOT outputsLen EQUAL outputSizesLen) if (outputSizes MATCHES NOTFOUND OR NOT outputsLen EQUAL outputSizesLen)
snippet_error("${snippet}" "outputs and outputSizes do not match") json_error("${snippet}" "outputs and outputSizes do not match")
endif() endif()
endif() endif()
return(PROPAGATE ERROR_MESSAGE RunCMake_TEST_FAILED role) return(PROPAGATE ERROR_MESSAGE RunCMake_TEST_FAILED role)