2 * QTest testcase for the EMC141X temperature sensor
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
8 #include "qemu/osdep.h"
10 #include "libqtest-single.h"
11 #include "libqos/qgraph.h"
12 #include "libqos/i2c.h"
13 #include "qapi/qmp/qdict.h"
14 #include "hw/misc/emc141x_regs.h"
16 #define EMC1414_TEST_ID "emc1414-test"
18 static int qmp_emc1414_get_temperature(const char *id
)
23 response
= qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, "
24 "'property': 'temperature0' } }", id
);
25 g_assert(qdict_haskey(response
, "return"));
26 ret
= qdict_get_int(response
, "return");
27 qobject_unref(response
);
31 static void qmp_emc1414_set_temperature(const char *id
, int value
)
35 response
= qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, "
36 "'property': 'temperature0', 'value': %d } }", id
, value
);
37 g_assert(qdict_haskey(response
, "return"));
38 qobject_unref(response
);
41 static void send_and_receive(void *obj
, void *data
, QGuestAllocator
*alloc
)
44 QI2CDevice
*i2cdev
= (QI2CDevice
*)obj
;
46 value
= qmp_emc1414_get_temperature(EMC1414_TEST_ID
);
47 g_assert_cmpuint(value
, ==, 0);
49 value
= i2c_get8(i2cdev
, EMC141X_TEMP_HIGH0
);
50 g_assert_cmphex(value
, ==, 0);
52 /* The default max value is 85C, 0x55=85 */
53 value
= i2c_get8(i2cdev
, EMC141X_TEMP_MAX_HIGH0
);
54 g_assert_cmphex(value
, ==, 0x55);
56 value
= i2c_get8(i2cdev
, EMC141X_TEMP_MIN_HIGH0
);
57 g_assert_cmphex(value
, ==, 0);
60 qmp_emc1414_set_temperature(EMC1414_TEST_ID
, 30000);
61 value
= qmp_emc1414_get_temperature(EMC1414_TEST_ID
);
62 g_assert_cmpuint(value
, ==, 30000);
64 value
= i2c_get8(i2cdev
, EMC141X_TEMP_HIGH0
);
65 g_assert_cmphex(value
, ==, 30);
69 static void emc1414_register_nodes(void)
71 QOSGraphEdgeOptions opts
= {
72 .extra_device_opts
= "id=" EMC1414_TEST_ID
",address=0x70"
74 add_qi2c_address(&opts
, &(QI2CAddress
) { 0x70 });
76 qos_node_create_driver("emc1414", i2c_device_create
);
77 qos_node_consumes("emc1414", "i2c-bus", &opts
);
79 qos_add_test("tx-rx", "emc1414", send_and_receive
, NULL
);
81 libqos_init(emc1414_register_nodes
);