qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, qemu-s390x@nongnu.org,
	qemu-block@nongnu.org, qemu-riscv@nongnu.org,
	qemu-ppc@nongnu.org, qemu-arm@nongnu.org,
	"Titus Rwantare" <titusr@google.com>,
	"Hao Wu" <wuhaotsh@google.com>,
	"Corey Minyard" <cminyard@mvista.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Tyrone Ting" <kfting@nuvoton.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PULL 54/60] tests/qtest: add tests for ADM1266
Date: Mon,  6 Nov 2023 12:03:26 +0100	[thread overview]
Message-ID: <20231106110336.358-55-philmd@linaro.org> (raw)
In-Reply-To: <20231106110336.358-1-philmd@linaro.org>

From: Titus Rwantare <titusr@google.com>

The ADM1266 can have string fields written by the driver, so
it's worth specifically testing.

Reviewed-by: Hao Wu <wuhaotsh@google.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Titus Rwantare <titusr@google.com>
[PMD: Cover file in MAINTAINERS]
Message-ID: <20231023-staging-pmbus-v3-v4-6-07a8cb7cd20a@google.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 MAINTAINERS                |   1 +
 tests/qtest/adm1266-test.c | 122 +++++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build    |   1 +
 3 files changed, 124 insertions(+)
 create mode 100644 tests/qtest/adm1266-test.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e6a2f57442..c01c2e6ec0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -862,6 +862,7 @@ F: hw/*/npcm*
 F: hw/sensor/adm1266.c
 F: include/hw/*/npcm*
 F: tests/qtest/npcm*
+F: tests/qtest/adm1266-test.c
 F: pc-bios/npcm7xx_bootrom.bin
 F: roms/vbootrom
 F: docs/system/arm/nuvoton.rst
diff --git a/tests/qtest/adm1266-test.c b/tests/qtest/adm1266-test.c
new file mode 100644
index 0000000000..6c312c499f
--- /dev/null
+++ b/tests/qtest/adm1266-test.c
@@ -0,0 +1,122 @@
+/*
+ * 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 c9945e69b1..47dabf91d0 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -241,6 +241,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.41.0



  parent reply	other threads:[~2023-11-06 11:14 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 11:02 [PULL 00/60] Misc HW/UI patches for 2023-11-06 Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 01/60] vl: Free machine list Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 02/60] vl: constify default_list Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 03/60] tests/vm/ubuntu.aarch64: Correct comment about TCG specific delay Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 04/60] tests/unit/test-seccomp: Remove mentions of softmmu in test names Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 05/60] accel/tcg: Declare tcg_flush_jmp_cache() in 'exec/tb-flush.h' Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 06/60] accel: Introduce cpu_exec_reset_hold() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 07/60] accel/tcg: Factor tcg_cpu_reset_hold() out Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 08/60] target: Unify QOM style Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 09/60] target: Mention 'cpu-qom.h' is target agnostic Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 10/60] target/arm: Move internal declarations from 'cpu-qom.h' to 'cpu.h' Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 11/60] target/ppc: Remove CPU_RESOLVING_TYPE from 'cpu-qom.h' Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 12/60] target/riscv: " Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 13/60] target: Declare FOO_CPU_TYPE_NAME/SUFFIX in 'cpu-qom.h' Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 14/60] target/hexagon: Declare QOM definitions " Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 15/60] target/loongarch: " Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 16/60] target/nios2: " Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 17/60] target/openrisc: " Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 18/60] target/riscv: Move TYPE_RISCV_CPU_BASE definition to 'cpu.h' Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 19/60] target/ppc: Use env_archcpu() in helper_book3s_msgsndp() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 20/60] target/riscv: Use env_archcpu() in [check_]nanbox() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 21/60] target/s390x: Use env_archcpu() in handle_diag_308() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 22/60] target/xtensa: Use env_archcpu() in update_c[compare|count]() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 23/60] target/i386/hvf: Use x86_cpu in simulate_[rdmsr|wrmsr]() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 24/60] target/i386/hvf: Use env_archcpu() in simulate_[rdmsr/wrmsr]() Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 25/60] target/i386/hvf: Use CPUState typedef Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 26/60] target/i386/hvf: Rename 'CPUState *cpu' variable as 'cs' Philippe Mathieu-Daudé
2023-11-06 11:02 ` [PULL 27/60] target/i386/hvf: Rename 'X86CPU *x86_cpu' variable as 'cpu' Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 28/60] target/i386/kvm: Correct comment in kvm_cpu_realize() Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 29/60] target/i386/monitor: synchronize cpu state for lapic info Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 30/60] target/mips: Fix MSA BZ/BNZ opcodes displacement Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 31/60] target/mips: Fix TX79 LQ/SQ opcodes Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 32/60] sysemu/kvm: Restrict kvmppc_get_radix_page_info() to ppc targets Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 33/60] hw/ppc/e500: Restrict ppce500_init_mpic_kvm() to KVM Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 34/60] target/ppc: Restrict KVM objects to system emulation Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 35/60] target/ppc: Prohibit target specific KVM prototypes on user emulation Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 36/60] target/nios2: Create IRQs *after* accelerator vCPU is realized Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 37/60] target/alpha: Tidy up alpha_cpu_class_by_name() Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 38/60] hw/cpu: Call object_class_is_abstract() once in cpu_class_by_name() Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 39/60] exec/cpu: Have cpu_exec_realize() return a boolean Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 40/60] hw/cpu: Clean up global variable shadowing Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 41/60] hw/loader: Clean up global variable shadowing in rom_add_file() Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 42/60] hw/isa/i82378: Propagate error if PC_SPEAKER device creation failed Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 43/60] hw/i386: Fix comment style in topology.h Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 44/60] tests/unit: Rename test-x86-cpuid.c to test-x86-topo.c Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 45/60] system/cpus: Fix CPUState.nr_cores' calculation Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 46/60] hw/cpu: Update the comments of nr_cores and nr_dies Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 47/60] hw/ide: reset: cancel async DMA operation before resetting state Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 48/60] tests/qtest: ahci-test: add test exposing reset issue with pending callback Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 49/60] hw/i2c: pmbus add support for block receive Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 50/60] hw/i2c: pmbus: add vout mode bitfields Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 51/60] hw/i2c: pmbus: add fan support Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 52/60] hw/i2c: pmbus: add VCAP register Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 53/60] hw/sensor: add ADM1266 device model Philippe Mathieu-Daudé
2023-11-06 11:03 ` Philippe Mathieu-Daudé [this message]
2023-11-06 11:03 ` [PULL 55/60] hw/i2c: pmbus: immediately clear faults on request Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 56/60] hw/i2c: pmbus: reset page register for out of range reads Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 57/60] MAINTAINERS: Add include/hw/timer/tmu012.h to the SH4 R2D section Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 58/60] MAINTAINERS: Add the CAN documentation file to the CAN section Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 59/60] MAINTAINERS: update libvirt devel mailing list address Philippe Mathieu-Daudé
2023-11-06 11:03 ` [PULL 60/60] ui/sdl2: use correct key names in win title on mac Philippe Mathieu-Daudé
2023-11-07  1:39 ` [PULL 00/60] Misc HW/UI patches for 2023-11-06 Stefan Hajnoczi
2023-11-07  8:51   ` Philippe Mathieu-Daudé

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=20231106110336.358-55-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=cminyard@mvista.com \
    --cc=kfting@nuvoton.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=thuth@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).