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:
Jeferson Fernando 2024-05-02 00:50:10 +00:00 committed by Alberto Escolar
commit 4810914d00
4 changed files with 102 additions and 0 deletions

View 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})

View 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

View 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);

View file

@ -0,0 +1,6 @@
tests:
lorawan.channels_mask.set_channels_mask:
tags: lorawan
depends_on: lora
integration_platforms:
- b_l072z_lrwan1