From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 14/17] rtc-test: cleanup register_b_set_flag test
Date: Tue, 1 Aug 2017 18:17:22 +0200 [thread overview]
Message-ID: <1501604245-33460-15-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1501604245-33460-1-git-send-email-pbonzini@redhat.com>
Introduce set_datetime_bcd/assert_datetime_bcd, and handle
UIP correctly.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
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"
+#define UIP_HOLD_LENGTH (8 * NANOSECONDS_PER_SECOND / 32768)
+
static uint8_t base = 0x70;
static int bcd2dec(int value)
@@ -297,16 +299,30 @@ static void alarm_time(void)
g_assert(cmos_read(RTC_REG_C) == 0);
}
+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);
}
#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), ==, s); \
} while(0)
+#define assert_datetime_bcd(h, min, s, d, m, y) \
+ do { \
+ g_assert_cmpint(cmos_read(RTC_HOURS), ==, h); \
+ g_assert_cmpint(cmos_read(RTC_MINUTES), ==, min); \
+ g_assert_cmpint(cmos_read(RTC_SECONDS), ==, s); \
+ g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), ==, d); \
+ g_assert_cmpint(cmos_read(RTC_MONTH), ==, m); \
+ g_assert_cmpint(cmos_read(RTC_YEAR), ==, (y & 0xFF)); \
+ g_assert_cmpint(cmos_read(RTC_CENTURY), ==, (y >> 8)); \
+ } while(0)
+
static void basic_12h_bcd(void)
{
/* set BCD 12 hour mode */
@@ -506,41 +533,30 @@ static void fuzz_registers(void)
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, ==, 0);
+
/* Enable binary-coded decimal (BCD) mode and SET flag in Register B*/
cmos_write(RTC_REG_B, REG_B_24H | REG_B_SET);
- 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);
- /* Since SET flag is still enabled, these are equality checks. */
- g_assert_cmpint(cmos_read(RTC_HOURS), ==, 0x02);
- g_assert_cmpint(cmos_read(RTC_MINUTES), ==, 0x04);
- g_assert_cmpint(cmos_read(RTC_SECONDS), ==, 0x58);
- g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), ==, 0x02);
- g_assert_cmpint(cmos_read(RTC_MONTH), ==, 0x02);
- g_assert_cmpint(cmos_read(RTC_YEAR), ==, 0x11);
- g_assert_cmpint(cmos_read(RTC_CENTURY), ==, 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);
/* Disable SET flag in Register B */
cmos_write(RTC_REG_B, cmos_read(RTC_REG_B) & ~REG_B_SET);
- g_assert_cmpint(cmos_read(RTC_HOURS), ==, 0x02);
- g_assert_cmpint(cmos_read(RTC_MINUTES), ==, 0x04);
+ assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011);
- /* 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), >=, 0x58);
- g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), ==, 0x02);
- g_assert_cmpint(cmos_read(RTC_MONTH), ==, 0x02);
- g_assert_cmpint(cmos_read(RTC_YEAR), ==, 0x11);
- g_assert_cmpint(cmos_read(RTC_CENTURY), ==, 0x20);
+ /* Since SET flag is disabled, the clock now advances. */
+ clock_step(1000000000LL);
+ assert_datetime_bcd(0x02, 0x04, 0x59, 0x02, 0x02, 0x2011);
}
#define RTC_PERIOD_CODE1 13 /* 8 Hz */
--
1.8.3.1
next prev parent reply other threads:[~2017-08-01 16:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-01 16:17 [Qemu-devel] [PULL 00/17] Misc changes for QEMU 2.10-rc1 (?) Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 01/17] vl.c/exit: pause cpus before closing block devices Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 02/17] cpu_physical_memory_sync_dirty_bitmap: Fix alignment check Paolo Bonzini
2017-08-01 17:56 ` Peter Maydell
2017-08-01 18:04 ` Dr. David Alan Gilbert
2017-08-02 7:39 ` Paolo Bonzini
2017-08-07 10:07 ` Alex Bennée
2017-08-01 16:17 ` [Qemu-devel] [PULL 03/17] accel: cleanup error output Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 04/17] char-fd: remove useless chr pointer Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 05/17] char: don't exit on hmp 'chardev-add help' Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 06/17] docs: document deprecation policy & deprecated features in appendix Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 07/17] target-i386: kvm_get/put_vcpu_events don't handle sipi_vector Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 08/17] exec: Add lock parameter to qemu_ram_ptr_length Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 09/17] bt: stop the sdp memory allocation craziness Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 10/17] qemu-options: document existance of versioned machine types Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 11/17] migration: optimize the downtime Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 12/17] hw/scsi/vmw_pvscsi: Remove the dead error handling Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 13/17] hw/scsi/vmw_pvscsi: Convert to realize Paolo Bonzini
2017-08-01 16:17 ` Paolo Bonzini [this message]
2017-08-01 16:17 ` [Qemu-devel] [PULL 15/17] rtc-test: introduce more update tests Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 16/17] mc146818rtc: simplify check_update_timer Paolo Bonzini
2017-08-01 16:17 ` [Qemu-devel] [PULL 17/17] mc146818rtc: implement UIP latching as intended Paolo Bonzini
2017-08-01 16:48 ` [Qemu-devel] [PULL 00/17] Misc changes for QEMU 2.10-rc1 (?) no-reply
2017-08-01 16:50 ` Paolo Bonzini
2017-08-01 17:10 ` Peter Maydell
2017-08-01 17:17 ` Paolo Bonzini
2017-08-01 17:22 ` Peter Maydell
2017-08-01 17:26 ` Paolo Bonzini
2017-08-01 17:56 ` Peter Maydell
2017-08-02 5:48 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1501604245-33460-15-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).