Received: by 2002:ac2:48a3:0:0:0:0:0 with SMTP id u3csp570774lfg; Fri, 11 Mar 2022 13:39:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZrgQjDI5nO8sFWtz8Pdvkrr3r+Lc3RPa45mZHjtQ2Suq6ovYxr2B4XtyjWR9Ig3pf7Cq3 X-Received: by 2002:a63:de0c:0:b0:378:9365:c3c6 with SMTP id f12-20020a63de0c000000b003789365c3c6mr10015260pgg.301.1647034745693; Fri, 11 Mar 2022 13:39:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647034745; cv=none; d=google.com; s=arc-20160816; b=BznZRIqZNn4aAmkEzkT+ksE9YbK2n9cK7+SUWXZfQIjNxLu6z0gTsGLmCgMPMKzqcr QblAKRJcaKG9AIPXsZZgx5ttUTF4pbL3Mn7GNllCZ79pNSjBE0A1SWD/8cBmU9SNwUTK 2Q6peY0jwAZRJhO8GD+IOMV9LeUwyTFSPS87m4Xmc/K43jXT4zl2t/GZBDOBS92OJY1t ATrXWR/lwzooTLR9XZ5h8qWCzzjQETjjNks/DWn2WVGaKPcI0M5Tpr7QgcqCeKmKdQMn aUgD2aBpDsNyrmPYyprYJxjpL1rkBSaPwO9q8WRHNDgV2BWF7vn8/NJwso+Zla5QILes J2qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SOwKI/JWlE04bP10q/tiaI9Kor0jtXpP5KU+ERCqxE8=; b=Uihu1tpbvtVpjZz6R2k5kvrIEn3zMmGX3az+IkVJvDcTKo0k2OpY8uAP/cASn1xdGQ I9yAyKCVk6m5BDFR8k1C/XHkVqxklybxlQcXliDmoPJDjBtagQJGF1TumnWC1InQzlLb 8FeO4hi/t0xInfRFAPx+Zad7lQnXIM2oXVepdBzlU6bMhJPDEAe13AloBgb7EfEZ6K84 ZoP6R7VAMYYPw+0ooojzyZ8M/4wNoc93gjPronkZVRbgMaLGiGkOCQs2JN0j7Cyv0VOh JFs6WZ+yl7wXdc5MlW/p0H1F0iHBoNdzGL/Ecu6paGX8Z0QfvlriGhpC8esXKrI7Oxp1 Ujfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=dUbUv7mW; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p5-20020a637405000000b00362b90cd1e9si8898280pgc.738.2022.03.11.13.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 13:39:05 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=dUbUv7mW; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 817F61DA01E; Fri, 11 Mar 2022 13:06:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345661AbiCKQ1S (ORCPT + 99 others); Fri, 11 Mar 2022 11:27:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350320AbiCKQ0q (ORCPT ); Fri, 11 Mar 2022 11:26:46 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C1BD1C4B19; Fri, 11 Mar 2022 08:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1647015910; x=1678551910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SOwKI/JWlE04bP10q/tiaI9Kor0jtXpP5KU+ERCqxE8=; b=dUbUv7mWtf+c3LWzRTfbJkhMrEtDtCiaeRGU8CH1Yq/h6X9L3V6jZkIH y/odUFE3MUF94LzL7R86u1K9EQekBS3qdPQPQaDGHbVI9Frj5ndn53Yvm 2Vz9JbadMPime4MsqhgBaRMIV3Z4fMFD0W5ldK1xZZLqyML2A3owB35s7 wNV4nPftyCaSDUUI+mpyclSAGGCw2cO0xvabEFT3Ddl6eOC2yxGqGbNrA vGJ47m6s9yPXiV+JNsV/yi75+S/WaubAncWPAn2V2OhveumOrH78o0r5N sWTbFvWiPerWD4PWR1oUzZwhoo3kdLf6Kc9Ao0z9zaOw6CsvJ2FfetGkH Q==; From: Vincent Whitchurch To: CC: , Vincent Whitchurch , , , , , , , , , , , , , , Subject: [RFC v1 07/10] iio: light: opt3001: add roadtest Date: Fri, 11 Mar 2022 17:24:42 +0100 Message-ID: <20220311162445.346685-8-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220311162445.346685-1-vincent.whitchurch@axis.com> References: <20220311162445.346685-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a regression test for the problem fixed by the following patch, which would require specific environmental conditions to be able to be reproduced and regression-tested on real hardware: iio: light: opt3001: Fixed timeout error when 0 lux https://lore.kernel.org/lkml/20210920125351.6569-1-valek@2n.cz/ No other aspects of the driver are tested. Signed-off-by: Vincent Whitchurch --- .../roadtest/roadtest/tests/iio/__init__.py | 0 .../roadtest/roadtest/tests/iio/config | 1 + .../roadtest/tests/iio/light/__init__.py | 0 .../roadtest/roadtest/tests/iio/light/config | 1 + .../roadtest/tests/iio/light/test_opt3001.py | 95 +++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 tools/testing/roadtest/roadtest/tests/iio/__init__.py create mode 100644 tools/testing/roadtest/roadtest/tests/iio/config create mode 100644 tools/testing/roadtest/roadtest/tests/iio/light/__init__.py create mode 100644 tools/testing/roadtest/roadtest/tests/iio/light/config create mode 100644 tools/testing/roadtest/roadtest/tests/iio/light/test_opt3001.py diff --git a/tools/testing/roadtest/roadtest/tests/iio/__init__.py b/tools/testing/roadtest/roadtest/tests/iio/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tools/testing/roadtest/roadtest/tests/iio/config b/tools/testing/roadtest/roadtest/tests/iio/config new file mode 100644 index 000000000000..a08d9e23ce38 --- /dev/null +++ b/tools/testing/roadtest/roadtest/tests/iio/config @@ -0,0 +1 @@ +CONFIG_IIO=y diff --git a/tools/testing/roadtest/roadtest/tests/iio/light/__init__.py b/tools/testing/roadtest/roadtest/tests/iio/light/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tools/testing/roadtest/roadtest/tests/iio/light/config b/tools/testing/roadtest/roadtest/tests/iio/light/config new file mode 100644 index 000000000000..b9753f2d0728 --- /dev/null +++ b/tools/testing/roadtest/roadtest/tests/iio/light/config @@ -0,0 +1 @@ +CONFIG_OPT3001=m diff --git a/tools/testing/roadtest/roadtest/tests/iio/light/test_opt3001.py b/tools/testing/roadtest/roadtest/tests/iio/light/test_opt3001.py new file mode 100644 index 000000000000..abf20b8f3516 --- /dev/null +++ b/tools/testing/roadtest/roadtest/tests/iio/light/test_opt3001.py @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright Axis Communications AB + +from typing import Any, Final + +from roadtest.backend.i2c import SMBusModel +from roadtest.core.devicetree import DtFragment, DtVar +from roadtest.core.hardware import Hardware +from roadtest.core.modules import insmod, rmmod +from roadtest.core.suite import UMLTestCase +from roadtest.core.sysfs import I2CDriver, read_float + +REG_RESULT: Final = 0x00 +REG_CONFIGURATION: Final = 0x01 +REG_LOW_LIMIT: Final = 0x02 +REG_HIGH_LIMIT: Final = 0x03 +REG_MANUFACTURER_ID: Final = 0x7E +REG_DEVICE_ID: Final = 0x7F + +REG_CONFIGURATION_CRF: Final = 1 << 7 + + +class OPT3001(SMBusModel): + def __init__(self, **kwargs: Any) -> None: + super().__init__(regbytes=2, byteorder="big", **kwargs) + # Reset values from datasheet + self.regs = { + REG_RESULT: 0x0000, + REG_CONFIGURATION: 0xC810, + REG_LOW_LIMIT: 0xC000, + REG_HIGH_LIMIT: 0xBFFF, + REG_MANUFACTURER_ID: 0x5449, + REG_DEVICE_ID: 0x3001, + } + + def reg_read(self, addr: int) -> int: + val = self.regs[addr] + + if addr == REG_CONFIGURATION: + # Always indicate that the conversion is ready. This is good + # enough for our current purposes. + val |= REG_CONFIGURATION_CRF + + return val + + def reg_write(self, addr: int, val: int) -> None: + assert addr in self.regs + self.regs[addr] = val + + +class TestOPT3001(UMLTestCase): + dts = DtFragment( + src=""" +&i2c { + light-sensor@$addr$ { + compatible = "ti,opt3001"; + reg = <0x$addr$>; + }; +}; + """, + variables={ + "addr": DtVar.I2C_ADDR, + }, + ) + + @classmethod + def setUpClass(cls) -> None: + insmod("opt3001") + + @classmethod + def tearDownClass(cls) -> None: + rmmod("opt3001") + + def setUp(self) -> None: + self.driver = I2CDriver("opt3001") + self.hw = Hardware("i2c") + self.hw.load_model(OPT3001) + + def tearDown(self) -> None: + self.hw.close() + + def test_illuminance(self) -> None: + data = [ + # Some values from datasheet, and 0 + (0b_0000_0000_0000_0000, 0), + (0b_0000_0000_0000_0001, 0.01), + (0b_0011_0100_0101_0110, 88.80), + (0b_0111_1000_1001_1010, 2818.56), + ] + with self.driver.bind(self.dts["addr"]) as dev: + luxfile = dev.path / "iio:device0/in_illuminance_input" + + for regval, lux in data: + self.hw.reg_write(REG_RESULT, regval) + self.assertEqual(read_float(luxfile), lux) -- 2.34.1