From nobody Wed Dec 17 06:01:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1765409434; cv=none; d=zohomail.com; s=zohoarc; b=VHjZ0AfEQr49eorWMLmWJzt+Ec6/CBvHue8JnoauAh5LJVDgdvCzJa/RkTOkWLMYKH76gHAU9DVbxA6+qI24FD2YDb9yUzCw52DB22d5eBPgUzn7VdBfnRxM4aYM6LEVbZq3GQEsFD3k06sdx9+AYgnrgkO1o6g/kO+XUzqmcck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409434; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=V/p7p5kZiMeVzqeCpGXZV3o/BNSDBxLa3oyslXCE1Sk=; b=ZqOiG4IAommmhAf7Lm2KNz7d52C2ZD3sNoePycYvUMBGf/Icw6bf3iIHi1BB3ZTZT6ZLyZ4Dfg+4rw611QTHapaAnZyAnbsiwV+svmqh7UmB2MZdGQubnFAkdoBVLugzy5UlSDHjzuL62Cal8SNVz+zm4v+kbkFl4pxb4ucWghw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765409434644969.9587622861148; Wed, 10 Dec 2025 15:30:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTd7-0004Cv-OU; Wed, 10 Dec 2025 18:29:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3aAI6aQYKCqUdZGNSeLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--yubinz.bounces.google.com>) id 1vTTd0-0004AG-Pz for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:50 -0500 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3aAI6aQYKCqUdZGNSeLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--yubinz.bounces.google.com>) id 1vTTcy-0005jL-Da for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:49 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b471737e673so372613a12.1 for ; Wed, 10 Dec 2025 15:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409384; x=1766014184; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V/p7p5kZiMeVzqeCpGXZV3o/BNSDBxLa3oyslXCE1Sk=; b=f9hUcmNvCVDVI4969Bfa6rt1jhb+81inln16CRKyFHJ5NJfh1BBoXvLT8P2vd+Uo1J mTa/oxyeoS7HKxp70iFM3vHb8hggXGywZmsVK2TX65Y3a+jbEjrL/b+YxxWwqow7kknl GV1gPpoWodVH/bmog7KhQpPombRMSfIiZAI8eOdZe8ZEsE0NuCBDskdNWEM6cvedwTUy SYwJ7pqRwM0AZxoGO43eGdv+l3JeaoNeAEgADSEoZQ4q7rRthUO9Ms4lXmtuBDPjI5zL SmpANUjiPZF+pwdKkLnPF5RC7aexADWAwGjOmCSFy/JPBwZlD6ppGEcoJQLmSvo4a3qj r41g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409384; x=1766014184; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V/p7p5kZiMeVzqeCpGXZV3o/BNSDBxLa3oyslXCE1Sk=; b=wcPA9CZBrD5FchKDj7P7AmNYQOjJ4GhGTrNKePa6OjPw4VOgPuYG+RowwkPf9mtirx VxEgTCTAgtF3MhK0VlA6KxNryS/acKqs/pE3SX/ANbOcJUJ9vaelwHD6HUtq2JmMZ7kL T/4lhm3TNqJdgFZWlA2E92tNLz41oKg5ij6hmnTPyPFIphggSOVEukjvBoBk7BI3OBC0 uDiTcLYWvu0pbjgKgxedsLio4sl+nQ+/qnpt7MGC0hj+c5hRT/f4lQOP6U5CU/13R4L6 qGu9hsosq6V+Asv1yGIMFVakW7DDepESwI9e8dGn4uYq3sIL+wHCkoFZ+yXU6vRn0sob QlWg== X-Gm-Message-State: AOJu0YwoMvVnRnrDIhQhuvd0a5PmEeZWMk4S8Y4HWG3ZAY2TUUE02FQY veF7MHjbOD2Cd/eO2mC6oTHwq3PJLv2EqQTlSXkkqClAnf1biwC1bCrUoBD/jR7BulaoU1tbQI5 nmXljMRUyozR9l4KrHXLxk1jcBaNq2a7a/LjNddRi6gkW5xY3T77mQNtJ5vvpgK2psMA/HzvOw5 p79f0phVBtphEba9u24OiLT5xmW4c7/6DZdd8= X-Google-Smtp-Source: AGHT+IFnH1Uj5Zp6ckTavj8XiQlSDJn8c8GXpiFB4Kilp7a2eKpL0MER75YlbhZzBEKq2HvudOppQknKwWg= X-Received: from dlbrb20.prod.google.com ([2002:a05:7022:f014:b0:11b:a892:80ac]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e21:b0:119:e569:f615 with SMTP id a92af1059eb24-11f2963f1bamr3036459c88.14.1765409384218; Wed, 10 Dec 2025 15:29:44 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:17 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-6-eb8b0cf3dd51@google.com> Subject: [PATCH v3 6/6] test/qtest: Add Unit test for Aspeed SGPIO From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3aAI6aQYKCqUdZGNSeLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--yubinz.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1765409437142158500 Content-Transfer-Encoding: quoted-printable This commit introduces a new qtest for the Aspeed SGPIO controller The test covers the following: - Setting and clearing SGPIO output pins and verifying the pin state. - Setting and clearing SGPIO input pins and verifying the pin state. - Verifying that level-high interrupts are correctly triggered and cleare= d. Signed-off-by: Yubin Zou --- tests/qtest/ast2700-sgpio-test.c | 152 +++++++++++++++++++++++++++++++++++= ++++ tests/qtest/meson.build | 1 + 2 files changed, 153 insertions(+) diff --git a/tests/qtest/ast2700-sgpio-test.c b/tests/qtest/ast2700-sgpio-t= est.c new file mode 100644 index 0000000000000000000000000000000000000000..fc52839c4b149a3010c6a035d8b= 29f9ad295930a --- /dev/null +++ b/tests/qtest/ast2700-sgpio-test.c @@ -0,0 +1,152 @@ +/* + * QTest testcase for the ASPEED AST2700 GPIO Controller. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2025 Google LLC. + */ + +#include "qemu/osdep.h" +#include "qobject/qdict.h" +#include "qemu/bitops.h" +#include "qemu/timer.h" +#include "qobject/qdict.h" +#include "libqtest-single.h" +#include "qemu/error-report.h" +#include "hw/registerfields.h" +#include "hw/gpio/aspeed_sgpio.h" + +#define ASPEED_SGPIO_MAX_PIN_PAIR 256 +#define AST2700_SGPIO0_BASE 0x14C0C000 +#define AST2700_SGPIO1_BASE 0x14C0D000 + +static void test_output_pins(const char *machine, const uint32_t base, int= idx) +{ + QTestState *s =3D qtest_init(machine); + char name[16]; + char qom_path[64]; + uint32_t offset =3D 0; + uint32_t value =3D 0; + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR; i++) { + /* Odd index is output port */ + sprintf(name, "sgpio%d", i * 2 + 1); + sprintf(qom_path, "/machine/soc/sgpio[%d]", idx); + offset =3D base + (R_SGPIO_0_CONTROL + i) * 4; + /* set serial output */ + qtest_writel(s, offset, 0x00000001); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_OUT_VAL), = =3D=3D, 1); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, tru= e); + + /* clear serial output */ + qtest_writel(s, offset, 0x00000000); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_OUT_VAL), = =3D=3D, 0); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, fal= se); + } + qtest_quit(s); +} + +static void test_input_pins(const char *machine, const uint32_t base, int = idx) +{ + QTestState *s =3D qtest_init(machine); + char name[16]; + char qom_path[64]; + uint32_t offset =3D 0; + uint32_t value =3D 0; + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR; i++) { + /* Even index is input port */ + sprintf(name, "sgpio%d", i * 2); + sprintf(qom_path, "/machine/soc/sgpio[%d]", idx); + offset =3D base + (R_SGPIO_0_CONTROL + i) * 4; + /* set serial input */ + qtest_qom_set_bool(s, qom_path, name, true); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 1); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, tru= e); + + /* clear serial input */ + qtest_qom_set_bool(s, qom_path, name, false); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 0); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, fal= se); + } + qtest_quit(s); +} + +static void test_irq_level_high(const char *machine, + const uint32_t base, int idx) +{ + QTestState *s =3D qtest_init(machine); + char name[16]; + char qom_path[64]; + uint32_t ctrl_offset =3D 0; + uint32_t int_offset =3D 0; + uint32_t int_reg_idx =3D 0; + uint32_t int_bit_idx =3D 0; + uint32_t value =3D 0; + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR; i++) { + /* Even index is input port */ + sprintf(name, "sgpio%d", i * 2); + sprintf(qom_path, "/machine/soc/sgpio[%d]", idx); + int_reg_idx =3D i / 32; + int_bit_idx =3D i % 32; + int_offset =3D base + (R_SGPIO_INT_STATUS_0 + int_reg_idx) * 4; + ctrl_offset =3D base + (R_SGPIO_0_CONTROL + i) * 4; + + /* Enable the interrupt */ + value =3D SHARED_FIELD_DP32(value, SGPIO_INT_EN, 1); + qtest_writel(s, ctrl_offset, value); + + /* Set the interrupt type to level-high trigger */ + value =3D SHARED_FIELD_DP32(qtest_readl(s, ctrl_offset), + SGPIO_INT_TYPE, 3); + qtest_writel(s, ctrl_offset, value); + + /* Set serial input high */ + qtest_qom_set_bool(s, qom_path, name, true); + value =3D qtest_readl(s, ctrl_offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 1); + + /* Interrupt status is set */ + value =3D qtest_readl(s, int_offset); + g_assert_cmphex(extract32(value, int_bit_idx, 1), =3D=3D, 1); + + /* Clear Interrupt */ + value =3D SHARED_FIELD_DP32(qtest_readl(s, ctrl_offset), + SGPIO_INT_STATUS, 1); + qtest_writel(s, ctrl_offset, value); + value =3D qtest_readl(s, int_offset); + g_assert_cmphex(extract32(value, int_bit_idx, 1), =3D=3D, 0); + + /* Clear serial input */ + qtest_qom_set_bool(s, qom_path, name, false); + value =3D qtest_readl(s, ctrl_offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 0); + } + qtest_quit(s); +} + +static void test_2700_input_pins(void) +{ + test_input_pins("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_input_pins("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); + test_output_pins("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_output_pins("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); + test_irq_level_high("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_irq_level_high("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/ast2700/sgpio/input_pins", test_2700_input_pins); + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 669d07c06bdedc6be0c69acadeba989dc15ddf3f..5c80b2ed6de1f453d2483db482c= 1b0e7801ba980 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -221,6 +221,7 @@ qtests_aspeed =3D \ qtests_aspeed64 =3D \ ['ast2700-gpio-test', 'ast2700-hace-test', + 'ast2700-sgpio-test', 'ast2700-smc-test'] =20 qtests_stm32l4x5 =3D \ --=20 2.52.0.239.gd5f0c6e74e-goog