From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Julia Suvorova <jusual@mail.ru>, qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Jim Mussared" <jim@groklearning.com>,
"Steffen Görtz" <mail@steffen-goertz.de>,
"Thomas Huth" <thuth@redhat.com>, "Joel Stanley" <joel@jms.id.au>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3] tests/microbit-test: Check nRF51 UART functionality
Date: Mon, 5 Nov 2018 17:16:15 +0100 [thread overview]
Message-ID: <df0c970c-4180-a9ae-6bb6-5149e93883ae@redhat.com> (raw)
In-Reply-To: <20181105104524.933-1-jusual@mail.ru>
Hi Julia,
On 5/11/18 11:45, Julia Suvorova via Qemu-devel wrote:
> Some functional tests for:
> Basic reception/transmittion
> Suspending
> INTEN* registers
>
> Based-on: <20181031002526.14262-1-contrib@steffen-goertz.de>
> Signed-off-by: Julia Suvorova <jusual@mail.ru>
> ---
Lines below '---' are not included in the git history.
The Based-on: tag is temporary and not relevant to the history, you
should insert it here, so it will be automatically dropped once your
patch get applied.
Regards,
Phil.
> This patch was part of nRF51 UART patchset, but wasn't included in the latest
> revision. Due to upcoming loader fixes, we need this test instead of
> boot-serial-test, which doesn't support -device loader.
>
> v3:
> * Fix directory leak [Stefan]
>
> tests/microbit-test.c | 109 +++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 107 insertions(+), 2 deletions(-)
>
> diff --git a/tests/microbit-test.c b/tests/microbit-test.c
> index ab319eb466..23d343cfdd 100644
> --- a/tests/microbit-test.c
> +++ b/tests/microbit-test.c
> @@ -21,9 +21,87 @@
> #include "hw/arm/nrf51.h"
> #include "hw/nvram/nrf51_nvm.h"
> #include "hw/gpio/nrf51_gpio.h"
> +#include "hw/char/nrf51_uart.h"
> +
> +#include <sys/socket.h>
> +#include <sys/un.h>
>
> #define FLASH_SIZE (256 * NRF51_PAGE_SIZE)
>
> +static bool wait_for_event(uint32_t event_addr)
> +{
> + int i;
> +
> + for (i = 0; i < 1000; i++) {
> + if (readl(event_addr) == 1) {
> + writel(event_addr, 0x00);
> + return true;
> + }
> + g_usleep(10000);
> + }
> +
> + return false;
> +}
> +
> +static void rw_to_rxd(int sock_fd, const char *in, char *out)
> +{
> + int i;
> +
> + g_assert(write(sock_fd, in, strlen(in)) == strlen(in));
> + for (i = 0; i < strlen(in); i++) {
> + g_assert(wait_for_event(NRF51_UART_BASE + A_UART_RXDRDY));
> + out[i] = readl(NRF51_UART_BASE + A_UART_RXD);
> + }
> + out[i] = '\0';
> +}
> +
> +static void w_to_txd(const char *in)
> +{
> + int i;
> +
> + for (i = 0; i < strlen(in); i++) {
> + writel(NRF51_UART_BASE + A_UART_TXD, in[i]);
> + g_assert(wait_for_event(NRF51_UART_BASE + A_UART_TXDRDY));
> + }
> +}
> +
> +static void test_nrf51_uart(const void *data)
> +{
> + int sock_fd = *((const int *) data);
> + char s[10];
> +
> + g_assert(write(sock_fd, "c", 1) == 1);
> + g_assert(readl(NRF51_UART_BASE + A_UART_RXD) == 0);
> +
> + writel(NRF51_UART_BASE + A_UART_ENABLE, 0x04);
> + writel(NRF51_UART_BASE + A_UART_STARTRX, 0x01);
> +
> + g_assert(wait_for_event(NRF51_UART_BASE + A_UART_RXDRDY));
> + writel(NRF51_UART_BASE + A_UART_RXDRDY, 0x00);
> + g_assert(readl(NRF51_UART_BASE + A_UART_RXD) == 'c');
> +
> + writel(NRF51_UART_BASE + A_UART_INTENSET, 0x04);
> + g_assert(readl(NRF51_UART_BASE + A_UART_INTEN) == 0x04);
> + writel(NRF51_UART_BASE + A_UART_INTENCLR, 0x04);
> + g_assert(readl(NRF51_UART_BASE + A_UART_INTEN) == 0x00);
> +
> + rw_to_rxd(sock_fd, "hello", s);
> + g_assert(strcmp(s, "hello") == 0);
> +
> + writel(NRF51_UART_BASE + A_UART_STARTTX, 0x01);
> + w_to_txd("d");
> + g_assert(read(sock_fd, s, 10) == 1);
> + g_assert(s[0] == 'd');
> +
> + writel(NRF51_UART_BASE + A_UART_SUSPEND, 0x01);
> + writel(NRF51_UART_BASE + A_UART_TXD, 'h');
> + writel(NRF51_UART_BASE + A_UART_STARTTX, 0x01);
> + w_to_txd("world");
> + g_assert(read(sock_fd, s, 10) == 5);
> + g_assert(strcmp(s, "world") == 0);
> +}
> +
> +
> static void fill_and_erase(hwaddr base, hwaddr size, uint32_t address_reg)
> {
> /* Fill memory */
> @@ -223,17 +301,44 @@ static void test_nrf51_gpio(void)
>
> int main(int argc, char **argv)
> {
> - int ret;
> + int ret, sock_fd;
> + char serialtmpdir[] = "/tmp/qtest-microbit-serial-sXXXXXX";
> + char serialtmp[40];
> + struct sockaddr_un addr;
> +
> + g_assert(mkdtemp(serialtmpdir));
> + sprintf(serialtmp, "%s/sock", serialtmpdir);
> +
> + sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
> + g_assert(sock_fd != -1);
> +
> + memset(&addr, 0, sizeof(struct sockaddr_un));
> +
> + addr.sun_family = AF_UNIX;
> + strncpy(addr.sun_path, serialtmp, sizeof(addr.sun_path) - 1);
>
> g_test_init(&argc, &argv, NULL);
>
> - global_qtest = qtest_initf("-machine microbit");
> + global_qtest = qtest_initf("-machine microbit "
> + "-chardev socket,id=s0,path=%s,server,nowait "
> + "-no-shutdown -serial chardev:s0",
> + serialtmp);
> +
> + g_assert(connect(sock_fd, (const struct sockaddr *) &addr,
> + sizeof(struct sockaddr_un)) != -1);
>
> + unlink(serialtmp);
> + rmdir(serialtmpdir);
> +
> + qtest_add_data_func("/microbit/nrf51/uart", &sock_fd, test_nrf51_uart);
> qtest_add_func("/microbit/nrf51/nvmc", test_nrf51_nvmc);
> qtest_add_func("/microbit/nrf51/gpio", test_nrf51_gpio);
>
> ret = g_test_run();
>
> qtest_quit(global_qtest);
> +
> + close(sock_fd);
> +
> return ret;
> }
>
next prev parent reply other threads:[~2018-11-05 16:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-05 10:45 [Qemu-devel] [PATCH v3] tests/microbit-test: Check nRF51 UART functionality Julia Suvorova
2018-11-05 12:24 ` Alex Bennée
2018-11-05 13:26 ` Julia Suvorova
2018-11-05 15:29 ` no-reply
2018-11-05 15:32 ` no-reply
2018-11-05 16:16 ` Philippe Mathieu-Daudé [this message]
2018-11-05 16:36 ` Julia Suvorova
2018-11-05 17:54 ` Peter Maydell
2018-11-08 10:50 ` Stefan Hajnoczi
2018-11-08 10:45 ` Stefan Hajnoczi
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=df0c970c-4180-a9ae-6bb6-5149e93883ae@redhat.com \
--to=philmd@redhat.com \
--cc=jim@groklearning.com \
--cc=joel@jms.id.au \
--cc=jusual@mail.ru \
--cc=mail@steffen-goertz.de \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.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).