From patchwork Mon Feb 19 01:17:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kambalin X-Patchwork-Id: 13562106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7712DC48BF6 for ; Mon, 19 Feb 2024 01:23:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbsJM-0004kh-Ao; Sun, 18 Feb 2024 20:19:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rbsIg-0003Zj-Sr; Sun, 18 Feb 2024 20:18:33 -0500 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbsIe-0004Kt-MT; Sun, 18 Feb 2024 20:18:30 -0500 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-6083cabc2f9so2536257b3.1; Sun, 18 Feb 2024 17:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708305505; x=1708910305; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bcTD91/m16WGwJ3DSpGyn7qEhzuO9jaCPYeEcaNO+p8=; b=DpQ9vikUCodJJDhmguFno9cjrnnESE33ai123igEJ9xMc0YmGebzy1nvorRjNzQ0H+ /ysYPzRtvgowKsEM3UvG0Kfld9T2HkjMSkgKYZWUPAY1RzampH7sKIiuoYzoWom8sKic njAOkRwVzrWZ6l6OCeOTE3zjio0UiHQa6vfT3/0mhhUDZLUDtriXhvXBX0ULxbEOiJb7 8rDMUrKVKWCj/XCbxCxXQjRkqi/4VzLqu0a9K6/X1yGJtjR+qm+2xiYhIzwZrCcghiEk tg7esZrg8c22oebvSrm2TGRikCAqx2biBZ/WWB7YOLBNBCSb5JkVWZOUd1t/pQ97EzlA BmtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708305505; x=1708910305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bcTD91/m16WGwJ3DSpGyn7qEhzuO9jaCPYeEcaNO+p8=; b=F++n8xVJ4X/0JShX2OtBW1vYWs0rSbGuS7/BvZyszWqWlHTZiJNlps8vE92GcQvGgP zBy2tCMe88PQnpCgWWtX8pyAT+EtDfWsW4aSIAQ2sAIWAP8AwLhQ4/Lp09LIkl2KiZLI 3FMj/r1turzL4t4SO0pWfcGmfbhsz7xwxic4O/YRlxF9KpfbE7s6vuBrF3dGEuIZ3AxR kRCoxlP5buGQMY/ZVgT7UeCSNRFHWygUrUe8Dy7CABMTt5uvUwxrBE5/+ob9rAhkLuwp kQCPSdYPBcaoALPEiKqaCkrBJ/BkEEJC0JigtxAA3siznl1FPYmgpuU5TmkxybFkBitl Q+QA== X-Gm-Message-State: AOJu0Yw7wxZzqpt7tsZE8oTIpuVhS/DwgXPePx833x92euzaZpMS4f8T YuO2StBVPSZlt1p91HsIVnXkeI9MumK1ipW92Hb1DiXexuSqsRpEXFOzZsaWbDQ= X-Google-Smtp-Source: AGHT+IHUOxPlC5qqUXHdQ26GFCrcP/O4m09bFzpqVgyz1FOkZ2yIoHbImOLG1qjGwIsE29W9g9xzmQ== X-Received: by 2002:a81:4902:0:b0:607:ce8e:fe26 with SMTP id w2-20020a814902000000b00607ce8efe26mr10201797ywa.14.1708305504995; Sun, 18 Feb 2024 17:18:24 -0800 (PST) Received: from localhost.localdomain ([201.203.117.224]) by smtp.gmail.com with ESMTPSA id m12-20020a819e0c000000b00607ff905ed3sm1204704ywj.58.2024.02.18.17.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 17:18:24 -0800 (PST) From: Sergey Kambalin X-Google-Original-From: Sergey Kambalin To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, Sergey Kambalin Subject: [PATCH v5 36/41] Add mailbox property tests. Part 1 Date: Sun, 18 Feb 2024 19:17:34 -0600 Message-Id: <20240219011739.2316619-37-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240219011739.2316619-1-sergey.kambalin@auriga.com> References: <20240219011739.2316619-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1134; envelope-from=serg.oker@gmail.com; helo=mail-yw1-x1134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Sergey Kambalin --- tests/qtest/bcm2838-mailbox.c | 1 - tests/qtest/bcm2838-mbox-property-test.c | 207 +++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 3 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/bcm2838-mbox-property-test.c diff --git a/tests/qtest/bcm2838-mailbox.c b/tests/qtest/bcm2838-mailbox.c index 1efd3c628a..0928a3dff8 100644 --- a/tests/qtest/bcm2838-mailbox.c +++ b/tests/qtest/bcm2838-mailbox.c @@ -11,7 +11,6 @@ #include "hw/registerfields.h" #include "libqtest-single.h" #include "bcm2838-mailbox.h" -#include "hw/arm/raspberrypi-fw-defs.h" REG32(MBOX_EXCHNG_REG, 0) FIELD(MBOX_EXCHNG_REG, CHANNEL, 0, 4) diff --git a/tests/qtest/bcm2838-mbox-property-test.c b/tests/qtest/bcm2838-mbox-property-test.c new file mode 100644 index 0000000000..acb421915b --- /dev/null +++ b/tests/qtest/bcm2838-mbox-property-test.c @@ -0,0 +1,207 @@ +/* + * Tests set for BCM2838 mailbox property interface. + * + * Copyright (c) 2022 Auriga + * + * 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 "hw/registerfields.h" +#include "libqtest-single.h" +#include "bcm2838-mailbox.h" +#include "hw/arm/raspberrypi-fw-defs.h" + +REG32(MBOX_SIZE_STAT, 0) +FIELD(MBOX_SIZE_STAT, SIZE, 0, 31) +FIELD(MBOX_SIZE_STAT, SUCCESS, 31, 1) + +REG32(SET_POWER_STATE_CMD, 0) +FIELD(SET_POWER_STATE_CMD, EN, 0, 1) +FIELD(SET_POWER_STATE_CMD, WAIT, 1, 1) + +REG32(GET_CLOCK_STATE_CMD, 0) +FIELD(GET_CLOCK_STATE_CMD, EN, 0, 1) +FIELD(GET_CLOCK_STATE_CMD, NPRES, 1, 1) + +#define MBOX_TEST_MESSAGE_ADDRESS 0x10000000 + +#define TEST_TAG(x) RPI_FWREQ_ ## x +#define TEST_TAG_TYPE(x) TAG_##x##_t + +#define TEST_FN_NAME(test, subtest) \ + test ## _ ## subtest ## _test + +#define SETUP_FN_NAME(test, subtest) \ + test ## _ ## subtest ## _setup + +#define CHECK_FN_NAME(test, subtest) \ + test ## _ ## subtest ## _spec_check + +#define DECLARE_TEST_CASE_SETUP(testname, ...) \ + void SETUP_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) * tag) + +/*----------------------------------------------------------------------------*/ +#define DECLARE_TEST_CASE(testname, ...) \ + __attribute__((weak)) \ + void SETUP_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) * tag); \ + static void CHECK_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) *tag); \ + static void TEST_FN_NAME(testname, __VA_ARGS__)(void) { \ + struct { \ + MboxBufHeader header; \ + TEST_TAG_TYPE(testname) tag; \ + uint32_t end_tag; \ + } mailbox_buffer = { 0 }; \ + \ + QTestState *qts = qtest_init("-machine raspi4b-2g"); \ + \ + mailbox_buffer.header.size = sizeof(mailbox_buffer); \ + mailbox_buffer.header.req_resp_code = MBOX_PROCESS_REQUEST; \ + \ + mailbox_buffer.tag.id = TEST_TAG(testname); \ + mailbox_buffer.tag.value_buffer_size = MAX( \ + sizeof(mailbox_buffer.tag.request.value), \ + sizeof(mailbox_buffer.tag.response.value)); \ + mailbox_buffer.tag.request.zero = 0; \ + \ + mailbox_buffer.end_tag = RPI_FWREQ_PROPERTY_END; \ + \ + if (SETUP_FN_NAME(testname, __VA_ARGS__)) { \ + SETUP_FN_NAME(testname, __VA_ARGS__)(&mailbox_buffer.tag); \ + } \ + \ + qtest_memwrite(qts, MBOX_TEST_MESSAGE_ADDRESS, \ + &mailbox_buffer, sizeof(mailbox_buffer)); \ + qtest_mbox1_write_message(qts, MBOX_CHANNEL_ID_PROPERTY, \ + MBOX_TEST_MESSAGE_ADDRESS); \ + \ + qtest_mbox0_read_message(qts, MBOX_CHANNEL_ID_PROPERTY, \ + &mailbox_buffer, sizeof(mailbox_buffer)); \ + \ + g_assert_cmphex(mailbox_buffer.header.req_resp_code, ==, MBOX_SUCCESS);\ + \ + g_assert_cmphex(mailbox_buffer.tag.id, ==, TEST_TAG(testname)); \ + \ + uint32_t size = FIELD_EX32(mailbox_buffer.tag.response.size_stat, \ + MBOX_SIZE_STAT, SIZE); \ + uint32_t success = FIELD_EX32(mailbox_buffer.tag.response.size_stat, \ + MBOX_SIZE_STAT, SUCCESS); \ + g_assert_cmpint(size, ==, sizeof(mailbox_buffer.tag.response.value)); \ + g_assert_cmpint(success, ==, 1); \ + \ + CHECK_FN_NAME(testname, __VA_ARGS__)(&mailbox_buffer.tag); \ + \ + qtest_quit(qts); \ + } \ + static void CHECK_FN_NAME(testname, __VA_ARGS__) \ + (TEST_TAG_TYPE(testname) * tag) + +/*----------------------------------------------------------------------------*/ + +#define QTEST_ADD_TEST_CASE(testname, ...) \ + qtest_add_func(stringify(/bcm2838/mbox/property/ \ + TEST_FN_NAME(testname, __VA_ARGS__)-test), \ + TEST_FN_NAME(testname, __VA_ARGS__)) + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_FIRMWARE_REVISION) { + g_assert_cmpint(tag->response.value.revision, ==, FIRMWARE_REVISION); +} + +// /*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_BOARD_REVISION) { + g_assert_cmpint(tag->response.value.revision, ==, BOARD_REVISION); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_ARM_MEMORY) { + g_assert_cmphex(tag->response.value.base, ==, ARM_MEMORY_BASE); + g_assert_cmphex(tag->response.value.size, ==, ARM_MEMORY_SIZE); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_VC_MEMORY) { + g_assert_cmphex(tag->response.value.base, ==, VC_MEMORY_BASE); + g_assert_cmphex(tag->response.value.size, ==, VC_MEMORY_SIZE); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(SET_POWER_STATE) { + uint32_t enabled = + FIELD_EX32(tag->response.value.cmd, SET_POWER_STATE_CMD, EN); + uint32_t wait = + FIELD_EX32(tag->response.value.cmd, SET_POWER_STATE_CMD, WAIT); + g_assert_cmphex(tag->response.value.device_id, ==, DEVICE_ID_UART0); + g_assert_cmpint(enabled, ==, 1); + g_assert_cmpint(wait, ==, 0); +} +DECLARE_TEST_CASE_SETUP(SET_POWER_STATE) { + tag->request.value.device_id = DEVICE_ID_UART0; + tag->response.value.cmd = + FIELD_DP32(tag->response.value.cmd, SET_POWER_STATE_CMD, EN, 1); + tag->response.value.cmd = + FIELD_DP32(tag->response.value.cmd, SET_POWER_STATE_CMD, WAIT, 1); +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_STATE) { + uint32_t enabled = + FIELD_EX32(tag->response.value.cmd, GET_CLOCK_STATE_CMD, EN); + uint32_t not_present = + FIELD_EX32(tag->response.value.cmd, GET_CLOCK_STATE_CMD, NPRES); + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_CORE); + g_assert_cmphex(enabled, ==, 1); + g_assert_cmphex(not_present, ==, 0); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_STATE) { + tag->request.value.clock_id = CLOCK_ID_CORE; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_CLOCK_RATE, EMMC) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_EMMC); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_EMMC); +} +DECLARE_TEST_CASE_SETUP(GET_CLOCK_RATE, EMMC) { + tag->request.value.clock_id = CLOCK_ID_EMMC; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MAX_CLOCK_RATE, EMMC) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_EMMC); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_EMMC); +} +DECLARE_TEST_CASE_SETUP(GET_MAX_CLOCK_RATE, EMMC) { + tag->request.value.clock_id = CLOCK_ID_EMMC; +} + +/*----------------------------------------------------------------------------*/ +DECLARE_TEST_CASE(GET_MIN_CLOCK_RATE, EMMC) { + g_assert_cmphex(tag->response.value.clock_id, ==, CLOCK_ID_EMMC); + g_assert_cmphex(tag->response.value.rate, ==, CLOCK_RATE_EMMC); +} +DECLARE_TEST_CASE_SETUP(GET_MIN_CLOCK_RATE, EMMC) { + tag->request.value.clock_id = CLOCK_ID_EMMC; +} + +/*----------------------------------------------------------------------------*/ +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + QTEST_ADD_TEST_CASE(GET_FIRMWARE_REVISION); + QTEST_ADD_TEST_CASE(GET_BOARD_REVISION); + QTEST_ADD_TEST_CASE(GET_ARM_MEMORY); + QTEST_ADD_TEST_CASE(GET_VC_MEMORY); + QTEST_ADD_TEST_CASE(SET_POWER_STATE); + QTEST_ADD_TEST_CASE(GET_CLOCK_STATE); + QTEST_ADD_TEST_CASE(GET_CLOCK_RATE, EMMC); + QTEST_ADD_TEST_CASE(GET_MAX_CLOCK_RATE, EMMC); + QTEST_ADD_TEST_CASE(GET_MIN_CLOCK_RATE, EMMC); + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index e312634963..6d829d35dd 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -229,7 +229,7 @@ qtests_aarch64 = \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', 'xlnx-versal-trng-test'] : []) + \ - (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2838-mbox-property-test'] : []) + \ (config_all_accel.has_key('CONFIG_TCG') and \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \ ['arm-cpu-features',