Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / qtest / aspeed_gpio-test.c
blobd38f51d71908eff866aea1b4f972529510911b9d
1 /*
2 * QTest testcase for the Aspeed GPIO Controller.
4 * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com)
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
26 #include "qemu/bitops.h"
27 #include "qemu/timer.h"
28 #include "qapi/qmp/qdict.h"
29 #include "libqtest-single.h"
31 #define AST2600_GPIO_BASE 0x1E780000
33 #define GPIO_ABCD_DATA_VALUE 0x000
34 #define GPIO_ABCD_DIRECTION 0x004
36 static void test_set_colocated_pins(const void *data)
38 QTestState *s = (QTestState *)data;
41 * gpioV4-7 occupy bits within a single 32-bit value, so we want to make
42 * sure that modifying one doesn't affect the other.
44 qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV4", true);
45 qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV5", false);
46 qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV6", true);
47 qtest_qom_set_bool(s, "/machine/soc/gpio", "gpioV7", false);
48 g_assert(qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV4"));
49 g_assert(!qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV5"));
50 g_assert(qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV6"));
51 g_assert(!qtest_qom_get_bool(s, "/machine/soc/gpio", "gpioV7"));
54 static void test_set_input_pins(const void *data)
56 QTestState *s = (QTestState *)data;
57 char name[16];
58 uint32_t value;
60 qtest_writel(s, AST2600_GPIO_BASE + GPIO_ABCD_DIRECTION, 0x00000000);
61 for (char c = 'A'; c <= 'D'; c++) {
62 for (int i = 0; i < 8; i++) {
63 sprintf(name, "gpio%c%d", c, i);
64 qtest_qom_set_bool(s, "/machine/soc/gpio", name, true);
67 value = qtest_readl(s, AST2600_GPIO_BASE + GPIO_ABCD_DATA_VALUE);
68 g_assert_cmphex(value, ==, 0xffffffff);
70 qtest_writel(s, AST2600_GPIO_BASE + GPIO_ABCD_DATA_VALUE, 0x00000000);
71 value = qtest_readl(s, AST2600_GPIO_BASE + GPIO_ABCD_DATA_VALUE);
72 g_assert_cmphex(value, ==, 0xffffffff);
75 int main(int argc, char **argv)
77 QTestState *s;
78 int r;
80 g_test_init(&argc, &argv, NULL);
82 s = qtest_init("-machine ast2600-evb");
83 qtest_add_data_func("/ast2600/gpio/set_colocated_pins", s,
84 test_set_colocated_pins);
85 qtest_add_data_func("/ast2600/gpio/set_input_pins", s, test_set_input_pins);
86 r = g_test_run();
87 qtest_quit(s);
89 return r;