tests: subsys: lorawan: add channels mask configuration tests
Checks the behavior of configuration of channels mask for LoRaWAN. Are passed wrong masks sizes as argument, NULL pointer instead channels mask buffer and the right case to validate the expected returns. Signed-off-by: Jeferson Fernando <jeferson.santos@edge.ufal.br>
This commit is contained in:
parent
c0a17a9a5e
commit
4810914d00
4 changed files with 102 additions and 0 deletions
8
tests/subsys/lorawan/channels_mask/CMakeLists.txt
Normal file
8
tests/subsys/lorawan/channels_mask/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(lorawan_channels_mask_test)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
11
tests/subsys/lorawan/channels_mask/prj.conf
Normal file
11
tests/subsys/lorawan/channels_mask/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_ASSERT=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_GPIO=y
|
||||
CONFIG_LORA=y
|
||||
CONFIG_LORAWAN=y
|
||||
CONFIG_LORAMAC_REGION_AS923=y
|
||||
CONFIG_LORAMAC_REGION_AU915=y
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
77
tests/subsys/lorawan/channels_mask/src/main.c
Normal file
77
tests/subsys/lorawan/channels_mask/src/main.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Jeferson Fernando <jeferson.santos@edge.ufal.br>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/lorawan/lorawan.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
/**
|
||||
* @brief Test channels mask with size 1
|
||||
*
|
||||
* This test will request the channels mask changes, passing valid
|
||||
* and invalid arguments and checking when it's successful or returns error
|
||||
*
|
||||
*/
|
||||
ZTEST(channels_mask, test_mask_size_1)
|
||||
{
|
||||
int err = 0;
|
||||
uint16_t channels_mask[LORAWAN_CHANNELS_MASK_SIZE_AS923] = {0xffff};
|
||||
|
||||
/* Test the function when a region with mask size 1 is being used */
|
||||
err = lorawan_set_region(LORAWAN_REGION_AS923);
|
||||
zassert_equal(err, 0, "Could not set region");
|
||||
|
||||
err = lorawan_start();
|
||||
zassert_equal(err, 0, "Could not start stack");
|
||||
|
||||
/* Configure channels mask with expected parameters */
|
||||
err = lorawan_set_channels_mask(channels_mask, LORAWAN_CHANNELS_MASK_SIZE_AS923);
|
||||
zassert_equal(err, 0, "Denied right channels mask configuration");
|
||||
|
||||
/* Configure channels mask with unexpected channels mask size */
|
||||
err = lorawan_set_channels_mask(channels_mask, LORAWAN_CHANNELS_MASK_SIZE_AU915);
|
||||
zassert_equal(err, -EINVAL, "Accepted an unexpected mask size for the selected region");
|
||||
|
||||
/* Configure channels mask with pointer to NULL */
|
||||
err = lorawan_set_channels_mask(NULL, LORAWAN_CHANNELS_MASK_SIZE_AS923);
|
||||
zassert_equal(err, -EINVAL, "Accepted a pointer to NULL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test channels mask with size 6
|
||||
*
|
||||
* This test will request the channels mask changes, passing valid
|
||||
* and invalid arguments and checking when it's successful or returns error
|
||||
*
|
||||
*/
|
||||
ZTEST(channels_mask, test_mask_size_6)
|
||||
{
|
||||
int err = 0;
|
||||
uint16_t channels_mask[LORAWAN_CHANNELS_MASK_SIZE_AU915] = {0};
|
||||
|
||||
/* Test the function when a region with mask size 6 is being used */
|
||||
err = lorawan_set_region(LORAWAN_REGION_AU915);
|
||||
zassert_equal(err, 0, "Could not set region");
|
||||
|
||||
err = lorawan_start();
|
||||
zassert_equal(err, 0, "Could not start stack");
|
||||
|
||||
/* Configure channels mask with expected parameters */
|
||||
err = lorawan_set_channels_mask(channels_mask, LORAWAN_CHANNELS_MASK_SIZE_AU915);
|
||||
zassert_equal(err, 0, "Denied right channels mask configuration");
|
||||
|
||||
/* Configure channels mask with unexpected channels mask size */
|
||||
err = lorawan_set_channels_mask(channels_mask, LORAWAN_CHANNELS_MASK_SIZE_AS923);
|
||||
zassert_equal(err, -EINVAL, "Accepted an unexpected mask size for the selected region");
|
||||
|
||||
/* Configure channels mask with pointer to NULL */
|
||||
err = lorawan_set_channels_mask(NULL, LORAWAN_CHANNELS_MASK_SIZE_AU915);
|
||||
zassert_equal(err, -EINVAL, "Accepted a pointer to NULL");
|
||||
}
|
||||
|
||||
ZTEST_SUITE(channels_mask, NULL, NULL, NULL, NULL, NULL);
|
6
tests/subsys/lorawan/channels_mask/testcase.yaml
Normal file
6
tests/subsys/lorawan/channels_mask/testcase.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
tests:
|
||||
lorawan.channels_mask.set_channels_mask:
|
||||
tags: lorawan
|
||||
depends_on: lora
|
||||
integration_platforms:
|
||||
- b_l072z_lrwan1
|
Loading…
Add table
Add a link
Reference in a new issue