|
| 1 | +/* |
| 2 | + mini404_dwarf_input_test.c - Test cases for the dwarf input peripheral. |
| 3 | +
|
| 4 | + Copyright (C) 2024 VintagePC <https://github.com/vintagepc> |
| 5 | +
|
| 6 | + This file is part of Mini404. |
| 7 | +
|
| 8 | + Mini404 is free software: you can redistribute it and/or modify |
| 9 | + it under the terms of the GNU General Public License as published by |
| 10 | + the Free Software Foundation, either version 3 of the License, or |
| 11 | + (at your option) any later version. |
| 12 | +
|
| 13 | + Mini404 is distributed in the hope that it will be useful, |
| 14 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + GNU General Public License for more details. |
| 17 | +
|
| 18 | + You should have received a copy of the GNU General Public License |
| 19 | + along with Mini404. If not, see <http://www.gnu.org/licenses/>. |
| 20 | +*/ |
| 21 | + |
| 22 | +#include "qemu/osdep.h" |
| 23 | +#include "libqtest-single.h" |
| 24 | + |
| 25 | +#define QOM_PATH "/machine/peripheral/dwarf-input" |
| 26 | +#define TEST_PREFIX "/mini404/parts/dward-input/" |
| 27 | +#define MACHINE "prusa-xl-extruder-040-0" |
| 28 | + |
| 29 | +static void test_key_control(void) |
| 30 | +{ |
| 31 | + /* Test code goes here */ |
| 32 | + QTestState *ts = qtest_init("-machine " MACHINE); |
| 33 | + qtest_irq_intercept_out(ts, QOM_PATH); |
| 34 | + /* Assertions and other test logic */ |
| 35 | + |
| 36 | + g_free(qtest_hmp(ts, "system_reset")); |
| 37 | + |
| 38 | + // Check start state |
| 39 | + g_assert_true(qtest_get_irq(ts, 0)); |
| 40 | + g_assert_true(qtest_get_irq(ts, 1)); |
| 41 | + |
| 42 | + g_free(qtest_hmp(ts, "sendkey w")); |
| 43 | + g_assert_false(qtest_get_irq(ts, 0)); |
| 44 | + g_assert_true(qtest_get_irq(ts, 1)); |
| 45 | + |
| 46 | + qtest_clock_step(ts, 101 * 1E6); // 100ms default hold-time |
| 47 | + g_assert_true(qtest_get_irq(ts, 0)); |
| 48 | + g_assert_true(qtest_get_irq(ts, 1)); |
| 49 | + |
| 50 | + g_free(qtest_hmp(ts, "sendkey s")); |
| 51 | + |
| 52 | + g_assert_true(qtest_get_irq(ts, 0)); |
| 53 | + g_assert_false(qtest_get_irq(ts, 1)); |
| 54 | + |
| 55 | + qtest_clock_step(ts, 100 * 1E6); // 100ms default hold-time |
| 56 | + |
| 57 | + g_assert_true(qtest_get_irq(ts, 0)); |
| 58 | + g_assert_true(qtest_get_irq(ts, 1)); |
| 59 | + |
| 60 | + qtest_quit(ts); |
| 61 | +} |
| 62 | + |
| 63 | +static void test_reset(void) |
| 64 | +{ |
| 65 | + /* Test code goes here */ |
| 66 | + QTestState *ts = qtest_init("-machine " MACHINE); |
| 67 | + qtest_irq_intercept_out(ts, QOM_PATH); |
| 68 | + /* Assertions and other test logic */ |
| 69 | + |
| 70 | + g_free(qtest_hmp(ts, "sendkey w")); |
| 71 | + g_assert_false(qtest_get_irq(ts, 0)); |
| 72 | + |
| 73 | + g_free(qtest_hmp(ts, "system_reset")); |
| 74 | + |
| 75 | + g_assert_true(qtest_get_irq(ts, 0)); |
| 76 | + g_assert_true(qtest_get_irq(ts, 1)); |
| 77 | + // Apparently HMP can't send multiple keys at once, delay until it's cleared. |
| 78 | + qtest_clock_step_next(ts); |
| 79 | + qtest_clock_step_next(ts); |
| 80 | + qtest_clock_step_next(ts); |
| 81 | + g_free(qtest_hmp(ts, "sendkey s")); |
| 82 | + |
| 83 | + g_assert_false(qtest_get_irq(ts, 1)); |
| 84 | + |
| 85 | + g_free(qtest_hmp(ts, "system_reset")); |
| 86 | + |
| 87 | + g_assert_true(qtest_get_irq(ts, 1)); |
| 88 | + |
| 89 | + qtest_quit(ts); |
| 90 | +} |
| 91 | + |
| 92 | +int main(int argc, char **argv) |
| 93 | +{ |
| 94 | + g_test_init(&argc, &argv, NULL); |
| 95 | + g_test_set_nonfatal_assertions(); |
| 96 | + |
| 97 | + /* Add your test case to the test suite */ |
| 98 | + qtest_add_func(TEST_PREFIX "keys", test_key_control); |
| 99 | + qtest_add_func(TEST_PREFIX "reset", test_reset); |
| 100 | + |
| 101 | + /* Run the tests */ |
| 102 | + return g_test_run(); |
| 103 | +} |
0 commit comments