From patchwork Wed Aug 8 21:07:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10560495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3161613BB for ; Wed, 8 Aug 2018 21:12:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5762AF4D for ; Wed, 8 Aug 2018 21:12:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12DAA2AF81; Wed, 8 Aug 2018 21:12:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D7FA2AF4D for ; Wed, 8 Aug 2018 21:12:16 +0000 (UTC) Received: from localhost ([::1]:45488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnVkd-0006Eg-Qi for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Aug 2018 17:12:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnVhi-0003IS-Dq for qemu-devel@nongnu.org; Wed, 08 Aug 2018 17:09:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnVhh-0006qN-CW for qemu-devel@nongnu.org; Wed, 08 Aug 2018 17:09:14 -0400 Received: from smtp20.mail.ru ([94.100.179.251]:45898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fnVhh-0006pX-48 for qemu-devel@nongnu.org; Wed, 08 Aug 2018 17:09:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Sr7MXCx2LEmWiHk5j1JicfIaLOE31DflgrBb5ds6PTY=; b=He3ms7soGvkqRapMJnHCpOtkd81xQnkrDKHjJyvjQM/ruueNOZl590Oyc7K7AocxHE3cpM1yqVn7sB4wihCSmYRrVS07iVtQ4v3siPmuEIRsmlnLl0+bLUQOG5Y0d7K/liKC4Wwn7JPApRy0s2hJp92POXrdJjOSPbqWGSsWikw=; Received: by smtp20.mail.ru with esmtpa (envelope-from ) id 1fnVhf-0002Hh-Fd; Thu, 09 Aug 2018 00:09:11 +0300 To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2018 00:07:50 +0300 Message-Id: <20180808210750.3915-5-jusual@mail.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180808210750.3915-1-jusual@mail.ru> References: <20180808210750.3915-1-jusual@mail.ru> Authentication-Results: smtp20.mail.ru; auth=pass smtp.auth=jusual@mail.ru smtp.mailfrom=jusual@mail.ru X-7FA49CB5: 0D63561A33F958A5F91DD0F7588CEEF16D2E4307B80EE54E321589DF743CA5A78941B15DA834481F8AA50765F7900637DCE3DBD6F8E38AFD389733CBF5DBD5E9B5C8C57E37DE458B4DA2F55E57A558BE49FD398EE364050F9647ADFADE5905B1BA3038C0950A5D36B5C8C57E37DE458B4C7702A67D5C33162DBA43225CD8A89FD2A95C73FD1EFF4533EC5F1D65593A419BD042E35019D45F43847C11F186F3C5E7DDDDC251EA7DABCC89B49CDF41148FFC2B27DE93B9EBF03B503F486389A921A5CC5B56E945C8DA X-Mailru-Sender: 7766D515518070DE138AAC7428EA760DF0CA256A8E08CE045EEB9165E073A771AD86B2CDA8E0145D7C4160E8B47E48163DDE9B364B0DF2898CB68AF7A628805D594FB4C9F0DBF412AE208404248635DF X-Mras: OK X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 94.100.179.251 Subject: [Qemu-devel] [PATCH v2 4/4] tests/microbit-test: Check nRF51 UART functionality X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Julia Suvorova via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: Julia Suvorova Cc: Peter Maydell , Jim Mussared , =?utf-8?q?Steffen_G=C3=B6rtz?= , Stefan Hajnoczi , Joel Stanley , Stefan Hajnoczi , Paolo Bonzini , Julia Suvorova Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some functional tests for: Basic reception/transmittion Suspending INTEN* registers Based-on: <20180806100114.21410-6-contrib@steffen-goertz.de> Signed-off-by: Julia Suvorova --- tests/microbit-test.c | 106 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/tests/microbit-test.c b/tests/microbit-test.c index 08e2210916..8b69d83684 100644 --- a/tests/microbit-test.c +++ b/tests/microbit-test.c @@ -17,7 +17,10 @@ #include "qemu/osdep.h" #include "exec/hwaddr.h" #include "libqtest.h" +#include "hw/char/nrf51_uart.h" +#include +#include #define PAGE_SIZE 1024 #define FLASH_SIZE (256 * PAGE_SIZE) @@ -48,7 +51,6 @@ #define GPIO_PULLDOWN 1 #define GPIO_PULLUP 3 - static void fill_and_erase(hwaddr base, hwaddr size, uint32_t address_reg) { /* Fill memory */ @@ -204,19 +206,117 @@ static void test_nrf51_gpio(void) g_assert_false(true); } +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(UART_BASE + A_UART_RXDRDY)); + out[i] = readl(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(UART_BASE + A_UART_TXD, in[i]); + g_assert(wait_for_event(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(UART_BASE + A_UART_RXD) == 0); + + writel(UART_BASE + A_UART_ENABLE, 0x04); + writel(UART_BASE + A_UART_STARTRX, 0x01); + + g_assert(wait_for_event(UART_BASE + A_UART_RXDRDY)); + writel(UART_BASE + A_UART_RXDRDY, 0x00); + g_assert(readl(UART_BASE + A_UART_RXD) == 'c'); + + writel(UART_BASE + A_UART_INTENSET, 0x04); + g_assert(readl(UART_BASE + A_UART_INTEN) == 0x04); + writel(UART_BASE + A_UART_INTENCLR, 0x04); + g_assert(readl(UART_BASE + A_UART_INTEN) == 0x00); + + rw_to_rxd(sock_fd, "hello", s); + g_assert(strcmp(s, "hello") == 0); + + writel(UART_BASE + A_UART_STARTTX, 0x01); + w_to_txd("d"); + g_assert(read(sock_fd, s, 10) == 1); + g_assert(s[0] == 'd'); + + writel(UART_BASE + A_UART_SUSPEND, 0x01); + writel(UART_BASE + A_UART_TXD, 'h'); + writel(UART_BASE + A_UART_STARTTX, 0x01); + w_to_txd("world"); + g_assert(read(sock_fd, s, 10) == 5); + g_assert(strcmp(s, "world") == 0); +} + int main(int argc, char **argv) { int ret; + char serialtmpdir[] = "/tmp/qtest-microbit-serial-sXXXXXX"; + char serialtmp[40]; + int sock_fd; + 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_startf("-machine microbit"); + global_qtest = qtest_startf("-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); qtest_add_func("/microbit/nrf51/nvmc", test_nrf51_nvmc); qtest_add_func("/microbit/nrf51/gpio", test_nrf51_gpio); - + qtest_add_data_func("/microbit/nrf51/uart", &sock_fd, test_nrf51_uart); ret = g_test_run(); qtest_quit(global_qtest); + + close(sock_fd); + rmdir(serialtmpdir); + return ret; }