1*2ec06378SPeter Delevoryas /* 2*2ec06378SPeter Delevoryas * QTest testcase for the Aspeed GPIO Controller. 3*2ec06378SPeter Delevoryas * 4*2ec06378SPeter Delevoryas * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) 5*2ec06378SPeter Delevoryas * 6*2ec06378SPeter Delevoryas * Permission is hereby granted, free of charge, to any person obtaining a copy 7*2ec06378SPeter Delevoryas * of this software and associated documentation files (the "Software"), to deal 8*2ec06378SPeter Delevoryas * in the Software without restriction, including without limitation the rights 9*2ec06378SPeter Delevoryas * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10*2ec06378SPeter Delevoryas * copies of the Software, and to permit persons to whom the Software is 11*2ec06378SPeter Delevoryas * furnished to do so, subject to the following conditions: 12*2ec06378SPeter Delevoryas * 13*2ec06378SPeter Delevoryas * The above copyright notice and this permission notice shall be included in 14*2ec06378SPeter Delevoryas * all copies or substantial portions of the Software. 15*2ec06378SPeter Delevoryas * 16*2ec06378SPeter Delevoryas * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*2ec06378SPeter Delevoryas * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*2ec06378SPeter Delevoryas * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19*2ec06378SPeter Delevoryas * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*2ec06378SPeter Delevoryas * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21*2ec06378SPeter Delevoryas * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22*2ec06378SPeter Delevoryas * THE SOFTWARE. 23*2ec06378SPeter Delevoryas */ 24*2ec06378SPeter Delevoryas 25*2ec06378SPeter Delevoryas #include "qemu/osdep.h" 26*2ec06378SPeter Delevoryas #include "qemu/bitops.h" 27*2ec06378SPeter Delevoryas #include "qemu/timer.h" 28*2ec06378SPeter Delevoryas #include "qapi/qmp/qdict.h" 29*2ec06378SPeter Delevoryas #include "libqtest-single.h" 30*2ec06378SPeter Delevoryas 31*2ec06378SPeter Delevoryas static bool qom_get_bool(QTestState *s, const char *path, const char *property) 32*2ec06378SPeter Delevoryas { 33*2ec06378SPeter Delevoryas QDict *r; 34*2ec06378SPeter Delevoryas bool b; 35*2ec06378SPeter Delevoryas 36*2ec06378SPeter Delevoryas r = qtest_qmp(s, "{ 'execute': 'qom-get', 'arguments': " 37*2ec06378SPeter Delevoryas "{ 'path': %s, 'property': %s } }", path, property); 38*2ec06378SPeter Delevoryas b = qdict_get_bool(r, "return"); 39*2ec06378SPeter Delevoryas qobject_unref(r); 40*2ec06378SPeter Delevoryas 41*2ec06378SPeter Delevoryas return b; 42*2ec06378SPeter Delevoryas } 43*2ec06378SPeter Delevoryas 44*2ec06378SPeter Delevoryas static void qom_set_bool(QTestState *s, const char *path, const char *property, 45*2ec06378SPeter Delevoryas bool value) 46*2ec06378SPeter Delevoryas { 47*2ec06378SPeter Delevoryas QDict *r; 48*2ec06378SPeter Delevoryas 49*2ec06378SPeter Delevoryas r = qtest_qmp(s, "{ 'execute': 'qom-set', 'arguments': " 50*2ec06378SPeter Delevoryas "{ 'path': %s, 'property': %s, 'value': %i } }", 51*2ec06378SPeter Delevoryas path, property, value); 52*2ec06378SPeter Delevoryas qobject_unref(r); 53*2ec06378SPeter Delevoryas } 54*2ec06378SPeter Delevoryas 55*2ec06378SPeter Delevoryas static void test_set_colocated_pins(const void *data) 56*2ec06378SPeter Delevoryas { 57*2ec06378SPeter Delevoryas QTestState *s = (QTestState *)data; 58*2ec06378SPeter Delevoryas 59*2ec06378SPeter Delevoryas /* 60*2ec06378SPeter Delevoryas * gpioV4-7 occupy bits within a single 32-bit value, so we want to make 61*2ec06378SPeter Delevoryas * sure that modifying one doesn't affect the other. 62*2ec06378SPeter Delevoryas */ 63*2ec06378SPeter Delevoryas qom_set_bool(s, "/machine/soc/gpio", "gpioV4", true); 64*2ec06378SPeter Delevoryas qom_set_bool(s, "/machine/soc/gpio", "gpioV5", false); 65*2ec06378SPeter Delevoryas qom_set_bool(s, "/machine/soc/gpio", "gpioV6", true); 66*2ec06378SPeter Delevoryas qom_set_bool(s, "/machine/soc/gpio", "gpioV7", false); 67*2ec06378SPeter Delevoryas g_assert(qom_get_bool(s, "/machine/soc/gpio", "gpioV4")); 68*2ec06378SPeter Delevoryas g_assert(!qom_get_bool(s, "/machine/soc/gpio", "gpioV5")); 69*2ec06378SPeter Delevoryas g_assert(qom_get_bool(s, "/machine/soc/gpio", "gpioV6")); 70*2ec06378SPeter Delevoryas g_assert(!qom_get_bool(s, "/machine/soc/gpio", "gpioV7")); 71*2ec06378SPeter Delevoryas } 72*2ec06378SPeter Delevoryas 73*2ec06378SPeter Delevoryas int main(int argc, char **argv) 74*2ec06378SPeter Delevoryas { 75*2ec06378SPeter Delevoryas QTestState *s; 76*2ec06378SPeter Delevoryas int r; 77*2ec06378SPeter Delevoryas 78*2ec06378SPeter Delevoryas g_test_init(&argc, &argv, NULL); 79*2ec06378SPeter Delevoryas 80*2ec06378SPeter Delevoryas s = qtest_init("-machine ast2600-evb"); 81*2ec06378SPeter Delevoryas qtest_add_data_func("/ast2600/gpio/set_colocated_pins", s, 82*2ec06378SPeter Delevoryas test_set_colocated_pins); 83*2ec06378SPeter Delevoryas r = g_test_run(); 84*2ec06378SPeter Delevoryas qtest_quit(s); 85*2ec06378SPeter Delevoryas 86*2ec06378SPeter Delevoryas return r; 87*2ec06378SPeter Delevoryas } 88