mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-10-06 04:03:27 +03:00
instrumentation: Null unknown static system info
Add tests to ensure the `staticSystemInformation` subfields are always either filled with meaningful data of a given type (i.e., non-empty string, or >0 integer), or `null` if the data cannot be determined. Issue: #27537, #27545
This commit is contained in:
1 parent
7867a36fdc
commit
98eca860d4
4 files changed
+60
-1
No files matched your search
@@ -503,7 +503,9 @@ generated whenever `Indexing`_ occurs and deleted after any user-specified
|
||||
|
||||
``staticSystemInformation``
|
||||
Specifies the static information collected about the host machine
|
||||
CMake is being run from. Only included when enabled by the `v1 Query Files`_.
|
||||
CMake is being run from. If CMake is unable to determine the value of any
|
||||
given field, it will be ``null``. Only included when enabled by the
|
||||
`v1 Query Files`_.
|
||||
|
||||
* ``OSName``
|
||||
* ``OSPlatform``
|
||||
|
||||
@@ -492,6 +492,14 @@ void cmInstrumentation::InsertStaticSystemInformation(Json::Value& root)
|
||||
static_cast<Json::Value::UInt64>(info.GetTotalVirtualMemory());
|
||||
infoRoot["vendorID"] = info.GetVendorID();
|
||||
infoRoot["vendorString"] = info.GetVendorString();
|
||||
|
||||
// Record fields unable to be determined as null JSON objects.
|
||||
for (std::string const& field : infoRoot.getMemberNames()) {
|
||||
if ((infoRoot[field].isNumeric() && infoRoot[field].asInt64() <= 0) ||
|
||||
(infoRoot[field].isString() && infoRoot[field].asString().empty())) {
|
||||
infoRoot[field] = Json::nullValue;
|
||||
}
|
||||
}
|
||||
root["staticSystemInformation"] = infoRoot;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,53 @@ if (NOT hasStaticInfo STREQUAL UNEXPECTED)
|
||||
json_has_key("${index}" "${staticSystemInformation}" totalVirtualMemory ${hasStaticInfo})
|
||||
json_has_key("${index}" "${staticSystemInformation}" vendorID ${hasStaticInfo})
|
||||
json_has_key("${index}" "${staticSystemInformation}" vendorString ${hasStaticInfo})
|
||||
|
||||
# FIXME(#27545): We currently do not guarantee that the fields above which
|
||||
# output strings are non-empty. `vendorString` and `processorName` especially
|
||||
# have shown issues on some platforms. This test is logically equivalent to
|
||||
# RunCMake.cmake_host_system_information, which uses the same underlying
|
||||
# implementation.
|
||||
set(string_fields
|
||||
OSName
|
||||
OSPlatform
|
||||
OSRelease
|
||||
OSVersion
|
||||
familyId
|
||||
hostname
|
||||
modelId
|
||||
vendorID
|
||||
vendorString
|
||||
)
|
||||
foreach (field IN LISTS string_fields)
|
||||
string(JSON ${field}_type TYPE "${staticSystemInformation}" ${field})
|
||||
if (NOT "${${field}_type}" STREQUAL "NULL" AND NOT "${${field}_type}" STREQUAL "STRING")
|
||||
add_error("Got bad type '${${field}_type}' for field '${field}': ${${field}}")
|
||||
endif()
|
||||
if ("${${field}_type}" STREQUAL "STRING" AND ${field} STREQUAL "")
|
||||
add_error("Got empty string for field '${field}'")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# We guarantee that the numeric fields are either indeed numeric, or else
|
||||
# null.
|
||||
set(numeric_fields
|
||||
numberOfLogicalCPU
|
||||
numberOfPhysicalCPU
|
||||
processorAPICID
|
||||
processorCacheSize
|
||||
processorClockFrequency
|
||||
totalPhysicalMemory
|
||||
totalVirtualMemory
|
||||
)
|
||||
foreach (field IN LISTS numeric_fields)
|
||||
string(JSON ${field}_type TYPE "${staticSystemInformation}" ${field})
|
||||
if (NOT "${${field}_type}" STREQUAL "NULL" AND NOT "${${field}_type}" STREQUAL "NUMBER")
|
||||
add_error("Got bad type '${${field}_type}' for field '${field}': ${${field}}")
|
||||
endif()
|
||||
if ("${${field}_type}" STREQUAL "NUMBER" AND ${field} LESS_EQUAL 0)
|
||||
add_error("Got bad value for field '${field}': ${${field}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
get_filename_component(v1 ${dataDir} DIRECTORY)
|
||||
|
||||
@@ -41,6 +41,7 @@ function(json_missing_key file json key)
|
||||
endfunction()
|
||||
|
||||
# Check if the JSON string `json` has `key` and its value matches `expected`.
|
||||
# If successful, return its value in `key`.
|
||||
function(json_assert_key file json key expected)
|
||||
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
|
||||
if (NOT missingKey MATCHES NOTFOUND)
|
||||
@@ -52,6 +53,7 @@ function(json_assert_key file json key expected)
|
||||
"Unexpected data in custom content file:\nGot ${data}, Expected ${expected}."
|
||||
)
|
||||
endif()
|
||||
set(${key} ${data} PARENT_SCOPE)
|
||||
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
|
||||
endfunction()
|
||||
|
||||
|
||||
Reference in new issue
Block a user