The clock-halt bit had no coverage, nor did its effect on the oscillator-stop flag.
Signed-off-by: Emmanuel Blot <[email protected]> --- tests/qtest/ds1338-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index fad0ca53d4..1b73dca98d 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -32,6 +32,7 @@ #define DS1338_CTRL_OSF 0x20 #define DS1338_CTRL_POR 0xb3 +#define DS1338_SEC_CH 0x80 /* The clock and calendar come up on the host time. */ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) @@ -85,6 +86,42 @@ static void test_osf_write_protect(void *obj, void *data, g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, ==, 0); } +/* Halting the clock freezes the counters; clearing the halt resumes them. */ +static void test_clock_halt(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + uint8_t frozen[7], again[7]; + unsigned idx; + + /* Clear OSF first, so that halting the clock is what sets it again. */ + i2c_set8(i2cdev, DS1338_CONTROL, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, ==, 0); + + i2c_set8(i2cdev, DS1338_SECONDS, DS1338_SEC_CH | 0x30); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_SECONDS), ==, + DS1338_SEC_CH | 0x30); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, + ==, DS1338_CTRL_OSF); + + i2c_read_block(i2cdev, DS1338_SECONDS, frozen, sizeof(frozen)); + g_usleep(1200 * 1000); + i2c_read_block(i2cdev, DS1338_SECONDS, again, sizeof(again)); + g_assert_cmpmem(frozen, sizeof(frozen), again, sizeof(again)); + + i2c_set8(i2cdev, DS1338_SECONDS, 0x30); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_SECONDS) & DS1338_SEC_CH, ==, 0); + for (idx = 0; idx < 50; idx++) { + if (i2c_get8(i2cdev, DS1338_SECONDS) != 0x30) { + break; + } + g_usleep(100 * 1000); + } + g_assert_cmpuint(from_bcd(i2c_get8(i2cdev, DS1338_SECONDS)), >, 30); + + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, + ==, DS1338_CTRL_OSF); +} + /* The user RAM returns what the guest wrote to it. */ static void test_nvram(void *obj, void *data, QGuestAllocator *alloc) { @@ -122,6 +159,7 @@ static void ds1338_register_nodes(void) qos_add_test("reset-defaults", "ds1338", test_reset_defaults, NULL); qos_add_test("control-register", "ds1338", test_control_register, NULL); qos_add_test("osf-write-protect", "ds1338", test_osf_write_protect, NULL); + qos_add_test("clock-halt", "ds1338", test_clock_halt, NULL); qos_add_test("nvram", "ds1338", test_nvram, NULL); qos_add_test("address-wrap", "ds1338", test_address_wrap, NULL); } -- 2.50.1
