|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Analog Devices, Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/ztest.h> |
| 8 | +#include <zephyr/devicetree.h> |
| 9 | +#include <zephyr/device.h> |
| 10 | +#include <zephyr/drivers/hwspinlock.h> |
| 11 | + |
| 12 | +#define TEST_HWSPINLOCK \ |
| 13 | + DT_NODELABEL(test_hwspinlock) |
| 14 | + |
| 15 | +#define TEST_HWSPINLOCK_DEV \ |
| 16 | + DT_NODELABEL(test_hwspinlock_dev) |
| 17 | + |
| 18 | +#define HWSPINLOCK_BY_IDX(node_id, prop, idx) \ |
| 19 | + HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, idx) |
| 20 | + |
| 21 | +static const struct hwspinlock_dt_spec spec[] = { |
| 22 | + DT_FOREACH_PROP_ELEM_SEP(TEST_HWSPINLOCK_DEV, hwlocks, HWSPINLOCK_BY_IDX, (,)) |
| 23 | +}; |
| 24 | + |
| 25 | +static const struct hwspinlock_dt_spec rd = |
| 26 | + HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, rd); |
| 27 | + |
| 28 | +static const struct hwspinlock_dt_spec wr = |
| 29 | + HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, wr); |
| 30 | + |
| 31 | +ZTEST(hwspinlock_dt_spec, test_dt_spec) |
| 32 | +{ |
| 33 | + for (int i = 0; i < ARRAY_SIZE(spec); i++) { |
| 34 | + zassert_equal(spec[i].dev, DEVICE_DT_GET(TEST_HWSPINLOCK)); |
| 35 | + zassert_equal(spec[i].id, i + 1); |
| 36 | + } |
| 37 | + |
| 38 | + zassert_equal(rd.dev, DEVICE_DT_GET(TEST_HWSPINLOCK)); |
| 39 | + zassert_equal(rd.id, 1); |
| 40 | + |
| 41 | + zassert_equal(wr.dev, DEVICE_DT_GET(TEST_HWSPINLOCK)); |
| 42 | + zassert_equal(wr.id, 2); |
| 43 | +} |
| 44 | + |
| 45 | +ZTEST_SUITE(hwspinlock_dt_spec, NULL, NULL, NULL, NULL, NULL); |
0 commit comments