From patchwork Mon Mar 31 16:26:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 335534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2BD61140085 for ; Tue, 1 Apr 2014 04:58:03 +1100 (EST) Received: from localhost ([::1]:50142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUf7V-00062h-CN for incoming@patchwork.ozlabs.org; Mon, 31 Mar 2014 12:31:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUf3C-0007wr-J1 for qemu-devel@nongnu.org; Mon, 31 Mar 2014 12:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUf33-0003Zo-Hr for qemu-devel@nongnu.org; Mon, 31 Mar 2014 12:27:06 -0400 Received: from mail-qa0-x230.google.com ([2607:f8b0:400d:c00::230]:32998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUf33-0003Zh-DY for qemu-devel@nongnu.org; Mon, 31 Mar 2014 12:26:57 -0400 Received: by mail-qa0-f48.google.com with SMTP id m5so8240379qaj.7 for ; Mon, 31 Mar 2014 09:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=RsrQq7pLGNkgYYCjDD8Q9Sv04G/ZOL542qAflzs4yhA=; b=z+MQsR4IBVJUxRy0Ov/T2FDZaUARfYXUJU/N+SYF30X0BXcjvYbbxZKvJvjykfrfJJ Dt1LnH/nOATB3CqDpnBShmO9wOh/lLIwCzqy3yqpu/4WFaHw2em+Kudp3uWXwPQnNkNa w1caOve/pThCdSbNFJe+TqfnQr28N2ybmk7mRTQD8WWqVjXiMkpjok0T3jW+jI6HHQFA XA41oWvrWJXrTwj3PXzaeJf2Rc4J1TyE8hIyn6e6LfTDw4oo6JaOMuMkO1OWy1F0YQx/ z85zaNWlFYSkjk4LmdlT+1m8faCV2+CWTwhwPzoQV8U9KDKNrmGdtCN2MXKGvdCeuHvh 2AXw== X-Received: by 10.224.131.132 with SMTP id x4mr3344874qas.97.1396283217023; Mon, 31 Mar 2014 09:26:57 -0700 (PDT) Received: from yakj.usersys.redhat.com (net-37-117-156-129.cust.vodafonedsl.it. [37.117.156.129]) by mx.google.com with ESMTPSA id j6sm29238827qan.37.2014.03.31.09.26.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Mar 2014 09:26:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 31 Mar 2014 18:26:33 +0200 Message-Id: <1396283195-6819-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396283195-6819-1-git-send-email-pbonzini@redhat.com> References: <1396283195-6819-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::230 Cc: peter.maydell@linaro.org, afaerber@suse.de Subject: [Qemu-devel] [PATCH for-2.0 5/7] tmp105-test: wrap simple building blocks for testing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The next patches will add more reads and writes. Add a simple testing API for this. Signed-off-by: Paolo Bonzini --- 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; -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] = 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], ==, 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]; - cmd[0] = TMP105_REG_CONFIG; - cmd[1] = 0x0; /* matches the reset value */ + cmd[0] = reg; + cmd[1] = value; i2c_send(i2c, addr, cmd, 2); i2c_recv(i2c, addr, resp, 1); g_assert_cmphex(resp[0], ==, cmd[1]); +} - cmd[0] = TMP105_REG_T_LOW; - cmd[1] = 0x12; - cmd[2] = 0x34; - i2c_send(i2c, addr, cmd, 3); - i2c_recv(i2c, addr, resp, 2); - g_assert_cmphex(resp[0], ==, cmd[1]); - g_assert_cmphex(resp[1], ==, 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]; - cmd[0] = TMP105_REG_T_HIGH; - cmd[1] = 0x42; - cmd[2] = 0x31; + cmd[0] = reg; + cmd[1] = value >> 8; + cmd[2] = value & 255; i2c_send(i2c, addr, cmd, 3); i2c_recv(i2c, addr, resp, 2); g_assert_cmphex(resp[0], ==, cmd[1]); g_assert_cmphex(resp[1], ==, cmd[2]); } + +static void send_and_receive(void) +{ + uint16_t value; + + value = tmp105_get16(i2c, addr, TMP105_REG_TEMPERATURE); + g_assert_cmpuint(value, ==, 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 = NULL;