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

From: Zhang Xiaoxu
Date: Sat Nov 18 2023 - 05:42:07 EST


From: Zhang Xiaoxu <zhangxiaoxu5@xxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@xxxxxxxxxx>
---
.../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 --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@xxxxxxxxxx>
+
+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)
--
2.34.1