qtest: add rtc periodic timer test

It tests the accuracy of rtc periodic timer which is recently
improved & fixed by commit 7ffcb539a3 ("mc146818rtc: precisely count
the clock for periodic timer", 2017-05-19).

Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
Message-Id: <20170527025301.23499-1-xiaoguangrong@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Xiao Guangrong 2017-05-27 10:53:01 +08:00 committed by Paolo Bonzini
parent e0c8b950d1
commit bd618eab76
3 changed files with 72 additions and 12 deletions

View file

@ -65,4 +65,24 @@
#define REG_C_AF 0x20
#define REG_C_MASK 0x70
static inline uint32_t periodic_period_to_clock(int period_code)
{
if (!period_code) {
return 0;
}
if (period_code <= 2) {
period_code += 7;
}
/* period in 32 Khz cycles */
return 1 << (period_code - 1);
}
#define RTC_CLOCK_RATE 32768
static inline int64_t periodic_clock_to_ns(int64_t clocks)
{
return muldiv64(clocks, NANOSECONDS_PER_SECOND, RTC_CLOCK_RATE);
}
#endif