From patchwork Fri Jan 29 10:59:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 373313 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp2099434jam; Fri, 29 Jan 2021 03:18:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD4cElPWYLcq66RPh1b26CyNvd9njNUHCx2HfHdKspANrMTfc32YnZIZkOn9s4C+ivGVSb X-Received: by 2002:a25:db46:: with SMTP id g67mr5299155ybf.512.1611919092684; Fri, 29 Jan 2021 03:18:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611919092; cv=none; d=google.com; s=arc-20160816; b=aZ7aSHbsWRGI6UpnEUJKkmP65uYWUfPDoeBCALT3/8eFSa5hskxXR1KNje9bMzHQE3 PBSKaRBlncuXOwRWDWNcAIJBFF6XpEkc7I8L13gR9T0W3kCRm88KWuv2LfUekt0Kux5k w3eTfaBW7GYq7xflJ7MVE7CTAzlmDP/X+HNUkvIPbebtadOHiL8bhyoIrewK+UuQ4DjO 8uJ3iGrNWWgxKVbI8Imh8FSHN0lZC9SZU21KIU/LyxMC/2VECm/jtTO5tpvGA0fBiEoE IADLXy/Y/rZh5JCMVg3XDdeOpaDsDI9CUVmBtiYM8HiqpCNg9XxMY+bCOnD4YjLaQP4n rSLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=nplRZ0mA6SSMDFMU5PGJhWszXu30YiUjDAjM91AQhkA=; b=jvrtyXERMvqxfk+7w5quJzDY6AjRseFnXdEgPGX7BFilhanNjIUpisj4CLy1Ee6fIZ DYk5+pnQmrUcgemNxoM6ZqAELNUXfzvjCpgr198/csfJG4sbmtxGraeOF654mLifOSms d4OC4KWhsRP6BQ9Ek8c35zMPamtU4Yb4ZCHbk+NXnvX07gAnpLc/XL6ONVQnMQ3iWnia juCsjGMysNu+ainOMCJ99lnNEu+qCsJhcK/vFlDhJPHrc59xWtbeRJ+HqrzUC8/Nuion 0tI/n1IjuVtk9pJx7rFyj8a7NwXbkaPbGEq8SbgaLf82SpqYKQGmR1wjjVAWzwJp9I8Z iwtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=swBOAMvK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s4si7884523ybm.126.2021.01.29.03.18.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jan 2021 03:18:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=swBOAMvK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5Rn2-0003nh-5g for patch@linaro.org; Fri, 29 Jan 2021 06:18:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5RWF-0004qn-Pn for qemu-devel@nongnu.org; Fri, 29 Jan 2021 06:00:51 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:52192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5RW3-00073V-2z for qemu-devel@nongnu.org; Fri, 29 Jan 2021 06:00:51 -0500 Received: by mail-wm1-x32c.google.com with SMTP id m2so6510838wmm.1 for ; Fri, 29 Jan 2021 03:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=nplRZ0mA6SSMDFMU5PGJhWszXu30YiUjDAjM91AQhkA=; b=swBOAMvKaFzZos3fbUiUs/muhiKGRDc0CATH0v00uROW8po+LbhPQy139YsBrzoyoe 0RPGQVcCCbne8qsQxdk41tb2YfkFQ5dAtrN5Sz6D9lZ6aFsgcSN72CByJm0S52LpmB/s 5GIoxiHuW4EJGzqOBrMI6jIGjsunek5HEqfUvTxCedEmPmGvmjTPN/Qks7oyl5LFDGl3 ZUU/TXpE8LC0E8Q77BDqV0qGPHwEHoFd/yk67Z5aCO5LLvmLr8oUd5VzA22Xy/kfcNEa bNDFCrkHZCnGsv6jW7w+IOzcD6edlzDjUKwKTNbX4mi+OcNUPuYhSg+puDBOokFcHq30 7PMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nplRZ0mA6SSMDFMU5PGJhWszXu30YiUjDAjM91AQhkA=; b=fskpE0mCHtLRHH1Tt8J3xCpS+CMlG9z2P8jSdfSziR+LngNFXCzeIw6ieAY2oQJdgD +R93zVmEqZrrmp286MrbitsMR062pHQ376jRW5yf3Yh3WroL2C3I7uvtBJQWSCfl2r9Y R21RmTZoIDrSsRj2x3UHpTCVkxYWn9+/2Hqbg/rOlR0ovMmf3H0GCztAo6ZAHXRPSwzp BmfBdEuT5mzTDoUvIBTC1AxjV+OpMofxOwSzlHLYt8Odqa9nkKxEww3by5MqIcT6E9vJ XhJin30bUK33gUUV789y7IToFKz6cd+2+vxpwQgu2Av+XWaBmyvo5Ng9PYDtp6t0hHlu RGEg== X-Gm-Message-State: AOAM532hzH2RIMTkdJdspBTfi/wCbIRz5JRmTmFPZIrMSIlYoyyle4Od oHudeAE8BzwwKBVay3mSqW/lVeFdRZonbQ== X-Received: by 2002:a1c:7402:: with SMTP id p2mr3203865wmc.43.1611918037753; Fri, 29 Jan 2021 03:00:37 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id w20sm9268761wmm.12.2021.01.29.03.00.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 03:00:37 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 25/46] tests: Add a simple test of the CMSDK APB watchdog Date: Fri, 29 Jan 2021 10:59:51 +0000 Message-Id: <20210129110012.8660-26-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210129110012.8660-1-peter.maydell@linaro.org> References: <20210129110012.8660-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add a simple test of the CMSDK watchdog, since we're about to do some refactoring of how it is clocked. Signed-off-by: Peter Maydell Reviewed-by: Luc Michel Tested-by: Philippe Mathieu-Daudé Reviewed-by: Philippe Mathieu-Daudé Message-id: 20210128114145.20536-5-peter.maydell@linaro.org Message-id: 20210121190622.22000-5-peter.maydell@linaro.org Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/cmsdk-apb-watchdog-test.c | 79 +++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 3 files changed, 81 insertions(+) create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.c -- 2.20.1 diff --git a/tests/qtest/cmsdk-apb-watchdog-test.c b/tests/qtest/cmsdk-apb-watchdog-test.c new file mode 100644 index 00000000000..950f64c527b --- /dev/null +++ b/tests/qtest/cmsdk-apb-watchdog-test.c @@ -0,0 +1,79 @@ +/* + * QTest testcase for the CMSDK APB watchdog device + * + * Copyright (c) 2021 Linaro Limited + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" + +/* + * lm3s811evb watchdog; at board startup this runs at 200MHz / 16 == 12.5MHz, + * which is 80ns per tick. + */ +#define WDOG_BASE 0x40000000 + +#define WDOGLOAD 0 +#define WDOGVALUE 4 +#define WDOGCONTROL 8 +#define WDOGINTCLR 0xc +#define WDOGRIS 0x10 +#define WDOGMIS 0x14 +#define WDOGLOCK 0xc00 + +static void test_watchdog(void) +{ + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + + writel(WDOG_BASE + WDOGCONTROL, 1); + writel(WDOG_BASE + WDOGLOAD, 1000); + + /* Step to just past the 500th tick */ + clock_step(500 * 80 + 1); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + + /* Just past the 1000th tick: timer should have fired */ + clock_step(500 * 80); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); + + /* VALUE reloads at following tick */ + clock_step(80); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + + /* Writing any value to WDOGINTCLR clears the interrupt and reloads */ + clock_step(500 * 80); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); + writel(WDOG_BASE + WDOGINTCLR, 0); + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +} + +int main(int argc, char **argv) +{ + int r; + + g_test_init(&argc, &argv, NULL); + + qtest_start("-machine lm3s811evb"); + + qtest_add_func("/cmsdk-apb-watchdog/watchdog", test_watchdog); + + r = g_test_run(); + + qtest_end(); + + return r; +} diff --git a/MAINTAINERS b/MAINTAINERS index 6c15f7db317..3729b89f359 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -588,6 +588,7 @@ F: hw/char/cmsdk-apb-uart.c F: include/hw/char/cmsdk-apb-uart.h F: hw/watchdog/cmsdk-apb-watchdog.c F: include/hw/watchdog/cmsdk-apb-watchdog.h +F: tests/qtest/cmsdk-apb-watchdog-test.c F: hw/misc/tz-ppc.c F: include/hw/misc/tz-ppc.h F: hw/misc/tz-mpc.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 519a40d5b82..5b10bfbcfb0 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -143,6 +143,7 @@ qtests_npcm7xx = \ 'npcm7xx_watchdog_timer-test'] qtests_arm = \ (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ + (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ ['arm-cpu-features',