Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/subsys/ipc/ipc_sessions/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ config IPC_TEST_SKIP_CORE_RESET
help
Some of the cores cannot be safely restarted.
Skip the tests that require it in such a cases.

config IPC_TEST_BLOCK_SIZE
int "Block size for multiple transfers test"
default 32

config IPC_TEST_BLOCK_CNT
int "Number of blocks for multiple transfers test"
default 8000
35 changes: 35 additions & 0 deletions tests/subsys/ipc/ipc_sessions/common/test_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
IPC_TEST_CMD_ECHO_RSP, /**< Echo respond */
IPC_TEST_CMD_REBOND, /**< Unbond and rebond back whole interface */
IPC_TEST_CMD_REBOOT, /**< Restart remote CPU after a given delay */
/* Commands used for data transfer test */
IPC_TEST_CMD_RXSTART, /**< Start receiving data */
IPC_TEST_CMD_TXSTART, /**< Start sending data */
IPC_TEST_CMD_RXGET, /**< Get rx status */
IPC_TEST_CMD_TXGET, /**< Get tx status */
IPC_TEST_CMD_XSTAT, /**< rx/tx status response */
IPC_TEST_CMD_XDATA, /**< Transfer data block */
/* End of commands used for data transfer test */
};

Check notice on line 28 in tests/subsys/ipc/ipc_sessions/common/test_commands.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/ipc/ipc_sessions/common/test_commands.h:28 - IPC_TEST_CMD_RXSTART, /**< Start receiving data */ - IPC_TEST_CMD_TXSTART, /**< Start sending data */ - IPC_TEST_CMD_RXGET, /**< Get rx status */ - IPC_TEST_CMD_TXGET, /**< Get tx status */ - IPC_TEST_CMD_XSTAT, /**< rx/tx status response */ - IPC_TEST_CMD_XDATA, /**< Transfer data block */ - /* End of commands used for data transfer test */ + IPC_TEST_CMD_RXSTART, /**< Start receiving data */ + IPC_TEST_CMD_TXSTART, /**< Start sending data */ + IPC_TEST_CMD_RXGET, /**< Get rx status */ + IPC_TEST_CMD_TXGET, /**< Get tx status */ + IPC_TEST_CMD_XSTAT, /**< rx/tx status response */ + IPC_TEST_CMD_XDATA, /**< Transfer data block */ + /* End of commands used for data transfer test */

/**
* @brief Base command structure
Expand All @@ -43,4 +51,31 @@
uint32_t timeout_ms;
};

/**
* @brief Start the rx or tx transfer
*/
struct ipc_test_cmd_xstart {
struct ipc_test_cmd base;
uint32_t blk_size;
uint32_t blk_cnt;
uint32_t seed;
};

/**
* @brief Get the status of rx or tx transfer
*/
struct ipc_test_cmd_xstat {
struct ipc_test_cmd base;
uint32_t blk_cnt; /**< Transfers left */
int32_t result; /**< Current result */
};

Check notice on line 71 in tests/subsys/ipc/ipc_sessions/common/test_commands.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/ipc/ipc_sessions/common/test_commands.h:71 - int32_t result; /**< Current result */ + int32_t result; /**< Current result */

/**
* @brief The result of rx or tx transfer
*/
struct ipc_test_cmd_xrsp {
struct ipc_test_cmd base;
int32_t result;
};

#endif /* TEST_COMMANDS_H */
3 changes: 3 additions & 0 deletions tests/subsys/ipc/ipc_sessions/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright 2021 Carlo Caione <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# We need rand_r function
CONFIG_GNU_C_EXTENSIONS=y

CONFIG_ZTEST=y
CONFIG_MMU=y
CONFIG_IPC_SERVICE=y
Expand Down
2 changes: 2 additions & 0 deletions tests/subsys/ipc/ipc_sessions/remote/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

# We need rand_r function
CONFIG_GNU_C_EXTENSIONS=y
CONFIG_PRINTK=y
CONFIG_EVENTS=y

Expand Down
146 changes: 144 additions & 2 deletions tests/subsys/ipc/ipc_sessions/remote/src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdlib.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
Expand All @@ -18,12 +19,23 @@

#define IPC_TEST_EV_REBOND 0x01
#define IPC_TEST_EV_BOND 0x02
#define IPC_TEST_EV_TXTEST 0x04

static const struct device *ipc0_instance = DEVICE_DT_GET(DT_NODELABEL(ipc0));
static volatile bool ipc0_bounded;
K_SEM_DEFINE(bound_sem, 0, 1);
K_EVENT_DEFINE(ipc_ev_req);

struct ipc_xfer_params {
uint32_t blk_size;
uint32_t blk_cnt;
unsigned int seed;
int result;
};

static struct ipc_xfer_params ipc_rx_params;
static struct ipc_xfer_params ipc_tx_params;

static struct k_timer timer_reboot;
static struct k_timer timer_rebond;

Expand Down Expand Up @@ -136,8 +148,6 @@
return;
}

LOG_INF("Command received: %u", cmd->cmd);

switch (cmd->cmd) {
case IPC_TEST_CMD_NONE:
LOG_INF("Command processing: NONE");
Expand Down Expand Up @@ -189,6 +199,99 @@
k_timer_start(&timer_reboot, K_MSEC(cmd_reboot->timeout_ms), K_FOREVER);
break;
}
case IPC_TEST_CMD_RXSTART: {
LOG_INF("Command processing: RXSTART");

struct ipc_test_cmd_xstart *cmd_rxstart = (struct ipc_test_cmd_xstart *)cmd;

ipc_rx_params.blk_size = cmd_rxstart->blk_size;
ipc_rx_params.blk_cnt = cmd_rxstart->blk_cnt;
ipc_rx_params.seed = cmd_rxstart->seed;
ipc_rx_params.result = 0;
break;
}
case IPC_TEST_CMD_TXSTART: {
LOG_INF("Command processing: TXSTART");

struct ipc_test_cmd_xstart *cmd_txstart = (struct ipc_test_cmd_xstart *)cmd;

ipc_tx_params.blk_size = cmd_txstart->blk_size;
ipc_tx_params.blk_cnt = cmd_txstart->blk_cnt;
ipc_tx_params.seed = cmd_txstart->seed;
ipc_tx_params.result = 0;
k_event_set(&ipc_ev_req, IPC_TEST_EV_TXTEST);
break;
}
case IPC_TEST_CMD_RXGET: {
LOG_INF("Command processing: RXGET");

int ret;
struct ipc_test_cmd_xstat cmd_stat = {
.base.cmd = IPC_TEST_CMD_XSTAT,
.blk_cnt = ipc_rx_params.blk_cnt,
.result = ipc_rx_params.result
};

Check notice on line 234 in tests/subsys/ipc/ipc_sessions/remote/src/remote.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/ipc/ipc_sessions/remote/src/remote.c:234 - struct ipc_test_cmd_xstat cmd_stat = { - .base.cmd = IPC_TEST_CMD_XSTAT, - .blk_cnt = ipc_rx_params.blk_cnt, - .result = ipc_rx_params.result - }; + struct ipc_test_cmd_xstat cmd_stat = {.base.cmd = IPC_TEST_CMD_XSTAT, + .blk_cnt = ipc_rx_params.blk_cnt, + .result = ipc_rx_params.result};
ret = ipc_service_send(ep, &cmd_stat, sizeof(cmd_stat));
if (ret < 0) {
LOG_ERR("RXGET response send failed");
}
break;
}
case IPC_TEST_CMD_TXGET: {
LOG_INF("Command processing: TXGET");

int ret;
struct ipc_test_cmd_xstat cmd_stat = {
.base.cmd = IPC_TEST_CMD_XSTAT,
.blk_cnt = ipc_tx_params.blk_cnt,
.result = ipc_tx_params.result
};

Check notice on line 250 in tests/subsys/ipc/ipc_sessions/remote/src/remote.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/ipc/ipc_sessions/remote/src/remote.c:250 - struct ipc_test_cmd_xstat cmd_stat = { - .base.cmd = IPC_TEST_CMD_XSTAT, - .blk_cnt = ipc_tx_params.blk_cnt, - .result = ipc_tx_params.result - }; + struct ipc_test_cmd_xstat cmd_stat = {.base.cmd = IPC_TEST_CMD_XSTAT, + .blk_cnt = ipc_tx_params.blk_cnt, + .result = ipc_tx_params.result};
ret = ipc_service_send(ep, &cmd_stat, sizeof(cmd_stat));
if (ret < 0) {
LOG_ERR("TXGET response send failed");
}
break;
}
case IPC_TEST_CMD_XDATA: {
if ((ipc_rx_params.blk_cnt % 1000) == 0) {
/* Logging only every N-th command not to slowdown the transfer too much */
LOG_INF("Command processing: XDATA (left: %u)", ipc_rx_params.blk_cnt);
}

/* Ignore if there is an error */
if (ipc_rx_params.result) {
LOG_ERR("There is error in Rx transfer already");
break;
}

if (len != ipc_rx_params.blk_size + offsetof(struct ipc_test_cmd, data)) {
LOG_ERR("Size mismatch");
ipc_rx_params.result = -EMSGSIZE;
break;
}

if (ipc_rx_params.blk_cnt <= 0) {
LOG_ERR("Data not expected");
ipc_rx_params.result = -EFAULT;
break;
}

/* Check the data */
for (size_t n = 0; n < ipc_rx_params.blk_size; ++n) {
uint8_t expected = (uint8_t)rand_r(&ipc_rx_params.seed);

if (cmd->data[n] != expected) {
LOG_ERR("Data value error at %u", n);
ipc_rx_params.result = -EINVAL;
break;
}
}

ipc_rx_params.blk_cnt -= 1;
break;
}
default:
LOG_ERR("Unhandled command: %u", cmd->cmd);
break;
Expand Down Expand Up @@ -299,9 +402,48 @@
}
LOG_INF("Bonding done");
}
if (ev & IPC_TEST_EV_TXTEST) {
LOG_INF("Transfer TX test started");

size_t cmd_size = ipc_tx_params.blk_size + offsetof(struct ipc_test_cmd, data);

Check warning on line 408 in tests/subsys/ipc/ipc_sessions/remote/src/remote.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

tests/subsys/ipc/ipc_sessions/remote/src/remote.c:408 line length of 103 exceeds 100 columns
struct ipc_test_cmd *cmd_data = k_malloc(cmd_size);

Check notice on line 409 in tests/subsys/ipc/ipc_sessions/remote/src/remote.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/ipc/ipc_sessions/remote/src/remote.c:409 - size_t cmd_size = ipc_tx_params.blk_size + offsetof(struct ipc_test_cmd, data); + size_t cmd_size = + ipc_tx_params.blk_size + offsetof(struct ipc_test_cmd, data);

if (!cmd_data) {
LOG_ERR("Cannot create TX test buffer");
ipc_tx_params.result = -ENOMEM;
continue;
}

LOG_INF("Initial seed: %u", ipc_tx_params.seed);

cmd_data->cmd = IPC_TEST_CMD_XDATA;
for (/* No init */; ipc_tx_params.blk_cnt > 0; --ipc_tx_params.blk_cnt) {
int ret;

if (ipc_tx_params.blk_cnt % 1000 == 0) {
LOG_INF("Sending: %u blocks left", ipc_tx_params.blk_cnt);
}
/* Generate the block data */
for (size_t n = 0; n < ipc_tx_params.blk_size; ++n) {
cmd_data->data[n] = (uint8_t)rand_r(&ipc_tx_params.seed);
}
do {
ret = ipc_service_send(ep_cfg.priv, cmd_data, cmd_size);
} while (ret == -ENOMEM);
if (ret < 0) {
LOG_ERR("Cannot send TX test buffer: %d", ret);
ipc_tx_params.result = -EIO;
continue;
}
}

k_free(cmd_data);

LOG_INF("Transfer TX test finished");
}


}

Check notice on line 446 in tests/subsys/ipc/ipc_sessions/remote/src/remote.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/ipc/ipc_sessions/remote/src/remote.c:446 - -

return 0;
}
Loading
Loading