From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUjUQ-0006vG-6X for qemu-devel@nongnu.org; Mon, 31 Mar 2014 17:11:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUjUA-0006IA-Gx for qemu-devel@nongnu.org; Mon, 31 Mar 2014 17:11:30 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49328 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUjUA-0006Hx-9r for qemu-devel@nongnu.org; Mon, 31 Mar 2014 17:11:14 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 31 Mar 2014 23:11:00 +0200 Message-Id: <1396300262-10430-15-git-send-email-afaerber@suse.de> In-Reply-To: <1396300262-10430-1-git-send-email-afaerber@suse.de> References: <1396300262-10430-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0 14/16] tmp105-test: Wrap simple building blocks for testing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Paolo Bonzini The next patches will add more reads and writes. Add a simple testing API for this. Signed-off-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- tests/tmp105-test.c | 54 +++++++++++++++++++++++++++++++++++------------= ------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index 0834219..20a1894 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -20,39 +20,57 @@ static I2CAdapter *i2c; static uint8_t addr; =20 -static void send_and_receive(void) +static uint16_t tmp105_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg) { - uint8_t cmd[3]; uint8_t resp[2]; - - cmd[0] =3D TMP105_REG_TEMPERATURE; - i2c_send(i2c, addr, cmd, 1); + i2c_send(i2c, addr, ®, 1); i2c_recv(i2c, addr, resp, 2); - g_assert_cmpuint(((uint16_t)resp[0] << 8) | resp[1], =3D=3D, 0); + return (resp[0] << 8) | resp[1]; +} + +static void tmp105_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t value) +{ + uint8_t cmd[2]; + uint8_t resp[1]; =20 - cmd[0] =3D TMP105_REG_CONFIG; - cmd[1] =3D 0x0; /* matches the reset value */ + cmd[0] =3D reg; + cmd[1] =3D value; i2c_send(i2c, addr, cmd, 2); i2c_recv(i2c, addr, resp, 1); g_assert_cmphex(resp[0], =3D=3D, cmd[1]); +} =20 - cmd[0] =3D TMP105_REG_T_LOW; - cmd[1] =3D 0x12; - cmd[2] =3D 0x34; - i2c_send(i2c, addr, cmd, 3); - i2c_recv(i2c, addr, resp, 2); - g_assert_cmphex(resp[0], =3D=3D, cmd[1]); - g_assert_cmphex(resp[1], =3D=3D, cmd[2]); +static void tmp105_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint16_t value) +{ + uint8_t cmd[3]; + uint8_t resp[2]; =20 - cmd[0] =3D TMP105_REG_T_HIGH; - cmd[1] =3D 0x42; - cmd[2] =3D 0x31; + cmd[0] =3D reg; + cmd[1] =3D value >> 8; + cmd[2] =3D value & 255; i2c_send(i2c, addr, cmd, 3); i2c_recv(i2c, addr, resp, 2); g_assert_cmphex(resp[0], =3D=3D, cmd[1]); g_assert_cmphex(resp[1], =3D=3D, cmd[2]); } =20 + +static void send_and_receive(void) +{ + uint16_t value; + + value =3D tmp105_get16(i2c, addr, TMP105_REG_TEMPERATURE); + g_assert_cmpuint(value, =3D=3D, 0); + + /* reset */ + tmp105_set8(i2c, addr, TMP105_REG_CONFIG, 0); + + tmp105_set16(i2c, addr, TMP105_REG_T_LOW, 0x1234); + tmp105_set16(i2c, addr, TMP105_REG_T_HIGH, 0x4231); +} + int main(int argc, char **argv) { QTestState *s =3D NULL; --=20 1.8.4.5