|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <mock_nrf_rpc_transport.h> |
| 8 | +#include <ot_rpc_ids.h> |
| 9 | +#include <test_rpc_env.h> |
| 10 | + |
| 11 | +#include <zephyr/fff.h> |
| 12 | +#include <zephyr/kernel.h> |
| 13 | +#include <zephyr/ztest.h> |
| 14 | + |
| 15 | +#include <openthread/udp.h> |
| 16 | + |
| 17 | +#define FOREACH_FAKE(f) \ |
| 18 | + f(otUdpIsOpen); \ |
| 19 | + f(otUdpOpen); \ |
| 20 | + f(otUdpClose); \ |
| 21 | + f(otUdpBind); \ |
| 22 | + f(otUdpConnect); \ |
| 23 | + f(otUdpSend) |
| 24 | + |
| 25 | +FAKE_VALUE_FUNC(bool, otUdpIsOpen, otInstance *, const otUdpSocket *); |
| 26 | +FAKE_VALUE_FUNC(otError, otUdpOpen, otInstance *, otUdpSocket *, otUdpReceive, void *); |
| 27 | +FAKE_VALUE_FUNC(otError, otUdpClose, otInstance *, otUdpSocket *); |
| 28 | +FAKE_VALUE_FUNC(otError, otUdpBind, otInstance *, otUdpSocket *, const otSockAddr *, |
| 29 | + otNetifIdentifier); |
| 30 | +FAKE_VALUE_FUNC(otError, otUdpConnect, otInstance *, otUdpSocket *, const otSockAddr *); |
| 31 | +FAKE_VALUE_FUNC(otError, otUdpSend, otInstance *, otUdpSocket *, otMessage *, |
| 32 | + const otMessageInfo *); |
| 33 | + |
| 34 | +static void nrf_rpc_err_handler(const struct nrf_rpc_err_report *report) |
| 35 | +{ |
| 36 | + zassert_ok(report->code); |
| 37 | +} |
| 38 | + |
| 39 | +static void tc_setup(void *f) |
| 40 | +{ |
| 41 | + mock_nrf_rpc_tr_expect_add(RPC_INIT_REQ, RPC_INIT_RSP); |
| 42 | + zassert_ok(nrf_rpc_init(nrf_rpc_err_handler)); |
| 43 | + mock_nrf_rpc_tr_expect_reset(); |
| 44 | + |
| 45 | + FOREACH_FAKE(RESET_FAKE); |
| 46 | + FFF_RESET_HISTORY(); |
| 47 | +} |
| 48 | + |
| 49 | +/* |
| 50 | + * Test reception of otUdpIsOpen() command with non-existent socket key. |
| 51 | + * Test serialization of the result: false. |
| 52 | + */ |
| 53 | +ZTEST(ot_rpc_udp, test_otUdpIsOpen_false) |
| 54 | +{ |
| 55 | + mock_nrf_rpc_tr_expect_add(RPC_RSP(CBOR_FALSE), NO_RSP); |
| 56 | + mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_UDP_IS_OPEN, CBOR_UINT32(1))); |
| 57 | + mock_nrf_rpc_tr_expect_done(); |
| 58 | + |
| 59 | + zassert_equal(otUdpIsOpen_fake.call_count, 0); |
| 60 | +} |
| 61 | + |
| 62 | +ZTEST_SUITE(ot_rpc_udp, NULL, NULL, tc_setup, NULL, NULL); |
0 commit comments