Stopping and restarting the oscillator had no coverage, nor did the time the clock resumes from.
Signed-off-by: Emmanuel Blot <[email protected]> --- tests/qtest/ds1339-test.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index e9dcdc36da..ac19ebd71d 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -121,6 +121,54 @@ static void test_stopped_reserved_bits(void *obj, void *data, g_assert_cmphex(resp[6], ==, 0xff); } +/* Setting EOSC stops the oscillator and sets OSF; OSF outlives the restart. */ +static void test_eosc(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_STATUS, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, ==, 0); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + ==, DS1339_STATUS_OSF); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + ==, DS1339_STATUS_OSF); + i2c_set8(i2cdev, DS1339_STATUS, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, ==, 0); +} + +/* A stopped clock resumes from the time it was programmed with. */ +static void test_eosc_restart(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + /* 10:20:30 on the 12th of July 2031, the day counter reading 2. */ + const uint8_t tod[7] = { 0x30, 0x20, 0x10, 0x02, 0x12, 0x07, 0x31 }; + uint8_t resp[7]; + unsigned idx; + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmpmem(resp, sizeof(resp), tod, sizeof(tod)); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18); + /* The seconds counter steps within a second of the restart. */ + for (idx = 0; idx < 15 && i2c_get8(i2cdev, DS1339_SECONDS) == 0x30; idx++) { + g_usleep(100 * 1000); + } + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmpuint(from_bcd(resp[0]), >, 30); + g_assert_cmphex(resp[2], ==, 0x10); + g_assert_cmphex(resp[4], ==, 0x12); + g_assert_cmphex(resp[5] & 0x1f, ==, 0x07); + g_assert_cmphex(resp[6], ==, 0x31); +} + /* The register pointer wraps at the end of the map. */ static void test_address_wrap(void *obj, void *data, QGuestAllocator *alloc) { @@ -206,6 +254,8 @@ static void ds1339_register_nodes(void) qos_add_test("control-register", "ds1339", test_control_register, NULL); qos_add_test("status-register", "ds1339", test_status_register, NULL); qos_add_test("osf-write-protect", "ds1339", test_osf_write_protect, NULL); + qos_add_test("eosc", "ds1339", test_eosc, NULL); + qos_add_test("eosc-restart", "ds1339", test_eosc_restart, NULL); qos_add_test("stopped-reserved-bits", "ds1339", test_stopped_reserved_bits, NULL); qos_add_test("address-wrap", "ds1339", test_address_wrap, NULL); -- 2.50.1
