Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp688630pxp; Wed, 16 Mar 2022 14:31:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx32XZbANcdIl7lEI6Nc5XB5NRjPBMht2OFqS0Aq0WqNLuYUvy7kVZn8Ed78CVgrg6pCcw0 X-Received: by 2002:a17:902:a614:b0:153:196d:634f with SMTP id u20-20020a170902a61400b00153196d634fmr1859522plq.39.1647466293589; Wed, 16 Mar 2022 14:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647466293; cv=none; d=google.com; s=arc-20160816; b=itsd09GbfdelYfWICAaKhweHllmVjIhn7O3bjBseIQkfxlFHkf7l4LpcqXoDtuuqct OyRRkC8kzVlsiGWbSDVblFX4pMcVM9Bg6tesVdMWiesADXtVx+pN+8fgTkEv1viCNNbb A2dXdpC6Spc+CitB9asv8usJWdih+O8L1RRWEpvDo6SNPx7hH+2A8x1236uNJmCgdOE2 ij7MSj6LKkYGdqYKqB674rhOmkV80EmV0og9gPO+0bsY9l1Z8aoEqODA41MR/qj02hdA 90+ClUfH5TISCeRmVJwtvMKfqY1kykCKW/xD3Pvc/yZaje5viVouUitj4WG1wixA9oBo 1lGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=13A/gfkIaAByq4gAjyXkarTV6d8yj2S6x1jqYzFsBbY=; b=ZthQ/xXRzdM0Q/HwMC3HrO0oSqih43qyZxuAxMSsocE1t9zqKZZGkIxA+OJO9CJXvg YmjDodFkBa8l4yumkDccGmPEoWs0yPnDzBGxU0mMjeaypeyDKj/K1oOcj9Rv/fpvxQnM vgdRcP/geG9H3aFQEFr+M6Uh2VcyaQrcVrUuxjydKMfpRZ8WlrX9HC0Hc13oTDpYm2AX oglOyiOXeK6Zp40OqcfnfCJp/+e6aq7+FuzQF/+LQanrM6lw4tL8D/pHdFybhmdkjvIX Rca2Hy+iCmjFAkLn10XSudssHlqeLpMOUfsIwPjJfU4u1Lp5wHJKZo1Id1GIVmH8nsZe Ogtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XyhHGdts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a056a00178100b004f737cdd03fsi3315044pfg.72.2022.03.16.14.31.19; Wed, 16 Mar 2022 14:31:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XyhHGdts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343605AbiCNXNR (ORCPT + 99 others); Mon, 14 Mar 2022 19:13:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343593AbiCNXNP (ORCPT ); Mon, 14 Mar 2022 19:13:15 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66D803BF9D for ; Mon, 14 Mar 2022 16:12:04 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id hw13so36037876ejc.9 for ; Mon, 14 Mar 2022 16:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=13A/gfkIaAByq4gAjyXkarTV6d8yj2S6x1jqYzFsBbY=; b=XyhHGdtsqR5jO4+gdhJ+ojCimLghZaCx6WwKcAAr9p/2GHkSdRv19zrt+XUtu0LuJ1 4Gi3j0ozCaHiWgxhJc4o3NtmD//SjQ72LePzqe4q9e8nM9zUasMsb8biiDYMtwoPpEiK HiEQwniQHvCSrEdIgduOKuvq5s7i1I61Hc25rgZasnYsPug81ADoCsCnTDZdjqQkvvrc u7MiR0TGkpcQ8Zcq8IwJmMfz/vudNt99WnaGo1qHlKZqAE+13K9TG1hMprm48aLrDHKG KLTxKsyGj+myiFI0F5MUapN41yj6qFYTl4WnkkqKuAziWcCDY/3yvCe8iF3wjdp+upo9 pSbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=13A/gfkIaAByq4gAjyXkarTV6d8yj2S6x1jqYzFsBbY=; b=snR9xbn++encXDvsG73Z79FK9moLEwH8aQMWF1bURw/xlLaVqohyVuR/Bp9iQfE9Vk nD6mX5XCVxHmV7dW0wiDfEEeShRLGgWY9weUb7h5MNPFe6lNq3s1pL8CFyi6+YX9HsC/ 5LdbWfBKWzw3xaS410RsbkFh4Orxkj228KIG3QWSiSm+4CCjvR2wg5nR0cVvoANlPYOY mMAm1nK8pcLTu1Uyyzk0PMghMvDEKzDYnE5Is2OHFw0TU6PvNNuRQEPFmQe8FfY7mPKg FEfWjxHeOj+bNe6j1WX5L1HVCzlRIdb7iwhzbcKRFRUjwMuFSGsfinb9EaMl7YNeFRv2 E8jg== X-Gm-Message-State: AOAM531J4pkKuyZ42i6XbwU7wZQLDKg0IFZLFQOv/0MozuffbFV6UQia tOfeRKaoXKlIO4pkqDdci8VcImH9oSAnUeHVRBNGPw== X-Received: by 2002:a17:906:36ce:b0:6d6:e540:ed65 with SMTP id b14-20020a17090636ce00b006d6e540ed65mr20941241ejc.330.1647299522669; Mon, 14 Mar 2022 16:12:02 -0700 (PDT) MIME-Version: 1.0 References: <20220311162445.346685-1-vincent.whitchurch@axis.com> <20220311162445.346685-8-vincent.whitchurch@axis.com> In-Reply-To: <20220311162445.346685-8-vincent.whitchurch@axis.com> From: Brendan Higgins Date: Mon, 14 Mar 2022 19:11:50 -0400 Message-ID: Subject: Re: [RFC v1 07/10] iio: light: opt3001: add roadtest To: Vincent Whitchurch Cc: linux-kernel@vger.kernel.org, kernel@axis.com, devicetree@vger.kernel.org, linux-um@lists.infradead.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, jic23@kernel.org, linux-iio@vger.kernel.org, lgirdwood@gmail.com, broonie@kernel.org, a.zummo@towertech.it, alexandre.belloni@bootlin.com, linux-rtc@vger.kernel.org, corbet@lwn.net, linux-doc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Fri, Mar 11, 2022 at 11:24 AM Vincent Whitchurch wrote: > > 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): I am partial to starting with UML since there are a lot of nice easy things about starting there; however, I imagine people will eventually want to use this on other architectures (speaking from experience). How difficult do you think it would be to extend this to support manipulating fake devices in say QEMU? I also have some colleagues inside of Google that worked on some projects to simulate simple devices on an FPGA to test software and adjacent devices in a conceptually similar way; one of these teams built a Domain Specific Language kind of like roadtest to implement the tests and the environment for the tests. The main reason I mention this here is I am thinking about maybe one day having an API you can implement so you can run your roadtests on UML, QEMU, or on any emulator or hardware testbed that implements the appropriate API. I'll try to dig up some people who might be interested and add them here. > + 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) I love the framework; this looks very easy to use. One nit about this test; it seems like you cover just one test case here - the happy path. Can you cover some other one? Particularly some error paths? Sorry, I am not trying to be cheeky here; it looks like this driver actually should probably be fully (or very close to fully) testable via roadtest as I understand it. It only looks like there are a handful of cases to cover for the driver: the device is busy, the device returned something invalid, the user requested something invalid, and several SMBus read/write failures - it really only looks like there are a handful of paths and I think they are all accessible via the I2C interface (except for maybe the user requesting something invalid).