|
| 1 | +/* |
| 2 | + * Copyright 2025 NXP |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/ztest.h> |
| 8 | +#include <zephyr/device.h> |
| 9 | +#include <zephyr/drivers/sent/sent.h> |
| 10 | + |
| 11 | +#define SENT_NODE DT_ALIAS(sent_node) |
| 12 | +#define SENT_CHANNEL 1 |
| 13 | + |
| 14 | +const struct device *dev = DEVICE_DT_GET(SENT_NODE); |
| 15 | + |
| 16 | +static void *sent_setup(void) |
| 17 | +{ |
| 18 | + zassert_true(device_is_ready(dev), "SENT device is not ready"); |
| 19 | + |
| 20 | + return NULL; |
| 21 | +} |
| 22 | + |
| 23 | +void rx_cb(const struct device *dev, uint8_t channel_id, struct sent_frame *frame, |
| 24 | + enum sent_status status, void *user_data) |
| 25 | +{ |
| 26 | + ARG_UNUSED(dev); |
| 27 | + ARG_UNUSED(channel_id); |
| 28 | + ARG_UNUSED(frame); |
| 29 | + ARG_UNUSED(status); |
| 30 | + ARG_UNUSED(user_data); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * @brief Test starting rx is not allowed while started. |
| 35 | + */ |
| 36 | +ZTEST_USER(sent_api, test_start_rx_while_started) |
| 37 | +{ |
| 38 | + int err; |
| 39 | + |
| 40 | + err = sent_start_rx(dev, SENT_CHANNEL); |
| 41 | + zassert_equal(err, 0, "Failed to start rx (err %d)", err); |
| 42 | + |
| 43 | + err = sent_start_rx(dev, SENT_CHANNEL); |
| 44 | + zassert_not_equal(err, 0, "Started rx while started"); |
| 45 | + zassert_equal(err, -EALREADY, "Wrong error return code (err %d)", err); |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * @brief Test stopping rx is not allowed while stopped. |
| 50 | + */ |
| 51 | +ZTEST_USER(sent_api, test_stop_rx_while_stopped) |
| 52 | +{ |
| 53 | + int err; |
| 54 | + |
| 55 | + err = sent_stop_rx(dev, SENT_CHANNEL); |
| 56 | + zassert_equal(err, 0, "Failed to stop rx (err %d)", err); |
| 57 | + |
| 58 | + err = sent_stop_rx(dev, SENT_CHANNEL); |
| 59 | + zassert_not_equal(err, 0, "Stopped rx while stopped"); |
| 60 | + zassert_equal(err, -EALREADY, "Wrong error return code (err %d)", err); |
| 61 | + |
| 62 | + err = sent_start_rx(dev, SENT_CHANNEL); |
| 63 | + zassert_equal(err, 0, "Failed to start rx (err %d)", err); |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * @brief Test setting the rx callback. |
| 68 | + */ |
| 69 | +ZTEST(sent_api, test_set_rx_callback) |
| 70 | +{ |
| 71 | + int err; |
| 72 | + |
| 73 | + err = sent_add_rx_callback(dev, SENT_CHANNEL, rx_cb, NULL); |
| 74 | + zassert_equal(err, 0, "Failed to set rx callback (err %d)", err); |
| 75 | + |
| 76 | + sent_add_rx_callback(dev, SENT_CHANNEL, NULL, NULL); |
| 77 | + zassert_equal(err, 0, "Failed to set rx callback (err %d)", err); |
| 78 | + |
| 79 | + err = sent_add_rx_callback(dev, SENT_CHANNEL, rx_cb, NULL); |
| 80 | + zassert_equal(err, 0, "Failed to set rx callback (err %d)", err); |
| 81 | +} |
| 82 | + |
| 83 | +ZTEST_SUITE(sent_api, NULL, sent_setup, NULL, NULL, NULL); |
0 commit comments