From 767880ffafceafdd491cfb9f6274a92cf0aabcc4 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 27 Jan 2025 22:49:28 -0500 Subject: [PATCH] ui: Display default driving model name (#623) * ui: Display default driving model if in use * add ref commit and tests * fix commit * update msg * update msg * fix lint * use sha256 hash instead --- common/model.h | 1 + .../qt/offroad/settings/software_panel.cc | 4 ++- sunnypilot/modeld/tests/model_hash | 1 + sunnypilot/modeld/tests/test_default_model.py | 34 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 common/model.h create mode 100644 sunnypilot/modeld/tests/model_hash create mode 100644 sunnypilot/modeld/tests/test_default_model.py diff --git a/common/model.h b/common/model.h new file mode 100644 index 0000000000..4444601f33 --- /dev/null +++ b/common/model.h @@ -0,0 +1 @@ +#define DEFAULT_MODEL "Notre Dame (Default)" diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc index 2f10d7d147..ddee1362bb 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc @@ -10,6 +10,8 @@ #include #include +#include "common/model.h" + /** * @brief Constructs the software panel with model bundle selection functionality * @param parent Parent widget @@ -105,7 +107,7 @@ QString SoftwarePanelSP::GetActiveModelName() { return QString::fromStdString(model_manager.getActiveBundle().getDisplayName()); } - return ""; + return DEFAULT_MODEL; } void SoftwarePanelSP::updateModelManagerState() { diff --git a/sunnypilot/modeld/tests/model_hash b/sunnypilot/modeld/tests/model_hash new file mode 100644 index 0000000000..f7ef0739ba --- /dev/null +++ b/sunnypilot/modeld/tests/model_hash @@ -0,0 +1 @@ +39786068cae1ed8c0dc34ef80c281dfcc67ed18a50e06b90765c49bcfdbf7db4 \ No newline at end of file diff --git a/sunnypilot/modeld/tests/test_default_model.py b/sunnypilot/modeld/tests/test_default_model.py new file mode 100644 index 0000000000..6f3c835f24 --- /dev/null +++ b/sunnypilot/modeld/tests/test_default_model.py @@ -0,0 +1,34 @@ +import os +import hashlib + +from openpilot.common.basedir import BASEDIR + +MODEL_HASH_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class TestDefaultModel: + @classmethod + def setup_class(cls): + cls.onnx_path = os.path.join(BASEDIR, "selfdrive", "modeld", "models", "supercombo.onnx") + cls.current_hash_path = os.path.join(MODEL_HASH_DIR, "model_hash") + + @staticmethod + def get_hash(path: str) -> str: + sha256_hash = hashlib.sha256() + with open(path, "rb") as f: + for byte_block in iter(lambda: f.read(4096), b""): + sha256_hash.update(byte_block) + return sha256_hash.hexdigest() + + def test_compare_onnx_hashes(self): + new_hash = self.get_hash(str(self.onnx_path)) + + with open(self.current_hash_path) as f: + current_hash = f.read().strip() + + assert new_hash == current_hash, ( + "Driving model updated!\n" + + f"Current hash: {current_hash}\n" + + f"New hash: {new_hash}\n" + + "Please update common/model.h if the default driving model name has changed." + )