From: Corey Minyard <minyard@acm.org>
To: Titus Rwantare <titusr@google.com>
Cc: philmd@linaro.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org,
Hao Wu <wuhaotsh@google.com>
Subject: Re: [PATCH 7/7] tests/qtest: add tests for ADM1266
Date: Fri, 31 Mar 2023 09:01:09 -0500 [thread overview]
Message-ID: <ZCbnpcnaj2dnfYXV@minyard.net> (raw)
In-Reply-To: <20230331000756.1712787-8-titusr@google.com>
On Fri, Mar 31, 2023 at 12:07:56AM +0000, Titus Rwantare wrote:
> The ADM1266 can have string fields written by the driver, so
> it's worth specifically testing.
>
> Reviewed-by: Hao Wu <wuhaotsh@google.com>
> Signed-off-by: Titus Rwantare <titusr@google.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
> ---
> tests/qtest/adm1266-test.c | 123 +++++++++++++++++++++++++++++++++++++
> tests/qtest/meson.build | 1 +
> 2 files changed, 124 insertions(+)
> create mode 100644 tests/qtest/adm1266-test.c
>
> diff --git a/tests/qtest/adm1266-test.c b/tests/qtest/adm1266-test.c
> new file mode 100644
> index 0000000000..6431a21de6
> --- /dev/null
> +++ b/tests/qtest/adm1266-test.c
> @@ -0,0 +1,123 @@
> +/*
> + * Analog Devices ADM1266 Cascadable Super Sequencer with Margin Control and
> + * Fault Recording with PMBus
> + *
> + * Copyright 2022 Google LLC
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include <math.h>
> +#include "hw/i2c/pmbus_device.h"
> +#include "libqtest-single.h"
> +#include "libqos/qgraph.h"
> +#include "libqos/i2c.h"
> +#include "qapi/qmp/qdict.h"
> +#include "qapi/qmp/qnum.h"
> +#include "qemu/bitops.h"
> +
> +#define TEST_ID "adm1266-test"
> +#define TEST_ADDR (0x12)
> +
> +#define ADM1266_BLACKBOX_CONFIG 0xD3
> +#define ADM1266_PDIO_CONFIG 0xD4
> +#define ADM1266_READ_STATE 0xD9
> +#define ADM1266_READ_BLACKBOX 0xDE
> +#define ADM1266_SET_RTC 0xDF
> +#define ADM1266_GPIO_SYNC_CONFIGURATION 0xE1
> +#define ADM1266_BLACKBOX_INFORMATION 0xE6
> +#define ADM1266_PDIO_STATUS 0xE9
> +#define ADM1266_GPIO_STATUS 0xEA
> +
> +/* Defaults */
> +#define ADM1266_OPERATION_DEFAULT 0x80
> +#define ADM1266_CAPABILITY_DEFAULT 0xA0
> +#define ADM1266_CAPABILITY_NO_PEC 0x20
> +#define ADM1266_PMBUS_REVISION_DEFAULT 0x22
> +#define ADM1266_MFR_ID_DEFAULT "ADI"
> +#define ADM1266_MFR_ID_DEFAULT_LEN 32
> +#define ADM1266_MFR_MODEL_DEFAULT "ADM1266-A1"
> +#define ADM1266_MFR_MODEL_DEFAULT_LEN 32
> +#define ADM1266_MFR_REVISION_DEFAULT "25"
> +#define ADM1266_MFR_REVISION_DEFAULT_LEN 8
> +#define TEST_STRING_A "a sample"
> +#define TEST_STRING_B "b sample"
> +#define TEST_STRING_C "rev c"
> +
> +static void compare_string(QI2CDevice *i2cdev, uint8_t reg,
> + const char *test_str)
> +{
> + uint8_t len = i2c_get8(i2cdev, reg);
> + char i2c_str[SMBUS_DATA_MAX_LEN] = {0};
> +
> + i2c_read_block(i2cdev, reg, (uint8_t *)i2c_str, len);
> + g_assert_cmpstr(i2c_str, ==, test_str);
> +}
> +
> +static void write_and_compare_string(QI2CDevice *i2cdev, uint8_t reg,
> + const char *test_str, uint8_t len)
> +{
> + char buf[SMBUS_DATA_MAX_LEN] = {0};
> + buf[0] = len;
> + strncpy(buf + 1, test_str, len);
> + i2c_write_block(i2cdev, reg, (uint8_t *)buf, len + 1);
> + compare_string(i2cdev, reg, test_str);
> +}
> +
> +static void test_defaults(void *obj, void *data, QGuestAllocator *alloc)
> +{
> + uint16_t i2c_value;
> + QI2CDevice *i2cdev = (QI2CDevice *)obj;
> +
> + i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION);
> + g_assert_cmphex(i2c_value, ==, ADM1266_OPERATION_DEFAULT);
> +
> + i2c_value = i2c_get8(i2cdev, PMBUS_REVISION);
> + g_assert_cmphex(i2c_value, ==, ADM1266_PMBUS_REVISION_DEFAULT);
> +
> + compare_string(i2cdev, PMBUS_MFR_ID, ADM1266_MFR_ID_DEFAULT);
> + compare_string(i2cdev, PMBUS_MFR_MODEL, ADM1266_MFR_MODEL_DEFAULT);
> + compare_string(i2cdev, PMBUS_MFR_REVISION, ADM1266_MFR_REVISION_DEFAULT);
> +}
> +
> +/* test r/w registers */
> +static void test_rw_regs(void *obj, void *data, QGuestAllocator *alloc)
> +{
> + QI2CDevice *i2cdev = (QI2CDevice *)obj;
> +
> + /* empty strings */
> + i2c_set8(i2cdev, PMBUS_MFR_ID, 0);
> + compare_string(i2cdev, PMBUS_MFR_ID, "");
> +
> + i2c_set8(i2cdev, PMBUS_MFR_MODEL, 0);
> + compare_string(i2cdev, PMBUS_MFR_MODEL, "");
> +
> + i2c_set8(i2cdev, PMBUS_MFR_REVISION, 0);
> + compare_string(i2cdev, PMBUS_MFR_REVISION, "");
> +
> + /* test strings */
> + write_and_compare_string(i2cdev, PMBUS_MFR_ID, TEST_STRING_A,
> + sizeof(TEST_STRING_A));
> + write_and_compare_string(i2cdev, PMBUS_MFR_ID, TEST_STRING_B,
> + sizeof(TEST_STRING_B));
> + write_and_compare_string(i2cdev, PMBUS_MFR_ID, TEST_STRING_C,
> + sizeof(TEST_STRING_C));
> +}
> +
> +static void adm1266_register_nodes(void)
> +{
> + QOSGraphEdgeOptions opts = {
> + .extra_device_opts = "id=" TEST_ID ",address=0x12"
> + };
> + add_qi2c_address(&opts, &(QI2CAddress) { TEST_ADDR });
> +
> + qos_node_create_driver("adm1266", i2c_device_create);
> + qos_node_consumes("adm1266", "i2c-bus", &opts);
> +
> + qos_add_test("test_defaults", "adm1266", test_defaults, NULL);
> + qos_add_test("test_rw_regs", "adm1266", test_rw_regs, NULL);
> +}
> +
> +libqos_init(adm1266_register_nodes);
> +
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 85ea4e8d99..d3cf7b2287 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -232,6 +232,7 @@ qos_test_ss = ss.source_set()
> qos_test_ss.add(
> 'ac97-test.c',
> 'adm1272-test.c',
> + 'adm1266-test.c',
> 'ds1338-test.c',
> 'e1000-test.c',
> 'eepro100-test.c',
> --
> 2.40.0.423.gd6c402a77b-goog
>
prev parent reply other threads:[~2023-03-31 14:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-31 0:07 [PATCH 0/7] PMBus fixes and new functions Titus Rwantare
2023-03-31 0:07 ` [PATCH 1/7] hw/i2c: pmbus add support for block receive Titus Rwantare
2023-03-31 13:47 ` Corey Minyard
2023-03-31 0:07 ` [PATCH 2/7] hw/i2c: pmbus: add vout mode bitfields Titus Rwantare
2023-03-31 13:50 ` Corey Minyard
2023-03-31 0:07 ` [PATCH 3/7] hw/i2c: pmbus: add fan support Titus Rwantare
2023-03-31 13:51 ` Corey Minyard
2023-03-31 0:07 ` [PATCH 4/7] hw/i2c: pmbus: block uninitialised string reads Titus Rwantare
2023-03-31 13:53 ` Corey Minyard
2023-03-31 0:07 ` [PATCH 5/7] hw/i2c: pmbus: add VCAP register Titus Rwantare
2023-03-31 13:53 ` Corey Minyard
2023-03-31 0:07 ` [PATCH 6/7] hw/sensor: add ADM1266 device model Titus Rwantare
2023-03-31 13:59 ` Corey Minyard
2023-03-31 0:07 ` [PATCH 7/7] tests/qtest: add tests for ADM1266 Titus Rwantare
2023-03-31 14:01 ` Corey Minyard [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZCbnpcnaj2dnfYXV@minyard.net \
--to=minyard@acm.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=titusr@google.com \
--cc=wuhaotsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.