From dc007c84abc90171545d0dacb291fc22948c6ea0 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Mon, 4 Nov 2024 13:11:19 +0400 Subject: [PATCH] Fix ATA testing with when JSON parser is used. --- src/applib/selftest.cpp | 2 +- src/applib/smartctl_json_ata_parser.cpp | 14 ++++++++++++-- src/applib/storage_property.h | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/applib/selftest.cpp b/src/applib/selftest.cpp index 942e2bc..7ed1fe5 100644 --- a/src/applib/selftest.cpp +++ b/src/applib/selftest.cpp @@ -445,7 +445,7 @@ hz::ExpectedVoid SelfTest::update(const std::shared_ptr< // we use the "self-test status" capability. StorageProperty p; for (const auto& e : property_repo.get_properties()) { - if (e.is_value_type() || e.get_value().test_num != 0 + if (!e.is_value_type() || e.get_value().test_num != 0 || e.generic_name != "ata_smart_data/self_test/status/_merged") continue; p = e; diff --git a/src/applib/smartctl_json_ata_parser.cpp b/src/applib/smartctl_json_ata_parser.cpp index 0fa79c1..0e5880f 100644 --- a/src/applib/smartctl_json_ata_parser.cpp +++ b/src/applib/smartctl_json_ata_parser.cpp @@ -498,7 +498,7 @@ hz::ExpectedVoid SmartctlJsonAtaParser::parse_section_capab } }, - {"ata_smart_data/self_test/status/value/_decoded", _("Self-test execution status"), + {"ata_smart_data/self_test/status/_merged", _("Self-test execution status"), [](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name) -> hz::ExpectedValue { @@ -536,9 +536,19 @@ hz::ExpectedVoid SmartctlJsonAtaParser::parse_section_capab default: status = AtaStorageSelftestEntry::Status::Reserved; break; } + AtaStorageSelftestEntry sse; + sse.test_num = 0; // capability uses 0 + sse.status_str = AtaStorageSelftestEntry::get_readable_status_name(status); + sse.status = status; + + sse.remaining_percent = -1; // unknown or n/a + if (auto remaining_percent_val = get_node_data(root_node, "ata_smart_data/self_test/status/remaining_percent"); remaining_percent_val.has_value()) { + sse.remaining_percent = remaining_percent_val.value(); + } + StorageProperty p; p.set_name(key, key, displayable_name); - p.value = AtaStorageSelftestEntry::get_readable_status_name(status); + p.value = sse; return p; } diff --git a/src/applib/storage_property.h b/src/applib/storage_property.h index c7cfe7f..349f8ad 100644 --- a/src/applib/storage_property.h +++ b/src/applib/storage_property.h @@ -209,7 +209,7 @@ class AtaStorageSelftestEntry { std::int8_t remaining_percent = -1; ///< Remaining %. 0% for completed, 90% for started. -1 if n/a. std::uint32_t lifetime_hours = 0; ///< When the test happened (in lifetime hours). capability: unused. std::string lba_of_first_error; ///< LBA of the first error. "-" or value (format? usually hex). capability: unused. - bool passed = false; ///< Test passed or not. + bool passed = false; ///< Test passed or not. capability: unused. };