1 /* 2 * QTest testcase for the Aspeed GPIO Controller. 3 * 4 * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) 5 * 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: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 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. 23 */ 24 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" 30 31 static bool qom_get_bool(QTestState *s, const char *path, const char *property) 32 { 33 QDict *r; 34 bool b; 35 36 r = qtest_qmp(s, "{ 'execute': 'qom-get', 'arguments': " 37 "{ 'path': %s, 'property': %s } }", path, property); 38 b = qdict_get_bool(r, "return"); 39 qobject_unref(r); 40 41 return b; 42 } 43 44 static void qom_set_bool(QTestState *s, const char *path, const char *property, 45 bool value) 46 { 47 QDict *r; 48 49 r = qtest_qmp(s, "{ 'execute': 'qom-set', 'arguments': " 50 "{ 'path': %s, 'property': %s, 'value': %i } }", 51 path, property, value); 52 qobject_unref(r); 53 } 54 55 static void test_set_colocated_pins(const void *data) 56 { 57 QTestState *s = (QTestState *)data; 58 59 /* 60 * gpioV4-7 occupy bits within a single 32-bit value, so we want to make 61 * sure that modifying one doesn't affect the other. 62 */ 63 qom_set_bool(s, "/machine/soc/gpio", "gpioV4", true); 64 qom_set_bool(s, "/machine/soc/gpio", "gpioV5", false); 65 qom_set_bool(s, "/machine/soc/gpio", "gpioV6", true); 66 qom_set_bool(s, "/machine/soc/gpio", "gpioV7", false); 67 g_assert(qom_get_bool(s, "/machine/soc/gpio", "gpioV4")); 68 g_assert(!qom_get_bool(s, "/machine/soc/gpio", "gpioV5")); 69 g_assert(qom_get_bool(s, "/machine/soc/gpio", "gpioV6")); 70 g_assert(!qom_get_bool(s, "/machine/soc/gpio", "gpioV7")); 71 } 72 73 int main(int argc, char **argv) 74 { 75 QTestState *s; 76 int r; 77 78 g_test_init(&argc, &argv, NULL); 79 80 s = qtest_init("-machine ast2600-evb"); 81 qtest_add_data_func("/ast2600/gpio/set_colocated_pins", s, 82 test_set_colocated_pins); 83 r = g_test_run(); 84 qtest_quit(s); 85 86 return r; 87 } 88