Refactor/cov subscriptions encoding decoding test (#1296)
* Add BACnetRecipientProcess type encoding and decoding functions with associated tests * Refactor COV subscription encoding and decoding functions to reduce code size and reuse existing unit tested functions. * Refactor COV subscription handling to simplify error checking
This commit is contained in:
@@ -193,6 +193,8 @@ list(APPEND testdirs
|
||||
bacnet/basic/object/trendlog
|
||||
# basic/program
|
||||
bacnet/basic/program/ubasic
|
||||
# basic/service
|
||||
bacnet/basic/service/h_cov
|
||||
# basic/server
|
||||
bacnet/basic/server/bacnet_device
|
||||
# basic/sys
|
||||
|
||||
@@ -245,6 +245,89 @@ static void test_BACnetRecipient_ASCII(void)
|
||||
zassert_true(status, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test BACnetRecipientProcess encode, decode, copy functions
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(bacnet_destination_tests, testBACnetRecipientProcess)
|
||||
#else
|
||||
static void testBACnetRecipientProcess(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
BACNET_RECIPIENT_PROCESS value = { 0 }, test_value = { 0 };
|
||||
BACNET_MAC_ADDRESS mac = { .len = 1, .adr[0] = 0x01 };
|
||||
BACNET_MAC_ADDRESS adr = { .len = 1, .adr[0] = 0x02 };
|
||||
uint16_t snet = 4321;
|
||||
BACNET_ADDRESS address = { 0 };
|
||||
int apdu_len = 0, null_len = 0, test_len = 0;
|
||||
uint8_t tag_number = 3;
|
||||
bool status = false;
|
||||
|
||||
/* device recipient */
|
||||
bacnet_recipient_device_set(&value.recipient, OBJECT_DEVICE, 5678);
|
||||
value.process_identifier = 99;
|
||||
null_len = bacnet_recipient_process_encode(NULL, &value);
|
||||
apdu_len = bacnet_recipient_process_encode(apdu, &value);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_recipient_process_decode(apdu, apdu_len, &test_value);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
zassert_equal(
|
||||
value.process_identifier, test_value.process_identifier, NULL);
|
||||
status = bacnet_recipient_same(&value.recipient, &test_value.recipient);
|
||||
zassert_true(status, NULL);
|
||||
/* NULL decode target - length-only */
|
||||
test_len = bacnet_recipient_process_decode(apdu, apdu_len, NULL);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
|
||||
/* copy */
|
||||
memset(&test_value, 0, sizeof(test_value));
|
||||
bacnet_recipient_process_copy(&test_value, &value);
|
||||
zassert_equal(
|
||||
value.process_identifier, test_value.process_identifier, NULL);
|
||||
status = bacnet_recipient_same(&value.recipient, &test_value.recipient);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
/* address recipient */
|
||||
status = bacnet_address_init(&address, &mac, snet, &adr);
|
||||
zassert_true(status, NULL);
|
||||
bacnet_recipient_address_set(&value.recipient, &address);
|
||||
value.process_identifier = 42;
|
||||
null_len = bacnet_recipient_process_encode(NULL, &value);
|
||||
apdu_len = bacnet_recipient_process_encode(apdu, &value);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_recipient_process_decode(apdu, apdu_len, &test_value);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
zassert_equal(
|
||||
value.process_identifier, test_value.process_identifier, NULL);
|
||||
status = bacnet_recipient_same(&value.recipient, &test_value.recipient);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
/* context encode/decode */
|
||||
bacnet_recipient_device_set(&value.recipient, OBJECT_DEVICE, 1234);
|
||||
value.process_identifier = 7;
|
||||
null_len =
|
||||
bacnet_recipient_process_context_encode(NULL, tag_number, &value);
|
||||
apdu_len =
|
||||
bacnet_recipient_process_context_encode(apdu, tag_number, &value);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_recipient_process_context_decode(
|
||||
apdu, apdu_len, tag_number, &test_value);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
zassert_equal(
|
||||
value.process_identifier, test_value.process_identifier, NULL);
|
||||
status = bacnet_recipient_same(&value.recipient, &test_value.recipient);
|
||||
zassert_true(status, NULL);
|
||||
/* wrong tag - expect zero (tag mismatch) */
|
||||
test_len = bacnet_recipient_process_context_decode(
|
||||
apdu, apdu_len, tag_number + 1, &test_value);
|
||||
zassert_equal(test_len, 0, NULL);
|
||||
|
||||
/* negative: NULL apdu */
|
||||
test_len = bacnet_recipient_process_decode(NULL, apdu_len, &test_value);
|
||||
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST_SUITE(bacnet_destination_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
@@ -254,7 +337,8 @@ void test_main(void)
|
||||
bacnet_destination_tests, ztest_unit_test(testBACnetDestination),
|
||||
ztest_unit_test(test_BACnetDestination_ASCII),
|
||||
ztest_unit_test(testBACnetRecipient),
|
||||
ztest_unit_test(test_BACnetRecipient_ASCII));
|
||||
ztest_unit_test(test_BACnetRecipient_ASCII),
|
||||
ztest_unit_test(testBACnetRecipientProcess));
|
||||
|
||||
ztest_run_test_suite(bacnet_destination_tests);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,16 @@
|
||||
|
||||
void bip_get_my_address(BACNET_ADDRESS *my_address)
|
||||
{
|
||||
(void)my_address;
|
||||
if (my_address) {
|
||||
my_address->mac_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int bip_send_pdu(
|
||||
BACNET_ADDRESS *dest,
|
||||
BACNET_NPDU_DATA *npdu_data,
|
||||
uint8_t *pdu,
|
||||
unsigned pdu_len)
|
||||
uint16_t pdu_len)
|
||||
{
|
||||
(void)dest;
|
||||
(void)npdu_data;
|
||||
|
||||
@@ -46,3 +46,57 @@ int Device_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
(void)rpdata;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Device_Valid_Object_Id(
|
||||
BACNET_OBJECT_TYPE object_type, uint32_t object_instance)
|
||||
{
|
||||
(void)object_type;
|
||||
(void)object_instance;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device_Value_List_Supported(BACNET_OBJECT_TYPE object_type)
|
||||
{
|
||||
(void)object_type;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device_COV(BACNET_OBJECT_TYPE object_type, uint32_t object_instance)
|
||||
{
|
||||
(void)object_type;
|
||||
(void)object_instance;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Device_COV_Clear(BACNET_OBJECT_TYPE object_type, uint32_t object_instance)
|
||||
{
|
||||
(void)object_type;
|
||||
(void)object_instance;
|
||||
}
|
||||
|
||||
bool Device_Encode_Value_List(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_VALUE *value_list)
|
||||
{
|
||||
(void)object_type;
|
||||
(void)object_instance;
|
||||
(void)value_list;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t Routed_Device_Object_Index(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Set_Routed_Device_Object_Index(uint16_t index)
|
||||
{
|
||||
(void)index;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t Get_Num_Managed_Devices(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||
|
||||
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(test_${basename}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C)
|
||||
|
||||
string(REGEX REPLACE
|
||||
"/test/bacnet/[a-zA-Z0-9_/-]*$"
|
||||
"/src"
|
||||
SRC_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
string(REGEX REPLACE
|
||||
"/test/bacnet/[a-zA-Z0-9_/-]*$"
|
||||
"/test"
|
||||
TST_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||
|
||||
add_compile_definitions(
|
||||
BACNET_BIG_ENDIAN=0
|
||||
CONFIG_ZTEST=1
|
||||
BACAPP_ALL=1
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/basic/service/h_cov.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
${SRC_DIR}/bacnet/access_rule.c
|
||||
${SRC_DIR}/bacnet/bacaction.c
|
||||
${SRC_DIR}/bacnet/bacaddr.c
|
||||
${SRC_DIR}/bacnet/bacapp.c
|
||||
${SRC_DIR}/bacnet/bacdcode.c
|
||||
${SRC_DIR}/bacnet/bacdest.c
|
||||
${SRC_DIR}/bacnet/bacdevobjpropref.c
|
||||
${SRC_DIR}/bacnet/bacint.c
|
||||
${SRC_DIR}/bacnet/baclog.c
|
||||
${SRC_DIR}/bacnet/bacreal.c
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/bacerror.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/basic/sys/debug.c
|
||||
${SRC_DIR}/bacnet/basic/tsm/tsm.c
|
||||
${SRC_DIR}/bacnet/bactimevalue.c
|
||||
${SRC_DIR}/bacnet/calendar_entry.c
|
||||
${SRC_DIR}/bacnet/channel_value.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
${SRC_DIR}/bacnet/memcopy.c
|
||||
${SRC_DIR}/bacnet/secure_connect.c
|
||||
${SRC_DIR}/bacnet/shed_level.c
|
||||
${SRC_DIR}/bacnet/special_event.c
|
||||
${SRC_DIR}/bacnet/timer_value.c
|
||||
${SRC_DIR}/bacnet/timestamp.c
|
||||
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||
${SRC_DIR}/bacnet/abort.c
|
||||
${SRC_DIR}/bacnet/dcc.c
|
||||
${SRC_DIR}/bacnet/npdu.c
|
||||
${SRC_DIR}/bacnet/reject.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${TST_DIR}/bacnet/basic/object/test/apdu_mock.c
|
||||
${TST_DIR}/bacnet/basic/object/test/bip_mock.c
|
||||
${TST_DIR}/bacnet/basic/object/test/device_mock.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,348 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief test BACnet COV service handler
|
||||
* @date 2025
|
||||
* @copyright SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/bacdef.h>
|
||||
#include <bacnet/cov.h>
|
||||
#include <bacnet/basic/services.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Mock functions for Device_ */
|
||||
#include <bacnet/basic/object/device.h>
|
||||
|
||||
/* Mocks have been moved to bacnet/basic/object/test/ */
|
||||
/**
|
||||
* @brief Test test_h_cov_init_encode
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_init_encode)
|
||||
#else
|
||||
static void test_h_cov_init_encode(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int apdu_size = sizeof(apdu);
|
||||
int len;
|
||||
uint8_t service_request[128] = { 0 };
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data = { 0 };
|
||||
|
||||
handler_cov_init();
|
||||
|
||||
len = handler_cov_encode_subscriptions(apdu, apdu_size);
|
||||
/* Should be zero because we initialized the handler */
|
||||
zassert_equal(len, 0, NULL);
|
||||
|
||||
/* Create a valid subscription */
|
||||
cov_data.subscriberProcessIdentifier = 1;
|
||||
cov_data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
cov_data.monitoredObjectIdentifier.instance = 0;
|
||||
cov_data.cancellationRequest = false;
|
||||
cov_data.issueConfirmedNotifications = false;
|
||||
cov_data.lifetime = 0;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ABORT, NULL);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
|
||||
/* Normal encode */
|
||||
len = handler_cov_encode_subscriptions(apdu, apdu_size);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
zassert_not_equal(len, BACNET_STATUS_ABORT, NULL);
|
||||
|
||||
/* edge case: exact size buffer encode */
|
||||
len = handler_cov_encode_subscriptions(apdu, len);
|
||||
zassert_equal(len, len, NULL);
|
||||
|
||||
/* edge case: buffer too small */
|
||||
len = handler_cov_encode_subscriptions(apdu, len - 1);
|
||||
zassert_equal(len, BACNET_STATUS_ABORT, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test test_h_cov_timer
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_timer)
|
||||
#else
|
||||
static void test_h_cov_timer(void)
|
||||
#endif
|
||||
{
|
||||
handler_cov_timer_seconds(1);
|
||||
zassert_true(true, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test test_h_cov_fsm
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_fsm)
|
||||
#else
|
||||
static void test_h_cov_fsm(void)
|
||||
#endif
|
||||
{
|
||||
bool idle;
|
||||
uint8_t service_request[128] = { 0 };
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data = { 0 };
|
||||
int len;
|
||||
|
||||
handler_cov_init();
|
||||
|
||||
idle = handler_cov_fsm();
|
||||
zassert_true(idle, NULL); /* No subscriptions, quickly back to idle */
|
||||
|
||||
/* Subscribe Unconfirmed */
|
||||
cov_data.subscriberProcessIdentifier = 1;
|
||||
cov_data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
cov_data.monitoredObjectIdentifier.instance = 0;
|
||||
cov_data.cancellationRequest = false;
|
||||
cov_data.issueConfirmedNotifications = false;
|
||||
cov_data.lifetime = 0;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
|
||||
/* IDLE -> MARK */
|
||||
idle = handler_cov_fsm();
|
||||
zassert_false(idle, NULL);
|
||||
/* MARK -> CLEAR */
|
||||
idle = handler_cov_fsm();
|
||||
zassert_false(idle, NULL);
|
||||
/* CLEAR -> FREE */
|
||||
idle = handler_cov_fsm();
|
||||
zassert_false(idle, NULL);
|
||||
/* FREE -> SEND */
|
||||
idle = handler_cov_fsm();
|
||||
zassert_false(idle, NULL);
|
||||
/* SEND -> IDLE */
|
||||
idle = handler_cov_fsm();
|
||||
zassert_true(idle, NULL);
|
||||
|
||||
/* Subscribe Confirmed */
|
||||
cov_data.subscriberProcessIdentifier = 2;
|
||||
cov_data.issueConfirmedNotifications = true;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
|
||||
/* Run FSM again */
|
||||
handler_cov_fsm(); /* IDLE -> MARK */
|
||||
handler_cov_fsm(); /* MARK -> CLEAR */
|
||||
handler_cov_fsm(); /* CLEAR -> FREE */
|
||||
handler_cov_fsm(); /* FREE -> SEND */
|
||||
handler_cov_fsm(); /* SEND -> IDLE */
|
||||
|
||||
/* Trigger Confirmed free branch by expiring */
|
||||
cov_data.lifetime = 10;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
|
||||
handler_cov_fsm(); /* IDLE -> MARK */
|
||||
handler_cov_fsm(); /* MARK -> CLEAR */
|
||||
handler_cov_fsm(); /* CLEAR -> FREE */
|
||||
handler_cov_fsm(); /* FREE -> SEND */
|
||||
handler_cov_fsm(); /* SEND -> IDLE */
|
||||
|
||||
/* Expire */
|
||||
handler_cov_timer_seconds(15);
|
||||
|
||||
handler_cov_task();
|
||||
zassert_true(true, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test test_h_cov_subscribe_error_cases
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_subscribe_error_cases)
|
||||
#else
|
||||
static void test_h_cov_subscribe_error_cases(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t service_request[128] = { 0 };
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data = { 0 };
|
||||
int len;
|
||||
|
||||
handler_cov_init();
|
||||
|
||||
/* test segment abort */
|
||||
service_data.segmented_message = true;
|
||||
handler_cov_subscribe(service_request, 10, &src, &service_data);
|
||||
zassert_true(true, NULL);
|
||||
|
||||
/* test missing required parameter */
|
||||
service_data.segmented_message = false;
|
||||
handler_cov_subscribe(service_request, 0, &src, &service_data);
|
||||
zassert_true(true, NULL);
|
||||
|
||||
/* test bad request decode */
|
||||
handler_cov_subscribe(service_request, 1, &src, &service_data);
|
||||
zassert_true(true, NULL);
|
||||
|
||||
/* test valid decode but object valid (by mock) */
|
||||
cov_data.subscriberProcessIdentifier = 1;
|
||||
cov_data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
cov_data.monitoredObjectIdentifier.instance = 12345;
|
||||
cov_data.cancellationRequest = false;
|
||||
cov_data.issueConfirmedNotifications = false;
|
||||
cov_data.lifetime = 0;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
zassert_true(true, NULL);
|
||||
|
||||
/* test cancellation of non-existing */
|
||||
cov_data.cancellationRequest = true;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
zassert_true(true, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test test_h_cov_subscribe_out_of_space
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_subscribe_out_of_space)
|
||||
#else
|
||||
static void test_h_cov_subscribe_out_of_space(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t service_request[128] = { 0 };
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data = { 0 };
|
||||
int len;
|
||||
int i;
|
||||
|
||||
handler_cov_init();
|
||||
|
||||
cov_data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
cov_data.monitoredObjectIdentifier.instance = 0;
|
||||
cov_data.cancellationRequest = false;
|
||||
cov_data.issueConfirmedNotifications = false;
|
||||
cov_data.lifetime = 0;
|
||||
|
||||
for (i = 0; i < 130; i++) {
|
||||
cov_data.subscriberProcessIdentifier = i;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
}
|
||||
zassert_true(true, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test test_h_cov_timer_expiration
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_timer_expiration)
|
||||
#else
|
||||
static void test_h_cov_timer_expiration(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t service_request[128] = { 0 };
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data = { 0 };
|
||||
int len;
|
||||
|
||||
handler_cov_init();
|
||||
|
||||
/* Subscribe with lifetime */
|
||||
cov_data.subscriberProcessIdentifier = 1;
|
||||
cov_data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
cov_data.monitoredObjectIdentifier.instance = 0;
|
||||
cov_data.cancellationRequest = false;
|
||||
cov_data.issueConfirmedNotifications = true;
|
||||
cov_data.lifetime = 10;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
|
||||
/* Check timer decreasing */
|
||||
handler_cov_timer_seconds(5);
|
||||
handler_cov_timer_seconds(10); /* Should expire here */
|
||||
zassert_true(true, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test test_h_cov_address_management
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(h_cov_tests, test_h_cov_address_management)
|
||||
#else
|
||||
static void test_h_cov_address_management(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t service_request[128] = { 0 };
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data = { 0 };
|
||||
int len;
|
||||
int i;
|
||||
|
||||
handler_cov_init();
|
||||
|
||||
cov_data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
cov_data.monitoredObjectIdentifier.instance = 0;
|
||||
cov_data.cancellationRequest = false;
|
||||
cov_data.issueConfirmedNotifications = false;
|
||||
cov_data.lifetime = 0;
|
||||
|
||||
/* Add subscriptions from 18 different sources */
|
||||
for (i = 0; i < 18; i++) {
|
||||
src.mac_len = 1;
|
||||
src.mac[0] = i + 1;
|
||||
cov_data.subscriberProcessIdentifier = i;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
}
|
||||
|
||||
/* Cancel one, to free an address */
|
||||
src.mac_len = 1;
|
||||
src.mac[0] = 1;
|
||||
cov_data.subscriberProcessIdentifier = 0;
|
||||
cov_data.cancellationRequest = true;
|
||||
len = cov_subscribe_service_request_encode(
|
||||
service_request, sizeof(service_request), &cov_data);
|
||||
handler_cov_subscribe(service_request, len, &src, &service_data);
|
||||
|
||||
zassert_true(true, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST_SUITE(h_cov_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(
|
||||
h_cov_tests, ztest_unit_test(test_h_cov_init_encode),
|
||||
ztest_unit_test(test_h_cov_timer), ztest_unit_test(test_h_cov_fsm),
|
||||
ztest_unit_test(test_h_cov_subscribe_error_cases),
|
||||
ztest_unit_test(test_h_cov_subscribe_out_of_space),
|
||||
ztest_unit_test(test_h_cov_timer_expiration),
|
||||
ztest_unit_test(test_h_cov_address_management));
|
||||
|
||||
ztest_run_test_suite(h_cov_tests);
|
||||
}
|
||||
#endif
|
||||
@@ -342,6 +342,69 @@ static void testCOVSubscribePropertyData(
|
||||
}
|
||||
}
|
||||
|
||||
static void testCOVSubscriptionData(
|
||||
const BACNET_COV_SUBSCRIPTION *data,
|
||||
const BACNET_COV_SUBSCRIPTION *test_data)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
zassert_equal(
|
||||
test_data->time_remaining, data->time_remaining,
|
||||
"time-remaining mismatch");
|
||||
zassert_equal(
|
||||
test_data->issue_confirmed_notifications,
|
||||
data->issue_confirmed_notifications,
|
||||
"issue-confirmed-notifications mismatch");
|
||||
zassert_equal(
|
||||
test_data->cov_increment_present, data->cov_increment_present,
|
||||
"cov-increment-present mismatch");
|
||||
if (test_data->cov_increment_present) {
|
||||
zassert_false(
|
||||
islessgreater(test_data->cov_increment, data->cov_increment),
|
||||
"cov-increment mismatch");
|
||||
}
|
||||
zassert_equal(
|
||||
test_data->recipient.process_identifier,
|
||||
data->recipient.process_identifier,
|
||||
"recipient process-identifier mismatch");
|
||||
status = bacnet_recipient_same(
|
||||
&test_data->recipient.recipient, &data->recipient.recipient);
|
||||
zassert_true(status, "recipient mismatch");
|
||||
status = bacnet_object_property_reference_same(
|
||||
&test_data->monitored_property_reference,
|
||||
&data->monitored_property_reference);
|
||||
zassert_true(status, "monitored-property-reference mismatch");
|
||||
}
|
||||
|
||||
static void testCOVSubscriptionEncoding(const BACNET_COV_SUBSCRIPTION *data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
size_t len = 0, null_len = 0;
|
||||
BACNET_COV_SUBSCRIPTION test_data = { 0 };
|
||||
int decode_len = 0;
|
||||
|
||||
null_len = bacnet_cov_subscription_encode(NULL, sizeof(apdu), data);
|
||||
len = bacnet_cov_subscription_encode(&apdu[0], sizeof(apdu), data);
|
||||
zassert_true(len > 0, NULL);
|
||||
zassert_equal(len, null_len, NULL);
|
||||
|
||||
if (len > 0) {
|
||||
zassert_equal(
|
||||
bacnet_cov_subscription_encode(&apdu[0], len - 1, data), 0, NULL);
|
||||
}
|
||||
|
||||
decode_len = bacnet_cov_subscription_decode(NULL, len, &test_data);
|
||||
zassert_equal(decode_len, 0, NULL);
|
||||
decode_len = bacnet_cov_subscription_decode(&apdu[0], 0, &test_data);
|
||||
zassert_equal(decode_len, 0, NULL);
|
||||
|
||||
decode_len = bacnet_cov_subscription_decode(&apdu[0], len, NULL);
|
||||
zassert_equal(decode_len, (int)len, NULL);
|
||||
decode_len = bacnet_cov_subscription_decode(&apdu[0], len, &test_data);
|
||||
zassert_equal(decode_len, (int)len, NULL);
|
||||
testCOVSubscriptionData(data, &test_data);
|
||||
}
|
||||
|
||||
static void testCOVSubscribeEncoding(
|
||||
uint8_t invoke_id, const BACNET_SUBSCRIBE_COV_DATA *data)
|
||||
{
|
||||
@@ -450,6 +513,33 @@ static void testCOVSubscribeProperty(void)
|
||||
testCOVSubscribePropertyEncoding(invoke_id, &data);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(cov_tests, testCOVSubscription)
|
||||
#else
|
||||
static void testCOVSubscription(void)
|
||||
#endif
|
||||
{
|
||||
BACNET_COV_SUBSCRIPTION data = { 0 };
|
||||
|
||||
data.time_remaining = 456;
|
||||
data.issue_confirmed_notifications = true;
|
||||
data.recipient.process_identifier = 1;
|
||||
bacnet_recipient_device_set(&data.recipient.recipient, OBJECT_DEVICE, 123);
|
||||
data.monitored_property_reference.object_identifier.type =
|
||||
OBJECT_ANALOG_INPUT;
|
||||
data.monitored_property_reference.object_identifier.instance = 321;
|
||||
data.monitored_property_reference.property_identifier = PROP_PRESENT_VALUE;
|
||||
data.monitored_property_reference.property_array_index = BACNET_ARRAY_ALL;
|
||||
|
||||
data.cov_increment_present = false;
|
||||
data.cov_increment = 0.0f;
|
||||
testCOVSubscriptionEncoding(&data);
|
||||
|
||||
data.cov_increment_present = true;
|
||||
data.cov_increment = 1.5f;
|
||||
testCOVSubscriptionEncoding(&data);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(cov_tests, test_COV_Value_List_Encode)
|
||||
#else
|
||||
@@ -606,6 +696,7 @@ void test_main(void)
|
||||
cov_tests, ztest_unit_test(testCOVNotify),
|
||||
ztest_unit_test(testCOVSubscribe),
|
||||
ztest_unit_test(testCOVSubscribeProperty),
|
||||
ztest_unit_test(testCOVSubscription),
|
||||
ztest_unit_test(test_COV_Value_List_Encode));
|
||||
|
||||
ztest_run_test_suite(cov_tests);
|
||||
|
||||
Reference in New Issue
Block a user