From 74971ad5d87c0df15c2fdc0ec5b93d4be577c470 Mon Sep 17 00:00:00 2001 From: yuhaiyan Date: Thu, 21 Aug 2025 17:37:18 +0800 Subject: [PATCH] Add testcases for get_cann_version and _is_gte_cann_version --- test/npu/test_cann_version.py | 11 +++++++++++ torch_npu/csrc/core/npu/GetCANNInfo.cpp | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/npu/test_cann_version.py b/test/npu/test_cann_version.py index 76925b9b443..3663bc78683 100644 --- a/test/npu/test_cann_version.py +++ b/test/npu/test_cann_version.py @@ -17,12 +17,23 @@ class TestCANNversion(TestCase): or re.match("([0-9]+).([0-9]+).T([0-9]+)", version) or re.match("([0-9]+).([0-9]+).RC([0-9]+).alpha([0-9]+)", version)) self.assertTrue(is_match, f"The env version is {version_env}. The format of cann version {version} is invalid.") + + version = get_cann_version(module="CAN") + self.assertTrue(version == "", "When module is invalid, the result of get_cann_version is not right.") def test_compare_cann_version(self): version_env = get_cann_version_from_env() if not version_env.startswith("CANN") and version_env >= "8.1.RC1": result = _is_gte_cann_version("8.1.RC1", module="CANN") self.assertTrue(result, f"The env version is {version_env}, the result from _is_gte_cann_version is False") + + tags = get_cann_version(module="CANN") + major = int(tags[0]) + 1 + result1 = _is_gte_cann_version(f"{major}.0.0", module="CANN") + result2 = _is_gte_cann_version(f"{major}.0.T10", module="CANN") + result3 = _is_gte_cann_version(f"{major}.0.RC1.alpha001", module="CANN") + self.assertTrue(not result1 and not result2 and not result3, "the result from _is_gte_cann_version is not right.") + else: with self.assertRaisesRegex(RuntimeError, "When the version 7.0.0 is less than \"8.1.RC1\", this function is not supported"): diff --git a/torch_npu/csrc/core/npu/GetCANNInfo.cpp b/torch_npu/csrc/core/npu/GetCANNInfo.cpp index cc817f5506a..22daec8ea04 100644 --- a/torch_npu/csrc/core/npu/GetCANNInfo.cpp +++ b/torch_npu/csrc/core/npu/GetCANNInfo.cpp @@ -138,7 +138,7 @@ std::string GetCANNVersion(const std::string& module) } auto find_module = packageNameMap.find(module); if (find_module == packageNameMap.end()) { - TORCH_NPU_WARN_ONCE("module " + module + "is invalid."); + TORCH_NPU_WARN_ONCE("module " + module + " is invalid."); CANNVersionCache[module] = ""; return ""; } -- Gitee