aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-12-10 14:26:35 +0000
committerPeter Maydell <peter.maydell@linaro.org>2020-12-10 14:26:35 +0000
commit379e9eaed497a2e09b5985e1e15967d7bfea8296 (patch)
tree45cb9eff91601d0de760d40097829b0b565f934f /tests/qtest
parent00ef48ff0de9c3e5834e7e3f6691bbc80d08c114 (diff)
parent6f5f6507e49df4820207a94f3aeaaeab08092d32 (diff)
Merge remote-tracking branch 'remotes/legoater/tags/pull-aspeed-20201210' into staging
Aspeed patches : * New device model for EMC1413/EMC1414 temperature sensors (I2C) * New g220a-bmc Aspeed machine * couple of Aspeed cleanups # gpg: Signature made Thu 10 Dec 2020 11:58:10 GMT # gpg: using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1 # gpg: Good signature from "Cédric Le Goater <clg@kaod.org>" [undefined] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: A0F6 6548 F048 95EB FE6B 0B60 51A3 43C7 CFFB ECA1 * remotes/legoater/tags/pull-aspeed-20201210: aspeed: g220a-bmc: Add an FRU aspeed/smc: Add support for address lane disablement ast2600: SRAM is 89KB aspeed: Add support for the g220a-bmc board hw/misc: add an EMC141{3,4} device model Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/qtest')
-rw-r--r--tests/qtest/emc141x-test.c81
-rw-r--r--tests/qtest/meson.build1
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/qtest/emc141x-test.c b/tests/qtest/emc141x-test.c
new file mode 100644
index 0000000000..714058806a
--- /dev/null
+++ b/tests/qtest/emc141x-test.c
@@ -0,0 +1,81 @@
+/*
+ * QTest testcase for the EMC141X temperature sensor
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "libqtest-single.h"
+#include "libqos/qgraph.h"
+#include "libqos/i2c.h"
+#include "qapi/qmp/qdict.h"
+#include "hw/misc/emc141x_regs.h"
+
+#define EMC1414_TEST_ID "emc1414-test"
+
+static int qmp_emc1414_get_temperature(const char *id)
+{
+ QDict *response;
+ int ret;
+
+ response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, "
+ "'property': 'temperature0' } }", id);
+ g_assert(qdict_haskey(response, "return"));
+ ret = qdict_get_int(response, "return");
+ qobject_unref(response);
+ return ret;
+}
+
+static void qmp_emc1414_set_temperature(const char *id, int value)
+{
+ QDict *response;
+
+ response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, "
+ "'property': 'temperature0', 'value': %d } }", id, value);
+ g_assert(qdict_haskey(response, "return"));
+ qobject_unref(response);
+}
+
+static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
+{
+ uint16_t value;
+ QI2CDevice *i2cdev = (QI2CDevice *)obj;
+
+ value = qmp_emc1414_get_temperature(EMC1414_TEST_ID);
+ g_assert_cmpuint(value, ==, 0);
+
+ value = i2c_get8(i2cdev, EMC141X_TEMP_HIGH0);
+ g_assert_cmphex(value, ==, 0);
+
+ /* The default max value is 85C, 0x55=85 */
+ value = i2c_get8(i2cdev, EMC141X_TEMP_MAX_HIGH0);
+ g_assert_cmphex(value, ==, 0x55);
+
+ value = i2c_get8(i2cdev, EMC141X_TEMP_MIN_HIGH0);
+ g_assert_cmphex(value, ==, 0);
+
+ /* 3000mc = 30C */
+ qmp_emc1414_set_temperature(EMC1414_TEST_ID, 30000);
+ value = qmp_emc1414_get_temperature(EMC1414_TEST_ID);
+ g_assert_cmpuint(value, ==, 30000);
+
+ value = i2c_get8(i2cdev, EMC141X_TEMP_HIGH0);
+ g_assert_cmphex(value, ==, 30);
+
+}
+
+static void emc1414_register_nodes(void)
+{
+ QOSGraphEdgeOptions opts = {
+ .extra_device_opts = "id=" EMC1414_TEST_ID ",address=0x70"
+ };
+ add_qi2c_address(&opts, &(QI2CAddress) { 0x70 });
+
+ qos_node_create_driver("emc1414", i2c_device_create);
+ qos_node_consumes("emc1414", "i2c-bus", &opts);
+
+ qos_add_test("tx-rx", "emc1414", send_and_receive, NULL);
+}
+libqos_init(emc1414_register_nodes);
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 4ca83ce605..6a67c538be 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -189,6 +189,7 @@ qos_test_ss.add(
'sdhci-test.c',
'spapr-phb-test.c',
'tmp105-test.c',
+ 'emc141x-test.c',
'usb-hcd-ohci-test.c',
'virtio-test.c',
'virtio-blk-test.c',