From nobody Mon Feb 9 20:35:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501604420783818.3942425116112; Tue, 1 Aug 2017 09:20:20 -0700 (PDT) Received: from localhost ([::1]:43590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcZu7-0006J6-5K for importer@patchew.org; Tue, 01 Aug 2017 12:20:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcZrh-0004XU-BE for qemu-devel@nongnu.org; Tue, 01 Aug 2017 12:17:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcZrg-0007LX-Bd for qemu-devel@nongnu.org; Tue, 01 Aug 2017 12:17:49 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dcZrg-0007LD-2S for qemu-devel@nongnu.org; Tue, 01 Aug 2017 12:17:48 -0400 Received: by mail-wm0-x244.google.com with SMTP id r77so3776511wmd.2 for ; Tue, 01 Aug 2017 09:17:48 -0700 (PDT) Received: from 640k.lan (94-39-192-75.adsl-ull.clienti.tiscali.it. [94.39.192.75]) by smtp.gmail.com with ESMTPSA id u187sm1724160wmd.26.2017.08.01.09.17.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 09:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=yqoicxmgLD445rd6NIXHz3OKqLHMRZw+FF+lpctuUcE=; b=jXefNlx99H30fyTDKt8Dcuvc9F71+UDu4EUZfjtOW/QqvanMTk9lsMsJbVAghylD7F xV+RC5g4C6R9OnNdjx75/BgXFWiKWvkMbxgOOUGqXGewxYZGEVYNcjYaKnRxYsqhBFXP 7zb0bk7c8m92HW2iYFnsgFCv4z7xqyqG3c4R8aTs0tgd514MbTPxmpcVhBEttla9O3WB GivG7Wnj95h9ahunT/MMPiLMaJn/GFdbYcPPo2/O9gp1AoOSYZHfrJebPp8OcrYm47Lr I+wdZBFuQ87YaOvzKcslmytsjzSJtqabeCl588p1YzV+bZ8DmwexMult+CMLflQfSCCH jkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=yqoicxmgLD445rd6NIXHz3OKqLHMRZw+FF+lpctuUcE=; b=WqYgop+BNEj4XzGqtQLAmYYGB97LkS/aUfs/URUyvZSWw5LsGxnw9Rf83ApluZCLSO oJ6207iZJco5S/WBIkXcnmTMj41e/18jsGVe/sk2a4eU+k3svJW1UWCGYP6dWNIfrw4R O1CzsN8sng+jJEidifw8MMol7S+FCYgcX8J+/B0qWt+ys72ioLYCWQ8Xp4T1PL+EVP1W 1Ive3ywyIT/OJBzWtk/jdo6+AhEEz52MPwGUaMpYybe2ZHWcLLC3aqQqhAUESy7gOmpY B2CbzmuE5kk+aekkdhP8hHZT//VJDhUPu6s3Y0/gSj9syT0qnaGn6FTs4tUfPRwf6B2R u9cw== X-Gm-Message-State: AIVw111a5QP0c7byzz3nV3frJYLmiXfKQc5d0Vcj2kHVjzSyOkNohLOO ydlN9oA9Pc8Z0pKWyow= X-Received: by 10.28.49.134 with SMTP id x128mr1796023wmx.111.1501604266743; Tue, 01 Aug 2017 09:17:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 1 Aug 2017 18:17:22 +0200 Message-Id: <1501604245-33460-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1501604245-33460-1-git-send-email-pbonzini@redhat.com> References: <1501604245-33460-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 14/17] rtc-test: cleanup register_b_set_flag test 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce set_datetime_bcd/assert_datetime_bcd, and handle UIP correctly. Signed-off-by: Paolo Bonzini --- tests/rtc-test.c | 76 ++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/tests/rtc-test.c b/tests/rtc-test.c index e78f701..798cf5e 100644 --- a/tests/rtc-test.c +++ b/tests/rtc-test.c @@ -17,6 +17,8 @@ #include "qemu/timer.h" #include "hw/timer/mc146818rtc_regs.h" =20 +#define UIP_HOLD_LENGTH (8 * NANOSECONDS_PER_SECOND / 32768) + static uint8_t base =3D 0x70; =20 static int bcd2dec(int value) @@ -297,16 +299,30 @@ static void alarm_time(void) g_assert(cmos_read(RTC_REG_C) =3D=3D 0); } =20 +static void set_time_regs(int h, int m, int s) +{ + cmos_write(RTC_HOURS, h); + cmos_write(RTC_MINUTES, m); + cmos_write(RTC_SECONDS, s); +} + static void set_time(int mode, int h, int m, int s) { - /* set BCD 12 hour mode */ cmos_write(RTC_REG_B, mode); - cmos_write(RTC_REG_A, 0x76); + set_time_regs(h, m, s); + cmos_write(RTC_REG_A, 0x26); +} + +static void set_datetime_bcd(int h, int min, int s, int d, int m, int y) +{ cmos_write(RTC_HOURS, h); - cmos_write(RTC_MINUTES, m); + cmos_write(RTC_MINUTES, min); cmos_write(RTC_SECONDS, s); - cmos_write(RTC_REG_A, 0x26); + cmos_write(RTC_YEAR, y & 0xFF); + cmos_write(RTC_CENTURY, y >> 8); + cmos_write(RTC_MONTH, m); + cmos_write(RTC_DAY_OF_MONTH, d); } =20 #define assert_time(h, m, s) \ @@ -316,6 +332,17 @@ static void set_time(int mode, int h, int m, int s) g_assert_cmpint(cmos_read(RTC_SECONDS), =3D=3D, s); \ } while(0) =20 +#define assert_datetime_bcd(h, min, s, d, m, y) \ + do { \ + g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, h); \ + g_assert_cmpint(cmos_read(RTC_MINUTES), =3D=3D, min); \ + g_assert_cmpint(cmos_read(RTC_SECONDS), =3D=3D, s); \ + g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), =3D=3D, d); \ + g_assert_cmpint(cmos_read(RTC_MONTH), =3D=3D, m); \ + g_assert_cmpint(cmos_read(RTC_YEAR), =3D=3D, (y & 0xFF)); \ + g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, (y >> 8)); \ + } while(0) + static void basic_12h_bcd(void) { /* set BCD 12 hour mode */ @@ -506,41 +533,30 @@ static void fuzz_registers(void) =20 static void register_b_set_flag(void) { + if (cmos_read(RTC_REG_A) & REG_A_UIP) { + clock_step(UIP_HOLD_LENGTH + NANOSECONDS_PER_SECOND / 5); + } + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, =3D=3D, 0); + /* Enable binary-coded decimal (BCD) mode and SET flag in Register B*/ cmos_write(RTC_REG_B, REG_B_24H | REG_B_SET); =20 - cmos_write(RTC_REG_A, 0x76); - cmos_write(RTC_YEAR, 0x11); - cmos_write(RTC_CENTURY, 0x20); - cmos_write(RTC_MONTH, 0x02); - cmos_write(RTC_DAY_OF_MONTH, 0x02); - cmos_write(RTC_HOURS, 0x02); - cmos_write(RTC_MINUTES, 0x04); - cmos_write(RTC_SECONDS, 0x58); - cmos_write(RTC_REG_A, 0x26); + set_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); =20 - /* Since SET flag is still enabled, these are equality checks. */ - g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MINUTES), =3D=3D, 0x04); - g_assert_cmpint(cmos_read(RTC_SECONDS), =3D=3D, 0x58); - g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_YEAR), =3D=3D, 0x11); - g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, 0x20); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + /* Since SET flag is still enabled, time does not advance. */ + clock_step(1000000000LL); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); =20 /* Disable SET flag in Register B */ cmos_write(RTC_REG_B, cmos_read(RTC_REG_B) & ~REG_B_SET); =20 - g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MINUTES), =3D=3D, 0x04); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); =20 - /* Since SET flag is disabled, this is an inequality check. - * We (reasonably) assume that no (sexagesimal) overflow occurs. */ - g_assert_cmpint(cmos_read(RTC_SECONDS), >=3D, 0x58); - g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_YEAR), =3D=3D, 0x11); - g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, 0x20); + /* Since SET flag is disabled, the clock now advances. */ + clock_step(1000000000LL); + assert_datetime_bcd(0x02, 0x04, 0x59, 0x02, 0x02, 0x2011); } =20 #define RTC_PERIOD_CODE1 13 /* 8 Hz */ --=20 1.8.3.1