tests: subsys: modem: add test suite for pipelink
Add test suite for pipelink module Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This commit is contained in:
parent
1f7d0b6cb0
commit
03596feda1
8
tests/subsys/modem/modem_pipelink/CMakeLists.txt
Normal file
8
tests/subsys/modem/modem_pipelink/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2024 Trackunit Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(modem_pipelink_test)
|
||||
|
||||
target_sources(app PRIVATE src/main.c src/pipelink.c)
|
||||
4
tests/subsys/modem/modem_pipelink/app.overlay
Normal file
4
tests/subsys/modem/modem_pipelink/app.overlay
Normal file
@ -0,0 +1,4 @@
|
||||
/ {
|
||||
test_node: test_node {
|
||||
};
|
||||
};
|
||||
7
tests/subsys/modem/modem_pipelink/prj.conf
Normal file
7
tests/subsys/modem/modem_pipelink/prj.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2024 Trackunit Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
CONFIG_MODEM_MODULES=y
|
||||
CONFIG_MODEM_PIPE=y
|
||||
CONFIG_MODEM_PIPELINK=y
|
||||
CONFIG_ZTEST=y
|
||||
99
tests/subsys/modem/modem_pipelink/src/main.c
Normal file
99
tests/subsys/modem/modem_pipelink/src/main.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Trackunit Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/modem/pipe.h>
|
||||
#include <zephyr/modem/pipelink.h>
|
||||
#include <zephyr/sys/atomic.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#define TEST_NODE DT_NODELABEL(test_node)
|
||||
#define TEST_PIPELINK_NAME test_pipelink_0
|
||||
|
||||
#define TEST_EVENTS_CONNECTED_BIT 0
|
||||
#define TEST_EVENTS_DISCONNECTED_BIT 1
|
||||
|
||||
MODEM_PIPELINK_DT_DECLARE(TEST_NODE, TEST_PIPELINK_NAME);
|
||||
|
||||
static struct modem_pipelink *test_pipelink =
|
||||
MODEM_PIPELINK_DT_GET(TEST_NODE, TEST_PIPELINK_NAME);
|
||||
|
||||
static struct modem_pipe test_pipe;
|
||||
static atomic_t events;
|
||||
static uint32_t test_user_data;
|
||||
|
||||
static void test_pipelink_callback(struct modem_pipelink *link,
|
||||
enum modem_pipelink_event event,
|
||||
void *user_data)
|
||||
{
|
||||
zassert_equal(test_pipelink, link);
|
||||
zassert_equal((void *)(&test_user_data), user_data);
|
||||
|
||||
switch (event) {
|
||||
case MODEM_PIPELINK_EVENT_CONNECTED:
|
||||
atomic_set_bit(&events, TEST_EVENTS_CONNECTED_BIT);
|
||||
break;
|
||||
|
||||
case MODEM_PIPELINK_EVENT_DISCONNECTED:
|
||||
atomic_set_bit(&events, TEST_EVENTS_DISCONNECTED_BIT);
|
||||
break;
|
||||
|
||||
default:
|
||||
zassert(0, "invalid event");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_reset_events(void)
|
||||
{
|
||||
atomic_set(&events, 0);
|
||||
}
|
||||
|
||||
static void *test_setup(void)
|
||||
{
|
||||
modem_pipelink_init(test_pipelink, &test_pipe);
|
||||
test_reset_events();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void test_before(void *f)
|
||||
{
|
||||
ARG_UNUSED(f);
|
||||
|
||||
modem_pipelink_notify_disconnected(test_pipelink);
|
||||
modem_pipelink_release(test_pipelink);
|
||||
test_reset_events();
|
||||
}
|
||||
|
||||
ZTEST(modem_pipelink, test_connect_not_attached)
|
||||
{
|
||||
zassert_false(modem_pipelink_is_connected(test_pipelink));
|
||||
modem_pipelink_notify_connected(test_pipelink);
|
||||
zassert_true(modem_pipelink_is_connected(test_pipelink));
|
||||
modem_pipelink_notify_disconnected(test_pipelink);
|
||||
zassert_false(modem_pipelink_is_connected(test_pipelink));
|
||||
}
|
||||
|
||||
ZTEST(modem_pipelink, test_connect_attached)
|
||||
{
|
||||
modem_pipelink_attach(test_pipelink, test_pipelink_callback, &test_user_data);
|
||||
modem_pipelink_notify_connected(test_pipelink);
|
||||
zassert_true(atomic_test_bit(&events, TEST_EVENTS_CONNECTED_BIT));
|
||||
zassert_false(atomic_test_bit(&events, TEST_EVENTS_DISCONNECTED_BIT));
|
||||
test_reset_events();
|
||||
modem_pipelink_notify_connected(test_pipelink);
|
||||
zassert_false(atomic_test_bit(&events, TEST_EVENTS_CONNECTED_BIT));
|
||||
zassert_false(atomic_test_bit(&events, TEST_EVENTS_DISCONNECTED_BIT));
|
||||
modem_pipelink_notify_disconnected(test_pipelink);
|
||||
zassert_false(atomic_test_bit(&events, TEST_EVENTS_CONNECTED_BIT));
|
||||
zassert_true(atomic_test_bit(&events, TEST_EVENTS_DISCONNECTED_BIT));
|
||||
test_reset_events();
|
||||
modem_pipelink_notify_disconnected(test_pipelink);
|
||||
zassert_false(atomic_test_bit(&events, TEST_EVENTS_CONNECTED_BIT));
|
||||
zassert_false(atomic_test_bit(&events, TEST_EVENTS_DISCONNECTED_BIT));
|
||||
}
|
||||
|
||||
ZTEST_SUITE(modem_pipelink, NULL, test_setup, test_before, NULL, NULL);
|
||||
13
tests/subsys/modem/modem_pipelink/src/pipelink.c
Normal file
13
tests/subsys/modem/modem_pipelink/src/pipelink.c
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Trackunit Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/modem/pipelink.h>
|
||||
|
||||
#define TEST_NODE DT_NODELABEL(test_node)
|
||||
#define TEST_PIPELINK_NAME test_pipelink_0
|
||||
|
||||
/* Define pipelink in separate source file to test MODEM_PIPELINK_DT_DECLARE() */
|
||||
MODEM_PIPELINK_DT_DEFINE(TEST_NODE, TEST_PIPELINK_NAME);
|
||||
7
tests/subsys/modem/modem_pipelink/testcase.yaml
Normal file
7
tests/subsys/modem/modem_pipelink/testcase.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2024 Trackunit Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
tests:
|
||||
modem.modem_pipelink:
|
||||
tags: modem_pipelink
|
||||
harness: ztest
|
||||
Loading…
Reference in New Issue
Block a user