From 4ff0aaad9c6ca181fbc864b7f989551b8105e166 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Tue, 11 Jun 2024 13:53:23 +0400 Subject: [PATCH] Hide self-test tab if NVMe does not support self-tests. --- src/applib/selftest.cpp | 4 ++-- src/applib/smartctl_json_nvme_parser.cpp | 11 +++++------ src/gui/gsc_info_window.cpp | 2 -- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/applib/selftest.cpp b/src/applib/selftest.cpp index 21e7a02..5f489ff 100644 --- a/src/applib/selftest.cpp +++ b/src/applib/selftest.cpp @@ -169,7 +169,7 @@ bool SelfTest::is_supported() const case TestType::LongTest: { // Both short and long should be supported if the drive has a self-test log - const StorageProperty p = drive_->get_property_repository().lookup_property("nvme_self_test_log/_tests_supported"); + const StorageProperty p = drive_->get_property_repository().lookup_property("nvme_self_test_log/_exists"); return (!p.empty() && p.get_value()); } } @@ -504,7 +504,7 @@ hz::ExpectedVoid SelfTest::update(const std::shared_ptr< // seconds per 10%. use double, because e.g. 60sec test gives silly values with int. const double gran = (double(total.count()) / 9.); - // Add 1/10 for disk load delays, etc. . Limit to 15sec, in case of very quick tests. + // Add 1/10 for disk load delays, etc. Limit to 15sec, in case of very quick tests. poll_in_seconds_ = std::chrono::seconds(std::max(int64_t(15), int64_t(gran / 3. + (gran / 10.)))); // for long tests we don't want to make the user wait too much, so diff --git a/src/applib/smartctl_json_nvme_parser.cpp b/src/applib/smartctl_json_nvme_parser.cpp index 220727c..7687196 100644 --- a/src/applib/smartctl_json_nvme_parser.cpp +++ b/src/applib/smartctl_json_nvme_parser.cpp @@ -384,17 +384,16 @@ hz::ExpectedVoid SmartctlJsonNvmeParser::parse_section_self bool section_properties_found = false; - // If nvme_self_test_log is present, the drive supports tests - { + // If nvme_self_test_log is present, the drive supports tests. + // Create this property only if supported, so that the UI can hide the tab if not needed. + if (get_node_exists(json_root_node, "nvme_self_test_log").value_or(false)) { StorageProperty p; - p.set_name("nvme_self_test_log/_tests_supported", "nvme_self_test_log/_tests_supported", _("Self-tests supported")); + p.set_name("nvme_self_test_log/_exists", "nvme_self_test_log/_exists", _("Self-tests supported")); p.section = StoragePropertySection::SelftestLog; - // p.show_in_ui = false; - p.value = get_node_exists(json_root_node, "nvme_self_test_log").value_or(false); + p.value = true; add_property(p); } - { StorageProperty p; p.set_name("nvme_self_test_log/current_self_test_operation/value/_decoded", diff --git a/src/gui/gsc_info_window.cpp b/src/gui/gsc_info_window.cpp index e4dd445..3393d44 100644 --- a/src/gui/gsc_info_window.cpp +++ b/src/gui/gsc_info_window.cpp @@ -405,8 +405,6 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests } bool has_selftest = prop_repo.has_properties_for_section(StoragePropertySection::SelftestLog); - // NVMe spec supports self-tests by default. - has_selftest = has_selftest || drive_->get_detected_type() == StorageDeviceDetectedType::Nvme; if (note_page_box = lookup_widget("test_tab_vbox"); note_page_box != nullptr) { // Some USB flash drives erroneously report SMART as enabled. // note_page_box->set_visible(drive->get_smart_status() == StorageDevice::Status::Enabled);