From 32444714e548ff6f4358bf23a0a824c521a0e60a Mon Sep 17 00:00:00 2001 From: Martin Duffy Date: Thu, 16 Jan 2025 13:47:54 -0500 Subject: [PATCH] instrumentation: Update tests so that snippet verification runs Corrects regex matching in Tests/RunCMake/instrumentation so that snippet verification tests aren't skipped over. --- .../Instrumentation/check-data-dir.cmake | 30 ++++++++++--------- Tests/RunCMake/Instrumentation/hook.cmake | 6 ++-- .../Instrumentation/verify-snippet.cmake | 29 +++++++++--------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Tests/RunCMake/Instrumentation/check-data-dir.cmake b/Tests/RunCMake/Instrumentation/check-data-dir.cmake index 5776ce0e28..c5fab4e7aa 100644 --- a/Tests/RunCMake/Instrumentation/check-data-dir.cmake +++ b/Tests/RunCMake/Instrumentation/check-data-dir.cmake @@ -8,6 +8,8 @@ endif() set(FOUND_SNIPPETS "") foreach(snippet ${snippets}) + get_filename_component(filename ${snippet} NAME) + read_json(${snippet} contents) # Verify snippet file is valid @@ -19,7 +21,7 @@ foreach(snippet ${snippets}) endif() # Verify target - string(JSON target ERROR_VARIABLE noTarget GET ${contents} target) + string(JSON target ERROR_VARIABLE noTarget GET "${contents}" target) if (NOT target MATCHES NOTFOUND) set(targets "main;lib;customTarget;TARGET_NAME") if (NOT ${target} IN_LIST targets) @@ -28,16 +30,16 @@ foreach(snippet ${snippets}) endif() # Verify output - string(JSON result GET ${contents} result) + string(JSON result GET "${contents}" result) if (NOT ${result} EQUAL 0) snippet_error(${snippet} "Compile command had non-0 result") endif() # Verify contents of compile-* Snippets - if (snippet MATCHES ^compile-) - string(JSON target GET ${contents} target) - string(JSON source GET ${contents} source) - string(JSON language GET ${contents} language) + if (filename MATCHES ^compile-) + string(JSON target GET "${contents}" target) + string(JSON source GET "${contents}" source) + string(JSON language GET "${contents}" language) if (NOT language MATCHES "C\\+\\+") snippet_error(${snippet} "Expected C++ compile language") endif() @@ -47,9 +49,9 @@ foreach(snippet ${snippets}) endif() # Verify contents of link-* Snippets - if (snippet MATCHES ^link-) - string(JSON target GET ${contents} target) - string(JSON targetType GET ${contents} targetType) + if (filename MATCHES ^link-) + string(JSON target GET "${contents}" target) + string(JSON targetType GET "${contents}" targetType) if (target MATCHES main) if (NOT targetType MATCHES "EXECUTABLE") snippet_error(${snippet} "Expected EXECUTABLE, target type was ${targetType}") @@ -63,17 +65,17 @@ foreach(snippet ${snippets}) endif() # Verify contents of custom-* Snippets - if (snippet MATCHES ^custom-) - string(JSON outputs GET ${contents} outputs) + if (filename MATCHES ^custom-) + string(JSON outputs GET "${contents}" outputs) if (NOT output1 MATCHES "output1" OR NOT output2 MATCHES "output2") snippet_error(${snippet} "Custom command missing outputs") endif() endif() # Verify contents of test-* Snippets - if (snippet MATCHES ^test-) - string(JSON testName GET ${contents} testName) - if (NOT testName EQUAL "test") + if (filename MATCHES ^test-) + string(JSON testName GET "${contents}" testName) + if (NOT testName STREQUAL "test") snippet_error(${snippet} "Unexpected testName: ${testName}") endif() endif() diff --git a/Tests/RunCMake/Instrumentation/hook.cmake b/Tests/RunCMake/Instrumentation/hook.cmake index d3be3a41ba..973e7d89c7 100644 --- a/Tests/RunCMake/Instrumentation/hook.cmake +++ b/Tests/RunCMake/Instrumentation/hook.cmake @@ -6,7 +6,7 @@ if (NOT ${CMAKE_ARGV3}) set(hasStaticInfo "UNEXPECTED") endif() read_json(${index} contents) -string(JSON hook GET ${contents} hook) +string(JSON hook GET "${contents}" hook) # Output is verified by *-stdout.txt files that the HOOK is run message(STATUS ${hook}) @@ -19,7 +19,7 @@ endmacro() macro(has_key key json) cmake_parse_arguments(ARG "UNEXPECTED" "" "" ${ARGN}) unset(missingKey) - string(JSON ${key} ERROR_VARIABLE missingKey GET ${json} ${key}) + string(JSON ${key} ERROR_VARIABLE missingKey GET "${json}" ${key}) 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) @@ -39,7 +39,7 @@ endif() string(JSON length LENGTH ${snippets}) math(EXPR length ${length}-1) foreach(i RANGE ${length}) - string(JSON filename GET ${snippets} ${i}) + string(JSON filename GET "${snippets}" ${i}) if (NOT EXISTS ${dataDir}/${filename}) add_error("Listed snippet: ${dataDir}/${filename} does not exist") endif() diff --git a/Tests/RunCMake/Instrumentation/verify-snippet.cmake b/Tests/RunCMake/Instrumentation/verify-snippet.cmake index 5f23bf2392..bf2e42a1dc 100644 --- a/Tests/RunCMake/Instrumentation/verify-snippet.cmake +++ b/Tests/RunCMake/Instrumentation/verify-snippet.cmake @@ -9,44 +9,45 @@ macro(snippet_error snippet error) endmacro() macro(has_key snippet json key) - string(JSON data ERROR_VARIABLE missingKey GET ${json} ${key}) + string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key}) if (NOT ${missingKey} MATCHES NOTFOUND) snippet_error(${snippet} "Missing ${key}") endif() endmacro() macro(has_not_key snippet json key) - string(JSON data ERROR_VARIABLE missingKey GET ${json} ${key}) + string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key}) if (${missingKey} MATCHES NOTFOUND) snippet_error(${snippet} "Has unexpected ${key}") endif() endmacro() macro(snippet_has_fields snippet contents) + get_filename_component(filename ${snippet} NAME) has_key(${snippet} ${contents} command) has_key(${snippet} ${contents} role) has_key(${snippet} ${contents} result) - if (snippet MATCHES ^link-*) + if (filename MATCHES ^link-*) has_key(${snippet} ${contents} target) has_key(${snippet} ${contents} outputs) has_key(${snippet} ${contents} outputSizes) has_key(${snippet} ${contents} targetType) - elseif (snippet MATCHES ^compile-*) + elseif (filename MATCHES ^compile-*) has_key(${snippet} ${contents} target) has_key(${snippet} ${contents} outputs) has_key(${snippet} ${contents} outputSizes) has_key(${snippet} ${contents} source) has_key(${snippet} ${contents} language) - elseif (snippet MATCHES ^custom-*) + elseif (filename MATCHES ^custom-*) has_key(${snippet} ${contents} target) has_key(${snippet} ${contents} outputs) has_key(${snippet} ${contents} outputSizes) - elseif (snippet MATCHES ^test-*) + elseif (filename MATCHES ^test-*) has_key(${snippet} ${contents} testName) endif() if(ARGS_DYNAMIC_QUERY) 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) has_key(${snippet} ${dynamicSystemInfo} beforeCPULoadAverage) has_key(${snippet} ${dynamicSystemInfo} beforeHostMemoryUsed) @@ -55,7 +56,7 @@ macro(snippet_has_fields snippet contents) endif() else() has_not_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) has_not_key(${snippet} ${dynamicSystemInfo} beforeCPULoadAverage) has_not_key(${snippet} ${dynamicSystemInfo} beforeHostMemoryUsed) @@ -66,8 +67,8 @@ macro(snippet_has_fields snippet contents) endmacro() macro(snippet_valid_timing contents) - string(JSON start GET ${contents} timeStart) - string(JSON duration GET ${contents} duration) + string(JSON start GET "${contents}" timeStart) + string(JSON duration GET "${contents}" duration) if (${start} LESS 0) snippet_error(${snippet} "Negative time start: ${start}") endif() @@ -79,18 +80,18 @@ endmacro() macro(verify_snippet snippet contents) snippet_has_fields(${snippet} ${contents}) snippet_valid_timing(${contents}) - string(JSON version GET ${contents} version) + string(JSON version GET "${contents}" version) if (NOT ${version} EQUAL 1) snippet_error(${snippet} "Version must be 1, got: ${version}") endif() - string(JSON role GET ${contents} role) + string(JSON role GET "${contents}" role) get_filename_component(filename ${snippet} NAME) if (NOT ${filename} MATCHES ^${role}-) snippet_error(${snippet} "Role \"${role}\" doesn't match snippet filename") endif() - string(JSON outputs ERROR_VARIABLE noOutputs GET ${contents} outputs) + string(JSON outputs ERROR_VARIABLE noOutputs GET "${contents}" outputs) if (NOT outputs MATCHES NOTFOUND) - string(JSON outputSizes ERROR_VARIABLE noOutputSizes GET ${contents} outputSizes) + string(JSON outputSizes ERROR_VARIABLE noOutputSizes GET "${contents}" outputSizes) list(LENGTH outputs outputsLen) list(LENGTH outputSizes outputSizesLen) if (outputSizes MATCHES NOTFOUND OR NOT outputsLen EQUAL outputSizesLen)