[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v3 16/24] tests/qtest: add flexcomm tests
From: |
Octavian Purdila |
Subject: |
[RFC PATCH v3 16/24] tests/qtest: add flexcomm tests |
Date: |
Mon, 26 Aug 2024 23:45:20 -0700 |
Add flexcomm function selection unit tests.
Signed-off-by: Octavian Purdila <tavip@google.com>
---
tests/qtest/flexcomm-test.c | 86 +++++++++++++++++++++++++++++++++++++
tests/qtest/meson.build | 1 +
2 files changed, 87 insertions(+)
create mode 100644 tests/qtest/flexcomm-test.c
diff --git a/tests/qtest/flexcomm-test.c b/tests/qtest/flexcomm-test.c
new file mode 100644
index 0000000000..2258633646
--- /dev/null
+++ b/tests/qtest/flexcomm-test.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2024 Google LLC
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * 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 "qemu/log.h"
+#include "qemu/module.h"
+#include "qemu/main-loop.h"
+#include "exec/memory.h"
+#include "hw/irq.h"
+#include "hw/qdev-properties.h"
+
+#include "hw/misc/flexcomm.h"
+#include "hw/arm/svd/flexcomm.h"
+#include "hw/arm/svd/rt500.h"
+#include "reg-utils.h"
+
+#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE
+
+static void select_test(gconstpointer data)
+{
+ static const struct {
+ int persel;
+ int func;
+ } persel_func_map[] = {
+ { FLEXCOMM_PERSEL_USART, FLEXCOMM_FUNC_USART },
+ { FLEXCOMM_PERSEL_SPI, FLEXCOMM_FUNC_SPI },
+ { FLEXCOMM_PERSEL_I2C, FLEXCOMM_FUNC_I2C },
+ };
+
+ g_assert(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL) == 0);
+
+ /* no register access until a function is selected */
+ readl_fail(FLEXCOMM_BASE);
+ writel_fail(FLEXCOMM_BASE, 0);
+
+ for (int i = 0; i < ARRAY_SIZE(persel_func_map); i++) {
+ int persel = persel_func_map[i].persel;
+
+ REG32_WRITE(FLEXCOMM, PSELID, persel);
+ g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==,
+ persel);
+
+ /* test that we can access function registers */
+ writel(FLEXCOMM_BASE + 0x10, 0xabcd);
+ readl(FLEXCOMM_BASE + 0x10);
+ }
+
+ /* try to select something invalid */
+ REG32_WRITE(FLEXCOMM, PSELID, 7);
+ /* check for no function selected */
+ g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==, 0);
+
+ /* now select and lock USART */
+ REG32_WRITE(FLEXCOMM, PSELID,
+ FIELD_DP32(FLEXCOMM_PERSEL_USART, FLEXCOMM_PSELID, LOCK, 1));
+ g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==,
+ FLEXCOMM_PERSEL_USART);
+ g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, LOCK), ==, 1);
+
+ /* try to change the selection to spi */
+ REG32_WRITE(FLEXCOMM, PSELID, FLEXCOMM_PERSEL_SPI);
+ /* it should still be locked USART */
+ g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==,
+ FLEXCOMM_PERSEL_USART);
+ g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, LOCK), ==, 1);
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+
+ g_test_init(&argc, &argv, NULL);
+
+ qtest_add_data_func("/flexcomm/select", NULL, select_test);
+ qtest_start("-M rt595-evk");
+ ret = g_test_run();
+ qtest_end();
+
+ return ret;
+}
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 12792948ff..9631b6c401 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -229,6 +229,7 @@ qtests_arm = \
(config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ?
['aspeed_fsi-test'] : []) + \
(config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and
config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \
+ (config_all_devices.has_key('CONFIG_FLEXCOMM')? ['flexcomm-test'] : []) + \
['arm-cpu-features',
'boot-serial-test']
--
2.46.0.295.g3b9ea8a38a-goog
- [RFC PATCH v3 05/24] hw/misc: add basic flexcomm device model, (continued)
- [RFC PATCH v3 05/24] hw/misc: add basic flexcomm device model, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 04/24] Add mcux-soc-svd subproject, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 06/24] hw/char: add support for flexcomm usart, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 07/24] hw/i2c: add support for flexcomm i2c, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 17/24] tests/qtest: add flexcomm usart tests, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 08/24] hw/ssi: add support for flexcomm spi, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 20/24] hw/ssi: allow NULL realize callbacks for peripherals, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 24/24] test/unit: add unit tests for RT500's clock controller, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 10/24] hw/ssi: add support for flexspi, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 09/24] hw/misc: add support for RT500's clock controller, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 16/24] tests/qtest: add flexcomm tests,
Octavian Purdila <=
- [RFC PATCH v3 12/24] hw/arm: add basic support for the RT500 SoC, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 11/24] hw/misc: add support for RT500's reset controller, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 14/24] tests/qtest: add register access macros and functions, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 15/24] system/qtest: add APIS to check for memory access failures, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 13/24] hw/arm: add RT595-EVK board, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 23/24] systems/qtest: add device clock APIs, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 19/24] tests/qtest: add tests for flexcomm i2c, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 18/24] hw/misc: add i2c-tester, Octavian Purdila, 2024/08/27
- [RFC PATCH v3 21/24] hw/misc: add spi-tester, Octavian Purdila, 2024/08/27