tests: lib: devicetree: Add hwspinlock dt spec test

Extends the devicetree library test to exercise the hwspinlock dt spec
macros and detect the context initializer build warning that was fixed
in commit 8b208b0d5a. Previously the build
warning wasn't reproducible in-tree.

Signed-off-by: Maureen Helm <maureen.helm@analog.com>
This commit is contained in:
Maureen Helm
2025-11-06 14:09:01 -06:00
committed by Benjamin Cabé
parent cdfecb6354
commit 5f33d75bce
9 changed files with 118 additions and 0 deletions

View File

@@ -3,3 +3,4 @@
zephyr_library()
zephyr_library_sources_ifdef(CONFIG_SQN_HWSPINLOCK sqn_hwspinlock.c)
zephyr_library_sources_ifdef(CONFIG_HWSPINLOCK_TEST hwspinlock_test.c)

View File

@@ -22,6 +22,7 @@ config HWSPINLOCK_INIT_PRIORITY
# zephyr-keep-sorted-start
source "drivers/hwspinlock/Kconfig.sqn"
source "drivers/hwspinlock/Kconfig.test"
# zephyr-keep-sorted-stop
endif

View File

@@ -0,0 +1,6 @@
# Copyright (c) 2025 Analog Devices, Inc.
# SPDX-License-Identifier: Apache-2.0
#
config HWSPINLOCK_TEST
def_bool DT_HAS_VND_HWSPINLOCK_ENABLED
depends on DT_HAS_VND_HWSPINLOCK_ENABLED

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2025 Analog Devices, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/drivers/hwspinlock.h>
#define DT_DRV_COMPAT vnd_hwspinlock
static void vnd_hwspinlock_lock(const struct device *dev, uint32_t id)
{
}
static void vnd_hwspinlock_unlock(const struct device *dev, uint32_t id)
{
}
static uint32_t vnd_hwspinlock_get_max_id(const struct device *dev)
{
return 0;
}
static DEVICE_API(hwspinlock, vnd_hwspinlock_api) = {
.lock = vnd_hwspinlock_lock,
.unlock = vnd_hwspinlock_unlock,
.get_max_id = vnd_hwspinlock_get_max_id,
};
#define VND_HWSPINLOCK_INIT(idx) \
DEVICE_DT_INST_DEFINE(idx, NULL, NULL, NULL, NULL, POST_KERNEL, \
CONFIG_HWSPINLOCK_INIT_PRIORITY, \
&vnd_hwspinlock_api)
DT_INST_FOREACH_STATUS_OKAY(VND_HWSPINLOCK_INIT);

View File

@@ -0,0 +1,12 @@
# Copyright (c) 2025 Analog Devices, Inc.
# SPDX-License-Identifier: Apache-2.0
description: Test hardware spinlock device node
compatible: "vnd,hwspinlock-device"
include: base.yaml
properties:
hwlocks:
required: true

View File

@@ -0,0 +1,11 @@
# Copyright (c) 2025 Analog Devices, Inc.
# SPDX-License-Identifier: Apache-2.0
description: Test hardware spinlock node
compatible: "vnd,hwspinlock"
include: [base.yaml, hwspinlock-controller.yaml]
hwlock-cells:
- id

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) ABN 41 687 119 230.
* Copyright (c) 2025 Analog Devices, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -75,5 +76,18 @@
mboxes = <&test_mbox 1>, <&test_mbox 2>, <&test_mbox_zero_cell>;
mbox-names = "tx", "rx", "zero";
};
test_hwspinlock: hwspinlock {
compatible = "vnd,hwspinlock";
#hwlock-cells = <1>;
status = "okay";
};
test_hwspinlock_dev: hwspinlock-dev {
compatible = "vnd,hwspinlock-device";
hwlocks = <&test_hwspinlock 1>, <&test_hwspinlock 2>;
hwlock-names = "rd", "wr";
status = "okay";
};
};
};

View File

@@ -1,3 +1,5 @@
CONFIG_ZTEST=y
CONFIG_ADC=y
CONFIG_MBOX=y
CONFIG_HWSPINLOCK=y
CONFIG_SPIN_VALIDATE=n

View File

@@ -1,6 +1,7 @@
/*
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) ABN 41 687 119 230.
* Copyright (c) 2025 Analog Devices, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -11,6 +12,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/adc.h>
#include <zephyr/drivers/mbox.h>
#include <zephyr/drivers/hwspinlock.h>
#include <zephyr/linker/devicetree_regions.h>
@@ -59,4 +61,37 @@ ZTEST(devicetree_api_ext, test_mbox_dt_spec)
zassert_equal(channel_zero.channel_id, 0, "");
}
#define TEST_HWSPINLOCK \
DT_NODELABEL(test_hwspinlock)
#define TEST_HWSPINLOCK_DEV \
DT_NODELABEL(test_hwspinlock_dev)
#define HWSPINLOCK_BY_IDX(node_id, prop, idx) \
HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, idx)
static const struct hwspinlock_dt_spec spec[] = {
DT_FOREACH_PROP_ELEM_SEP(TEST_HWSPINLOCK_DEV, hwlocks, HWSPINLOCK_BY_IDX, (,))
};
static const struct hwspinlock_dt_spec rd =
HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, rd);
static const struct hwspinlock_dt_spec wr =
HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, wr);
ZTEST(devicetree_api_ext, test_hwspinlock_dt_spec)
{
for (int i = 0; i < ARRAY_SIZE(spec); i++) {
zassert_equal(spec[i].dev, DEVICE_DT_GET(TEST_HWSPINLOCK));
zassert_equal(spec[i].id, i + 1);
}
zassert_equal(rd.dev, DEVICE_DT_GET(TEST_HWSPINLOCK));
zassert_equal(rd.id, 1);
zassert_equal(wr.dev, DEVICE_DT_GET(TEST_HWSPINLOCK));
zassert_equal(wr.id, 2);
}
ZTEST_SUITE(devicetree_api_ext, NULL, NULL, NULL, NULL, NULL);