From patchwork Mon Mar 20 14:38:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9634317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 61B786020B for ; Mon, 20 Mar 2017 14:41:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53B4A27CF3 for ; Mon, 20 Mar 2017 14:41:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4820527F17; Mon, 20 Mar 2017 14:41:12 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B67D427CF3 for ; Mon, 20 Mar 2017 14:41:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpySb-0001M4-Hg; Mon, 20 Mar 2017 14:39:01 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpySZ-0001Li-W4 for xen-devel@lists.xenproject.org; Mon, 20 Mar 2017 14:39:00 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id DD/B6-01936-389EFC85; Mon, 20 Mar 2017 14:38:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrrBXrfp5fk Ig4sbLC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxLJ7cxFjxTrZjc+Jy1gXGCXBcjJ4eEgL/E m08LWUFsNgEDiRXTrzJ2MXJwiAioSNzeawASZhaIkvh08yE7iC0soCPxfOtURhCbRUBVYva9N 2CtvAJ2Er//nWOCGCkvsWjTDBYQm1PAXmJV5xQwWwioZt/K2UwQtprEjYXLWCB6BSVOznzCAr FLQuLgixfMExh5ZyFJzUKSWsDItIpRvTi1qCy1SNdCL6koMz2jJDcxM0fX0MBULze1uDgxPTU nMalYLzk/dxMjMHAYgGAH48Fm50OMkhxMSqK8KoInIoT4kvJTKjMSizPii0pzUosPMcpwcChJ 8N4IAMoJFqWmp1akZeYAQxgmLcHBoyTC2xoIlOYtLkjMLc5Mh0idYlSUEud9CNInAJLIKM2Da 4PFzSVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ834FmcKTmVcCN/0V0GImoMWJP4+ALC5JRE hJNTBO4pA50cEukiV3O/zwkx0f/1lOvWm1Wu15QleuZ2zL8s9f22L7Vuq3BD45mfNnd82rF3P qqmJUZSdGPRDvj+06F3nOJOHDpI+3/yy6HnXVvf3R02eBiuGctnlcDLv2Gkqb1N1pKRI/7bCd W6SifcKNPw0bp7m938GzPn9i1rTJ2tHbLlkfNPdTYinOSDTUYi4qTgQARsW0CZYCAAA= X-Env-Sender: prvs=2458ceb18=anthony.perard@citrix.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1490020736!90275121!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9976 invoked from network); 20 Mar 2017 14:38:58 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-8.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 20 Mar 2017 14:38:58 -0000 X-IronPort-AV: E=Sophos;i="5.36,194,1486425600"; d="scan'208";a="423820547" From: Anthony PERARD To: Date: Mon, 20 Mar 2017 14:38:46 +0000 Message-ID: <20170320143846.21234-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170320143846.21234-1-anthony.perard@citrix.com> References: <20170320143846.21234-1-anthony.perard@citrix.com> MIME-Version: 1.0 Cc: Anthony PERARD , Andrew Cooper Subject: [Xen-devel] [PATCH 2/2] Add vlapic timer checks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anthony PERARD --- tests/vlapic-timer/Makefile | 9 +++ tests/vlapic-timer/main.c | 131 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 tests/vlapic-timer/Makefile create mode 100644 tests/vlapic-timer/main.c diff --git a/tests/vlapic-timer/Makefile b/tests/vlapic-timer/Makefile new file mode 100644 index 0000000..01fa4ea --- /dev/null +++ b/tests/vlapic-timer/Makefile @@ -0,0 +1,9 @@ +include $(ROOT)/build/common.mk + +NAME := vlapic-timer +CATEGORY := functional +TEST-ENVS := $(HVM_ENVIRONMENTS) + +obj-perenv += main.o + +include $(ROOT)/build/gen.mk diff --git a/tests/vlapic-timer/main.c b/tests/vlapic-timer/main.c new file mode 100644 index 0000000..b081661 --- /dev/null +++ b/tests/vlapic-timer/main.c @@ -0,0 +1,131 @@ +/** + * @file tests/vlapic-timer/main.c + * @ref test-vlapic-timer - LAPIC Timer Emulation + * + * @page test-vlapic-timer LAPIC Timer Emulation + * + * Tests the behavior of the vlapic timer emulation by Xen. + * + * This tests should work on baremetal. + * + * It is testing switch between different mode, one-shot and periodic. + * + * @see tests/vlapic-timer/main.c + */ +#include +#include +#include + +const char test_title[] = "Test vlapic-timer"; + +static inline void apic_write(unsigned long reg, uint32_t v) +{ + *((volatile uint32_t *)(APIC_BASE + reg)) = v; +} + +static inline uint32_t apic_read(unsigned long reg) +{ + return *((volatile uint32_t *)(APIC_BASE + reg)); +} + +static inline void change_mode(unsigned long new_mode) +{ + uint32_t lvtt; + + lvtt = apic_read(APIC_LVTT); + apic_write(APIC_LVTT, (lvtt & ~APIC_TIMER_MODE_MASK) | new_mode); +} + +void wait_until_tmcct_is_zero(uint32_t initial_count, bool stop_when_half) +{ + uint32_t tmcct = apic_read(APIC_TMCCT); + + if ( tmcct ) + { + while ( tmcct > (initial_count / 2) ) + tmcct = apic_read(APIC_TMCCT); + + if ( stop_when_half ) + return; + + /* Wait until the counter reach 0 or wrap-around */ + while ( tmcct <= (initial_count / 2) && tmcct > 0 ) + tmcct = apic_read(APIC_TMCCT); + } +} + +void test_main(void) +{ + uint32_t tmict = 0x999999; + + apic_write(APIC_TMICT, tmict); + /* + * Assuming that the initial mode is one-shot, change it to periodic. TMICT + * should not be reset. + */ + change_mode(APIC_TIMER_MODE_PERIODIC); + if ( apic_read(APIC_TMICT) != tmict ) + xtf_failure("Fail: TMICT value reset\n"); + + /* Testing one-shot */ + printk("Testing one-shot mode\n"); + change_mode(APIC_TIMER_MODE_ONESHOT); + apic_write(APIC_TMICT, tmict); + if ( !apic_read(APIC_TMCCT) ) + xtf_failure("Fail: TMCCT should have a non-zero value\n"); + wait_until_tmcct_is_zero(tmict, false); + if ( apic_read(APIC_TMCCT) ) + xtf_failure("Fail: TMCCT should have reached 0\n"); + + /* + * Write TMICT before changing mode from one-shot to periodic TMCCT should + * be reset to TMICT periodicly + */ + apic_write(APIC_TMICT, tmict); + wait_until_tmcct_is_zero(tmict, true); + printk("Testing periodic mode\n"); + change_mode(APIC_TIMER_MODE_PERIODIC); + if ( !apic_read(APIC_TMCCT) ) + xtf_failure("Fail: TMCCT should have a non-zero value\n"); + /* + * After the change of mode, the counter should not be reset and continue + * counting down from where it was + */ + if ( apic_read(APIC_TMCCT) > (tmict / 2) ) + xtf_failure("Fail: TMCCT should not be reset to TMICT value\n"); + wait_until_tmcct_is_zero(tmict, false); + if ( apic_read(APIC_TMCCT) < (tmict / 2) ) + xtf_failure("Fail: TMCCT should be reset to the initial-count\n"); + + wait_until_tmcct_is_zero(tmict, true); + /* + * Keep the same TMICT and change timer mode to one-shot + * TMCCT should be > 0 and count-down to 0 + */ + printk("Testing one-shot after periodic (no tmict reset)\n"); + change_mode(APIC_TIMER_MODE_ONESHOT); + if ( !apic_read(APIC_TMCCT) ) + xtf_failure("Fail: TMCCT should have a non-zero value\n"); + if ( apic_read(APIC_TMCCT) > (tmict / 2) ) + xtf_failure("Fail: TMCCT should not be reset to init\n"); + wait_until_tmcct_is_zero(tmict, false); + if ( apic_read(APIC_TMCCT) ) + xtf_failure("Fail: TMCCT should have reach zero\n"); + + /* now tmcct == 0 and tmict != 0 */ + change_mode(APIC_TIMER_MODE_PERIODIC); + if ( apic_read(APIC_TMCCT) ) + xtf_failure("Fail: TMCCT should stay at zero\n"); + + xtf_success(NULL); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */