From: Chris Laplante <chris@laplante.io>
To: qemu-devel@nongnu.org
Cc: Joel Stanley <joel@jms.id.au>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-arm@nongnu.org, Chris Laplante <chris@laplante.io>
Subject: [PATCH 6/6] qtest: microbit-test: add tests for nRF51 DETECT
Date: Fri, 14 Jul 2023 23:27:51 +0000 [thread overview]
Message-ID: <20230714232659.76434-7-chris@laplante.io> (raw)
In-Reply-To: <20230714232659.76434-1-chris@laplante.io>
Exercise the DETECT mechanism of the GPIO peripheral.
Signed-off-by: Chris Laplante <chris@laplante.io>
---
tests/qtest/microbit-test.c | 42 +++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/tests/qtest/microbit-test.c b/tests/qtest/microbit-test.c
index 6022a92b6a..3c85adba37 100644
--- a/tests/qtest/microbit-test.c
+++ b/tests/qtest/microbit-test.c
@@ -393,6 +393,47 @@ static void test_nrf51_gpio(void)
qtest_quit(qts);
}
+static void test_nrf51_gpio_detect(void) {
+ QTestState *qts = qtest_init("-M microbit");
+ int i;
+
+ // Connect input buffer on pins 1-7, configure SENSE for high level
+ for (i = 1; i <= 7; i++) {
+ qtest_writel(qts, NRF51_GPIO_BASE + NRF51_GPIO_REG_CNF_START + i * 4, deposit32(0, 16, 2, 2));
+ }
+
+ qtest_irq_intercept_out_named(qts, "/machine/nrf51", "detect");
+
+ for (i = 1; i <= 7; i++) {
+ // Set pin high
+ qtest_set_irq_in(qts, "/machine/nrf51", "unnamed-gpio-in", i, 1);
+ uint32_t actual = qtest_readl(qts, NRF51_GPIO_BASE + NRF51_GPIO_REG_IN);
+ g_assert_cmpuint(actual, ==, 1 << i);
+
+ // Check that DETECT is high
+ g_assert_true(qtest_get_irq(qts, 0));
+
+ // Set pin low, check that DETECT goes low.
+ qtest_set_irq_in(qts, "/machine/nrf51", "unnamed-gpio-in", i, 0);
+ actual = qtest_readl(qts, NRF51_GPIO_BASE + NRF51_GPIO_REG_IN);
+ g_assert_cmpuint(actual, ==, 0x0);
+ g_assert_false(qtest_get_irq(qts, 0));
+ }
+
+ // Set pin 0 high, check that DETECT doesn't fire
+ qtest_set_irq_in(qts, "/machine/nrf51", "unnamed-gpio-in", 0, 1);
+ g_assert_false(qtest_get_irq(qts, 0));
+ qtest_set_irq_in(qts, "/machine/nrf51", "unnamed-gpio-in", 0, 0);
+
+ // Set pins 1, 2, and 3 high, then set 3 low. Check that DETECT is still high.
+ for (i = 1; i <= 3; i++) {
+ qtest_set_irq_in(qts, "/machine/nrf51", "unnamed-gpio-in", i, 1);
+ }
+ g_assert_true(qtest_get_irq(qts, 0));
+ qtest_set_irq_in(qts, "/machine/nrf51", "unnamed-gpio-in", 3, 0);
+ g_assert_true(qtest_get_irq(qts, 0));
+}
+
static void timer_task(QTestState *qts, hwaddr task)
{
qtest_writel(qts, NRF51_TIMER_BASE + task, NRF51_TRIGGER_TASK);
@@ -499,6 +540,7 @@ int main(int argc, char **argv)
qtest_add_func("/microbit/nrf51/uart", test_nrf51_uart);
qtest_add_func("/microbit/nrf51/gpio", test_nrf51_gpio);
+ qtest_add_func("/microbit/nrf51/gpio_detect", test_nrf51_gpio_detect);
qtest_add_func("/microbit/nrf51/nvmc", test_nrf51_nvmc);
qtest_add_func("/microbit/nrf51/timer", test_nrf51_timer);
qtest_add_func("/microbit/microbit/i2c", test_microbit_i2c);
--
2.39.2
next prev parent reply other threads:[~2023-07-14 23:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 23:27 [PATCH 0/6] Add nRF51 DETECT signal with test Chris Laplante
2023-07-14 23:27 ` [PATCH 1/6] hw/gpio/nrf51: implement DETECT signal Chris Laplante
2023-07-24 16:10 ` Peter Maydell
2023-07-14 23:27 ` [PATCH 2/6] qtest: implement named interception of out-GPIO Chris Laplante
2023-07-14 23:27 ` [PATCH 3/6] qtest: bail from irq_intercept_in if name is specified Chris Laplante
2023-07-24 16:17 ` Peter Maydell
2023-07-14 23:27 ` [PATCH 4/6] qtest: factor out qtest_install_gpio_out_intercepts Chris Laplante
2023-07-24 16:18 ` Peter Maydell
2023-07-14 23:27 ` [PATCH 5/6] qtest: irq_intercept_[out/in]: return FAIL if no intercepts are installed Chris Laplante
2023-07-24 16:19 ` Peter Maydell
2023-07-25 4:03 ` Chris Laplante
2023-07-14 23:27 ` Chris Laplante [this message]
2023-07-24 16:24 ` [PATCH 6/6] qtest: microbit-test: add tests for nRF51 DETECT Peter Maydell
2023-07-24 16:27 ` [PATCH 0/6] Add nRF51 DETECT signal with test Peter Maydell
2023-07-25 3:24 ` Chris Laplante
2023-07-25 9:23 ` Peter Maydell
2023-07-26 2:58 ` Chris Laplante
2023-07-27 22:51 ` Chris Laplante
2023-07-28 9:32 ` Peter Maydell
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=20230714232659.76434-7-chris@laplante.io \
--to=chris@laplante.io \
--cc=joel@jms.id.au \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).