Skip to content

Commit 389c438

Browse files
committed
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 8b208b0. Previously the build warning wasn't reproducible in-tree. Signed-off-by: Maureen Helm <maureen.helm@analog.com>
1 parent c02592c commit 389c438

File tree

9 files changed

+118
-0
lines changed

9 files changed

+118
-0
lines changed

drivers/hwspinlock/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
zephyr_library()
44

55
zephyr_library_sources_ifdef(CONFIG_SQN_HWSPINLOCK sqn_hwspinlock.c)
6+
zephyr_library_sources_ifdef(CONFIG_HWSPINLOCK_TEST hwspinlock_test.c)

drivers/hwspinlock/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config HWSPINLOCK_INIT_PRIORITY
2222

2323
# zephyr-keep-sorted-start
2424
source "drivers/hwspinlock/Kconfig.sqn"
25+
source "drivers/hwspinlock/Kconfig.test"
2526
# zephyr-keep-sorted-stop
2627

2728
endif

drivers/hwspinlock/Kconfig.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 Analog Devices, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
config HWSPINLOCK_TEST
5+
def_bool DT_HAS_VND_HWSPINLOCK_ENABLED
6+
depends on DT_HAS_VND_HWSPINLOCK_ENABLED
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/hwspinlock.h>
9+
10+
#define DT_DRV_COMPAT vnd_hwspinlock
11+
12+
static void vnd_hwspinlock_lock(const struct device *dev, uint32_t id)
13+
{
14+
}
15+
16+
static void vnd_hwspinlock_unlock(const struct device *dev, uint32_t id)
17+
{
18+
}
19+
20+
static uint32_t vnd_hwspinlock_get_max_id(const struct device *dev)
21+
{
22+
return 0;
23+
}
24+
25+
static DEVICE_API(hwspinlock, vnd_hwspinlock_api) = {
26+
.lock = vnd_hwspinlock_lock,
27+
.unlock = vnd_hwspinlock_unlock,
28+
.get_max_id = vnd_hwspinlock_get_max_id,
29+
};
30+
31+
#define VND_HWSPINLOCK_INIT(idx) \
32+
DEVICE_DT_INST_DEFINE(idx, NULL, NULL, NULL, NULL, POST_KERNEL, \
33+
CONFIG_HWSPINLOCK_INIT_PRIORITY, \
34+
&vnd_hwspinlock_api)
35+
36+
DT_INST_FOREACH_STATUS_OKAY(VND_HWSPINLOCK_INIT);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 Analog Devices, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Test hardware spinlock device node
5+
6+
compatible: "vnd,hwspinlock-device"
7+
8+
include: base.yaml
9+
10+
properties:
11+
hwlocks:
12+
required: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025 Analog Devices, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Test hardware spinlock node
5+
6+
compatible: "vnd,hwspinlock"
7+
8+
include: [base.yaml, hwspinlock-controller.yaml]
9+
10+
hwlock-cells:
11+
- id

tests/lib/devicetree/api_ext/app.overlay

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research
33
* Organisation (CSIRO) ABN 41 687 119 230.
4+
* Copyright (c) 2025 Analog Devices, Inc.
45
*
56
* SPDX-License-Identifier: Apache-2.0
67
*
@@ -75,5 +76,18 @@
7576
mboxes = <&test_mbox 1>, <&test_mbox 2>, <&test_mbox_zero_cell>;
7677
mbox-names = "tx", "rx", "zero";
7778
};
79+
80+
test_hwspinlock: hwspinlock {
81+
compatible = "vnd,hwspinlock";
82+
#hwlock-cells = <1>;
83+
status = "okay";
84+
};
85+
86+
test_hwspinlock_dev: hwspinlock-dev {
87+
compatible = "vnd,hwspinlock-device";
88+
hwlocks = <&test_hwspinlock 1>, <&test_hwspinlock 2>;
89+
hwlock-names = "rd", "wr";
90+
status = "okay";
91+
};
7892
};
7993
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
CONFIG_ZTEST=y
22
CONFIG_ADC=y
33
CONFIG_MBOX=y
4+
CONFIG_HWSPINLOCK=y
5+
CONFIG_SPIN_VALIDATE=n

tests/lib/devicetree/api_ext/src/main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research
33
* Organisation (CSIRO) ABN 41 687 119 230.
4+
* Copyright (c) 2025 Analog Devices, Inc.
45
*
56
* SPDX-License-Identifier: Apache-2.0
67
*/
@@ -11,6 +12,7 @@
1112
#include <zephyr/drivers/gpio.h>
1213
#include <zephyr/drivers/adc.h>
1314
#include <zephyr/drivers/mbox.h>
15+
#include <zephyr/drivers/hwspinlock.h>
1416

1517
#include <zephyr/linker/devicetree_regions.h>
1618

@@ -59,4 +61,37 @@ ZTEST(devicetree_api_ext, test_mbox_dt_spec)
5961
zassert_equal(channel_zero.channel_id, 0, "");
6062
}
6163

64+
#define TEST_HWSPINLOCK \
65+
DT_NODELABEL(test_hwspinlock)
66+
67+
#define TEST_HWSPINLOCK_DEV \
68+
DT_NODELABEL(test_hwspinlock_dev)
69+
70+
#define HWSPINLOCK_BY_IDX(node_id, prop, idx) \
71+
HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, idx)
72+
73+
static const struct hwspinlock_dt_spec spec[] = {
74+
DT_FOREACH_PROP_ELEM_SEP(TEST_HWSPINLOCK_DEV, hwlocks, HWSPINLOCK_BY_IDX, (,))
75+
};
76+
77+
static const struct hwspinlock_dt_spec rd =
78+
HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, rd);
79+
80+
static const struct hwspinlock_dt_spec wr =
81+
HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, wr);
82+
83+
ZTEST(devicetree_api_ext, test_hwspinlock_dt_spec)
84+
{
85+
for (int i = 0; i < ARRAY_SIZE(spec); i++) {
86+
zassert_equal(spec[i].dev, DEVICE_DT_GET(TEST_HWSPINLOCK));
87+
zassert_equal(spec[i].id, i + 1);
88+
}
89+
90+
zassert_equal(rd.dev, DEVICE_DT_GET(TEST_HWSPINLOCK));
91+
zassert_equal(rd.id, 1);
92+
93+
zassert_equal(wr.dev, DEVICE_DT_GET(TEST_HWSPINLOCK));
94+
zassert_equal(wr.id, 2);
95+
}
96+
6297
ZTEST_SUITE(devicetree_api_ext, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)