]> git.proxmox.com Git - qemu.git/blame - tests/tmp105-test.c
rng-egd: remove redundant free
[qemu.git] / tests / tmp105-test.c
CommitLineData
6e998903
AF
1/*
2 * QTest testcase for the TMP105 temperature sensor
3 *
4 * Copyright (c) 2012 Andreas Färber
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9#include "libqtest.h"
cc9936a3 10#include "libqos/i2c.h"
0d09e41a 11#include "hw/misc/tmp105_regs.h"
6e998903
AF
12
13#include <glib.h>
14
15#define OMAP2_I2C_1_BASE 0x48070000
16
17#define N8X0_ADDR 0x48
18
19static I2CAdapter *i2c;
20static uint8_t addr;
21
22static void send_and_receive(void)
23{
24 uint8_t cmd[3];
25 uint8_t resp[2];
26
27 cmd[0] = TMP105_REG_TEMPERATURE;
28 i2c_send(i2c, addr, cmd, 1);
29 i2c_recv(i2c, addr, resp, 2);
30 g_assert_cmpuint(((uint16_t)resp[0] << 8) | resp[1], ==, 0);
31
32 cmd[0] = TMP105_REG_CONFIG;
33 cmd[1] = 0x0; /* matches the reset value */
34 i2c_send(i2c, addr, cmd, 2);
35 i2c_recv(i2c, addr, resp, 1);
36 g_assert_cmphex(resp[0], ==, cmd[1]);
37
38 cmd[0] = TMP105_REG_T_LOW;
39 cmd[1] = 0x12;
40 cmd[2] = 0x34;
41 i2c_send(i2c, addr, cmd, 3);
42 i2c_recv(i2c, addr, resp, 2);
43 g_assert_cmphex(resp[0], ==, cmd[1]);
44 g_assert_cmphex(resp[1], ==, cmd[2]);
45
46 cmd[0] = TMP105_REG_T_HIGH;
47 cmd[1] = 0x42;
48 cmd[2] = 0x31;
49 i2c_send(i2c, addr, cmd, 3);
50 i2c_recv(i2c, addr, resp, 2);
51 g_assert_cmphex(resp[0], ==, cmd[1]);
52 g_assert_cmphex(resp[1], ==, cmd[2]);
53}
54
55int main(int argc, char **argv)
56{
57 QTestState *s = NULL;
58 int ret;
59
60 g_test_init(&argc, &argv, NULL);
61
2ad645d2 62 s = qtest_start("-machine n800");
6e998903
AF
63 i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
64 addr = N8X0_ADDR;
65
66 qtest_add_func("/tmp105/tx-rx", send_and_receive);
67
68 ret = g_test_run();
69
70 if (s) {
71 qtest_quit(s);
72 }
73 g_free(i2c);
74
75 return ret;
76}