| /* Copyright 2021 Carlo Caione, <ccaione@baylibre.com> |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| #include <zephyr/device.h> |
| #include <zephyr/devicetree.h> |
| #include <ztest.h> |
| #include <zephyr/ipc/ipc_service.h> |
| |
| static void received_cb(const void *data, size_t len, void *priv) |
| { |
| uintptr_t expected = (uintptr_t) priv; |
| uint8_t *msg = (uint8_t *) data; |
| |
| zassert_equal(*msg, expected, "msg doesn't match the expected value"); |
| |
| printk("Received: %d, expected: %ld\n", *msg, expected); |
| } |
| |
| static struct ipc_ept_cfg ept_cfg = { |
| .name = "test_ept", |
| .cb = { |
| .received = received_cb, |
| }, |
| }; |
| |
| void test_ipc_service(void) |
| { |
| const struct device *dev_10; |
| const struct device *dev_20; |
| struct ipc_ept ept_10; |
| struct ipc_ept ept_20; |
| uint8_t msg; |
| int ret; |
| |
| dev_10 = DEVICE_DT_GET(DT_NODELABEL(ipc10)); |
| dev_20 = DEVICE_DT_GET(DT_NODELABEL(ipc20)); |
| |
| /* |
| * We send 10 through the ipc10 instance so we expect 20 in the |
| * receiving callback (10 + 10 == 20) |
| */ |
| msg = 10; |
| printk("Sending %d\n", msg); |
| |
| /* Save the expected result in priv */ |
| ept_cfg.priv = (void *) 20; |
| |
| ret = ipc_service_register_endpoint(dev_10, &ept_10, &ept_cfg); |
| zassert_ok(ret, "ipc_service_register_endpoint() failed", NULL); |
| |
| ret = ipc_service_send(&ept_10, &msg, sizeof(msg)); |
| zassert_ok(ret, "ipc_service_send() failed", NULL); |
| |
| /* |
| * We send 10 again this time through the ipc20 instance so we expect |
| * 20 in the receiving callback (10 + 20 == 30) |
| */ |
| msg = 10; |
| printk("Sending %d\n", msg); |
| |
| /* Save the expected result in priv */ |
| ept_cfg.priv = (void *) 30; |
| |
| ret = ipc_service_register_endpoint(dev_20, &ept_20, &ept_cfg); |
| zassert_ok(ret, "ipc_service_register_endpoint() failed", NULL); |
| |
| ret = ipc_service_send(&ept_20, &msg, sizeof(msg)); |
| zassert_ok(ret, "ipc_service_send() failed", NULL); |
| } |
| |
| void test_main(void) |
| { |
| ztest_test_suite(ipc_service, |
| ztest_unit_test(test_ipc_service)); |
| ztest_run_test_suite(ipc_service); |
| } |