libqos: move common i2c code to libqos

The functions to read/write 8-bit or 16-bit registers are the same
in tmp105 and pca9552 tests, and in fact they are a special case of
"read block"/"write block" functionality; read block in turn is used
in ds1338-test.

Move everything inside libqos-test, removing the duplication.  Account
for the small differences by adding to tmp105-test.c the "read register
after writing" behavior that is specific to it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2019-03-18 15:09:51 +01:00
parent 7d8ada6e4d
commit e8ecb706a8
5 changed files with 88 additions and 95 deletions

View file

@ -35,17 +35,11 @@ static inline uint8_t bcd2bin(uint8_t x)
static void send_and_receive(void)
{
uint8_t cmd[1];
uint8_t resp[7];
time_t now = time(NULL);
struct tm *tm_ptr = gmtime(&now);
/* reset the index in the RTC memory */
cmd[0] = 0;
i2c_send(i2c, addr, cmd, 1);
/* retrieve the date */
i2c_recv(i2c, addr, resp, 7);
i2c_read_block(i2c, addr, 0, resp, sizeof(resp));
/* check retrieved time againt local time */
g_assert_cmpuint(bcd2bin(resp[4]), == , tm_ptr->tm_mday);