From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF88D606A322 for ; Thu, 3 Dec 2026 00:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=D4enHHiz Received: from list by lists.xenproject.org with outflank-mailman.1511331.1703771 (Exim 4.92) (envelope-from ) id 1xYumy-0005xK-GO; Thu, 03 Dec 2026 00:35:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1511331.1703771; Thu, 03 Dec 2026 00:35:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYumy-0005xD-DY; Thu, 03 Dec 2026 00:35:08 +0000 Received: by outflank-mailman (input) for mailman id 1511331; Thu, 03 Dec 2026 00:35:07 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYumx-0005x7-Gn for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 00:35:07 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYumw-0029eh-N7 for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 01:35:06 +0100 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b10b8ec-8faa-0a2a0a5109dd-0a2a45068bb4-24 for ; Thu, 03 Dec 2026 01:35:06 +0100 Received: from [172.234.252.31] (helo=sea.source.kernel.org) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b10b938-195a-0a2a45060019-aceafc1f979e-3 for ; Thu, 03 Dec 2026 01:35:06 +0100 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 34B6B4569E; Thu, 3 Dec 2026 00:35:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2A731F00893; Thu, 3 Dec 2026 00:35:01 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=k20260515 header.d=kernel.org header.i="@kernel.org" header.h="Date:From:To:cc:Subject:In-Reply-To:References" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796258104; bh=Am49dbJi97VkMETXts5eCQkTljXGwCbr7m6z2OpCCgk=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=D4enHHizU23+qhlxCeQnQgBaa8SxQ70RgFHXXY6cClaI+Qm6ysYfFnViGdix/FYKN pt8XsXxpCaXhWNbXAMlBNOyQBVgzeb17gWiQKucY+xtNxwZvhvxvQPQs6QtitzMN2o NKW4KlJlOBYQ52oLo1ej0qHGKUQRp7HWYUSgDDW16rPlm6aZ/tdRpYiYI06Ya+8KpP gOWeckRNudjkIZ4Pj7HK3M8Fa1/DiQ7qrs3jJrRJs7TBiTzevAQ+ttIXntCtU3kcbj Hni89oALxeEOuO7/GPQjkaLW97FghzqbPeMH3y+YacgHuIbKwUIkKZrqbD1ke52RZm AUcS/rQ8SU6XA== Date: Wed, 2 Dec 2026 16:35:00 -0800 (PST) From: Stefano Stabellini To: Denis Mukhin cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger@xenproject.org, sstabellini@kernel.org, dmukhin@xen.org Subject: Re: [XTF PATCH v1 6/6] x86: add NS16550-compatible emulator test In-Reply-To: <20261111195109.1070169-7-dmukhin@ford.com> Message-ID: References: <20261111195109.1070169-1-dmukhin@ford.com> <20261111195109.1070169-7-dmukhin@ford.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-purgate-ID: tlsNG-16d1c6/1796258106-F5C0F77B-4294E603/0/0 X-purgate-type: clean X-purgate-size: 28764 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, 11 Nov 2026, dmukhin@ford.com wrote: > From: Denis Mukhin > > Add initial test suite for NS16550-compatible emulator. > > Signed-off-by: Denis Mukhin > --- > tests/emul-ns16x50/.gitignore | 3 + > tests/emul-ns16x50/Makefile | 9 + > tests/emul-ns16x50/main.c | 644 ++++++++++++++++++++++++++++++++++ > tests/emul-ns16x50/patterns.c | 65 ++++ > 4 files changed, 721 insertions(+) > create mode 100644 tests/emul-ns16x50/.gitignore > create mode 100644 tests/emul-ns16x50/Makefile > create mode 100644 tests/emul-ns16x50/main.c > create mode 100644 tests/emul-ns16x50/patterns.c > > diff --git a/tests/emul-ns16x50/.gitignore b/tests/emul-ns16x50/.gitignore > new file mode 100644 > index 000000000000..28fbd61de7b5 > --- /dev/null > +++ b/tests/emul-ns16x50/.gitignore > @@ -0,0 +1,3 @@ > +*.swo > +*.swp > + > diff --git a/tests/emul-ns16x50/Makefile b/tests/emul-ns16x50/Makefile > new file mode 100644 > index 000000000000..11ddfc82fb74 > --- /dev/null > +++ b/tests/emul-ns16x50/Makefile > @@ -0,0 +1,9 @@ > +include $(ROOT)/build/common.mk > + > +NAME := emul-ns16x50 > +CATEGORY := functional > +TEST-ENVS := hvm64 > + > +obj-perenv += main.o patterns.o > + > +include $(ROOT)/build/gen.mk > diff --git a/tests/emul-ns16x50/main.c b/tests/emul-ns16x50/main.c > new file mode 100644 > index 000000000000..39a566d2b1d5 > --- /dev/null > +++ b/tests/emul-ns16x50/main.c > @@ -0,0 +1,644 @@ > +/** > + * Tests for NS16550-compatible emulator. > + */ > + > +#include > +#include > + > +const char test_title[] = "NS16550-compatible emulator tests"; > + > +extern const char *pattern_4096; > + > +#define COM_PORT(n,b) \ > +{ \ > + .name = n, \ > + .base = b, \ > + .reg_shift = 0, \ > + .reg_width = 1, \ > + .clk_freq = 1843200U, \ > + .baud = 115200U, \ > +} > + > +/* > + * PC COM ports. > + */ > +static const struct ns16550 com_ports[] = { > + COM_PORT("com1", 0x3f8U), > + COM_PORT("com2", 0x2f8U), > + COM_PORT("com3", 0x3e8U), > + COM_PORT("com4", 0x2e8U), > +}; > + > +static const struct ns16550 *uart; > + > +static int ns16550_parse_cmdline(const char *s) > +{ > + const char *console = "console="; > + size_t console_len = strlen(console); > + unsigned int idx; > + > + if (!s) > + return -1; > + > + /* console=com2 */ > + while ( *s && *s == ' ' ) > + s++; > + > + if ( strncmp(s, console, console_len) ) > + return -1; > + > + s += console_len; > + > + for ( idx = 0; idx < ARRAY_SIZE(com_ports); idx++ ) > + if ( !strncmp(s, com_ports[idx].name, strlen(com_ports[idx].name)) ) > + break; > + > + if ( idx == ARRAY_SIZE(com_ports) ) > + return -1; > + > + return idx; > +} > + > +void test_setup(void) > +{ > + const char *cmdline; > + int idx; > + > + if ( !IS_DEFINED(CONFIG_HVM) ) > + return xtf_skip("N/A\n"); > + > + cmdline = (const char *)(uintptr_t)pvh_start_info->cmdline_paddr; pvh_start_info can be NULL on HVM > + idx = ns16550_parse_cmdline(cmdline); > + if ( idx < 0 ) > + return xtf_failure("not configured\n"); > + > + uart = &com_ports[idx]; > + printk("Testing with %s (0x%lx)...\n", uart->name, uart->base); > + > + if ( ns16550_init(uart) ) > + return xtf_failure("failed to initialize\n"); > +} > + > +static void test_thr(const char *banner) > +{ > + uint8_t iir; > + > + ns16550_outb(uart, UART_IER, UART_IER_ETHREI); > + > + ns16550_puts(uart, pattern_4096); > + > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & (UART_IIR_NOINT | UART_IIR_THR)) == UART_IIR_NOINT ) should this be: (iir & UART_IIR_MASK) != UART_IIR_THR ? > + return xtf_failure("%s: expect UART_IIR_THR\n", banner); > + > + ns16550_outb(uart, UART_IER, 0); > +} > + > +static void test_scr(const char *banner) > +{ > + unsigned int in, out; > + > + /* Enable all interrupt reasons */ > + ns16550_outb(uart, UART_IER, > + UART_IER_ERDAI | UART_IER_ETHREI | > + UART_IER_ELSI | UART_IER_EMSI); > + > + for ( in = 0; in < 256; in++ ) > + { > + ns16550_outb(uart, UART_SCR, in); > + out = ns16550_inb(uart, UART_SCR); > + if ( in != out ) > + return xtf_failure("%s: wrote 0x%02x, read 0x%02x\n", > + banner, in, out); in and out are swapped > + } > + > + ns16550_outb(uart, UART_IER, 0); > +} > + > +static void test_lcr(const char *banner) > +{ > + static const uint8_t patterns[] = { > + 0, > + UART_LCR_WLEN8, > + UART_LCR_WLEN8 | UART_LCR_STB, > + UART_LCR_WLEN7 | UART_LCR_PE | UART_LCR_EP, > + UART_LCR_WLEN8 | UART_LCR_SB, > + UART_LCR_WLEN8 | UART_LCR_DLAB, > + 0xff, > + }; > + unsigned int i; > + > + for ( i = 0; i < ARRAY_SIZE(patterns); i++ ) > + { > + uint8_t r; > + > + ns16550_outb(uart, UART_LCR, patterns[i]); > + r = ns16550_inb(uart, UART_LCR); > + if ( r != patterns[i] ) > + xtf_failure("%s: wrote %#x, read %#x\n", > + banner, patterns[i], r); > + } > + > + ns16550_outb(uart, UART_LCR, UART_LCR_8N1); > +} > + > +static void test_ier(const char *banner) > +{ > + uint8_t in, out; > + > + /* Test valid permutations. */ > + for ( out = 0; out <= UART_IER_MASK; out++ ) > + { > + ns16550_outb(uart, UART_IER, out); > + in = ns16550_inb(uart, UART_IER); > + if ( in != out ) > + xtf_failure("%s: wrote %#x, read %#x\n", > + banner, out, in); > + } > + > + /* Ensure reserved bits are not touched. */ > + out = 0xff; > + ns16550_outb(uart, UART_IER, out); > + in = ns16550_inb(uart, UART_IER); > + if ( in != UART_IER_MASK ) > + xtf_failure("%s: wrote %x, read %#x (expected %x)\n", > + banner, out, in, UART_IER_MASK); > +} > + > +static void test_divisor_latch(const char *banner) > +{ > + /* > + * divisor = 115200 / baud > + * divisor 0 is invalid > + * > + * DLL = divisor & 0xff > + * DLM = divisor >> 8 > + */ > + static const struct { > + uint8_t dll; > + uint8_t dlm; > + } baud_rates[] = { > + { 0x00, 0x00 }, /* unsupported */ > + { 0xff, 0xff }, /* unsupported */ > + { 0x00, 0x09 }, /* 50 baud */ > + { 0x00, 0x06 }, /* 75 baud */ > + { 0x17, 0x04 }, /* 110 baud (approx) */ > + { 0x59, 0x03 }, /* 134.5 baud (approx) */ > + { 0x00, 0x03 }, /* 150 baud */ > + { 0x80, 0x01 }, /* 300 baud */ > + { 0xc0, 0x00 }, /* 600 baud */ > + { 0x60, 0x00 }, /* 1200 baud */ > + { 0x40, 0x00 }, /* 1800 baud */ > + { 0x3a, 0x00 }, /* 2000 baud (approx) */ > + { 0x30, 0x00 }, /* 2400 baud */ > + { 0x20, 0x00 }, /* 3600 baud */ > + { 0x18, 0x00 }, /* 4800 baud */ > + { 0x10, 0x00 }, /* 7200 baud */ > + { 0x0c, 0x00 }, /* 9600 baud */ > + { 0x08, 0x00 }, /* 14400 baud */ > + { 0x06, 0x00 }, /* 19200 baud */ > + { 0x04, 0x00 }, /* 28800 baud */ > + { 0x03, 0x00 }, /* 38400 baud */ > + { 0x02, 0x00 }, /* 57600 baud */ > + { 0x01, 0x00 }, /* 115200 baud */ > + }; > + unsigned i, n; > + > + /* DLAB=0 */ > + ns16550_outb(uart, UART_LCR, UART_LCR_8N1); > + /* Plant IER - that will be asserted later */ > + ns16550_outb(uart, UART_IER, UART_IER_MASK); > + > + for ( i = 0; i < ARRAY_SIZE(baud_rates); i++ ) > + { > + uint8_t dll, dlm, r; > + > + /* DLAB=1 */ > + ns16550_outb(uart, UART_LCR, UART_LCR_DLAB); > + > + /* Pre-poison to catch any cross-write. */ > + ns16550_outb(uart, UART_DLL, ~baud_rates[i].dll); > + ns16550_outb(uart, UART_DLM, ~baud_rates[i].dlm); > + > + ns16550_outb(uart, UART_DLL, baud_rates[i].dll); > + ns16550_outb(uart, UART_DLM, baud_rates[i].dlm); > + > + dll = ns16550_inb(uart, UART_DLL); > + dlm = ns16550_inb(uart, UART_DLM); > + > + if ( dll != baud_rates[i].dll || dlm != baud_rates[i].dlm ) > + xtf_failure("%s: 1st attempt failed: wrote {%#x,%#x}, read {%#x,%#x}\n", > + banner, > + baud_rates[i].dll, baud_rates[i].dlm, > + dll, dlm); > + > + /* Flip DLAB, plant THR, assert on planted IER */ > + for ( n = 0; n < 8; n++ ) > + { > + ns16550_outb(uart, UART_LCR, UART_LCR_8N1); > + > + /* THR offset is the same as DLL */ > + ns16550_outb(uart, UART_THR, '\0'); > + > + /* IER offset is the same as DLM */ > + r = ns16550_inb(uart, UART_IER); > + if ( r != UART_IER_MASK ) > + xtf_failure("%s: IER not survided DLAB flip %d: read %#x expect %#x\n", > + banner, n, r, UART_IER_MASK); > + > + ns16550_outb(uart, UART_LCR, UART_LCR_DLAB); > + } > + > + /* Check divisor latch survives */ > + dll = ns16550_inb(uart, UART_DLL); > + dlm = ns16550_inb(uart, UART_DLM); > + > + if ( dll != baud_rates[i].dll || dlm != baud_rates[i].dlm ) > + xtf_failure("%s: 2nd attempt failed: wrote {%#x,%#x}, read {%#x,%#x}\n", > + banner, > + baud_rates[i].dll, baud_rates[i].dlm, > + dll, dlm); > + > + /* DLAB=0 */ > + ns16550_outb(uart, UART_LCR, UART_LCR_8N1); > + } > +} > + > +static void test_mcr(const char *banner) > +{ > + uint8_t in, out; > + > + /* > + * Test combinations of DTR/RTS/OUT1/OUT2 except LOOP, which > + * is exercised by a separate test. > + */ > + for ( out = 0; out <= (UART_MCR_DTR | UART_MCR_RTS | > + UART_MCR_OUT1 | UART_MCR_OUT2); out++ ) > + { > + ns16550_outb(uart, UART_MCR, out); > + in = ns16550_inb(uart, UART_MCR); > + if ( in != out ) > + xtf_failure("%s: wrote %#x, read %#x\n", banner, in, out); > + } > + > + /* > + * Reserved bits must read as zero. > + */ > + ns16550_outb(uart, UART_MCR, 0xff); > + in = ns16550_inb(uart, UART_MCR); > + if ( in & ~UART_MCR_MASK ) > + xtf_failure("%s: reserved bits readable: %#x\n", banner, in); > + > + ns16550_outb(uart, UART_MCR, 0); > +} > + > +static void test_fcr_toggle(const char *banner) > +{ > + uint8_t iir; > + > + ns16550_outb(uart, UART_FCR, 0); > + iir = ns16550_inb(uart, UART_IIR); > + if ( iir & UART_IIR_FE ) > + xtf_failure("%s: IIR FIFO bits set with UART_FCR_ENABLE clear: %#x\n", > + banner, iir); > + > + ns16550_outb(uart, UART_FCR, UART_FCR_ENABLE); > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_FE) != UART_IIR_FE ) > + xtf_failure("%s: IIR FIFO bits not 0b11 with UART_FCR_ENABLE set: %#x\n", > + banner, iir); > + > + ns16550_outb(uart, UART_FCR, 0); > + iir = ns16550_inb(uart, UART_IIR); > + if ( iir & UART_IIR_FE ) > + xtf_failure("%s: IIR FIFO bits stuck after UART_FCR_ENABLE clear: %#x\n", > + banner, iir); > +} > + > +static void test_fcr_trigger(const char *banner) > +{ > + static const uint8_t levels[] = { > + UART_FCR_TRG1, > + UART_FCR_TRG4, > + UART_FCR_TRG8, > + UART_FCR_TRG14, > + }; > + unsigned int i; > + > + for ( i = 0; i < ARRAY_SIZE(levels); i++ ) > + { > + uint8_t iir; > + > + ns16550_outb(uart, UART_FCR, UART_FCR_ENABLE | levels[i]); > + iir = ns16550_inb(uart, UART_IIR); > + > +#ifdef STRICT STRICT is not defined? > + if ( !(iir & UART_IIR_NOINT) ) > + xtf_failure("%s: FCR trigger %#x raised an interrupt (IIR %#x)\n", > + banner, levels[i], iir); > +#endif > + if ( (iir & UART_IIR_FE) != UART_IIR_FE ) > + xtf_failure("%s: FIFO indication lost at trigger %#x (IIR %#x)\n", > + banner, levels[i], iir); > + } > +} > + > +static void test_fcr_clear(const char *banner) > +{ > + unsigned int i; > + uint8_t lsr; > + > + ns16550_outb(uart, UART_IER, UART_IER_MASK); > + > + for ( i = 0; i < 16; i++ ) > + { > + ns16550_outb(uart, UART_FCR, > + UART_FCR_ENABLE | UART_FCR_CLRX | UART_FCR_CLTX); > + } > + > + /* Plant a byte via loopback. */ > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP); > + ns16550_outb(uart, UART_THR, 'A'); > + > + lsr = ns16550_inb(uart, UART_LSR); > + if ( lsr & UART_LSR_DR ) > + { > + ns16550_outb(uart, UART_FCR, UART_FCR_ENABLE | UART_FCR_CLRX); > + lsr = ns16550_inb(uart, UART_LSR); > + if ( lsr & UART_LSR_DR ) > + xtf_failure("%s: DR still set after UART_FCR_CLRX (LSR %#x)\n", > + banner, lsr); > + > + ns16550_outb(uart, UART_MCR, 0); > + ns16550_outb(uart, UART_FCR, 0); > + } > + else > + { > + return xtf_failure("%s: loopback byte not delivered (LSR %#x)\n", > + banner, lsr); > + } > +} > + > +/* > + * MCR.LOOP. Data path first, then the modem path (in loopback the > + * four MCR outputs route to the four MSR inputs: DTR->DSR, RTS->CTS, > + * OUT1->RI, OUT2->DCD). > + */ > +static void test_loopback_data_path(const char *banner) > +{ > + unsigned int v; > + > + ns16550_outb(uart, UART_LCR, UART_LCR_8N1); > + ns16550_outb(uart, UART_IER, 0); > + ns16550_outb(uart, UART_FCR, UART_FCR_CLRX | UART_FCR_CLTX); Without FCR_ENABLE this doesn't clear anything on real hardware and the FIFOs are already off at this point. Same in the other places. > + /* Discard any stale delta state. */ > + ns16550_inb(uart, UART_MSR); > + > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP); > + if ( !(ns16550_inb(uart, UART_MCR) & UART_MCR_LOOP) ) > + return xtf_failure("%s: UART_MCR_LOOP did not stick\n", > + banner); > + > + for ( v = 0; v < 256; v++ ) > + { > + uint8_t lsr, r; > + > + lsr = ns16550_inb(uart, UART_LSR); > + if ( !(lsr & UART_LSR_THRE) ) > + return xtf_failure("%s: THRE clear before THR read %#x (LSR %#x)\n", > + banner, v, lsr); > + > + ns16550_outb(uart, UART_THR, v); > + > + lsr = ns16550_inb(uart, UART_LSR); > + if ( !(lsr & UART_LSR_DR) ) > + return xtf_failure("%s: DR clear after THT read %#x (LSR %#x)\n", > + banner, v, lsr); > + if ( lsr & UART_LSR_ERRORS ) > + return xtf_failure("%s: error status after THR read %#x (LSR %#x)\n", > + banner, v, lsr); > + > + r = ns16550_inb(uart, UART_RBR); > + if ( r != v ) > + return xtf_failure("%s: loopback corrupted byte: sent %#x, got %#x\n", > + banner, v, r); > + > + lsr = ns16550_inb(uart, UART_LSR); > + if ( lsr & UART_LSR_DR ) > + return xtf_failure("%s: DR still set after draining RBR (LSR %#x)\n", > + banner, lsr); > + } > +} > + > +static void test_loopback_modem_path(const char *banner) > +{ > + uint8_t msr, mask; > + > + ns16550_outb(uart, UART_LCR, UART_LCR_8N1); > + ns16550_outb(uart, UART_IER, 0); > + ns16550_outb(uart, UART_FCR, UART_FCR_CLRX | UART_FCR_CLTX); > + > + /* Discard any stale delta state. */ > + ns16550_inb(uart, UART_MSR); > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP | UART_MCR_DTR | > + UART_MCR_RTS | UART_MCR_OUT1 | > + UART_MCR_OUT2); > + > + if ( !(ns16550_inb(uart, UART_MCR) & UART_MCR_LOOP) ) > + return xtf_failure("%s: UART_MCR_LOOP did not stick\n", > + banner); > + > + msr = ns16550_inb(uart, UART_MSR); > + mask = UART_MSR_CTS | UART_MSR_DSR | UART_MSR_RI | UART_MSR_DCD | > + UART_MSR_DCTS | UART_MSR_DDSR | UART_MSR_TERI | UART_MSR_DDCD; TERI is set on the trailing edge of RI not when it is raised > + if ( msr != mask ) > + xtf_failure("%s: MSR after raising all outputs: %#x (expected %#x)\n", > + banner, msr, mask); > + > + /* The read above consumed the deltas; lines persist. */ > + msr = ns16550_inb(uart, UART_MSR); > + mask = UART_MSR_CTS | UART_MSR_DSR | UART_MSR_RI | UART_MSR_DCD; > + if ( msr != mask ) > + xtf_failure("%s: MSR deltas not cleared by read: %#x (expected %#x)\n", > + banner, msr, mask); > + > + /* > + * Drop all outputs. Lines fall, DCTS/DDSR/DDCD latch again, and > + * this time no TERI. > + */ > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP); > + > + msr = ns16550_inb(uart, UART_MSR); > + mask = UART_MSR_DCTS | UART_MSR_DDSR | UART_MSR_DDCD; > + if ( msr != mask ) > + xtf_failure("%s: MSR after dropping all outputs: %#x (expected %#x)\n", > + banner, msr, mask); > + > + msr = ns16550_inb(uart, UART_MSR); > + if ( msr ) > + xtf_failure("%s: MSR not clear after delta consumption: %#x\n", > + banner, msr); > +} > + > +static void test_iir_noint(const char *banner) > +{ > + uint8_t iir; > + > + ns16550_outb(uart, UART_FCR, UART_FCR_CLRX | UART_FCR_CLTX); > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP); > + ns16550_outb(uart, UART_IER, 0); > + ns16550_outb(uart, UART_THR, '\0'); > + > + iir = ns16550_inb(uart, UART_IIR); > + if ( !(iir & UART_IIR_NOINT) ) > + xtf_failure("%s: interrupt reported with IER == 0: IIR %#x\n", > + banner, iir); > +} > + > +static void test_iir_thr_source(const char *banner) > +{ > + uint8_t iir; > + > + ns16550_outb(uart, UART_FCR, UART_FCR_CLRX | UART_FCR_CLTX); > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP); > + > + /* > + * THR is already empty, so enabling ETHREI must immediately > + * assert the THR-empty source. > + */ > + ns16550_outb(uart, UART_IER, UART_IER_ETHREI); > + > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_MASK) != UART_IIR_THR ) > + xtf_failure("%s: THR source not asserted on ETHREI enable: IIR %#x\n", > + banner, iir); > + > + ns16550_outb(uart, UART_THR, '\0'); > + ns16550_drain_rx(uart); > + > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_MASK) != UART_IIR_THR ) > + xtf_failure("%s: THR source not regenerated by THR write: IIR %#x\n", > + banner, iir); > + > + /* Disabling ETHREI must retract the indication. */ > + ns16550_outb(uart, UART_IER, 0); > + iir = ns16550_inb(uart, UART_IIR); > + if ( !(iir & UART_IIR_NOINT) ) > + xtf_failure("%s: THR source survives ETHREI disable: IIR %#x\n", > + banner, iir); > +} > + > +static void test_iir_rda_source(const char *banner) > +{ > + uint8_t iir; > + > + ns16550_outb(uart, UART_FCR, UART_FCR_CLRX | UART_FCR_CLTX); > + ns16550_outb(uart, UART_MCR, UART_MCR_LOOP); > + ns16550_outb(uart, UART_IER, UART_IER_ERDAI); > + > + /* Nothing pending yet. */ > + iir = ns16550_inb(uart, UART_IIR); > + if ( !(iir & UART_IIR_NOINT) ) > + xtf_failure("%s: RDA asserted with no Rx data: IIR %#x\n", > + banner, iir); > + > + /* Plant a byte; RDA must assert. */ > + ns16550_outb(uart, UART_THR, '\0'); > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_MASK) != UART_IIR_RDA ) > + xtf_failure("%s: RDA not asserted with Rx data pending: IIR %#x\n", > + banner, iir); > + > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_MASK) != UART_IIR_RDA ) > + xtf_failure("%s: RDA cleared by IIR read: IIR %#x\n", > + banner, iir); > + > + ns16550_inb(uart, UART_RBR); > + iir = ns16550_inb(uart, UART_IIR); > + if ( !(iir & UART_IIR_NOINT) ) > + xtf_failure("%s: RDA not cleared by draining RBR: IIR %#x\n", > + banner, iir); > +} > + > +static void test_iir_priority(const char *banner) > +{ > + uint8_t iir; > + > + ns16550_outb(uart, UART_IER, UART_IER_ERDAI | UART_IER_ETHREI); > + ns16550_outb(uart, UART_THR, '\0'); > + > + /* > + * Priority order is LSI > RDA > timeout > THR > MSI > + */ > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_MASK) != UART_IIR_RDA ) > + xtf_failure("%s: RDA does not outrank THR: IIR %#x\n", > + banner, iir); > + > + /* > + * Drain Rx; THR-empty is still outstanding (the THR write above > + * re-armed it, and no IIR read has identified it as the source > + * while it was the highest priority), so IIR falls back to THR. > + */ > + ns16550_inb(uart, UART_RBR); > + iir = ns16550_inb(uart, UART_IIR); > + if ( (iir & UART_IIR_MASK) != UART_IIR_THR ) > + xtf_failure("%s: THR not reported after RDA drained: IIR %#x\n", > + banner, iir); > +} > + > +struct test_case { > + const char *banner; > + void (*run)(const char *banner); > +}; > + > +#define TEST_CASE(b, r) { .banner = (b), .run = (r) } > + > +static const struct test_case test_suite[] = { > + TEST_CASE("THR", test_thr), > + TEST_CASE("SCR", test_scr), > + TEST_CASE("LCR", test_lcr), > + TEST_CASE("IER", test_ier), > + TEST_CASE("DLL/DLM", test_divisor_latch), > + TEST_CASE("MCR", test_mcr), > + TEST_CASE("FCR-togggle", test_fcr_toggle), > + TEST_CASE("FCR-trigger", test_fcr_trigger), > + TEST_CASE("FCR-clear", test_fcr_clear), > + TEST_CASE("LOOPBACK-data", test_loopback_data_path), > + TEST_CASE("LOOPBACK-modem", test_loopback_modem_path), > + TEST_CASE("IIR-noint", test_iir_noint), > + TEST_CASE("IIR-thr", test_iir_thr_source), > + TEST_CASE("IIR-rda", test_iir_rda_source), > + TEST_CASE("IIR-prio", test_iir_priority), > +}; > + > +void test_main(void) > +{ > + unsigned i; > + > + for ( i = 0; i < ARRAY_SIZE(test_suite); i++ ) > + { > + const struct test_case *t = &test_suite[i]; > + > + printk(" Test: %s\n", t->banner); > + t->run(t->banner); > + } > + > + if ( !xtf_status_reported() ) > + xtf_success(NULL); > + > + xtf_report_status(); xtf_exit already does it > +} > + > +/* > + * Local variables: > + * mode: C > + * c-file-style: "BSD" > + * c-basic-offset: 4 > + * tab-width: 4 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/tests/emul-ns16x50/patterns.c b/tests/emul-ns16x50/patterns.c > new file mode 100644 > index 000000000000..b47cb6345364 > --- /dev/null > +++ b/tests/emul-ns16x50/patterns.c > @@ -0,0 +1,65 @@ > +const char *pattern_4096 = > + "The quick brown fox jumps over the lazy dog. The quick brown fox" > + " jumps over the lazy dog. The quick brown fox jumps over the laz" > + "y dog. The quick brown fox jumps over the lazy dog. The quick br" > + "own fox jumps over the lazy dog. The quick brown fox jumps over " > + "the lazy dog. The quick brown fox jumps over the lazy dog. The q" > + "uick brown fox jumps over the lazy dog. The quick brown fox jump" > + "s over the lazy dog. The quick brown fox jumps over the lazy dog" > + ". The quick brown fox jumps over the lazy dog. The quick brown f" > + "ox jumps over the lazy dog. The quick brown fox jumps over the l" > + "azy dog. The quick brown fox jumps over the lazy dog. The quick " > + "brown fox jumps over the lazy dog. The quick brown fox jumps ove" > + "r the lazy dog. The quick brown fox jumps over the lazy dog. The" > + " quick brown fox jumps over the lazy dog. The quick brown fox ju" > + "mps over the lazy dog. The quick brown fox jumps over the lazy d" > + "og. The quick brown fox jumps over the lazy dog. The quick brown" > + " fox jumps over the lazy dog. The quick brown fox jumps over the" > + " lazy dog. The quick brown fox jumps over the lazy dog. The quic" > + "k brown fox jumps over the lazy dog. The quick brown fox jumps o" > + "ver the lazy dog. The quick brown fox jumps over the lazy dog. T" > + "he quick brown fox jumps over the lazy dog. The quick brown fox " > + "jumps over the lazy dog. The quick brown fox jumps over the lazy" > + " dog. The quick brown fox jumps over the lazy dog. The quick bro" > + "wn fox jumps over the lazy dog. The quick brown fox jumps over t" > + "he lazy dog. The quick brown fox jumps over the lazy dog. The qu" > + "ick brown fox jumps over the lazy dog. The quick brown fox jumps" > + " over the lazy dog. The quick brown fox jumps over the lazy dog." > + " The quick brown fox jumps over the lazy dog. The quick brown fo" > + "x jumps over the lazy dog. The quick brown fox jumps over the la" > + "zy dog. The quick brown fox jumps over the lazy dog. The quick b" > + "rown fox jumps over the lazy dog. The quick brown fox jumps over" > + " the lazy dog. The quick brown fox jumps over the lazy dog. The " > + "quick brown fox jumps over the lazy dog. The quick brown fox jum" > + "ps over the lazy dog. The quick brown fox jumps over the lazy do" > + "g. The quick brown fox jumps over the lazy dog. The quick brown " > + "fox jumps over the lazy dog. The quick brown fox jumps over the " > + "lazy dog. The quick brown fox jumps over the lazy dog. The quick" > + " brown fox jumps over the lazy dog. The quick brown fox jumps ov" > + "er the lazy dog. The quick brown fox jumps over the lazy dog. Th" > + "e quick brown fox jumps over the lazy dog. The quick brown fox j" > + "umps over the lazy dog. The quick brown fox jumps over the lazy " > + "dog. The quick brown fox jumps over the lazy dog. The quick brow" > + "n fox jumps over the lazy dog. The quick brown fox jumps over th" > + "e lazy dog. The quick brown fox jumps over the lazy dog. The qui" > + "ck brown fox jumps over the lazy dog. The quick brown fox jumps " > + "over the lazy dog. The quick brown fox jumps over the lazy dog. " > + "The quick brown fox jumps over the lazy dog. The quick brown fox" > + " jumps over the lazy dog. The quick brown fox jumps over the laz" > + "y dog. The quick brown fox jumps over the lazy dog. The quick br" > + "own fox jumps over the lazy dog. The quick brown fox jumps over " > + "the lazy dog. The quick brown fox jumps over the lazy dog. The q" > + "uick brown fox jumps over the lazy dog. The quick brown fox jump" > + "s over the lazy dog. The quick brown fox jumps over the lazy dog" > + ". The quick brown fox jumps over the lazy dog. The quick brown f" > + "ox jumps over the lazy dog. The quick brown fox jumps over the l" > + "azy dog. The quick brown fox jumps over the lazy dog. The quick " > + "brown fox jumps over the lazy dog. The quick brown fox jumps ove" > + "r the lazy dog. The quick brown fox jumps over the lazy dog. The" > + " quick brown fox jumps over the lazy dog. The quick brown fox ju" > + "mps over the lazy dog. The quick brown fox jumps over the lazy d" > + "og. The quick brown fox jumps over the lazy dog. The quick brown" > + " fox jumps over the lazy dog. The quick brown fox jumps over the" > + " lazy dog. The quick brown fox jumps over the lazy dog. The quic" > + "k brown fox jumps over the lazy dog. The quick brown fox jumps o" > + "ver the lazy dog. The quick brown fox jumps over the lazy dog.\n"; > -- > 2.56.0 >