Skip to content

Commit

Permalink
tests: modem: Modem backend mock update
Browse files Browse the repository at this point in the history
Added possibility for link 2 modem mock instance for
validating P2P communication without any data stubbing.

Signed-off-by: Juha Heiskanen <[email protected]>
  • Loading branch information
Juha Heiskanen authored and fabiobaltieri committed Dec 8, 2023
1 parent 093efc4 commit 6943cd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/subsys/modem/mock/modem_backend_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ static int modem_backend_mock_transmit(void *data, const uint8_t *buf, size_t si
int ret;

size = (mock->limit < size) ? mock->limit : size;

if (mock->bridge) {
struct modem_backend_mock *t_mock = mock->bridge;

ret = ring_buf_put(&t_mock->rx_rb, buf, size);
k_work_submit(&t_mock->received_work_item.work);
return ret;
}

ret = ring_buf_put(&mock->tx_rb, buf, size);
if (modem_backend_mock_update(mock, buf, size)) {
modem_backend_mock_put(mock, mock->transaction->put,
Expand Down Expand Up @@ -130,3 +139,9 @@ void modem_backend_mock_prime(struct modem_backend_mock *mock,
mock->transaction = transaction;
mock->transaction_match_cnt = 0;
}

void modem_backend_mock_bridge(struct modem_backend_mock *mock_a, struct modem_backend_mock *mock_b)
{
mock_a->bridge = mock_b;
mock_b->bridge = mock_a;
}
5 changes: 5 additions & 0 deletions tests/subsys/modem/mock/modem_backend_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct modem_backend_mock {

/* Max allowed read/write size */
size_t limit;
/* Mock Brige pair */
struct modem_backend_mock *bridge;
};

struct modem_backend_mock_config {
Expand All @@ -63,4 +65,7 @@ void modem_backend_mock_put(struct modem_backend_mock *mock, const uint8_t *buf,
void modem_backend_mock_prime(struct modem_backend_mock *mock,
const struct modem_backend_mock_transaction *transaction);

void modem_backend_mock_bridge(struct modem_backend_mock *mock_a,
struct modem_backend_mock *mock_b);

#endif /* ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK */

0 comments on commit 6943cd4

Please sign in to comment.