Issue 87 execute tests with GitHub ci (#234)
* Enable lcov coverage in unit testing via cmake. * fix pipeline build error * add compile options for unit test to silence some warnings * remove all BAC_TEST unit tests in src/bacnet/ folder. They are now in test/bacnet/ folders using ztest. * removed key.c - only used for unit test. * produce XML test result output for parsing * produce junit XML test result output * change lint workflow to quality * update readme badge for quality results Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -1572,798 +1572,3 @@ int bvlc6_decode_distribute_broadcast_to_network(uint8_t *pdu,
|
||||
|
||||
return bytes_consumed;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
static void test_BVLC6_Address(Test *pTest,
|
||||
BACNET_IP6_ADDRESS *bip6_address_1,
|
||||
BACNET_IP6_ADDRESS *bip6_address_2)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
if (bip6_address_1 && bip6_address_2) {
|
||||
ct_test(pTest, bip6_address_1->port == bip6_address_2->port);
|
||||
for (i = 0; i < IP6_ADDRESS_MAX; i++) {
|
||||
ct_test(pTest,
|
||||
bip6_address_1->address[i] == bip6_address_2->address[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int test_BVLC6_Header(Test *pTest,
|
||||
uint8_t *pdu,
|
||||
uint16_t pdu_len,
|
||||
uint8_t *message_type,
|
||||
uint16_t *length)
|
||||
|
||||
{
|
||||
int bytes_consumed = 0;
|
||||
int len = 0;
|
||||
|
||||
if (pdu && message_type && length) {
|
||||
len = bvlc6_decode_header(pdu, pdu_len, message_type, length);
|
||||
ct_test(pTest, len == 4);
|
||||
bytes_consumed = len;
|
||||
}
|
||||
|
||||
return bytes_consumed;
|
||||
}
|
||||
|
||||
static void test_BVLC6_Result_Code(
|
||||
Test *pTest, uint32_t vmac, uint16_t result_code)
|
||||
{
|
||||
uint8_t pdu[50] = { 0 };
|
||||
uint32_t test_vmac = 0;
|
||||
uint16_t test_result_code = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
|
||||
len = bvlc6_encode_result(pdu, sizeof(pdu), vmac, result_code);
|
||||
ct_test(pTest, len == 9);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_RESULT);
|
||||
ct_test(pTest, length == 9);
|
||||
test_len +=
|
||||
bvlc6_decode_result(&pdu[4], length - 4, &test_vmac, &test_result_code);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, vmac == test_vmac);
|
||||
ct_test(pTest, result_code == test_result_code);
|
||||
len = bvlc6_encode_result(pdu, sizeof(pdu), 0xffffff + 1, result_code);
|
||||
ct_test(pTest, len == 0);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Result(Test *pTest)
|
||||
{
|
||||
uint32_t vmac = 0;
|
||||
uint16_t result_code[6] = { BVLC6_RESULT_SUCCESSFUL_COMPLETION,
|
||||
BVLC6_RESULT_ADDRESS_RESOLUTION_NAK,
|
||||
BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK,
|
||||
BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK,
|
||||
BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK,
|
||||
BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK };
|
||||
unsigned int i = 0;
|
||||
|
||||
vmac = 4194303;
|
||||
for (i = 0; i < 6; i++) {
|
||||
test_BVLC6_Result_Code(pTest, vmac, result_code[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Original_Unicast_NPDU_Message(Test *pTest,
|
||||
uint8_t *npdu,
|
||||
uint16_t npdu_len,
|
||||
uint32_t vmac_src,
|
||||
uint32_t vmac_dst)
|
||||
{
|
||||
uint8_t test_npdu[50] = { 0 };
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint32_t test_vmac_dst = 0;
|
||||
uint16_t test_npdu_len = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, msg_len = 0, test_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
len = bvlc6_encode_original_unicast(
|
||||
pdu, sizeof(pdu), vmac_src, vmac_dst, npdu, npdu_len);
|
||||
msg_len = 10 + npdu_len;
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_ORIGINAL_UNICAST_NPDU);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len +=
|
||||
bvlc6_decode_original_unicast(&pdu[4], length - 4, &test_vmac_src,
|
||||
&test_vmac_dst, test_npdu, sizeof(test_npdu), &test_npdu_len);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
ct_test(pTest, vmac_dst == test_vmac_dst);
|
||||
ct_test(pTest, npdu_len == test_npdu_len);
|
||||
for (i = 0; i < npdu_len; i++) {
|
||||
ct_test(pTest, npdu[i] == test_npdu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Original_Unicast_NPDU(Test *pTest)
|
||||
{
|
||||
uint8_t npdu[50] = { 0 };
|
||||
uint32_t vmac_src = 0;
|
||||
uint32_t vmac_dst = 0;
|
||||
uint16_t npdu_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
test_BVLC6_Original_Unicast_NPDU_Message(
|
||||
pTest, npdu, npdu_len, vmac_src, vmac_dst);
|
||||
/* now with some NPDU data */
|
||||
for (i = 0; i < sizeof(npdu); i++) {
|
||||
npdu[i] = i;
|
||||
}
|
||||
npdu_len = sizeof(npdu);
|
||||
vmac_src = 4194303;
|
||||
vmac_dst = 4194302;
|
||||
test_BVLC6_Original_Unicast_NPDU_Message(
|
||||
pTest, npdu, npdu_len, vmac_src, vmac_dst);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Original_Broadcast_NPDU_Message(
|
||||
Test *pTest, uint8_t *npdu, uint16_t npdu_len, uint32_t vmac)
|
||||
{
|
||||
uint8_t test_npdu[50] = { 0 };
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac = 0;
|
||||
uint16_t test_npdu_len = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, msg_len = 0, test_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
len =
|
||||
bvlc6_encode_original_broadcast(pdu, sizeof(pdu), vmac, npdu, npdu_len);
|
||||
msg_len = 7 + npdu_len;
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_ORIGINAL_BROADCAST_NPDU);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_original_broadcast(&pdu[4], length - 4, &test_vmac,
|
||||
test_npdu, sizeof(test_npdu), &test_npdu_len);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac == test_vmac);
|
||||
ct_test(pTest, npdu_len == test_npdu_len);
|
||||
for (i = 0; i < npdu_len; i++) {
|
||||
ct_test(pTest, npdu[i] == test_npdu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Original_Broadcast_NPDU(Test *pTest)
|
||||
{
|
||||
uint8_t npdu[50] = { 0 };
|
||||
uint32_t vmac = 0;
|
||||
uint16_t npdu_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
test_BVLC6_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len, vmac);
|
||||
/* now with some NPDU data */
|
||||
for (i = 0; i < sizeof(npdu); i++) {
|
||||
npdu[i] = i;
|
||||
}
|
||||
npdu_len = sizeof(npdu);
|
||||
vmac = 4194303;
|
||||
test_BVLC6_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len, vmac);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Address_Resolution_Message(
|
||||
Test *pTest, uint32_t vmac_src, uint32_t vmac_target)
|
||||
{
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint32_t test_vmac_target = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 10;
|
||||
|
||||
len = bvlc6_encode_address_resolution(
|
||||
pdu, sizeof(pdu), vmac_src, vmac_target);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_ADDRESS_RESOLUTION);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_address_resolution(
|
||||
&pdu[4], length - 4, &test_vmac_src, &test_vmac_target);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
ct_test(pTest, vmac_target == test_vmac_target);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Address_Resolution(Test *pTest)
|
||||
{
|
||||
uint32_t vmac_src = 0;
|
||||
uint32_t vmac_target = 0;
|
||||
|
||||
test_BVLC6_Address_Resolution_Message(pTest, vmac_src, vmac_target);
|
||||
vmac_src = 4194303;
|
||||
vmac_target = 4194302;
|
||||
test_BVLC6_Address_Resolution_Message(pTest, vmac_src, vmac_target);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Forwarded_Address_Resolution_Message(Test *pTest,
|
||||
uint32_t vmac_src,
|
||||
uint32_t vmac_dst,
|
||||
BACNET_IP6_ADDRESS *bip6_address)
|
||||
{
|
||||
BACNET_IP6_ADDRESS test_bip6_address = { { 0 } };
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint32_t test_vmac_dst = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 4 + 3 + 3 + BIP6_ADDRESS_MAX;
|
||||
|
||||
len = bvlc6_encode_forwarded_address_resolution(
|
||||
pdu, sizeof(pdu), vmac_src, vmac_dst, bip6_address);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_FORWARDED_ADDRESS_RESOLUTION);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_forwarded_address_resolution(&pdu[4], length - 4,
|
||||
&test_vmac_src, &test_vmac_dst, &test_bip6_address);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
ct_test(pTest, vmac_dst == test_vmac_dst);
|
||||
test_BVLC6_Address(pTest, bip6_address, &test_bip6_address);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Forwarded_Address_Resolution(Test *pTest)
|
||||
{
|
||||
BACNET_IP6_ADDRESS bip6_address = { { 0 } };
|
||||
uint32_t vmac_src = 0;
|
||||
uint32_t vmac_target = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
test_BVLC6_Forwarded_Address_Resolution_Message(
|
||||
pTest, vmac_src, vmac_target, &bip6_address);
|
||||
/* now with some address data */
|
||||
for (i = 0; i < sizeof(bip6_address.address); i++) {
|
||||
bip6_address.address[i] = i;
|
||||
}
|
||||
bip6_address.port = 47808;
|
||||
vmac_src = 4194303;
|
||||
vmac_target = 4194302;
|
||||
test_BVLC6_Forwarded_Address_Resolution_Message(
|
||||
pTest, vmac_src, vmac_target, &bip6_address);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Address_Resolution_Ack_Message(
|
||||
Test *pTest, uint32_t vmac_src, uint32_t vmac_dst)
|
||||
{
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint32_t test_vmac_dst = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 10;
|
||||
|
||||
len = bvlc6_encode_address_resolution_ack(
|
||||
pdu, sizeof(pdu), vmac_src, vmac_dst);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_ADDRESS_RESOLUTION_ACK);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_address_resolution_ack(
|
||||
&pdu[4], length - 4, &test_vmac_src, &test_vmac_dst);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
ct_test(pTest, vmac_dst == test_vmac_dst);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Address_Resolution_Ack(Test *pTest)
|
||||
{
|
||||
uint32_t vmac_src = 0;
|
||||
uint32_t vmac_dst = 0;
|
||||
|
||||
test_BVLC6_Address_Resolution_Ack_Message(pTest, vmac_src, vmac_dst);
|
||||
vmac_src = 4194303;
|
||||
vmac_dst = 4194302;
|
||||
test_BVLC6_Address_Resolution_Ack_Message(pTest, vmac_src, vmac_dst);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Virtual_Address_Resolution_Message(
|
||||
Test *pTest, uint32_t vmac_src)
|
||||
{
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 7;
|
||||
|
||||
len = bvlc6_encode_virtual_address_resolution(pdu, sizeof(pdu), vmac_src);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_virtual_address_resolution(
|
||||
&pdu[4], length - 4, &test_vmac_src);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Virtual_Address_Resolution(Test *pTest)
|
||||
{
|
||||
uint32_t vmac_src = 0;
|
||||
|
||||
test_BVLC6_Virtual_Address_Resolution_Message(pTest, vmac_src);
|
||||
vmac_src = 0x1234;
|
||||
test_BVLC6_Virtual_Address_Resolution_Message(pTest, vmac_src);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Virtual_Address_Resolution_Ack_Message(
|
||||
Test *pTest, uint32_t vmac_src, uint32_t vmac_dst)
|
||||
{
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint32_t test_vmac_dst = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 10;
|
||||
|
||||
len = bvlc6_encode_virtual_address_resolution_ack(
|
||||
pdu, sizeof(pdu), vmac_src, vmac_dst);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_virtual_address_resolution_ack(
|
||||
&pdu[4], length - 4, &test_vmac_src, &test_vmac_dst);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
ct_test(pTest, vmac_dst == test_vmac_dst);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Virtual_Address_Resolution_Ack(Test *pTest)
|
||||
{
|
||||
uint32_t vmac_src = 0;
|
||||
uint32_t vmac_dst = 0;
|
||||
|
||||
test_BVLC6_Virtual_Address_Resolution_Ack_Message(
|
||||
pTest, vmac_src, vmac_dst);
|
||||
vmac_src = 4194303;
|
||||
vmac_dst = 4194302;
|
||||
test_BVLC6_Virtual_Address_Resolution_Ack_Message(
|
||||
pTest, vmac_src, vmac_dst);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Forwarded_NPDU_Message(Test *pTest,
|
||||
uint8_t *npdu,
|
||||
uint16_t npdu_len,
|
||||
uint32_t vmac_src,
|
||||
BACNET_IP6_ADDRESS *bip6_address)
|
||||
{
|
||||
uint8_t test_npdu[50] = { 0 };
|
||||
uint8_t pdu[75] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
BACNET_IP6_ADDRESS test_bip6_address = { { 0 } };
|
||||
uint16_t test_npdu_len = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, msg_len = 0, test_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
len = bvlc6_encode_forwarded_npdu(
|
||||
pdu, sizeof(pdu), vmac_src, bip6_address, npdu, npdu_len);
|
||||
msg_len = 1 + 1 + 2 + 3 + BIP6_ADDRESS_MAX + npdu_len;
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_FORWARDED_NPDU);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_forwarded_npdu(&pdu[4], length - 4, &test_vmac_src,
|
||||
&test_bip6_address, test_npdu, sizeof(test_npdu), &test_npdu_len);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
test_BVLC6_Address(pTest, bip6_address, &test_bip6_address);
|
||||
ct_test(pTest, npdu_len == test_npdu_len);
|
||||
for (i = 0; i < npdu_len; i++) {
|
||||
ct_test(pTest, npdu[i] == test_npdu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Forwarded_NPDU(Test *pTest)
|
||||
{
|
||||
uint8_t npdu[50] = { 0 };
|
||||
uint32_t vmac_src = 0;
|
||||
BACNET_IP6_ADDRESS bip6_address = { { 0 } };
|
||||
uint16_t npdu_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
test_BVLC6_Forwarded_NPDU_Message(
|
||||
pTest, npdu, npdu_len, vmac_src, &bip6_address);
|
||||
for (i = 0; i < sizeof(bip6_address.address); i++) {
|
||||
bip6_address.address[i] = i;
|
||||
}
|
||||
bip6_address.port = 47808;
|
||||
/* now with some NPDU data */
|
||||
for (i = 0; i < sizeof(npdu); i++) {
|
||||
npdu[i] = i;
|
||||
}
|
||||
npdu_len = sizeof(npdu);
|
||||
vmac_src = 4194303;
|
||||
test_BVLC6_Forwarded_NPDU_Message(
|
||||
pTest, npdu, npdu_len, vmac_src, &bip6_address);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Register_Foreign_Device_Message(
|
||||
Test *pTest, uint32_t vmac_src, uint16_t ttl_seconds)
|
||||
{
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
uint16_t test_ttl_seconds = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 9;
|
||||
|
||||
len = bvlc6_encode_register_foreign_device(
|
||||
pdu, sizeof(pdu), vmac_src, ttl_seconds);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_REGISTER_FOREIGN_DEVICE);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_register_foreign_device(
|
||||
&pdu[4], length - 4, &test_vmac_src, &test_ttl_seconds);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
ct_test(pTest, ttl_seconds == test_ttl_seconds);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Register_Foreign_Device(Test *pTest)
|
||||
{
|
||||
uint32_t vmac_src = 0;
|
||||
uint16_t ttl_seconds = 0;
|
||||
|
||||
test_BVLC6_Register_Foreign_Device_Message(pTest, vmac_src, ttl_seconds);
|
||||
vmac_src = 4194303;
|
||||
ttl_seconds = 600;
|
||||
test_BVLC6_Register_Foreign_Device_Message(pTest, vmac_src, ttl_seconds);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Delete_Foreign_Device_Message(Test *pTest,
|
||||
uint32_t vmac_src,
|
||||
BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry)
|
||||
{
|
||||
uint8_t pdu[64] = { 0 };
|
||||
uint32_t test_vmac_src = 0;
|
||||
BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY test_fdt_entry = { 0 };
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, test_len = 0;
|
||||
const int msg_len = 0x0019;
|
||||
|
||||
len = bvlc6_encode_delete_foreign_device(
|
||||
pdu, sizeof(pdu), vmac_src, &fdt_entry->bip6_address);
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_DELETE_FOREIGN_DEVICE);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_delete_foreign_device(
|
||||
&pdu[4], length - 4, &test_vmac_src, &test_fdt_entry.bip6_address);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac_src == test_vmac_src);
|
||||
test_BVLC6_Address(
|
||||
pTest, &fdt_entry->bip6_address, &test_fdt_entry.bip6_address);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Delete_Foreign_Device(Test *pTest)
|
||||
{
|
||||
uint32_t vmac_src = 0;
|
||||
BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY fdt_entry = { 0 };
|
||||
unsigned int i = 0;
|
||||
|
||||
/* test with zeros */
|
||||
test_BVLC6_Delete_Foreign_Device_Message(pTest, vmac_src, &fdt_entry);
|
||||
/* test with valid values */
|
||||
vmac_src = 4194303;
|
||||
for (i = 0; i < sizeof(fdt_entry.bip6_address.address); i++) {
|
||||
fdt_entry.bip6_address.address[i] = i;
|
||||
}
|
||||
fdt_entry.bip6_address.port = 47808;
|
||||
fdt_entry.ttl_seconds = 600;
|
||||
fdt_entry.ttl_seconds_remaining = 42;
|
||||
fdt_entry.next = NULL;
|
||||
test_BVLC6_Delete_Foreign_Device_Message(pTest, vmac_src, &fdt_entry);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Secure_BVLL_Message(
|
||||
Test *pTest, uint8_t *sbuf, uint16_t sbuf_len)
|
||||
{
|
||||
uint8_t test_sbuf[50] = { 0 };
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint16_t test_sbuf_len = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, msg_len = 0, test_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
len = bvlc6_encode_secure_bvll(pdu, sizeof(pdu), sbuf, sbuf_len);
|
||||
msg_len = 1 + 1 + 2 + sbuf_len;
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_SECURE_BVLL);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_secure_bvll(
|
||||
&pdu[4], length - 4, test_sbuf, sizeof(test_sbuf), &test_sbuf_len);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, sbuf_len == test_sbuf_len);
|
||||
for (i = 0; i < sbuf_len; i++) {
|
||||
ct_test(pTest, sbuf[i] == test_sbuf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Secure_BVLL(Test *pTest)
|
||||
{
|
||||
uint8_t sbuf[50] = { 0 };
|
||||
uint16_t sbuf_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
test_BVLC6_Secure_BVLL_Message(pTest, sbuf, sbuf_len);
|
||||
/* now with some NPDU data */
|
||||
for (i = 0; i < sizeof(sbuf); i++) {
|
||||
sbuf[i] = i;
|
||||
}
|
||||
sbuf_len = sizeof(sbuf);
|
||||
test_BVLC6_Secure_BVLL_Message(pTest, sbuf, sbuf_len);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Distribute_Broadcast_To_Network_Message(
|
||||
Test *pTest, uint8_t *npdu, uint16_t npdu_len, uint32_t vmac)
|
||||
{
|
||||
uint8_t test_npdu[50] = { 0 };
|
||||
uint8_t pdu[60] = { 0 };
|
||||
uint32_t test_vmac = 0;
|
||||
uint16_t test_npdu_len = 0;
|
||||
uint8_t message_type = 0;
|
||||
uint16_t length = 0;
|
||||
int len = 0, msg_len = 0, test_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
len = bvlc6_encode_distribute_broadcast_to_network(
|
||||
pdu, sizeof(pdu), vmac, npdu, npdu_len);
|
||||
msg_len = 7 + npdu_len;
|
||||
ct_test(pTest, len == msg_len);
|
||||
test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length);
|
||||
ct_test(pTest, test_len == 4);
|
||||
ct_test(pTest, message_type == BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK);
|
||||
ct_test(pTest, length == msg_len);
|
||||
test_len += bvlc6_decode_distribute_broadcast_to_network(&pdu[4],
|
||||
length - 4, &test_vmac, test_npdu, sizeof(test_npdu), &test_npdu_len);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, msg_len == test_len);
|
||||
ct_test(pTest, vmac == test_vmac);
|
||||
ct_test(pTest, npdu_len == test_npdu_len);
|
||||
for (i = 0; i < npdu_len; i++) {
|
||||
ct_test(pTest, npdu[i] == test_npdu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Distribute_Broadcast_To_Network(Test *pTest)
|
||||
{
|
||||
uint8_t npdu[50] = { 0 };
|
||||
uint32_t vmac = 0;
|
||||
uint16_t npdu_len = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
test_BVLC6_Distribute_Broadcast_To_Network_Message(
|
||||
pTest, npdu, npdu_len, vmac);
|
||||
/* now with some NPDU data */
|
||||
for (i = 0; i < sizeof(npdu); i++) {
|
||||
npdu[i] = i;
|
||||
}
|
||||
npdu_len = sizeof(npdu);
|
||||
vmac = 4194303;
|
||||
test_BVLC6_Distribute_Broadcast_To_Network_Message(
|
||||
pTest, npdu, npdu_len, vmac);
|
||||
}
|
||||
|
||||
static void test_BVLC6_Address_Copy(Test *pTest)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
BACNET_IP6_ADDRESS src = { { 0 } };
|
||||
BACNET_IP6_ADDRESS dst = { { 0 } };
|
||||
bool status = false;
|
||||
|
||||
/* test with zeros */
|
||||
status = bvlc6_address_copy(&dst, &src);
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
ct_test(pTest, !status);
|
||||
/* test with valid values */
|
||||
for (i = 0; i < sizeof(src.address); i++) {
|
||||
src.address[i] = 1 + i;
|
||||
}
|
||||
src.port = 47808;
|
||||
status = bvlc6_address_copy(&dst, &src);
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
ct_test(pTest, !status);
|
||||
/* test for different port */
|
||||
dst.port = 47809;
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
ct_test(pTest, status);
|
||||
/* test for different address */
|
||||
dst.port = src.port;
|
||||
for (i = 0; i < sizeof(src.address); i++) {
|
||||
dst.address[i] = 0;
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
ct_test(pTest, status);
|
||||
dst.address[i] = 1 + i;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_BVLC6_Address_Get_Set(Test *pTest)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
BACNET_IP6_ADDRESS src = { { 0 } };
|
||||
BACNET_IP6_ADDRESS dst = { { 0 } };
|
||||
uint16_t group = 1;
|
||||
uint16_t test_group = 0;
|
||||
uint16_t hextet[8] = { 0 };
|
||||
bool status = false;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
status = bvlc6_address_set(&src, group, 0, 0, 0, 0, 0, 0, 0);
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_get(
|
||||
&src, &test_group, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
ct_test(pTest, status);
|
||||
ct_test(pTest, group == test_group);
|
||||
group = group << 1;
|
||||
}
|
||||
/* test the ASCII hex to address */
|
||||
/* test too short */
|
||||
status = bvlc6_address_from_ascii(&src, "[1234:5678]");
|
||||
ct_test(pTest, status == false);
|
||||
status = bvlc6_address_from_ascii(
|
||||
&src, "[1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0]");
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_set(
|
||||
&dst, 0x1234, 0x5678, 0x9ABC, 0xDEF0, 0x1234, 0x5678, 0x9ABC, 0xDEF0);
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
ct_test(pTest, status == false);
|
||||
/* test zero compression */
|
||||
status = bvlc6_address_from_ascii(&src, "[1234:5678:9ABC::5678:9ABC:DEF0]");
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_set(
|
||||
&dst, 0x1234, 0x5678, 0x9ABC, 0x0000, 0x0000, 0x5678, 0x9ABC, 0xDEF0);
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
if (status) {
|
||||
status = bvlc6_address_get(&src, &hextet[0], &hextet[1], &hextet[2],
|
||||
&hextet[3], &hextet[4], &hextet[5], &hextet[6], &hextet[7]);
|
||||
printf("src:[%X:%X:%X:%X:%X:%X:%X:%X]\n", hextet[0], hextet[1],
|
||||
hextet[2], hextet[3], hextet[4], hextet[5], hextet[6], hextet[7]);
|
||||
status = bvlc6_address_get(&dst, &hextet[0], &hextet[1], &hextet[2],
|
||||
&hextet[3], &hextet[4], &hextet[5], &hextet[6], &hextet[7]);
|
||||
printf("dst:[%X:%X:%X:%X:%X:%X:%X:%X]\n", hextet[0], hextet[1],
|
||||
hextet[2], hextet[3], hextet[4], hextet[5], hextet[6], hextet[7]);
|
||||
}
|
||||
ct_test(pTest, status == false);
|
||||
/* test some compressed 16-bit zero fields */
|
||||
status =
|
||||
bvlc6_address_from_ascii(&src, "[234:678:ABC:EF0:1234:5678:9ABC:DEF0]");
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_set(
|
||||
&dst, 0x0234, 0x0678, 0x0ABC, 0x0EF0, 0x1234, 0x5678, 0x9ABC, 0xDEF0);
|
||||
ct_test(pTest, status);
|
||||
status = bvlc6_address_different(&dst, &src);
|
||||
ct_test(pTest, status == false);
|
||||
}
|
||||
|
||||
static void test_BVLC6_VMAC_Address_Get_Set(Test *pTest)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
BACNET_ADDRESS addr;
|
||||
uint32_t device_id = 1;
|
||||
uint32_t test_device_id = 0;
|
||||
bool status = false;
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
status = bvlc6_vmac_address_set(&addr, device_id);
|
||||
ct_test(pTest, status);
|
||||
ct_test(pTest, addr.mac_len == 3);
|
||||
ct_test(pTest, addr.net == 0);
|
||||
ct_test(pTest, addr.len == 0);
|
||||
status = bvlc6_vmac_address_get(&addr, &test_device_id);
|
||||
ct_test(pTest, status);
|
||||
ct_test(pTest, device_id == test_device_id);
|
||||
device_id = device_id << 1;
|
||||
}
|
||||
}
|
||||
|
||||
void test_BVLC6(Test *pTest)
|
||||
{
|
||||
bool rc;
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Result);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Original_Unicast_NPDU);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Original_Broadcast_NPDU);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Address_Resolution);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Forwarded_Address_Resolution);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Address_Resolution_Ack);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Virtual_Address_Resolution);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Virtual_Address_Resolution_Ack);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Forwarded_NPDU);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Register_Foreign_Device);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Delete_Foreign_Device);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Secure_BVLL);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Distribute_Broadcast_To_Network);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Address_Copy);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_Address_Get_Set);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_BVLC6_VMAC_Address_Get_Set);
|
||||
assert(rc);
|
||||
}
|
||||
|
||||
#ifdef TEST_BVLC6
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
|
||||
pTest = ct_create("BACnet Virtual Link Control IP/v6", NULL);
|
||||
test_BVLC6(pTest);
|
||||
/* configure output */
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BBMD */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
Reference in New Issue
Block a user