1 /* 2 * QTest testcase for the RS5C372 RTC 3 * 4 * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> 5 * 6 * Based on ds1338-test.c 7 * 8 * SPDX-License-Identifier: GPL-2.0-or-later 9 */ 10 11 #include "qemu/osdep.h" 12 #include "qemu/bcd.h" 13 #include "libqos/i2c.h" 14 15 #define RS5C372_ADDR 0x32 16 17 static void rs5c372_read_date(void *obj, void *data, QGuestAllocator *alloc) 18 { 19 QI2CDevice *i2cdev = obj; 20 21 uint8_t resp[0x10]; 22 time_t now = time(NULL); 23 struct tm *utc = gmtime(&now); 24 25 i2c_read_block(i2cdev, 0, resp, sizeof(resp)); 26 27 /* check retrieved time against local time */ 28 g_assert_cmpuint(from_bcd(resp[5]), == , utc->tm_mday); 29 g_assert_cmpuint(from_bcd(resp[6]), == , 1 + utc->tm_mon); 30 g_assert_cmpuint(2000 + from_bcd(resp[7]), == , 1900 + utc->tm_year); 31 } 32 33 static void rs5c372_register_nodes(void) 34 { 35 QOSGraphEdgeOptions opts = { }; 36 add_qi2c_address(&opts, &(QI2CAddress) { RS5C372_ADDR }); 37 38 qos_node_create_driver("rs5c372", i2c_device_create); 39 qos_node_consumes("rs5c372", "i2c-bus", &opts); 40 qos_add_test("read_date", "rs5c372", rs5c372_read_date, NULL); 41 } 42 43 libqos_init(rs5c372_register_nodes); 44