From 1b0d4e0a766c2f9cfab16f82e399e059fbd7eee1 Mon Sep 17 00:00:00 2001 From: DouZhichong Date: Fri, 26 Sep 2025 10:54:32 +0800 Subject: [PATCH] add blas test cases --- .../blas/tc_blas64_enhanced_fun004.yaml | 22 ++++++++++ .../blas/tc_blas64_test_fun003.yaml | 26 +++++++++++ .../blas/tc_blas_basic_fun001.yaml | 27 ++++++++++++ .../blas/tc_blas_devel_fun002.yaml | 30 +++++++++++++ .../blas/tc_blas_error_fun005.yaml | 29 +++++++++++++ .../blas/tc_blas64_enhanced_fun004.py | 38 ++++++++++++++++ .../system_base/blas/tc_blas64_test_fun003.py | 36 ++++++++++++++++ .../system_base/blas/tc_blas_basic_fun001.py | 39 +++++++++++++++++ .../system_base/blas/tc_blas_devel_fun002.py | 43 +++++++++++++++++++ .../system_base/blas/tc_blas_error_fun005.py | 38 ++++++++++++++++ 10 files changed, 328 insertions(+) create mode 100644 docs/system_base/blas/tc_blas64_enhanced_fun004.yaml create mode 100644 docs/system_base/blas/tc_blas64_test_fun003.yaml create mode 100644 docs/system_base/blas/tc_blas_basic_fun001.yaml create mode 100644 docs/system_base/blas/tc_blas_devel_fun002.yaml create mode 100644 docs/system_base/blas/tc_blas_error_fun005.yaml create mode 100644 tests/system_base/blas/tc_blas64_enhanced_fun004.py create mode 100644 tests/system_base/blas/tc_blas64_test_fun003.py create mode 100644 tests/system_base/blas/tc_blas_basic_fun001.py create mode 100644 tests/system_base/blas/tc_blas_devel_fun002.py create mode 100644 tests/system_base/blas/tc_blas_error_fun005.py diff --git a/docs/system_base/blas/tc_blas64_enhanced_fun004.yaml b/docs/system_base/blas/tc_blas64_enhanced_fun004.yaml new file mode 100644 index 00000000..55a532d7 --- /dev/null +++ b/docs/system_base/blas/tc_blas64_enhanced_fun004.yaml @@ -0,0 +1,22 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, blas64_ +用例描述: 测试增强版64位BLAS功能 +修改人: douzhichong + +前置条件: +- 安装blas64_软件包 +- 安装python3-scipy软件包 +- 安装python3-pytest软件包 + +测试步骤: +- 测试稀疏矩阵支持 + +期望结果: +- 稀疏矩阵操作结果正确 + +环境清理: +- 无特殊清理需求 \ No newline at end of file diff --git a/docs/system_base/blas/tc_blas64_test_fun003.yaml b/docs/system_base/blas/tc_blas64_test_fun003.yaml new file mode 100644 index 00000000..784b60e3 --- /dev/null +++ b/docs/system_base/blas/tc_blas64_test_fun003.yaml @@ -0,0 +1,26 @@ +作者: douzhichong +优先级: P1 +支持架构: x86_64,aarch64 +执行方式: 自动 +测试类型: 性能测试 +通用标签: local, blas64, large-matrix +用例描述: 测试64位BLAS大矩阵运算能力 +修改人: douzhichong + +前置条件: +- 执行命令: rpm -q blas64 python3-numpy +- 内存检查: 可用内存 > 8GB +- 版本验证: numpy支持64位索引 + +测试步骤: +- ## 测试大矩阵乘法 + - 执行命令: python3 -c "import numpy as np; m=np.zeros((1000,1000)); eye=np.eye(1000); print(np.array_equal(m@eye,m))" + - 验证输出: True + +期望结果: +- 矩阵乘法结果与单位矩阵乘后保持不变 +- 内存使用不超过8GB +- 执行时间小于15秒 + +环境清理: +- 释放大矩阵内存 \ No newline at end of file diff --git a/docs/system_base/blas/tc_blas_basic_fun001.yaml b/docs/system_base/blas/tc_blas_basic_fun001.yaml new file mode 100644 index 00000000..ebc43049 --- /dev/null +++ b/docs/system_base/blas/tc_blas_basic_fun001.yaml @@ -0,0 +1,27 @@ +作者: douzhichong +优先级: P0 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, blas, numpy +用例描述: 测试基础BLAS向量和矩阵运算功能 +修改人: douzhichong + +前置条件: +- 执行命令: rpm -q blas python3-numpy +- 安装验证: 确保返回包版本信息 +- Python环境: 能正常导入numpy模块 + +测试步骤: +- ## 测试向量加法 + - 执行命令: python3 -c "import numpy as np; v1=np.array([1.0,2.0,3.0]); v2=np.array([4.0,5.0,6.0]); print(v1+v2)" + - 验证输出: [5.0, 7.0, 9.0] + +- ## 测试矩阵乘法 + - 执行命令: python3 -c "import numpy as np; m1=np.array([[1.0,2.0],[3.0,4.0]]); m2=np.array([[5.0,6.0],[7.0,8.0]]); print(m1@m2)" + - 验证输出: [[19.0, 22.0], [43.0, 50.0]] + +期望结果: +- 向量加法结果精确匹配预期值 +- 矩阵乘法结果误差小于1e-10 +- 所有命令返回状态码为0 diff --git a/docs/system_base/blas/tc_blas_devel_fun002.yaml b/docs/system_base/blas/tc_blas_devel_fun002.yaml new file mode 100644 index 00000000..ebd3c613 --- /dev/null +++ b/docs/system_base/blas/tc_blas_devel_fun002.yaml @@ -0,0 +1,30 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, blas-devel, scipy +用例描述: 测试BLAS开发包高级函数 +修改人: douzhichong + +前置条件: +- 执行命令: rpm -q blas-devel python3-scipy python3-numpy +- 版本验证: scipy >= 1.0.0 +- 模块检查: 能导入scipy.linalg.blas + +测试步骤: +- ## 测试DAXPY操作 + - 执行命令: python3 -c "from scipy.linalg import blas; import numpy as np; x=np.array([1.0,2.0,3.0],dtype=np.float64); y=np.array([4.0,5.0,6.0],dtype=np.float64); blas.daxpy(x,y,a=2.0); print(y)" + - 验证输出: [6.0 9.0 12.0] + +- ## 测试DGEMV操作 + - 执行命令: python3 -c "from scipy.linalg import blas; import numpy as np; A=np.array([[1.0,2.0],[3.0,4.0]],dtype=np.float64); x=np.array([1.0,2.0],dtype=np.float64); print(blas.dgemv(1.0,A,x))" + - 验证输出: [5.0 11.0] + +期望结果: +- DAXPY操作后y向量值正确 +- DGEMV矩阵向量乘结果误差小于1e-12 +- 所有BLAS函数调用无异常 + +环境清理: +- 无临时文件产生 \ No newline at end of file diff --git a/docs/system_base/blas/tc_blas_error_fun005.yaml b/docs/system_base/blas/tc_blas_error_fun005.yaml new file mode 100644 index 00000000..690a4176 --- /dev/null +++ b/docs/system_base/blas/tc_blas_error_fun005.yaml @@ -0,0 +1,29 @@ +作者: douzhichong +优先级: P2 +支持架构: noarch +执行方式: 自动 +测试类型: 异常测试 +通用标签: local, blas, error-handling +用例描述: 测试BLAS错误处理机制 +修改人: douzhichong + +前置条件: +- 执行命令: rpm -q blas python3-numpy python3-pytest +- 环境准备: 安装pytest测试框架 + +测试步骤: +- ## 测试维度不匹配错误 + - 执行命令: python3 -c "import numpy as np; import pytest; with pytest.raises(ValueError): np.array([1,2]) @ np.array([1,2,3])" + - 验证: 命令返回状态码0 + +- ## 测试类型错误 + - 执行命令: python3 -c "import numpy as np; import pytest; with pytest.raises(TypeError): np.array(['a','b']) + np.array(['c','d'])" + - 验证: 命令返回状态码0 + +期望结果: +- 维度不匹配时抛出ValueError +- 无效类型操作时抛出TypeError +- 异常捕获机制正常工作 + +环境清理: +- 无持久化资源需要清理 \ No newline at end of file diff --git a/tests/system_base/blas/tc_blas64_enhanced_fun004.py b/tests/system_base/blas/tc_blas64_enhanced_fun004.py new file mode 100644 index 00000000..8950f893 --- /dev/null +++ b/tests/system_base/blas/tc_blas64_enhanced_fun004.py @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- + +""" +@File: tc_blas64_enhanced_fun004.py +@Time: 2025/09/26 10:00:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +""" + +import numpy as np +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_blas64_enhanced_fun004.yaml for details + + :avocado: tags=P1,noarch,local,blas64_ + """ + PARAM_DIC = {"pkg_name": "blas64_ python3-scipy python3-pytest"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.cmd("rpm -q blas64_") + + def test(self): + + from scipy.sparse import csr_matrix + + sparse_mat = csr_matrix((3, 3), dtype=np.float64) + eye_mat = np.eye(3) + result = sparse_mat + eye_mat + assert isinstance(result, np.ndarray), "Sparse matrix support failed" + + def tearDown(self): + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/blas/tc_blas64_test_fun003.py b/tests/system_base/blas/tc_blas64_test_fun003.py new file mode 100644 index 00000000..895d8a58 --- /dev/null +++ b/tests/system_base/blas/tc_blas64_test_fun003.py @@ -0,0 +1,36 @@ +# -*- encoding: utf-8 -*- + +""" +@File: tc_blas64_test_fun003.py +@Time: 2025/09/26 10:00:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +""" + +import numpy as np +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_blas64_test_fun003.yaml for details + + :avocado: tags=P1,noarch,local,blas64 + """ + PARAM_DIC = {"pkg_name": "blas64"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.cmd("rpm -q blas64") + + def test(self): + + large_matrix = np.zeros((1000, 1000)) + eye_matrix = np.eye(1000) + result = large_matrix @ eye_matrix + assert np.array_equal(result, large_matrix), "Large matrix multiplication failed" + + def tearDown(self): + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/blas/tc_blas_basic_fun001.py b/tests/system_base/blas/tc_blas_basic_fun001.py new file mode 100644 index 00000000..11d59535 --- /dev/null +++ b/tests/system_base/blas/tc_blas_basic_fun001.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- + +""" +@File: tc_blas_basic_fun001.py +@Time: 2025/09/26 10:00:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +""" + +import numpy as np +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_blas_basic_fun001.yaml for details + + :avocado: tags=P0,noarch,local,blas + """ + PARAM_DIC = {"pkg_name": "blas"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.cmd("rpm -q blas") + + def test(self): + + v1 = np.array([1.0, 2.0, 3.0]) + v2 = np.array([4.0, 5.0, 6.0]) + assert np.allclose(v1 + v2, [5.0, 7.0, 9.0]), "Vector addition failed" + + m1 = np.array([[1.0, 2.0], [3.0, 4.0]]) + m2 = np.array([[5.0, 6.0], [7.0, 8.0]]) + assert np.allclose(m1 @ m2, [[19.0, 22.0], [43.0, 50.0]]), "Matrix multiplication failed" + + def tearDown(self): + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/blas/tc_blas_devel_fun002.py b/tests/system_base/blas/tc_blas_devel_fun002.py new file mode 100644 index 00000000..9b12d6e0 --- /dev/null +++ b/tests/system_base/blas/tc_blas_devel_fun002.py @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- + +""" +@File: tc_blas_devel_fun002.py +@Time: 2025/09/26 10:00:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +""" + +import numpy as np +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_blas_devel_fun002.yaml for details + + :avocado: tags=P1,noarch,local,blas-devel + """ + PARAM_DIC = {"pkg_name": "blas-devel python3-scipy python3-pytest"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + + def test(self): + + from scipy.linalg import blas + + x = np.array([1.0, 2.0, 3.0], dtype=np.float64) + y = np.array([4.0, 5.0, 6.0], dtype=np.float64) + result = blas.daxpy(x, y, a=2.0) + assert np.allclose(result, [6.0, 9.0, 12.0]), "DAXPY operation failed" + + A = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float64) + x = np.array([1.0, 2.0], dtype=np.float64) + y_vec = np.array([0.0, 0.0], dtype=np.float64) + result = blas.dgemv(1.0, A, x, beta=0.0, y=y_vec) + assert np.allclose(result, [5.0, 11.0]), "DGEMV operation failed" + + def tearDown(self): + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/blas/tc_blas_error_fun005.py b/tests/system_base/blas/tc_blas_error_fun005.py new file mode 100644 index 00000000..99c6179f --- /dev/null +++ b/tests/system_base/blas/tc_blas_error_fun005.py @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- + +""" +@File: tc_blas_error_fun005.py +@Time: 2025/09/26 10:00:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +""" + +import numpy as np +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_blas_error_fun005.yaml for details + + :avocado: tags=P2,noarch,local,blas + """ + PARAM_DIC = {"pkg_name": "blas python3-scipy python3-pytest"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + + def test(self): + + import pytest + + with pytest.raises(ValueError): + np.array([1, 2]) @ np.array([1, 2, 3]) + + with pytest.raises(TypeError): + np.array(['a', 'b']) + np.array(['c', 'd']) + + def tearDown(self): + super().tearDown(self.PARAM_DIC) \ No newline at end of file -- Gitee