diff mbox series

[-next,11/14] kddv/tests/hwmon: Add test cases for max31722 driver

Message ID 20231118104040.386381-12-zhangxiaoxu@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series Implement a ligth weight device driver test framework | expand

Commit Message

huaweicloud Nov. 18, 2023, 10:40 a.m. UTC
From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

This add test case for max31722 hwmon driver, test for
the device loading and read temperature from the device.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 .../kddv/kddv/tests/hwmon/test_max31722.py    | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100755 tools/testing/kddv/kddv/tests/hwmon/test_max31722.py
diff mbox series

Patch

diff --git a/tools/testing/kddv/kddv/tests/hwmon/test_max31722.py b/tools/testing/kddv/kddv/tests/hwmon/test_max31722.py
new file mode 100755
index 000000000000..70223eb0ef7b
--- /dev/null
+++ b/tools/testing/kddv/kddv/tests/hwmon/test_max31722.py
@@ -0,0 +1,40 @@ 
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# Kernel device driver verification
+#
+# Copyright (C) 2022-2023 Huawei Technologies Co., Ltd
+# Author: Wei Yongjun <weiyongjun1@huawei.com>
+
+from kddv.core import SPIDriverTest
+from kddv.core.consts import CFG_REG_MASK
+from . import HwMonDriver
+import errno
+
+MAX31722_REG_CFG = 0x00
+MAX31722_REG_TEMP_LSB = 0x01
+MAX31722_MODE_CONTINUOUS = 0x00
+MAX31722_RESOLUTION_12BIT = 0x06
+
+class TestMax31722(SPIDriverTest, HwMonDriver):
+    name = 'max31722'
+
+    @property
+    def configs(self):
+        return { CFG_REG_MASK: 0x7f }
+
+    def test_device_probe(self):
+        with self.assertRaisesFault():
+            with self.device() as dev:
+                self.assertRegEqual(MAX31722_REG_CFG, MAX31722_RESOLUTION_12BIT)
+
+    def test_read_temp_input(self):
+        with self.device() as dev:
+            self.write_regs(MAX31722_REG_TEMP_LSB, [0x12, 0x34])
+            temp = self.hwmon_read_temp_input(dev)
+            self.assertEqual(temp, int(0x3412 * 125 / 32))
+
+            self.trigger_io_fault()
+            with self.assertRaises(OSError) as cm:
+                self.hwmon_read_temp_input(dev)
+            self.assertEqual(cm.exception.errno, errno.EIO)